Add Buttons to Windows Title Bar(Windows)
Posted: Tue Nov 09, 2010 8:22 pm
You need 2 images
state1.bmp 24 x 24 pixel to represent the button in normal state
state2.bmp 24 x 24 pixel to represent the button in hover state
You can make it 3 state button
Tested with XP SP2 & Win 7 x64 PB x86 4.51
state1.bmp 24 x 24 pixel to represent the button in normal state
state2.bmp 24 x 24 pixel to represent the button in hover state
You can make it 3 state button
Tested with XP SP2 & Win 7 x64 PB x86 4.51
Code: Select all
Global x,y,buttonW,buttonH,borderW
Procedure WndProc(hwnd, uMsg, wParam, lParam)
GetWindowRect_(WindowID(1),r.RECT)
x = r\right - (buttonW*5) - borderW ;5 = for Max & Restore & Min and 2 more buttons
y = r\top
If OSVersion() <= #PB_OS_Windows_XP
y = y + 5
Else
x = x + 10
EndIf
result = #PB_ProcessPureBasicEvents
Select uMsg
Case #WM_NOTIFY
Case #WM_GETMINMAXINFO
*pMinMax.MINMAXINFO = lParam
*pMinMax\ptMinTrackSize\x=buttonW*5
Case #WM_SIZE,#WM_MOVE,#WM_PAINT
If GetWindowState(1) = #PB_Window_Maximize
ResizeWindow(2,x,y+4,buttonW*2,buttonH)
Else
ResizeWindow(2,x,y,buttonW*2,buttonH)
EndIf
EndSelect
ProcedureReturn result
EndProcedure
LoadImage(0, "state1.bmp") ;24 x 24 pixel Button state 1
LoadImage(1, "state2.bmp") ;24 x 24 pixel Button state 2
buttonW = GetSystemMetrics_(#SM_CXSIZE)
buttonH = GetSystemMetrics_(#SM_CYSIZE)
borderW = GetSystemMetrics_(#SM_CXBORDER)
OpenWindow(1,0,0,600,400,"Add Button to Title Bar", #PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget|#PB_Window_ScreenCentered)
OpenWindow(2,0,0,buttonW*2,buttonH,"",#WS_POPUP,WindowID(1))
SetWindowColor(2,#Red)
SetWindowLong_(WindowID(2),#GWL_EXSTYLE,GetWindowLong_(WindowID(2),#GWL_EXSTYLE)|#WS_EX_LAYERED)
SetLayeredWindowAttributes_(WindowID(2),#Red,0,#LWA_COLORKEY)
ImageGadget(10,2,0,30,20,ImageID(0))
ImageGadget(11,28,0,30,20,ImageID(0))
SetWindowCallback(@WndProc())
SetActiveWindow(1)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Q = 1
Case #PB_Event_Gadget
Select EventGadget()
Case 10
Debug "Button 10 Pressed"
Case 11
Debug "Button 11 Pressed"
EndSelect
SetActiveWindow(1)
Case #WM_MOUSEMOVE
GetCursorPos_(@p.POINT)
If p\x >= x+5 And p\x <= x+30 And p\y >= y+4 And p\y <=y+25
SetGadgetState(10,ImageID(1))
Else
SetGadgetState(10,ImageID(0))
EndIf
If p\x >= x+35 And p\x <= x+55 And p\y >= y+4 And p\y <=y+25
SetGadgetState(11,ImageID(1))
Else
SetGadgetState(11,ImageID(0))
EndIf
EndSelect
Until Q =1
End