Restored from previous forum. Originally posted by Franco.
Code: Select all
; (c) 2002 - Franco's template - absolutely freeware
; This is a skeleton of a ToolWindow with CreateWindowEx
; Remember: You don't need WaitWindow() or something else
; Your Gadget event is catched and used by MyWindowProc
; So you have to code your events in it... instead the 'normal' way.
; Your Gadget handles need to be GLOBAL!
; You can use every PureBasic Gadget you want...
; A ToolWindow has no button in the TaskBar.
Global BG_hWnd1, BG_hWnd2, BG_hWnd3
Procedure RunApplication()
Shared Message.MSG
While GetMessage_(@Message, 0, 0, 0)
TranslateMessage_(@Message)
DispatchMessage_(@Message)
Wend
EndProcedure
Procedure MyWindowProc(hWnd, Msg, wParam, lParam)
Select Msg
Case #WM_COMMAND
Select lParam
Case 0
Select wParam
Case 12 ;MI_hWnd1
MessageRequester("MOUSE LEFTCLICK", "Menu Item # 1")
Case 13 ;MI_hWnd2
MessageRequester("MOUSE LEFTCLICK", "Menu Item # 2")
Case 14 ;MI_hWnd3
MessageRequester("MOUSE LEFTCLICK", "Menu Item # 3")
Case 0 ;TB_hWnd1
MessageRequester("MOUSE LEFTCLICK", "Toolbar Button # 1")
Case 1 ;TB_hWnd2
MessageRequester("MOUSE LEFTCLICK", "Toolbar Button # 2")
Case 2 ;TB_hWnd3
MessageRequester("MOUSE LEFTCLICK", "Toolbar Button # 3")
EndSelect
Case BG_hWnd1
MessageRequester("MOUSE LEFTCLICK", "Button # 1")
Case BG_hWnd2
MessageRequester("MOUSE LEFTCLICK", "Button # 2")
Case BG_hWnd3
MessageRequester("MOUSE LEFTCLICK", "Button # 3")
EndSelect
Case #WM_CLOSE
PostQuitMessage_(0)
EndSelect
ProcedureReturn DefWindowProc_(hWnd, Msg, wParam, lParam)
EndProcedure
Procedure OpenToolWindowEx(PosX, PosY, SizeX, SizeY, Title$)
ClassName.s = "MyToolWindow"
wc.WNDCLASSEX
wc\cbSize = SizeOf(WNDCLASSEX)
wc\style = #CS_HREDRAW | #CS_VREDRAW ;|#CS_GLOBALCLASS
wc\lpfnWndProc = @MyWindowProc()
wc\cbClsExtra = 0
wc\cbWndExtra = 0
wc\hInstance = GetModuleHandle_(0)
wc\hIcon = 0
wc\hCursor = LoadCursor_(#Null, #IDC_CROSS)
wc\hbrBackground = GetStockObject_(#LTGRAY_BRUSH) ;#WHITE_BRUSH);
wc\lpszMenuName = 0
wc\lpszClassName = @ClassName
wc\hIconSm = 0
If RegisterClassEx_(@wc)
hInstance = GetModuleHandle_(0)
hWnd = CreateWindowEx_(#WS_EX_TOOLWINDOW, "MyToolWindow", Title$,
#WS_POPUPWINDOW | #WS_DLGFRAME | #WS_CLIPSIBLINGS |
#WS_VISIBLE | #DS_MODALFRAME | #DS_3DLOOK, PosX,
PosY, SizeX, SizeY, 0, 0, GetModuleHandle_(0), 0)
Brush.LOGBRUSH\lbColor = GetSysColor_(#COLOR_BTNFACE)
SetClassLong_(hWnd, #GCL_HBRBACKGROUND, CreateBrushIndirect_(Brush))
RedrawWindow_(hWnd, 0, 0, 7)
SetWindowPos_(hWnd, #HWND_TOPMOST, PosX, PosY, SizeX, SizeY, 0)
ProcedureReturn hWnd
Else
MessageRequester("", "Failed to register the window class...")
ProcedureReturn 0
EndIf
EndProcedure
;here begins the 'normal' code...
Main_hWnd = OpenToolWindowEx(400, 300, 320, 240, "Demo")
If Main_hWnd
If CreateToolBar(0, Main_hWnd)
TB_hWnd1 = ToolBarStandardButton(0, #PB_ToolBarIcon_New)
ToolBarToolTip(0, 0, "ToolBarButton 0 ToolTip")
TB_hWnd2 = ToolBarStandardButton(1, #PB_ToolBarIcon_Open)
ToolBarToolTip(0, 1,"ToolBarButton 1 ToolTip")
TB_hWnd3 = ToolBarStandardButton(2, #PB_ToolBarIcon_Save)
ToolBarToolTip(0, 2,"ToolBarButton 2 ToolTip")
EndIf
If CreateMenu(0, Main_hWnd)
MenuTitle("Project")
MI_hWnd1 = MenuItem(12, "New")
MI_hWnd2 = MenuItem(13, "Open")
MI_hWnd3 = MenuItem(14, "Save")
EndIf
UseGadgetList(Main_hWnd)
BG_hWnd1 = ButtonGadget(1, 25, 50, 250, 24, "Butt1")
BG_hWnd2 = ButtonGadget(2, 25, 85, 250, 24, "Butt2")
BG_hWnd3 = ButtonGadget(3, 25, 125, 50, 24, "Butt3")
RunApplication()
EndIf
Select LoWord(lParam)
later changed to:
Select lParam
because of WinXP (hopefully it works still under Win98 - can't test it yet)
Have a nice day...
Franco
Sometimes you have to go a lonely way to accomplish genius things.
Edited by - franco on 06 April 2002 04:55:47