by the handle get gadget ident

Just starting out? Need help? Post your questions and find answers here.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: by the handle is a gadget

Post by ts-soft »

The same, shorter, without asm and with some correction:

Code: Select all

CompilerIf #PB_Compiler_OS = #PB_OS_Windows
Import ""
CompilerElse
ImportC ""
CompilerEndIf
  PB_Object_EnumerateStart(*object)
  PB_Object_EnumerateNext(*object,*id.Integer)
  PB_Object_EnumerateAbort(*object)
  PB_Gadget_Objects.i
EndImport
  
Procedure GetGadgetID(hWnd.i)
  Protected id
  
  PB_Object_EnumerateStart(PB_Gadget_Objects)
  While PB_Object_EnumerateNext(PB_Gadget_Objects, @id)
    If hWnd = GadgetID(id)
      PB_Object_EnumerateAbort(PB_Gadget_Objects)
      ProcedureReturn id
    EndIf
  Wend
  ProcedureReturn -1
EndProcedure
  
  
OpenWindow(10, 100, 100, 500, 300, "testwindow")
ButtonGadget(22, 10, 10, 100, 20 , "test")

Debug GetGadgetID(GadgetID(22))

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow   

  
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.
Image
mestnyi
Addict
Addict
Posts: 1098
Joined: Mon Nov 25, 2013 6:41 am

Re: by the handle is a gadget

Post by mestnyi »

I understand this is a special purebasic function, and I thought that means OS as it could do as much or as one problem is solved, thank you. .
User avatar
Bisonte
Addict
Addict
Posts: 1305
Joined: Tue Oct 09, 2007 2:15 am

Re: by the handle is a gadget

Post by Bisonte »

With ts-soft's start, I added Window, Gadget and Image.... (I only tested this with Windows)

Code: Select all

DeclareModule PB
  
  Enumeration
    #PB_ID_Window 
    #PB_ID_Gadget
    #PB_ID_Image
  EndEnumeration
  
  CompilerIf #PB_Compiler_OS = #PB_OS_Windows
    Import ""
  CompilerElse
    ImportC ""
  CompilerEndIf  
    PB_Object_EnumerateStart(*object)
    PB_Object_EnumerateNext(*object,*id.Integer)
    PB_Object_EnumerateAbort(*object)
    PB_Gadget_Objects.i
    PB_Image_Objects.i
    PB_Window_Objects.i
  EndImport
  
  Declare PBID(OS_Handle, Type = #PB_ID_Window)
    
EndDeclareModule
Module        PB
  
  EnableExplicit
  
  Procedure PBID(OS_Handle, Type = #PB_ID_Window)
    
    Protected ID, Objects, Result = -1
    
    If OS_Handle
      
      Select Type
        Case #PB_ID_Gadget : Objects = PB_Gadget_Objects
        Case #PB_ID_Image  : Objects = PB_Image_Objects
        Case #PB_ID_Window : Objects = PB_Window_Objects
      EndSelect
      
      PB_Object_EnumerateStart(Objects)
      While PB_Object_EnumerateNext(Objects, @ID)
        Select Type
          Case #PB_ID_Gadget
            If OS_Handle = GadgetID(ID) : Result = ID : PB_Object_EnumerateAbort(Objects) : Break : EndIf
          Case #PB_ID_Image
            If OS_Handle = ImageID(ID)  : Result = ID : PB_Object_EnumerateAbort(Objects) : Break : EndIf
          Case #PB_ID_Window
            If OS_Handle = WindowID(ID) : Result = ID : PB_Object_EnumerateAbort(Objects) : Break : EndIf
        EndSelect
      Wend
      
    EndIf
    
    ProcedureReturn Result
    
  EndProcedure

EndModule

LoadImage(12, #PB_Compiler_Home + "examples/sources/data/geegee2.bmp")
OpenWindow(3, 100, 100, 500, 300, "testwindow")
ButtonGadget(22, 10, 10, 100, 20 , "test")
Debug "Window = " + Str(PB::PBID(WindowID(3)))
Debug "Gadget = " + Str(PB::PBID(GadgetID(22),PB::#PB_ID_Gadget))
Debug "Image  = " + Str(PB::PBID(ImageID(12), PB::#PB_ID_Image))  
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow  
Last edited by Bisonte on Thu Feb 27, 2014 6:35 pm, edited 1 time in total.
PureBasic 6.21 (Windows x64) | Windows 11 Pro | AsRock B850 Steel Legend Wifi | R7 9800x3D | 64GB RAM | RTX 5080 | ThermaltakeView 270 TG ARGB | build by vannicom​​
English is not my native language... (I often use DeepL.)
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: by the handle is a gadget

Post by ts-soft »

You should change line 61 to:

Code: Select all

LoadImage(12, #PB_Compiler_Home + "examples/sources/Data/Geebee2.bmp")
:wink:
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.
Image
User avatar
Bisonte
Addict
Addict
Posts: 1305
Joined: Tue Oct 09, 2007 2:15 am

Re: by the handle is a gadget

Post by Bisonte »

ts-soft wrote:You should change line 61 to:

Code: Select all

LoadImage(12, #PB_Compiler_Home + "examples/sources/Data/Geebee2.bmp")
:wink:
aaaarg these %$&§" Slashes (Done) :lol:

By the way... are there more "PB.xxx.Objects", I can put in this procedure ?
Last edited by Bisonte on Thu Feb 27, 2014 6:37 pm, edited 1 time in total.
PureBasic 6.21 (Windows x64) | Windows 11 Pro | AsRock B850 Steel Legend Wifi | R7 9800x3D | 64GB RAM | RTX 5080 | ThermaltakeView 270 TG ARGB | build by vannicom​​
English is not my native language... (I often use DeepL.)
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: by the handle is a gadget

Post by ts-soft »

Bisonte wrote:aaaarg these %$&§" Slashes :lol:
Not only slashes, linux is casesensitiv!
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.
Image
User avatar
Bisonte
Addict
Addict
Posts: 1305
Joined: Tue Oct 09, 2007 2:15 am

Re: by the handle is a gadget

Post by Bisonte »

ts-soft wrote:
Bisonte wrote:aaaarg these %$&§" Slashes :lol:
Not only slashes, linux is casesensitiv!
On my windows installation I copy the path from the explorer window... with the capital letters....
PureBasic 6.21 (Windows x64) | Windows 11 Pro | AsRock B850 Steel Legend Wifi | R7 9800x3D | 64GB RAM | RTX 5080 | ThermaltakeView 270 TG ARGB | build by vannicom​​
English is not my native language... (I often use DeepL.)
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: by the handle is a gadget

Post by ts-soft »

Don't use the Windows-Explorer, that is not quite fairly to his users :mrgreen:
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.
Image
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: by the handle is a gadget

Post by Danilo »

Bisonte wrote:By the way... are there more "PB.xxx.Objects", I can put in this procedure ?
Sound, Sprite, Library, File, etc...

Doesn't make sense to put everything into one procedure, because you need
to always include all libraries then. Try calling your procedure with an ImageID()
and without opening a window and without using any command from the window lib.
Probably leads to an linker error if PB_Window_Objects is not included.

(EDIT: Doesn't throw a linker error because all libs get integrated anyway,
because GadgetID() / ImageID() / WindowID() are used within the module)

Also note that this are PB internal commands from the PB SDK. Internals could change at any time,
although the object system has been stable over the last few years.
mestnyi
Addict
Addict
Posts: 1098
Joined: Mon Nov 25, 2013 6:41 am

Re: by the handle is a gadget

Post by mestnyi »

Why did Fred isgadget (), iswindow (), isimage () here like it would be convenient to see for yourself.

Code: Select all

    DeclareModule Get_PB_Object
      Enumeration 1
        #PB_ID_Window
        #PB_ID_Gadget
        #PB_ID_Image
      EndEnumeration
     
      CompilerIf #PB_Compiler_OS = #PB_OS_Windows
        Import ""
      CompilerElse
        ImportC ""
      CompilerEndIf 
        PB_Object_EnumerateStart(*object)
        PB_Object_EnumerateNext(*object,*id.Integer)
        PB_Object_EnumerateAbort(*object)
        PB_Window_Objects.i
        PB_Gadget_Objects.i
        PB_Image_Objects.i
      EndImport
     
      Declare PB_ID(OS_Handle, Type = #PB_ID_Window)
    EndDeclareModule
    Module Get_PB_Object
     EnableExplicit
     Procedure PB_ID(OS_Handle, Type = #PB_ID_Window)
       Protected ID, Objects, Result = -1
        Select Type
            Case #PB_ID_Gadget :Objects = PB_Gadget_Objects
            Case #PB_ID_Image  :Objects = PB_Image_Objects
            Case #PB_ID_Window :Objects = PB_Window_Objects
          EndSelect
         
          PB_Object_EnumerateStart(Objects)
          While PB_Object_EnumerateNext(Objects, @ID)
            Select Type
              Case #PB_ID_Window :If OS_Handle = WindowID(ID) Or (IsWindow(OS_Handle) And OS_Handle = ID) :Result = ID :PB_Object_EnumerateAbort(Objects) :Break :EndIf
              Case #PB_ID_Gadget :If OS_Handle = GadgetID(ID) Or (IsGadget(OS_Handle) And OS_Handle = ID) :Result = ID :PB_Object_EnumerateAbort(Objects) :Break :EndIf
              Case #PB_ID_Image  :If OS_Handle = ImageID(ID)  Or (IsImage(OS_Handle)  And OS_Handle = ID) :Result = ID :PB_Object_EnumerateAbort(Objects) :Break :EndIf
            EndSelect
          Wend
         ProcedureReturn Result
      EndProcedure
     EndModule
    Macro Window(hWnd)
     Get_PB_Object::PB_ID(hWnd)
    EndMacro
    Macro Gadget(hWnd)
     Get_PB_Object::PB_ID(hWnd, Get_PB_Object::#PB_ID_Gadget)
    EndMacro
    Macro Image(hWnd)
     Get_PB_Object::PB_ID(hWnd, Get_PB_Object::#PB_ID_Image)
    EndMacro
    
    Procedure Is_Window(Window)
     ProcedureReturn IsWindow(Get_PB_Object::PB_ID(Window))
    EndProcedure
    Macro IsWindow(Window)
     Is_Window(Window)
    EndMacro
    
    Procedure Is_Gadget(Gadget)
     ProcedureReturn IsGadget(Get_PB_Object::PB_ID(Gadget, Get_PB_Object::#PB_ID_Gadget))
    EndProcedure
    Macro IsGadget(Gadget)
     Is_Gadget(Gadget)
    EndMacro
    
    Procedure Is_Image(Image)
     ProcedureReturn IsImage(Get_PB_Object::PB_ID(Image, Get_PB_Object::#PB_ID_Image))
    EndProcedure
    Macro IsImage(Image)
     Is_Image(Image)
    EndMacro
    
    LoadImage(10, #PB_Compiler_Home + "Examples/Sources/Data/GeeBee2.bmp")
    OpenWindow(10, 100, 100, 500, 300, "testwindow")
    ButtonGadget(10, 10, 10, 100, 20 , "test")
    
    img=10
    gad=10
    win=10
    
    
    Debug "Window = " + Str(Window(WindowID(win)))
    Debug "Gadget = " + Str(Gadget(GadgetID(gad)))
    Debug "Image  = " + Str(Image(ImageID(img))) 
    
    Debug IsWindow(win)
    Debug IsWindow(WindowID(win))

    Debug IsGadget(gad)
    Debug IsGadget(GadgetID(gad))
    
    Debug IsImage(img)
    Debug IsImage(ImageID(img))
    
    Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow  
Post Reply