How to set the WindowClass name?
How to set the WindowClass name?
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?
- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
The classname is set when the window is created, and 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, which takes you down a path that's a lot more work than a standard PB event loop, so you'd have to weigh whether or not the benefits would be worth the effort.
BERESHEIT
here: http://www.purebasic.fr/german/viewtopi ... 876#143876
is a small tool with source that patch the classname in the exe. I haven't test it
is a small tool with source that patch the classname in the exe. I haven't test it
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

The way makes no difference, as long as he leads to the successsrod wrote:Now that is one dirty low down trick!

PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Simple but also dirty

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()
Last edited by hallodri on Sun Aug 22, 2010 7:10 am, edited 3 times in total.
- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Re:
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
Re: How to set the WindowClass name?
Hi BarryG
Change hallodri code
Then please check and report
Edit : It works
Change hallodri code
Then please check and report
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
Egypt my love
Re: How to set the WindowClass name?
Thanks Rashad, yes, it's working great.