Button alignment WinXP theme

BlitzPlus Forums/BlitzPlus Programming/Button alignment WinXP theme

Paulo(Posted 2004) [#1]
Im having problems aligning buttons. When in the Default WinXP theme, the buttons align correctly, but as soon as I change to original Win98 theme, run the program again, the buttons jump down about 5 pixels. If I change the windows theme whilst the program is running, the buttons dont go anywhere, they stay aligned. Ive played with SETGADGETLAYOUT, trying 0,1 and 2, but this changes nothing.

My window setup consists of a tabber and a canvas. The buttons in question need to appear on top of the canvas, which they do. Can anyone spot any problems with the code, please?

Global window=CreateWindow( "Window",0,0,780,585,0,3)

;maximizewindow window  ;force the window to open up maximum

menu=WindowMenu(window) 


filemenu=CreateMenu("File",0,menu) 
CreateMenu"New",16,filemenu
CreateMenu "Quit",1,filemenu


UpdateWindowMenu window 


Global tabs = CreateTabber (0, 0, ClientWidth(window) ,ClientHeight(window), window)  

	SetGadgetLayout tabs, 1, 1, 1,1

	AddGadgetItem tabs, "Page1"
    AddGadgetItem tabs, "Page2"
    AddGadgetItem tabs, "Page3"
	AddGadgetItem tabs, "Page4"
	
	


Global canvas  = CreateCanvas( 0,0,ClientWidth(tabs),ClientHeight(tabs),tabs )




Global bar1editbut = CreateButton("",2,ClientHeight(canvas)-494,16,10,canvas,0)
SetGadgetLayout bar1editbut ,1,0,1,0

Global bar1editbut2 = CreateButton("",2,ClientHeight(canvas)-482,16,10,canvas,0)
SetGadgetLayout bar1editbut2 ,1,0,1,0

Global bar1editbut3 = CreateButton("",2,ClientHeight(canvas)-470,16,10,canvas,0)
SetGadgetLayout bar1editbut3 ,1,0,1,0

Global bar1editbut4 = CreateButton("",2,ClientHeight(canvas)-458,16,10,canvas,0)
SetGadgetLayout bar1editbut4 ,1,0,1,0

Global bar1editbut5 = CreateButton("",2,ClientHeight(canvas)-446,16,10,canvas,0)
SetGadgetLayout bar1editbut5 ,1,0,1,0

Global bar1editbut6 = CreateButton("",2,ClientHeight(canvas)-434,16,10,canvas,0)
SetGadgetLayout bar1editbut6 ,1,0,1,0



SetBuffer CanvasBuffer(canvas)


ClsColor 50,50,50



While Not KeyHit(1)  

ID=WaitEvent() 
If ID=$803 Then End 

If ID=$1001 Then 
EID=EventData() 
Select EID 

Case 1 
End

End Select

End If 


FlipCanvas canvas

Text 20,13, "--------  < Center of button aligns to this in WINXP Default theme"
Text 20,25, "--------  < Center of button aligns to this in WINXP Default theme"


Wend

End 



To see the problem, you'll have to switch themes and run the program again.


soja(Posted 2004) [#2]
It's because the client area is bigger in the original theme than the default theme, so when you create your buttons and give the coord like this:
ClientHeight(canvas)-494

...ClientHeight(canvas) is different each time.

I can see two possible solutions:
1) Position your buttons relative to the upper border, instead of the lower border. The upper border will always be 0.
2) Use client coordinates in your main window (start with attribute "35" instead of "3"). That way your canvas will always be the same size (but your window may grow or shrink, depending on the borders/skin applied to it).


Paulo(Posted 2004) [#3]
thanks a lot for the information Soja sounds like a plan :)


Rottbott(Posted 2004) [#4]
Here's my solution. It replaces CreateWindow(). It also makes the window centred, although you can remove that if you want. It's good because it makes sure that the window client area is always the same size, without using the client co-ordinates flag (which causes other problems!)

; Creates a centred window with a client area of the given size
Function CreateCentredWindow(Title$, W, H, Parent, Flags = 15)

	; Create initial centred window
	Win = CreateWindow(Title$, (ClientWidth(Parent) / 2) - (W / 2), (ClientHeight(Parent) / 2) - (H / 2), W, H, Parent, Flags)

	; Resize to make sure client area has the full size
	W = (W * 2) - ClientWidth(Win)
	H = (H * 2) - ClientHeight(Win)
	SetGadgetShape Win, (ClientWidth(Parent) / 2) - (W / 2), (ClientHeight(Parent) / 2) - (H / 2), W, H

	Return Win

End Function



Hotcakes(Posted 2004) [#5]
What other problems?


Paulo(Posted 2004) [#6]
in the end I made the clientheight(canvas) command a static value and it all worked out just fine.


Rottbott(Posted 2004) [#7]
If you want to record the size of your window in a file and then restore it when it loads back up, and you have used the client coordinates flag, it won't work. Your window gets bigger every time. Makes no difference whether you use GadgetWidth() or ClientWidth() to record the last size, it still does it.


Eikon(Posted 2004) [#8]
I remember someone saying that window style:

32 - The window shape is in 'client coordinates'


automatically solves this problem but I don't know for sure.

* edit * oops, Soja already mentioned this :|