Click to See Complete Forum and Search --> : Help With Buttons with BS_GROUPBOX


Vitucho
May 22nd, 2006, 10:48 PM
Hi, there!!.
My name is Victor, this is my first thread !! so i hope don't screw up! jejeje.

Well, i'm using dev-cpp and sometimes Visual C++ to program a work for the university, and well, like all of us, when we start to use an API (and a BIG API) there are always a lot of doubts at the beggining.

So, this it's my doubt :

I Create (Using CreateWindow) a button that it's in fact a a kind of container of buttons (like a GROUPBOX). Then i start to add buttons ("atomics buttons") to that GROUPBOX (setting like parent of this buttons the button whit the flag BS_GROUPBOX).

Visualy is beatiful, and all goes stick to plan.
But i not' able to catch the event's produces by clicking on they or pushing, cuz the WM_COMMAND message, is (i guess) only for buttons directly child to the main window, and not childs of childs. (Windows -> GroupBox in Window -> Button in GroupBOx)

Sorry by the grammar, i am from Argentina and well, besides i study english, is not easy to write in a perfect 100% =P.

The where i create Buttons is here, so if any kind soul that help me can fin where is the problem :

this is the button GROUPBOX:

MyGroupBox = CreateWindow ("BUTTON",Some Text,
BS_GROUPBOX|WS_CHILD|WS_VISIBLE,
x,y,witdh,height,
MAINWINDOW, // The father
NULL, // A menu in Group_box (?)...no thanks..
App, // my happy application
NULL); // more data.....mmm later...

and then i start to ADD like This :

Button = CreateWindow ("BUTTON",Some Text,
WS_VISIBLE|WS_CHILD|BS_DEFPUSHBUTTON|WS_TABSTOP|BS_CENTER,
x,y,witdh,height,
MyGroupBOx, // The father
NULL, // A MENU in a button (!) god help me...
App, // my happy application, a friend..always presents
NULL); // more data.....mmm later...

So i hope to not be bored, and someone help me with this...i have more doutbs, but a fell that is the stronger doubt...

Well, thanks anyway =D.
Vitucho.

Brenton S.
May 23rd, 2006, 07:40 AM
Hi Vitucho,

What I suggest you do is have your main window process the WM_PARENTNOTIFY message.

ex:

case WM_PARENTNOTIFY:

if(LOWORD(wParam) == WM_LBUTTONDOWN) // Left mouse button was pressed

{

POINT pt; // Position of cursor when button was pressed
HWND hwndButton; // Button at position of cursor

pt.x = GET_X_LPARAM(lParam);
pt.y = GET_Y_LPARAM(lParam);

hwndButton = ChildWindowFromPoint(MyGroupBox, pt);

if(GetWindowLong(hwndButton, GWL_ID) == IDC_BUTTON1)
{
// Do something...
}

}
break;

I hope I've been of some help

Vitucho
May 23rd, 2006, 05:57 PM
Thanks breton!!

that's good idea...WM_PARENTNOTIFY :

The WM_PARENTNOTIFY message is sent to the parent of a child window when the child window is created or destroyed, "or when the user clicks a mouse button while the cursor is over the child window"...yeah and i can use those flag and retrieve the mouse coordinates x,y and compare to the coordinates of the component inside...and do...well "thinks" jeje.

But i have try another way, like establish "manualy" the function that retrieves events from that window child that is (in this case) my GroupBox button...and it's work!!!!
[USING SetWindowLong (GROUPBOX,GWL_WNDPROC,(LONG)Procedure)]

Now the buttons inside de GroupBox (that'is inside the mainWindow) tell to the groupBox "ey..i am touched", so the dispacht a nice and know WM_COMMAND to the GroupBox (like a good partent windows the listen to they childs...(no like the ugly MAINWindows that only recgonise level 1 childs only.. (direct childs i am trying to say))

I Think that solution, pretty much like java callbacks (*), is a little more elegant (really don't know what's more eficient..), and allows you to split a Window in a separate modules that can be programed apart (by diferent's person).

(*) For those how never work with java swing o JFC, all componets in java (windows in "WINDOWS") can (must) have they callbacks rutine, if they not have it, when they have to notify for some event they ignore and pass the event to the parent component and so and so....(i guess know i have a little idea of the swing internal implementation for win32 plattaform...a very very very little....almost nothing jejeje)

Well, thanks a lot for the help Brenton!! always is good to heart other's ideas..bring it on...

bbruce
October 16th, 2006, 05:33 PM
Hi can you put the full code of de groupbox ???

My code:

case WM_PARENTNOTIFY:
if(LOWORD(wParam) == WM_LBUTTONDOWN) {
SetWindowLong (groupBoxCampo,GWL_WNDPROC,(LONG)MyProcedure);
}
break;

end code

when i just click in the first time, it works, but if I just pass the mouse on the window again it and donīt click, the procedure runs again!

Someone can help me ?

Thanks

JohnCz
October 24th, 2006, 09:13 PM
I do not quite understand your problem.

Button sends messages to a parent window regardless if a parent is a child window or not, hence your group box receives button messages.

Can you post your project?

bbruce
November 13th, 2006, 08:06 AM
hi JohnCz, i tried to treat the message but it not work.

Do you have a little example ?


thanks by the answer

bbruce
November 23rd, 2006, 11:04 AM
groupBox = CreateWindow("BUTTON", " Place ", BS_GROUPBOX|WS_CHILD|WS_VISIBLE, 130,540,170,42,hmae,NULL , hInst, NULL);


htest = CreateWindow("BUTTON","Left",BS_AUTORADIOBUTTON|WS_CHILD|WS_VISIBLE,
134,560,82,20,groupBox,(HMENU)ID_BTleft,hInstance,NULL);

CreateWindow("BUTTON","Right",BS_AUTORADIOBUTTON|WS_CHILD|WS_VISIBLE,
223,560,65,20,groupBox,(HMENU)ID_BTright,hInstance,NULL);


I need some help to receive the message from the groupbox, i tried a lot of things but no one works.

bbruce
November 23rd, 2006, 04:10 PM
I have done this but is not correct:

case WM_PARENTNOTIFY: {
if(LOWORD(wParam) == WM_LBUTTONDOWN) // Left mouse button was pressed
{

if(IsDlgButtonChecked(groupBox,ID_BTdireita)==BST_CHECKED){
//Do something
}
}
break;

Eloy
November 24th, 2006, 04:29 AM
Hello bbruce.

I usually work with groupboxes, and I have never proccessed the messages of the groupbox (I remember that it doesn't send notifies to the parent, does it?). I think that you must proccess the WM_COMMAND of the radio or check buttons, that's what I usually do and works fine for me.

bbruce
November 24th, 2006, 08:57 AM
It donīt work. Probably you have only one groupbox and you are using the main handle in the buttons. Try to do two groupbox and it will not work.