Optional parameter for OpenWindow - classname

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Little John
Addict
Addict
Posts: 4779
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Optional parameter for OpenWindow - classname

Post by Little John »

That's cool! 8) Thanks, hallodri!

Regards, Little John
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Optional parameter for OpenWindow - classname

Post by netmaestro »

Thank you for that, hallodri! It's very informative. :mrgreen:
BERESHEIT
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Optional parameter for OpenWindow - classname

Post 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.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Optional parameter for OpenWindow - classname

Post 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:
BERESHEIT
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Re: Optional parameter for OpenWindow - classname

Post 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.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
User_Russian
Addict
Addict
Posts: 1520
Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia

Re: Optional parameter for OpenWindow - classname

Post 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()
Rinzwind
Enthusiast
Enthusiast
Posts: 679
Joined: Wed Mar 11, 2009 4:06 pm
Location: NL

Re: Optional parameter for OpenWindow - classname

Post by Rinzwind »

Why? Well.. to find your window from the same or another process when the title is dynamic or even empty.
Rinzwind
Enthusiast
Enthusiast
Posts: 679
Joined: Wed Mar 11, 2009 4:06 pm
Location: NL

Re: Optional parameter for OpenWindow - classname

Post 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.
Post Reply