April 29, 2024, 07:09:37 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Sendmessage command

Started by Andy, October 18, 2017, 03:44:01 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Andy

Well for a long time now I've been using the Sendmessage command which in all honesty have been provided by my friends on here - I understand the concept of what it can do - but I'm never able to work out how many parameters I need, and what the parameters should be.

The help file says "See the sample file dirselector.iwb for a complete example of using SENDMESSAGE"

But there's no dirselector.iwb (at least on my machine) to look at - and msdn always assume you know what they are talking about.

Can any one help me get my head around the command please?

Thanks,
Andy.

Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Egil

The only file I can find with that name here, is an old IBA-Std file converted to CBA.
Should not be difficult to convert to IWB.
Enclose code plus a compressed EXE showing what it does.

'Example of using SENDMESSAGE to control a list box
'This presents a simple directory picker to the user.
'The directories can be entered by double clicking to show
'subdirectories. Double clicking on [..] moves up one level
'This example requires Creative BASIC 1.0 or greater

DEF d1:dialog
DEF path,temp:STRING
DEF sel,notify,pos,pos2:INT

'these values are from winuser.h
SETID "DDL_DIRECTORY",0x10
SETID "DDL_EXCLUSIVE",0x8000
'LB_DIR is a message that tells the list box to list
'a directory for its contents.
SETID "LB_DIR",0x018d
SETID "LB_RESETCONTENT",0x0184

path = "c:\*.*"
DIALOG d1,0,0,253,294,0x80C80080,0,"Select Directory",Handler
'we want our listbox to send double click messages so
'we use @CTLISTNOTIFY
CONTROL d1,"L,ListBox1,42,17,169,224,0x50B00140|@CTLISTNOTIFY,10"
CONTROL d1,"B,OK,91,262,70,20,0x50000001,1"

if(domodal(d1) = @IDOK)
messagebox 0,path,"Directory"
endif
end

SUB handler
SELECT @CLASS
CASE @IDINITDIALOG
CENTERWINDOW d1
SENDMESSAGE d1,@LB_DIR,@DDL_DIRECTORY|@DDL_EXCLUSIVE,path,10
CASE @IDCONTROL
SELECT @CONTROLID
CASE 1
sel = GETSELECTED(d1,10)
if(sel > -1)
path = LEFT$(path,LEN(path)-3) :REM remove *.*
temp = GETSTRING(d1,10,sel)
temp = MID$(temp,2) :REM remove [
temp = LEFT$(temp,LEN(temp)-1) :REM remove ]
path = path + temp + "\"
else
path = left$(path,len(path)-3) :REM remove *.*
endif
CLOSEDIALOG d1,@IDOK
CASE 10
IF @notifycode = @LBNDBLCLK
sel = GETSELECTED(d1,10)
IF(sel > -1)
path = LEFT$(path,LEN(path)-3) :REM remove *.*
temp = GETSTRING(d1,10,sel)
temp = MID$(temp,2) :REM remove [
temp = LEFT$(temp,LEN(temp)-1) :REM remove ]
REM account for .. in path
IF temp = ".."
path = LEFT$(path,LEN(path)-1) :REM remove \
REM find last \ in path string
pos = INSTR(path,"\")
WHILE pos
pos2 = pos
pos = INSTR(pos+1,path,"\")
ENDWHILE
IF pos2 THEN path = LEFT$(path,pos2) + "*.*"
ELSE
path = path + temp + "\*.*"
ENDIF
REM clear the list box
SENDMESSAGE d1,@LB_RESETCONTENT,0,0,10
REM list the new directory
SENDMESSAGE d1,@LB_DIR,@DDL_DIRECTORY|@DDL_EXCLUSIVE,path,10
ENDIF
ENDIF
ENDSELECT
ENDSELECT
RETURN

Support Amateur Radio  -  Have a ham  for dinner!

billhsln

Here is a short example of using SENDMESSAGE to change colors on a Listview:

$include "commctrl.inc"

CONST d1_LV1 = 200

DIALOG d1
UINT wCYAN, wBLACK

wCYAN    = RGB(0,255,255)
wBLACK   = RGB(0,0,0)

CONTROL d1,@LISTVIEW,"",10,10,680,380,@VSCROLL|0x50000001|@BORDER,d1_LV1

/* Set text colour */
SENDMESSAGE d1,LVM_SETTEXTCOLOR,0,wCYAN,d1_LV1
/* Set text background colour */
SENDMESSAGE d1,LVM_SETTEXTBKCOLOR,0,wBLACK,d1_LV1
/* Set background colour */
SENDMESSAGE d1,LVM_SETBKCOLOR,0,wBLACK,d1_LV1


Hope it helps,
Bill
When all else fails, get a bigger hammer.

LarryMc

Andy
A couple of points to remember that I've made elsewhere.
1) As far as MS is concerned when it comes to the MS sendmessage command there is no difference between a WINDOW/CONTROL/DIALOG.
2) The MS sendmessage command requires a hwnd, uint(wparam), Uint(lparam)/* pointer */
2a)SENDMESSAGE is the IWB wrapper for the sendmessage command.
3) The control tutorial has an explanation of how/what SENDMESSAGE is used for
http://www.ionicwind.com/forums/index.php?topic=4701.msg36562#msg36562

4)SENDMESSAGE has one more parameter, ID, used in conjunction with WIN to determine the actual window handle to send the message to.

5)message command ids 255 and below are reserved for MS commands like WM_PAINT etc.  Numbers above 255 are part of user defined like I have used on my custom controls.
6) wparam is always a number UINT  its a number that means something to the command; it could be something as simple as 0/1 representing on or off; or simply ignored (0).
7)lparam can be any type of variable. here is where you would pass strings and structures directly and anything else by reference.

So considering the above and reading the above tutorial should give you some good insight.

Now, consider this.
There has recently been some sub classing on the forum.
Would you believe if I told you that the main IWB window's handler is, in essence, is subclassed itself?

When you create a window based program the handler you see is something like this:
DEF w1 as WINDOW
OPENWINDOW w1,0,0,350,350,@MINBOX|@MAXBOX|@SIZE,NULL,"Simple Window",&main
PRINT w1,"Hello World"
WAITUNTIL w1 = 0
END

SUB main( ), INT
   select @MESSAGE
         case   @IDCLOSEWINDOW
               CLOSEWINDOW w1
    ENDselect
RETURN 0
ENDSUB

but in the shadows is really a routine that looks more similar to this

SUB main(w1.hwnd,@MESSAGE,wparam,lparam ), INT
   select @MESSAGE
         case   @IDCLOSEWINDOW
               CLOSEWINDOW w1

    ENDselect
RETURN 0
ENDSUB


Let me know if that doesn't help and I'll try again.
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

fasecero

October 19, 2017, 04:43:31 PM #4 Last Edit: October 19, 2017, 04:45:38 PM by fasecero
That was a very good explanation. I just want to add that when SendMessage sends a message to a window/control/dialog, it calls the procedure for the specified window/control/dialog and does not return until the procedure has totally processed the message (it's a synchronous function). To compensate this, winapi has a little less known PostMessage, wich just returns without waiting for the message to get executed (asynchronous).

Andy

October 19, 2017, 11:54:32 PM #5 Last Edit: October 20, 2017, 12:12:35 AM by Andy
I've taken a little time to digest what's been posted here.... it does help, but can I start from a basic question and see how (if you knew nothing about it) just how you would learn (for example) how to make a static control look like a button.

Step 1, create a normal static control.....

CONTROL w1,@STATIC,"Registry Location",10,20,200,25,@CTEDITLEFT,30   '(id = 30)

Problem 1:- knowing the command I need?
I found from searching this site that adding WS_DLGFRAME on creation of the control will make the static look like a button - but that's only by luck!

Problem 2:- knowing how to search and read up about the command.
Try as I might (and it probably says more about me) more often than not I cannot find what I'm looking for on msdn.

Problem 3:- why WS_ on ES_, SS_ etc...
I can guess (and that's all it is) the WS stands for window style?
and I seem to remeber (again by chance) that even controls are treated as windows?

Problem 4:- DLGFRAME?
Surely that is an abbreviation for dialog? it would have been better as BTNFRAME? or BTNBORDER - but I guess that's down to ms.

But logically to me it doesn't make sense.

Problem 5:- By some slight of hand, walking under a ladder, and having a black cat cross my path - I've got to the conclusion that I need to use WS_DLGFRAME.

How on earth do I use WS_DLGFRAME with the SENDMESSAGE command to change the static - OR am I completely on the wrong path after all?

If I could understand the logical approach to how some of you guys do this then that is what would really help me.

You've all been really helpful in giving me the solution in code, but I just cannot see how you get there in the first place.

I had this with dll's, until LarryMc (thank you Larry) told me about a dll viewer and then the mystery went away.

So to recap.... if you knew nothing about it, once you've created a static how would you learn how to modify it to look like a button?

MODIFYSTYLE is also and option but you're still left with finding WS_DLGFRAME.

Footnote:- I am (just in case you think otherwise) being light hearted about this NOT sarcastic!

I might not be sharpest tool in the box, but I can't be that blunt can I?  :'(

Thanks,
Andy.
???






Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

fasecero

I truly believe that others will be more useful than me on this one. I can provide code, but explaining it is different. Here is my two cents.

For me, to solve this or any other problem, it takes 2 things. First, some theory about on how our language works as well as winapi, I think you already have that knowledge in part. Second, the key is SEARCH. For me it is useless to try to reason too much, windows api is extremely complex and unintuitive. My way of solving these problems is to search on the browser for a solution instead of thinking about which of the thousands of functions api do I have to use.

QuoteProblem 1:- knowing the command I need?
You found that you have to use WS_DLGFRAME by luck. In fact there is the key, it is not so much about LEARNING, it is more about LEARNING TO SEARCH.

QuoteProblem 2:- knowing how to search and read up about the command.
I can not follow you here. I open the search engine, I wrote "WS_DLGFRAME". My first result is "Window Styles" in MSDN that says: "The window has a border of a style typically used with dialog boxes".

QuoteProblem 3:- why WS_ on ES_, SS_ etc...
Here you need the concept of CLASS. The base class is WINDOW, the others are derived classes: BUTTON, STATIC, EDIT, etc. The derived classes are WINDOW's but expanded to fulfill a more defined function. And yes, the base class styles can be used in derived classes. Apart from that, there are other cases, for example RICHEDIT is a class derived from EDIT, so RICHEDIT can use EDIT styles.

QuoteProblem 4:- DLGFRAME?
Never expect common sense in winapi.

QuoteProblem 5:- By some slight of hand, walking under a ladder, and having a black cat cross my path - I've got to the conclusion that I need to use WS_DLGFRAME.
QuoteHow on earth do I use WS_DLGFRAME with the SENDMESSAGE command to change the static
Here is your main error, you are ASSUMING that a function (SendMessage) is the solution of some problem. Here I go back to point 1, do not assume anything and search the web for a solution.

----

In short, what do I want to do? Add WS_DLGFRAME style to a control. On my browser I type "winapi window change style". After reading some sites some more relevant than others in the fifth psition I get this

https://stackoverflow.com/questions/2398746/removing-window-border

They are changing windows styles, but I simply adapt it to what I want to do, add a style. Check the code it is almost a copy-paste.


$INCLUDE "windowssdk.inc"

CONST STATIC_1 = 1
DIALOG d1
CREATEDIALOG d1,0,0,422,250,0x80C80080,0,"Caption",&d1_handler
CONTROL d1,@STATIC,"Static",107,62,104,27,0x5000010B,STATIC_1

DOMODAL d1

SUB d1_handler
SELECT @MESSAGE
CASE @IDINITDIALOG
CENTERWINDOW d1
/* Initialize any controls here */
INT hwnd = GETCONTROLHANDLE(d1, STATIC_1)
LONG lStyle = GetWindowLong(hwnd, GWL_STYLE)
lStyle = lStyle | WS_DLGFRAME
SetWindowLong(hwnd, GWL_STYLE, lStyle)
SetWindowPos(hwnd, NULL, 0,0,0,0, SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER)
CASE @IDCLOSEWINDOW
CLOSEDIALOG d1,@IDOK
CASE @IDCONTROL
SELECT @CONTROLID
ENDSELECT
ENDSELECT
RETURN
ENDSUB


QuoteYou've all been really helpful in giving me the solution in code, but I just cannot see how you get there in the first place

I can only speak for myself, but I get there every time I can using some knowledge that we all have about this language and winapi. The rest, by looking for on the web for a solution. I know that sometimes it can be frustrating. But like all the difficult things you just need some patience and advance one step at a time  :)


Andy

Fasecero,

Yes, it's just frustration on my part  :P, it will have to be one small step at a time for me.

I've only really started to look into ms commands in general, that is commands that are not ready made in IWB.

Thanks for taking the time to explain how you find a solution.
:)
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

LarryMc

@Andy
1st some info
when you add some controls to a project, IWB does some things  in the background for you that you don't realize are going on.
first of all, the following controls:
RGNBUTTON
SYSBUTTON
CHECKBOX
RADIOBUTTON
GROUPBOX
BUTTON
are all the same MS windows control class named "button"
Different combinations of MS style flags and user flags define them.
And the following are ownerdrawn (by IWB)
RGNBUTTON
SYSBUTTON
BUTTON

If you wanted to use the CONTROLEX command to create all the above control types then to would use the "button" control class and the state the proper styles,exstyles, and then it gets a little more complicated with the ownerdrawn controls.

Now a little advertisement here.
When I wrote IWB+, my visual designer, I made it were you could see what was going on.
When you add a control (or select any control that has already been added) you are able to see what style flags are added /currently applied to the control as well as the flags that may be applied to the control.  You may also see what notification messages are currently  in use/may be used by the control.
The same applies for windows/dialogs.
Now, you have to understand when I say all the style flags  and notification messages I mean the ones that have been assigned  IWB constant IDs.

Recently a question came up about about about making a static control act like a button.  With IWB+ that would have been an easy answer.
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library