How to set the WindowClass name?

Just starting out? Need help? Post your questions and find answers here.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: How to set the WindowClass name?

Post by Kwai chang caine »

Interesting :shock:
Works here too :wink:
Thanks Rashad and obviously Hallodri 8)
ImageThe happiness is a road...
Not a destination
Balmung
User
User
Posts: 24
Joined: Sat Dec 22, 2018 9:15 pm

Re: How to set the WindowClass name?

Post by Balmung »

It works so far good, but it seam it ignores any DPI settings, my windows are way too small.

Is there an easy fix or did i must fix that with some DPI calculation?

It's a shame that we still can not set a own Class name with PureBasic own stuff...
Rinzwind
Enthusiast
Enthusiast
Posts: 679
Joined: Wed Mar 11, 2009 4:06 pm
Location: NL

Re: How to set the WindowClass name?

Post by Rinzwind »

"There is no current GadgetList".

Does the below seem to be OK? Edit: seems bindevent does nothing..

Code: Select all

Procedure OpenWindow2(id, x, y, w, h, title.s, classname.s, flags = #WS_OVERLAPPEDWINDOW | #WS_VISIBLE, parent = 0)
  Define wnd.WNDCLASS, *winObj.Integer, hWnd, rc.rect
  
  With wnd
    \lpfnWndProc    = @_PB_Window_ProcessEvent() 
    \hInstance      = GetModuleHandle_(0)
    \hIcon          = PB_Window_Icon
    \hCursor        = PB_Window_Cursor
    \lpszClassName  = @classname
    \hbrBackground  = #COLOR_WINDOW
  EndWith    
  
  If RegisterClass_(wnd)
    w = DesktopScaledX(w)
    h = DesktopScaledX(h)
    SetRect_(rc, 0, 0, w, h)
    
    AdjustWindowRectEx_(rc,flags,0,#WS_EX_WINDOWEDGE)
    
    If x = #PB_Ignore Or y = #PB_Ignore
      x = #CW_USEDEFAULT
      y = #CW_USEDEFAULT
    Else
      x = DesktopScaledX(x)
      y = DesktopScaledX(y)      
    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 
      CreateGadgetList(hWnd)
      UseGadgetList(hWnd)        
      
      If id = #PB_Any
        id = *WinObj
      Else
        id = hWnd 
      EndIf
      
    Else 
      UnregisterClass_(GetModuleHandle_(0),classname)
    EndIf     
  EndIf
 
  ProcedureReturn id
EndProcedure
And yes, setting a class should be available out-of-the-box.
Post Reply