Re: SendMessage....Help!
"Robby" <Robby@discussions.microsoft.com> wrote in message
news:905775AD-7DF3-4240-8E58-9B026654D09E@microsoft.com
Hello,
The question in this post would probably solve the question in my
previous post.
However, I am quite discouraged with the SendMessage command, because
it really does'nt do what the help files claim, or more obviously
would be that I am most probably missing some notion about its
functionality.
Right now, I am stuck with this and I hope someone can help!
The code below is intended to function in the following manner:
Two buttons are in the client area, where after you click on the
first one, it stays down. And when I click on it again, it comes up.
Basically the two buttons retain their state. So if I click on
Button#1 and then click on button#2, they both should appear pressed.
However what is happening now, is that, If I click on button#1 (it
now appears pressed) and then I click on button#2, well, button#1
appears unpressed and button#2 apprears pressed. Their acting as a
set of radio buttons, and this is not what is desired.
If you can please view the code...... Thankyou!
===================================================
LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
WPARAM wParam, LPARAM
lParam) {
static bool SIState[4];
static HWND hdMW_btC3,hdMW_btC4;
switch(message)
{
case WM_CREATE:
//Innitialize array
SIState[0] = false;
SIState[1] = false;
SIState[2] = false;
SIState[3] = false;
//Below: "szMW_btC3_Name" is a string declared eslewhere, not to
worry about it!
//Button#1
hdMW_btC3 = CreateWindow(
TEXT ("button"),szMW_btC3_Name,
WS_CHILD | WS_VISIBLE |BS_PUSHBUTTON ,
10,100,50,50, hwnd,(HMENU)MW_btC3_ID,
(HINSTANCE) GetWindowLong(hwnd,GWL_HINSTANCE),NULL);
//Button#2
hdMW_btC4 = CreateWindow(
TEXT ("button"),szMW_btC4_Name,
WS_CHILD | WS_VISIBLE |BS_PUSHBUTTON ,
10,150,50,50, hwnd,(HMENU)MW_btC4_ID,
(HINSTANCE) GetWindowLong(hwnd,GWL_HINSTANCE),NULL);
return 0;
case WM_COMMAND:
if (LOWORD(wParam) == MW_btC3_ID)
{
if (SIState[0])
{SendMessage((HWND)lParam,BM_SETSTATE,0,0); SIState[0] = false;}
else
{SendMessage((HWND)lParam,BM_SETSTATE,1,0); SIState[0] = true;}
}
if (LOWORD(wParam) == MW_btC4_ID)
{
if (SIState[1])
{SendMessage((HWND)lParam,BM_SETSTATE,0,0);SIState[1] = false;}
else
{SendMessage((HWND)lParam,BM_SETSTATE,1,0);SIState[1] = true;}
}
//other code.....
====================================================
I don't understand why this wouldn't work, It seems very straight
forwards.
If I click on Button#1, then the "if" statement in the WM_COMMAND
handler checks to see if LOWORD of wParam (which contains the child
ID) equals "MW_btC3_ID" and then if it does, it gets the state of
the button to appear pushed by sending BM_SETSTATE parameter of the
SendMessage function.
If I click on Button#2, then the "if" statement in the WM_COMMAND
handler checks to see if LOWORD of wParam (which contains the child
ID) equals "MW_btC4_ID" and then if it does, it gets the state of
the button to appear pushed by sending BM_SETSTATE parameter of the
SendMessage function.
The buttons should retain their state until clicked on again right...
All weekend I have been trying to get this to work.... and I am stuck
and confused about this "SendMessage" and the way it is behaving. I
obviously don't understand it, and the Windows help doesn't say
much.... I would really appreciate any help that can get this program
to behave the way desired.
Thanking you all in advance for your gracefull help!
--
Best regards
Robert
When the first button is depressed and the second button is clicked, both
buttons are receiving BN_CLICKED notifications, so both change state in
response to your SendMessage calls.
I am not sure why the button that hasn't been clicked is sending a
notification to say that it has been. Then again, trying to turn a button
into a toggle switch is an unusual thing to do and whenever you do something
unusual in Windows, your chances of discovering buggy behaviour go up
considerably.
--
John Carson