WORKING Group Box?

BlitzPlus Forums/BlitzPlus Programming/WORKING Group Box?

Helios(Posted 2005) [#1]
Does anyone have code for a working group box? Ive seen a couple of others but non of them work properly, mostly due to them not getting re-painted?


Helios(Posted 2005) [#2]
Anyone?


Wiebo(Posted 2005) [#3]
I included group boxes in my form editor, but it's shareware... link in my sig, though!


Helios(Posted 2005) [#4]
Could you post the group box code? I pretty much broke at the moment!

ive got this but it dosent seem to redraw, does anyone know hos to get it to work?


Function CreateGroupBox(name$, x, y, w, h, p) 
Local groupbox, hwnd 
	groupbox = CreateButton(name, x, y, w, h, p) 
	hwnd = QueryObject(groupbox, 1) 
	api_SetWindowLong(hwnd, GWL_STYLE, api_GetWindowLong(hwnd, GWL_STYLE)+7) 
Return groupbox 
End Function



Cold Harbour(Posted 2005) [#5]
How about this. Some flicker when you resize the window. You can't parent anything to it either. I don't know if this is even possible since bizarrely, in Windows a groupbox is actually a button.

; 	.lib "User32.dll"
;       SendMessage%(hWnd%,Msg%,wParam%,lParam%):"SendMessageA" 
Const BM_SETSTYLE	=	244
Const BS_GROUPBOX 	=	7

Global win=CreateWindow ("Win",10,10,600,600,main,15)

groupbox=CreateGroupBox("Woo a Groupbox",10,10,300,300,win)

SetGadgetLayout groupbox,1,0,1,0

While WaitEvent(10)<>$803

Wend

End 


Function CreateGroupBox(name$, x, y, w, h, p) 

	groupbox = CreateButton(name, x, y, w, h, p,2)

	hwnd = QueryObject(groupbox, 1)

	SendMessage (hwnd, BM_SETSTYLE, BS_GROUPBOX  ,1)

	pan=CreatePanel (x,y,w,h,p)
	SetGadgetLayout pan,1,0,1,0

	Return groupbox

End Function



RiK(Posted 2005) [#6]
Wiebo - any updates planned? It's been a LOOOOONG while since there was any activity on the forum so I was just wondering..


Helios(Posted 2005) [#7]
its ok i made my own, ive posted it in the code archives if your intrested!


JoshK(Posted 2005) [#8]
I fixed your code so that the groupbox will be treated as a single gadget. The only caveat is you have to create any gadgets inside the group box before you make the groupbox, or you have to get the background panel handle and parent the gadget to that.

Const BM_SETSTYLE=244
Const BS_GROUPBOX=7

win=CreateWindow ("Win",10,10,400,400,main,15)
button1=CreateButton("test",40,40,80,30,win)
SetGadgetLayout button1,1,0,1,0
groupbox=CreateGroupBox("Woo a Groupbox",10,10,300,300,win)
SetGadgetLayout groupbox,1,1,1,1
button2=CreateButton("test2",200,40,80,30,win)
SetGadgetLayout button2,1,0,1,0
While WaitEvent(10)<>$803
Wend
End

Function CreateGroupBox(name$,x,y,w,h,parent) 
mainpanel=CreatePanel(x,y,w,h,parent)
groupbox=CreateButton(name,0,0,w,h,mainpanel)
SetGadgetLayout groupbox,1,1,1,1
SendMessage QueryObject(groupbox,1),BM_SETSTYLE,BS_GROUPBOX,1
backgroundpanel=CreatePanel(0,0,ClientWidth(mainpanel),ClientHeight(mainpanel),mainpanel)
SetGadgetLayout backgroundpanel,1,1,1,1
Return mainpanel
End Function



JoshK(Posted 2005) [#9]
Here's another method. SetGadgetLayout commands won't work on this, but gadgets can be parented to the groupbox, the groupbox clips its children, and the flicker is gone:
Const BM_SETSTYLE=244
Const BS_GROUPBOX=7

win=CreateWindow ("Win",10,10,400,400,main,15)
groupbox=CreateGroupBox("Woo a Groupbox",10,10,300,300,win)
button1=CreateButton("test",40,40,80,30,groupbox)
SetGadgetLayout button1,1,0,1,0
button2=CreateButton("test2",200,40,80,30,groupbox)
SetGadgetLayout button2,1,0,1,0
While WaitEvent(10)<>$803
Wend
End

Function CreateGroupBox(name$,x,y,w,h,parent) 
groupbox=CreateButton(name,x,y,w,h,parent)
SetGadgetLayout groupbox,1,1,1,1
SendMessage QueryObject(groupbox,1),BM_SETSTYLE,BS_GROUPBOX,1
backgroundpanel=CreatePanel(x+2,y+2,w-4,h-4,parent)
SetGadgetLayout backgroundpanel,1,1,1,1
Return backgroundpanel
End Function



NetGamer(Posted 2005) [#10]
And where does one find SendMessage?


Cold Harbour(Posted 2005) [#11]
See the commented out lines in my code above? That's telling you to add the line
SendMessage%(hWnd%,Msg%,wParam%,lParam%):"SendMessageA"

to your user32 userlib.

In short make a file called user32.decls
add the commented lines.
save it in your userlibs folder and restart B+.


NetGamer(Posted 2005) [#12]
Something funky goin on. I pulled in user32.decls from the code library (placed in userlibs subdir) and replaced SendMessage with api_SendMessage. It runs but abends.

I'm running B+ 1.40, XP SP2 on a 1.2GHz AMD and a Geforece 4800 video card (nothing special).


JoshK(Posted 2005) [#13]
Use this:
SendMessage%(hwnd%,wMsg%,wParam%,lParam%) : "SendMessageA"

NOT this:
SendMessage%(hwnd%,wMsg%,wParam%,lParam*) : "SendMessageA"


Kevin_(Posted 2005) [#14]
I really dont know why this feature isn't impleimented in the Panel gadget. A Panel is a naturual grouping gadget anyway and would only need an extra parameter to allow it to draw a border in the style of a group box and to allow a title at the top. Maybe this could be put in with the next update. Pretty please!

CreatePanel( x,y,width,height,group,Title$[,style])

If style is set to 2 then draw the group border.


JoshK(Posted 2005) [#15]
Panels don't have a title$ parameter. But you could use SetGadgetText() instead.


Kevin_(Posted 2005) [#16]
Panels don't have a title$ parameter.

Doh! I know they don't! What I am suggesting is that they include it as a parameter. Please read my post carefully.


JoshK(Posted 2005) [#17]
But they already have a [style] parameter, so that would mess up existing code, plus it would not follow the parameter order convention.

I would use CreateButton(title$,x,y,width,height,[style=3])


NetGamer(Posted 2005) [#18]
aero,
Thanks for the SendMessage clarification. Can you explain:
1. what's the difference between lParam* and lParam%
2. why the user32.decls file used lParam* instead of lParam% (and why it hasn't sufficiently screwed everyone to date so that it was adjusted?)


Kevin_(Posted 2005) [#19]
But they already have a [style] parameter

Forget it, you don't get what I mean and I'm not going to explain any further. OK, you are correct. Congratulations.