Thread: [Dev-C++] Win32 API SendMessage
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Geoff B. <Geo...@Vc...> - 2003-10-01 17:59:19
|
I am trying to setup a Push Button control that when pushed, runs a series
of commands, then calls itself to be run again. The reason behind this is
that there is another thread that needs to process some data prior to the
second half of the function being run. To do this I thought I could simply
send a message to my main window (put the message into the que) so that once
the other threads message has completed the button will be recalled.
However this does not seem to happen, it simply ignores my sendmesage (or so
it seems)
Code:
case 508:
switch(setup)
{
case 0:
FindSearch=FindInBuffer("]#",2);
if(FindSearch==1)
{
MessageBox(NULL,"Prompt
Check","Error",MB_OK|MB_ICONEXCLAMATION);
}
setup=1;
break;
case 1:
FindInBuffer("]#",1);
Command(" ",hwnd);
SendMessage(hwnd,WM_COMMAND,(WPARAM)NULL,(LPARAM)508);
break;
}
break;
End Code:
Does anyone know how to handle a situation like this?
> Thanks
> Geoff Baker
> Systems Integration Technologist
VCom (Formerly WaveCom)
> 150 Cardinal Place, Saskatoon, Sask. Canada S7L 6H7
> Phone: (306)955-7075 Ext 489 Fax:(306)955-9919
> Web Page: <http://www.vcom.com/>
>
>
|
|
From: <sol...@ya...> - 2003-10-02 16:37:43
|
That means your window is sending a message to itself, isn't it? That
seems to be not possible, always I try to do something like that it
doesn't react to it, and if I put a GetLastError() I get
INVALID_WINDOW_HANDLE.
Everytime I got that I had to do things another way, nothing comparable
with the situation where sending a message itself would be necessary.
If you really need do things like that and neither PostMessage work, I
would suggest making a dummy window, SW_HIDE, so you send the message to
the dummy and it resends it to the main, is the only way I can think about.
Did you try with PostMessage? Remember that SendMessage sends the
message and waits to the window to process it, but it can't do while it
is processing the current message.
Be careful about this situation:
Main receives "do push button" push button says itself "message: do it,
then continue". If things are like this and you send the message when
"do it" and after that is "then continue". If you do Sendmessage "do
it", it'll wait to "do it" to be done, but it can't if "then continue
isn't done" (Uhmm, the same would happen with the dummy window!!). If
you PostMessage then it would post "do it" and immediately it performs
"then continue", so it makes "then continue" before knowing the result
of "do it", so perhaps you would have to make: receive message (a) push
button posts message "do it" (b) and after do "do it" it posts "then
continue" (c), but perhaps it would need to happen that a=c, but with
some extra parameter so the program can distinguish beetwen the message
x being sent for start or for continue. Or perhaps, your program
performs steps that are not equivalent to this scheme and you don't need
worry about it.
Hope you get the perfect answer.
Geoff Baker wrote:
>I am trying to setup a Push Button control that when pushed, runs a series
>of commands, then calls itself to be run again. The reason behind this is
>that there is another thread that needs to process some data prior to the
>second half of the function being run. To do this I thought I could simply
>send a message to my main window (put the message into the que) so that once
>the other threads message has completed the button will be recalled.
>However this does not seem to happen, it simply ignores my sendmesage (or so
>it seems)
>
>Code:
> case 508:
> switch(setup)
> {
> case 0:
> FindSearch=FindInBuffer("]#",2);
> if(FindSearch==1)
> {
> MessageBox(NULL,"Prompt
>Check","Error",MB_OK|MB_ICONEXCLAMATION);
> }
> setup=1;
> break;
> case 1:
> FindInBuffer("]#",1);
> Command(" ",hwnd);
>
>SendMessage(hwnd,WM_COMMAND,(WPARAM)NULL,(LPARAM)508);
> break;
> }
> break;
>End Code:
>
>Does anyone know how to handle a situation like this?
>
>
>
>>Thanks
>>Geoff Baker
>>Systems Integration Technologist
>>
>>
>VCom (Formerly WaveCom)
>
>
>>150 Cardinal Place, Saskatoon, Sask. Canada S7L 6H7
>>Phone: (306)955-7075 Ext 489 Fax:(306)955-9919
>>Web Page: <http://www.vcom.com/>
>>
>>
>>
>>
>
>
>-------------------------------------------------------
>This sf.net email is sponsored by:ThinkGeek
>Welcome to geek heaven.
>http://thinkgeek.com/sf
>_______________________________________________
>Dev-cpp-users mailing list
>Dev...@li...
>TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
>https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
>
>
|
|
From: <or...@vp...> - 2003-10-02 18:09:02
|
Geoff Baker wrote:
> I am trying to setup a Push Button control that when pushed, runs a series
> of commands, then calls itself to be run again. The reason behind this is
> that there is another thread that needs to process some data prior to the
> second half of the function being run. To do this I thought I could simply
> send a message to my main window (put the message into the que) so that once
> the other threads message has completed the button will be recalled.
> However this does not seem to happen, it simply ignores my sendmesage (or so
> it seems)
>
> Code:
> case 508:
> switch(setup)
> {
> case 0:
> FindSearch=FindInBuffer("]#",2);
> if(FindSearch==1)
> {
> MessageBox(NULL,"Prompt
> Check","Error",MB_OK|MB_ICONEXCLAMATION);
> }
> setup=1;
> break;
> case 1:
> FindInBuffer("]#",1);
> Command(" ",hwnd);
>
> SendMessage(hwnd,WM_COMMAND,(WPARAM)NULL,(LPARAM)508);
> break;
> }
> break;
> End Code:
>
> Does anyone know how to handle a situation like this?
Note, that SendMessage() directly calls the Window procedure again, so
you'll get a re-entrant (that is, you re-enter the procedure). This
should cause no trouble at all, as it happens a lot of time. For
example, when you create a dialog box, that is always on top of your
program. That means, the dialogbox call will return ONLY if you close
the dialog box, but if you move around the box, your Window proc will be
called evetually again with WM_PAINT (though it should be locked because
of the dialog box).
You should be careful with calling the same Window proc from within, as
SendMessage will only return, if the window proc - for which it sends
the message - finishes it's work. This way, you can easily get an
endless loop. I don't know if Windows checks for this, but according to
what Carlos wrote, it seems it does.
--
Greetings,
Balázs
|