Window: List of PropertyNames

Share your advanced PureBasic knowledge/code with the community.
User avatar
mk-soft
Always Here
Always Here
Posts: 6412
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Window: List of PropertyNames

Post by mk-soft »

Surely someone can use it

Code: Select all

;-TOP by mk-soft, v1.01.1, 09.04.2023

Global NewList PropertyNames.s()

Procedure EnumPropNamesCB(hwnd, *lpstr, handle, *lparam.integer)
  Protected nAtom, lpBuffer.s
  If *lpstr & $FFFFFFFFFFFF0000
    ; Property String
    AddElement(PropertyNames())
    PropertyNames() = PeekS(*lpStr)
  Else
    ; Property Integer
    nAtom = GlobalFindAtom_(*lpstr)
    If nAtom
      lpBuffer = Space(#MAX_PATH)
      If GlobalGetAtomName_(nAtom, @lpBuffer, #MAX_PATH)
        AddElement(PropertyNames())
        PropertyNames() = lpBuffer
      EndIf
    EndIf
  EndIf
  ProcedureReturn #True
EndProcedure

Procedure GetPropertyNames(Handle)
  Protected r1, param
  ClearList(PropertyNames())
  r1 = EnumPropsEx_(Handle, @EnumPropNamesCB(), @param)
  ProcedureReturn r1
EndProcedure

; ****

CompilerIf #PB_Compiler_IsMainFile
  
  ;-Example
  
  #ProgramTitle = "Main Window"
  #ProgramVersion = "v1.01.2"
  
  Enumeration Windows
    #Main
  EndEnumeration
  
  Enumeration MenuBar
    #MainMenu
  EndEnumeration
  
  Enumeration MenuItems
    #MainMenuAbout
    #MainMenuExit
  EndEnumeration
  
  Enumeration Gadgets
    #MainList
  EndEnumeration
  
  Enumeration StatusBar
    #MainStatusBar
  EndEnumeration
  
  Procedure UpdateWindow()
    Protected dx, dy
    dx = WindowWidth(#Main)
    dy = WindowHeight(#Main) - StatusBarHeight(#MainStatusBar) - MenuHeight()
    ; Resize gadgets
    ResizeGadget(#MainList, 0, 0, dx, dy)
  EndProcedure
  
  Procedure Main()
    Protected dx, dy
    
    #MainStyle = #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget
    
    If OpenWindow(#Main, #PB_Ignore, #PB_Ignore, 800, 600, #ProgramTitle , #MainStyle)
      ; Menu
      CreateMenu(#MainMenu, WindowID(#Main))
      MenuTitle("&File")
      CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
        MenuItem(#PB_Menu_About, "")
      CompilerElse
        MenuItem(#MainMenuAbout, "About")
      CompilerEndIf
      ; Menu File Items
      
      CompilerIf Not #PB_Compiler_OS = #PB_OS_MacOS
        MenuBar()
        MenuItem(#MainMenuExit, "E&xit")
      CompilerEndIf
      
      ; StatusBar
      CreateStatusBar(#MainStatusBar, WindowID(#Main))
      AddStatusBarField(#PB_Ignore)
      
      ; Gadgets
      dx = WindowWidth(#Main)
      dy = WindowHeight(#Main) - StatusBarHeight(#MainStatusBar) - MenuHeight()
      ;ListViewGadget(#MainList, 0, 0, dx, dy)
      TextGadget(#MainList, 0, 0, dx, dy, "")
      ; Bind Events
      BindEvent(#PB_Event_SizeWindow, @UpdateWindow(), #Main)
      
      ;
      Debug "Add Integer Atom #1234 to Window"
      nAtom = GlobalAddAtom_("#1234")
      SetProp_(WindowID(#MainList), nAtom, 111)
      
      Debug "Add Gadget Property MyValue to Gadget"
      SetProp_(GadgetID(#MainList), "MyValue", 999)
      Debug "----"
      
      Debug "List Window Properties"
      GetPropertyNames(WindowID(#Main))
      ForEach PropertyNames()
        Debug "Property " + PropertyNames() + " = " + GetProp_(WindowID(#Main), PropertyNames()) 
      Next
      Debug "----"
      
      Debug "List Gadget Properties"
      GetPropertyNames(GadgetID(#MainList))
      ForEach PropertyNames()
        Debug "Property " + PropertyNames() + " = " + GetProp_(GadgetID(#MainList), PropertyNames()) 
      Next
      
      Repeat
        Select WaitWindowEvent()
          Case #PB_Event_CloseWindow
            Select EventWindow()
              Case #Main
                Break
                
            EndSelect
            
          Case #PB_Event_Menu
            Select EventMenu()
              CompilerIf #PB_Compiler_OS = #PB_OS_MacOS   
                Case #PB_Menu_About
                  PostEvent(#PB_Event_Menu, #Main, #MainMenuAbout)
                  
                Case #PB_Menu_Preferences
                  
                Case #PB_Menu_Quit
                  PostEvent(#PB_Event_CloseWindow, #Main, #Null)
                  
              CompilerEndIf
                
              Case #MainMenuExit
                PostEvent(#PB_Event_CloseWindow, #Main, #Null)
                
              Case #MainMenuAbout
                MessageRequester("About", #ProgramTitle + #LF$ + #ProgramVersion, #PB_MessageRequester_Info)
                
            EndSelect
            
            
          Case #PB_Event_Gadget
            Select EventGadget()
              Case #MainList
                Select EventType()
                  Case #PB_EventType_Change
                    ;
                EndSelect
                
            EndSelect
            
        EndSelect
      ForEver
      
    EndIf
    
  EndProcedure : Main()
  
CompilerEndIf
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
Caronte3D
Addict
Addict
Posts: 1379
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: Window: List of PropertyNames

Post by Caronte3D »

Interesting!
These properties can be accessed from another programs?
Possible useful uses?
Thanks for sharing :wink:
BarryG
Addict
Addict
Posts: 4269
Joined: Thu Apr 18, 2019 8:17 am

Re: Window: List of PropertyNames

Post by BarryG »

Yes, properties of a window can be read by other apps. Not sure if they can be changed by other apps (haven't tried it).
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5526
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Window: List of PropertyNames

Post by Kwai chang caine »

Surely someone can use it
You have right, this code can be usefull, i love codes who can be read property, often hidden of something :wink:
And it works here, thanks for sharing 8)
ImageThe happiness is a road...
Not a destination
Post Reply