Page 1 of 2
Re: by the handle is a gadget
Posted: Wed Feb 26, 2014 10:49 pm
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
Re: by the handle is a gadget
Posted: Thu Feb 27, 2014 5:29 am
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. .
Re: by the handle is a gadget
Posted: Thu Feb 27, 2014 9:21 am
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
Re: by the handle is a gadget
Posted: Thu Feb 27, 2014 9:48 am
by ts-soft
You should change line 61 to:
Code: Select all
LoadImage(12, #PB_Compiler_Home + "examples/sources/Data/Geebee2.bmp")

Re: by the handle is a gadget
Posted: Thu Feb 27, 2014 6:34 pm
by Bisonte
ts-soft wrote:You should change line 61 to:
Code: Select all
LoadImage(12, #PB_Compiler_Home + "examples/sources/Data/Geebee2.bmp")

aaaarg these %$&§" Slashes (Done)
By the way... are there more "PB.xxx.Objects", I can put in this procedure ?
Re: by the handle is a gadget
Posted: Thu Feb 27, 2014 6:37 pm
by ts-soft
Bisonte wrote:aaaarg these %$&§" Slashes

Not only slashes, linux is casesensitiv!
Re: by the handle is a gadget
Posted: Thu Feb 27, 2014 6:38 pm
by Bisonte
ts-soft wrote:Bisonte wrote:aaaarg these %$&§" Slashes

Not only slashes, linux is casesensitiv!
On my windows installation I copy the path from the explorer window... with the capital letters....
Re: by the handle is a gadget
Posted: Thu Feb 27, 2014 6:44 pm
by ts-soft
Don't use the Windows-Explorer, that is not quite fairly to his users

Re: by the handle is a gadget
Posted: Thu Feb 27, 2014 7:29 pm
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.
Re: by the handle is a gadget
Posted: Thu Feb 27, 2014 8:59 pm
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