Page 2 of 2

Re: Optional parameter for OpenWindow - classname

Posted: Sun Aug 22, 2010 8:06 am
by Little John
That's cool! 8) Thanks, hallodri!

Regards, Little John

Re: Optional parameter for OpenWindow - classname

Posted: Sun Aug 22, 2010 10:00 am
by netmaestro
Thank you for that, hallodri! It's very informative. :mrgreen:

Re: Optional parameter for OpenWindow - classname

Posted: Mon Aug 23, 2010 8:50 am
by Fred
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.

Re: Optional parameter for OpenWindow - classname

Posted: Mon Aug 23, 2010 11:41 am
by netmaestro
You're too kind Fred but since it seems to be only me I'd rather not rock the boat. I can learn to love WindowClass_. :mrgreen:

Re: Optional parameter for OpenWindow - classname

Posted: Mon Aug 23, 2010 12:36 pm
by gnozal
Personally, I don't understand the 'cosmetic' reasons, as almost no-one will peek at the class names. And if it's to hide that the executable was written with PB, there are other ways to know it : PB_ props, linker, etc...

Imho, having a different class for each window is handy if you use SetClassLong_(), so each window can have a different setting.

Furthermore, some apps may rely on the "WindowClass_X" naming scheme to detect purebasic windows, like some editor plugins.

Re: Optional parameter for OpenWindow - classname

Posted: Thu Nov 10, 2011 9:58 pm
by User_Russian
Why not switch focus when you press the TAB?

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()

Re: Optional parameter for OpenWindow - classname

Posted: Fri Oct 27, 2023 8:03 am
by Rinzwind
Why? Well.. to find your window from the same or another process when the title is dynamic or even empty.

Re: Optional parameter for OpenWindow - classname

Posted: Tue Oct 31, 2023 4:59 am
by Rinzwind
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.
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.