Grouping function for user32-handles
Grouping function for user32-handles
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.
A function eg. ControlID (...) would be great, to handle all 4 ID-Types in only one function.
Best regards,
Frank
Frank
Re: Grouping function for user32-handles
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

Last edited by xorc1zt on Sat Aug 25, 2012 1:37 pm, edited 1 time in total.
Re: Grouping function for user32-handles
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
Re: Grouping function for user32-handles
This code can't work correct! ID's only unique in one object!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
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.

Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Re: Grouping function for user32-handles
#PB_Any return a unique id no ?ts-soft wrote:This code can't work correct! ID's only unique in one object!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
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:
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)
the handles seem uniqueWaiting 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.
Re: Grouping function for user32-handles
This a pointer, the should unique.xorc1zt wrote: #PB_Any return a unique id no ?
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.

Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

-
- Addict
- Posts: 2344
- Joined: Mon Jun 02, 2003 9:16 am
- Location: Germany
- Contact:
Re: Grouping function for user32-handles
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.ts-soft wrote:This a pointer, the should unique.xorc1zt wrote: #PB_Any return a unique id no ?
bye,
Daniel
Daniel
Re: Grouping function for user32-handles
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
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)

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.

Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
