How to set the WindowClass name?
Posted: Wed Jul 11, 2007 8:20 pm
I would like to specify the class name of the window made by Visual Designer. I would like to use something other than WindowClass_#. Is this possible?
http://www.purebasic.com
https://www.purebasic.fr/english/
The way makes no difference, as long as he leads to the successsrod wrote:Now that is one dirty low down trick!
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,parent=0)
Protected wnd.wndclass
Protected classname.s = "MY_OWN_CLASS"
Protected *WinObj.integer
Protected hWnd.i
Protected rc.rect
With wnd
\style = #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,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()
NewOpenWindow(0,#PB_Ignore,#PB_Ignore,200,200,"333")
Repeat
event = WaitWindowEvent()
Until event = #PB_Event_CloseWindow
EndProcedure:Main()
Is this comment from 13 years ago still valid with the latest PureBasic version (5.73)? I need to change the class name of my window that I created with OpenWindow.netmaestro wrote:while there is a GetClassName_( API, there is no corresponding SetClassName_(, I don't believe this is something that can be changed after the window is created. You would have to create the window via API, registering your own classname
Code: Select all
Import "window.lib"
CompilerIf #PB_Compiler_Version < 550 And #PB_Compiler_Unicode
CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
_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_UNICODE"
CompilerEndIf
CompilerElse
CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
_PB_Window_ProcessEvent(a,b,c,d) As "_PB_Window_ProcessEvent@16"
CompilerElse
_PB_Window_ProcessEvent(a,b,c,d) As "PB_Window_ProcessEvent"
CompilerEndIf
CompilerEndIf
PB_Window_Icon
PB_Window_Cursor
PB_Window_Objects
PB_Object_GetOrAllocateID(*Object,id)
EndImport