Re: Optional parameter for OpenWindow - classname
Posted: Sun Aug 22, 2010 8:06 am
That's cool!
Thanks, hallodri!
Regards, Little John

Regards, Little John
http://www.purebasic.com
https://www.purebasic.fr/english/
Code: Select all
Import "window.lib"
CompilerIf #PB_Compiler_Unicode
_PB_Window_ProcessEvent(a,b,c,d) As "_PB_Window_ProcessEvent_UNICODE@16"
CompilerElse
_PB_Window_ProcessEvent(a,b,c,d) As "_PB_Window_ProcessEvent@16"
CompilerEndIf
PB_Window_Icon
PB_Window_Cursor
PB_Window_Objects
PB_Object_GetOrAllocateID(*Object,id)
EndImport
Procedure NewOpenWindow(id,x,y,cx,cy,title.s,flags=#WS_VISIBLE|#WS_OVERLAPPEDWINDOW|#WS_TABSTOP,parent=0)
Protected wnd.wndclass
Protected classname.s = "MY_OWN_CLASS"
Protected *WinObj.integer
Protected hWnd.i
Protected rc.rect
With wnd
\style = 0;#CS_HREDRAW|#CS_VREDRAW
\lpfnWndProc = @_PB_Window_ProcessEvent()
\hInstance = GetModuleHandle_(0)
\hIcon = PB_Window_Icon
\hCursor = PB_Window_Cursor
\lpszClassName = @classname
\hbrBackground = #COLOR_WINDOW
\cbWndExtra = 0
\cbClsExtra = 0
EndWith
If RegisterClass_(wnd)
SetRect_(rc,0,0,cx,cy)
AdjustWindowRectEx_(rc,flags,0,#WS_EX_WINDOWEDGE)
If x = #PB_Ignore Or y = #PB_Ignore
x = #CW_USEDEFAULT
y = #CW_USEDEFAULT
EndIf
hWnd = CreateWindowEx_(#WS_EX_WINDOWEDGE|#WS_EX_CONTROLPARENT,classname,title,flags,x,y,rc\right-rc\left,rc\bottom-rc\top,parent,0,GetModuleHandle_(0),0)
If hWnd
*WinObj = PB_Object_GetOrAllocateID(PB_Window_Objects,id)
*WinObj\i = hWnd
If id = #PB_Any
SetProp_(hWnd,"Pb_WindowID",*WinObj+1)
Else
SetProp_(hWnd,"Pb_WindowID",id+1)
EndIf
Else
UnregisterClass_(GetModuleHandle_(0),classname)
EndIf
EndIf
If id = #PB_Any
id = *WinObj
Else
id = hWnd
EndIf
ProcedureReturn id
EndProcedure
Procedure Main()
;OpenWindow(0, #PB_Ignore,#PB_Ignore,200,200,"Main")
NewOpenWindow(0,#PB_Ignore,#PB_Ignore,200,200,"333")
UseGadgetList(WindowID(0))
ButtonGadget(0,10,10,80,24,"OK")
ButtonGadget(1,10,50,80,24,"OK")
SetActiveGadget(0)
SendMessage_(WindowID(0), #WM_UPDATEUISTATE, $30002,0)
Repeat
event = WaitWindowEvent()
Until event = #PB_Event_CloseWindow
EndProcedure:Main()
This would be appreciated. Then one can find a specific app window from another process easily when needed. Useful for example for utilities where you only want to run one instance. When user tries to start another, show the existing window. Impact on existing code: none if one has the stance it 'is only technical background noise' as said in this topic.Fred wrote: Mon Aug 23, 2010 8:50 am We could put the program name instead of "WindowClass_", if it would help. Having a full choice makes things unnecessary complicated IMHO, as it's really hidden stuffs.