Page 1 of 1

Grouping function for user32-handles

Posted: Sat Aug 25, 2012 12:06 pm
by Frabbing
Sometimes it would be nice if there was a uniform function for Windows-Controls. WindowID, GadgetID, StatusbarID and ToolbarID are basically the same things.
A function eg. ControlID (...) would be great, to handle all 4 ID-Types in only one function.

Re: Grouping function for user32-handles

Posted: Sat Aug 25, 2012 1:35 pm
by xorc1zt
i don't recommend this but

Code: Select all

Procedure.i GetHandle (id.i)
    If (IsWindow(id))
        ProcedureReturn WindowID(id)
    ElseIf (IsFont(id))
        ProcedureReturn FontID(id)
    ElseIf (IsFile(id))
        ProcedureReturn FileID(id)
    ElseIf (IsThread(id))
        ProcedureReturn ThreadID(id)
    ElseIf (IsGadget(id))
        ProcedureReturn GadgetID(id)
    ElseIf (IsToolBar(id))
        ProcedureReturn ToolBarID(id)
    ElseIf (IsStatusBar(id)
        ProcedureReturn StatusBarID(id)
    EndIf
    
    ProcedureReturn 0
EndProcedure
:lol:

Re: Grouping function for user32-handles

Posted: Sat Aug 25, 2012 1:36 pm
by Josh
It would be nice, if there would be only be the ....ID and not have to use one time the ....Nr and the next time the ....ID.

Re: Grouping function for user32-handles

Posted: Sat Aug 25, 2012 1:48 pm
by ts-soft
xorc1zt wrote:i don't recommend this but

Code: Select all

Procedure.i GetHandle (id.i)
    If (IsWindow(id))
        ProcedureReturn WindowID(id)
    ElseIf (IsFont(id))
        ProcedureReturn FontID(id)
    ElseIf (IsFile(id))
        ProcedureReturn FileID(id)
    ElseIf (IsThread(id))
        ProcedureReturn ThreadID(id)
    ElseIf (IsGadget(id))
        ProcedureReturn GadgetID(id)
    ElseIf (IsToolBar(id))
        ProcedureReturn ToolBarID(id)
    ElseIf (IsStatusBar(id)
        ProcedureReturn StatusBarID(id)
    EndIf
    
    ProcedureReturn 0
EndProcedure
:lol:
This code can't work correct! ID's only unique in one object!

You can have ID 0 for Window and for Gadget and for File.

It make sense to have WindowID(), GadgetID() and so on. This is required for the object-system from PB

// edit:
see here: http://www.purebasic.com/documentation/ ... jects.html
Overview of the different PureBasic objects

Re: Grouping function for user32-handles

Posted: Sat Aug 25, 2012 2:07 pm
by xorc1zt
ts-soft wrote:
xorc1zt wrote:i don't recommend this but

Code: Select all

Procedure.i GetHandle (id.i)
    If (IsWindow(id))
        ProcedureReturn WindowID(id)
    ElseIf (IsFont(id))
        ProcedureReturn FontID(id)
    ElseIf (IsFile(id))
        ProcedureReturn FileID(id)
    ElseIf (IsThread(id))
        ProcedureReturn ThreadID(id)
    ElseIf (IsGadget(id))
        ProcedureReturn GadgetID(id)
    ElseIf (IsToolBar(id))
        ProcedureReturn ToolBarID(id)
    ElseIf (IsStatusBar(id)
        ProcedureReturn StatusBarID(id)
    EndIf
    
    ProcedureReturn 0
EndProcedure
:lol:
This code can't work correct! ID's only unique in one object!

You can have ID 0 for Window and for Gadget and for File.

It make sense to have WindowID(), GadgetID() and so on. This is required for the object-system from PB
#PB_Any return a unique id no ?

edit:

Code: Select all

Define testA.i = OpenWindow(#PB_Any, 10, 10, 100, 100, "hello")
Define testB.i = LoadFont(#PB_Any, "courrier", 10)
Define testC.i = ButtonGadget(#PB_Any, 10, 10, 200, 20, "Standard Button")

Debug testA
Debug testB
Debug testC

Debug WindowID(testA)
Debug FontID(testB)
Debug GadgetID(testC)
output here
Waiting for executable to start...
Executable type: Windows - x64 (64bit, Unicode)
Executable started.
[Debug] 30088032
[Debug] 30088224
[Debug] 30088256

[Debug] 133122
[Debug] -1257633389
[Debug] 133116
The Program execution has finished.
the handles seem unique

Re: Grouping function for user32-handles

Posted: Sat Aug 25, 2012 2:14 pm
by ts-soft
xorc1zt wrote: #PB_Any return a unique id no ?
This a pointer, the should unique.

Re: Grouping function for user32-handles

Posted: Sat Aug 25, 2012 2:53 pm
by DarkDragon
ts-soft wrote:
xorc1zt wrote: #PB_Any return a unique id no ?
This a pointer, the should unique.
This won't be guaranteed, as Fred could change the system in the future and use them as pointer offsets for example. E.g. he could create separated blocks of memory for Windows, Gadgets, ... and return offsets to the start of those blocks for better garbage collection at the end or whatever. Then they wouldn't be unique anymore. You should never care if those are globally unique over all controls.

Re: Grouping function for user32-handles

Posted: Sat Aug 25, 2012 5:48 pm
by xorc1zt
simpler

Code: Select all

Macro GetHandle(id)
    PeekI(id)
EndMacro

Define testA.i = OpenWindow(#PB_Any, 10, 10, 100, 100, "hello")
Define testB.i = LoadFont(#PB_Any, "courrier", 10)
Define testC.i = ButtonGadget(#PB_Any, 10, 10, 200, 20, "Standard Button")

Debug Str(WindowID(testA))+" : "+Str(GetHandle(testA))
Debug Str(FontID(testB))+" : "+Str(GetHandle(testB))
Debug Str(GadgetID(testC))+" : "+Str(GetHandle(testC))
Waiting for executable to start...
Executable type: Windows - x64 (64bit, Unicode)
Executable started.
[Debug] 133344 : 133344
[Debug] 1779044157 : 1779044157
[Debug] 133312 : 133312
The Program execution has finished.

Re: Grouping function for user32-handles

Posted: Sat Aug 25, 2012 6:03 pm
by ts-soft
simpler:

Code: Select all

Define *testA.Integer = OpenWindow(#PB_Any, 10, 10, 100, 100, "hello")
Define *testB.Integer = LoadFont(#PB_Any, "courrier", 10)
Define *testC.Integer= ButtonGadget(#PB_Any, 10, 10, 200, 20, "Standard Button")

Debug Str(WindowID(*testA))+" : "+Str(*testA\i)
Debug Str(FontID(*testB))+" : "+Str(*testB\i)
Debug Str(GadgetID(*testC))+" : "+Str(*testC\i)
:wink: