I found out today that the main window of pb always uses the number to create the class name.
No matter whether you use a constant or #PB_Any (I know, #PB_Any is a constant as well)
Result (for me): I can use a better version of FindWindowEx() to find my already running main window instance...
Code: Select all
#ProgramName$ = "TestApp"
#ProgramMainCaption$ = "Test App " + #PB_Editor_BuildCount+"."+#PB_Editor_CompileCount
#WND_Main = 123 ; Enumerations are recommended :)
#GDT_txtClassname = 1
#GDT_txtWindow = 2
Procedure CreateMainWindow(Window)
Protected hwnd, hwndFound, cn${#MAX_PATH}
hwnd = OpenWindow(Window, 0, 0, 320, 80, #ProgramMainCaption$, #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
If hwnd
If Window = #PB_Any
Window = hwnd ; Number
hwnd = WindowID(hwnd) ; Handle
EndIf
StringGadget(#GDT_txtClassname, 8, 8, 304, 20, "")
StringGadget(#GDT_txtWindow, 8, 32, 304, 20, "")
If GetClassName_(hwnd, @cn$, #MAX_PATH)
SetGadgetText(#GDT_txtClassname, "Classname" + #TAB$ + cn$)
EndIf
hwndFound = FindWindowEx_(#Null, #Null, "WindowClass_"+Window, #ProgramMainCaption$)
If hwndFound = hwnd
SetGadgetText(#GDT_txtWindow, "Window #" + Window + " " + #TAB$ + "found")
EndIf
ProcedureReturn #True
EndIf
ProcedureReturn #False
EndProcedure
Procedure Main()
CompilerIf 0 ; <- change this to 1 or 10 and see the difference
If CreateMainWindow(#WND_Main)
CompilerElse
If CreateMainWindow(#PB_Any)
CompilerEndIf
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
EndSelect
ForEver
EndIf
ProcedureReturn 0
EndProcedure
End Main()