Grouping function for user32-handles

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Frabbing
User
User
Posts: 10
Joined: Mon May 09, 2011 7:59 pm
Contact:

Grouping function for user32-handles

Post 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.
Best regards,
Frank
xorc1zt
Enthusiast
Enthusiast
Posts: 276
Joined: Sat Jul 09, 2011 7:57 am

Re: Grouping function for user32-handles

Post 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:
Last edited by xorc1zt on Sat Aug 25, 2012 1:37 pm, edited 1 time in total.
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

Re: Grouping function for user32-handles

Post 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.
sorry for my bad english
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Grouping function for user32-handles

Post 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
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
xorc1zt
Enthusiast
Enthusiast
Posts: 276
Joined: Sat Jul 09, 2011 7:57 am

Re: Grouping function for user32-handles

Post 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
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Grouping function for user32-handles

Post by ts-soft »

xorc1zt wrote: #PB_Any return a unique id no ?
This a pointer, the should unique.
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
DarkDragon
Addict
Addict
Posts: 2344
Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:

Re: Grouping function for user32-handles

Post 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.
bye,
Daniel
xorc1zt
Enthusiast
Enthusiast
Posts: 276
Joined: Sat Jul 09, 2011 7:57 am

Re: Grouping function for user32-handles

Post 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.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Grouping function for user32-handles

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