Page 1 of 2
GetDlgCtrlID_ behaves strange (or not?)
Posted: Wed Dec 08, 2021 4:13 am
by jacdelad
Code: Select all
Global wnd,ctrl
wnd=OpenWindow(#PB_Any,0,0,400,300,"Window",#PB_Window_ScreenCentered)
ctrl=TextGadget(#PB_Any,0,0,400,300,"")
Debug ctrl
Debug GadgetID(ctrl)
Debug GetDlgCtrlID_(GadgetID(ctrl))
Shouldn't the last line return the value of ctrl?
Tested on Windows 10 x64, PB x64 6.00 Alpha 5 ASM.
Edit: Works with 32 Bit Compiler, so maybe a problem with return value (.l instead of .i)?
Re: GetDlgCtrlID_ behaves strange (or not?)
Posted: Wed Dec 08, 2021 5:09 am
by BarryG
jacdelad wrote: Wed Dec 08, 2021 4:13 amTested on Windows 10 x64, PB x64 6.00 Alpha 5 ASM
How do you select ASM for the compiler? I just did a clean install of PureBasic v6.00 Beta 1 and I only get this option:

Re: GetDlgCtrlID_ behaves strange (or not?)
Posted: Wed Dec 08, 2021 5:26 am
by jacdelad
That is the ASM-Compiler.

The C-Compiler ist marked as "C Backend".
Re: GetDlgCtrlID_ behaves strange (or not?)
Posted: Wed Dec 08, 2021 6:15 am
by BarryG
Okay, I didn't realise. I don't get any other options though, such as the C backend. Seems a clean install doesn't include it.
Anyway, your code works fine for me with PB 6.00 Beta 1 (64-bit) on my Win 10 Pro (64-bit). Here's my debug output:
You said you're still using Alpha 5? Maybe time to test the Beta?
Re: GetDlgCtrlID_ behaves strange (or not?)
Posted: Wed Dec 08, 2021 6:52 am
by chi
@jacdelad: Your code works fine here... Win7 x64 / a5 asm + c, b1 asm + c (x64 + x86)
@BarryG: Under Preferences/Compiler click on "...", select the pbcompiler
c.exe and press "Add". You should now be able to switch to the C backend

At the moment you have to do this with every new alpha/beta version of PB or you will use the last added C backend.
Re: GetDlgCtrlID_ behaves strange (or not?)
Posted: Wed Dec 08, 2021 7:19 am
by jacdelad
Hm, that's strange. Didn't have this problem yesterday, even with the same compiler. Today TextGadget returned a large number, like a quad. But double converting it returned a smaller one, like a longint. Can't test it right now, I'm in bed and about to go to sleep (after nightshift). Will test it again in the evening.
Thanks for the replies. I don't use Beta 1 yet, I do a lot with maps and it seems to have more problems with them than Alpha 5.
Re: GetDlgCtrlID_ behaves strange (or not?)
Posted: Wed Dec 08, 2021 8:36 am
by BarryG
chi wrote: Wed Dec 08, 2021 6:52 amUnder Preferences/Compiler click on "...", select the pbcompiler
c.exe and press "Add". You should now be able to switch to the C backend

Ah, thanks for reminding me! I forgot about that. So this won't be necessary when v6.00 goes final, right?
Re: GetDlgCtrlID_ behaves strange (or not?)
Posted: Wed Dec 08, 2021 10:51 pm
by jacdelad

...under x64
Re: GetDlgCtrlID_ behaves strange (or not?)
Posted: Wed Dec 08, 2021 11:06 pm
by ChrisR
Strange, it works well here with PB5.73 x86 and x64 and also with PB6.00 beta 1 x64 asm and C Backend
GetDlgCtrlID_(GadgetID(ctrl)) = ctrl
Re: GetDlgCtrlID_ behaves strange (or not?)
Posted: Thu Dec 09, 2021 12:05 am
by jacdelad
Maybe I should switch to Beta 1. As I said, it worked before. Maybe sometimes the 64Bit-Handles are bigger than MaxLong (doesn't work), sometimes not (works)?
Re: GetDlgCtrlID_ behaves strange (or not?)
Posted: Thu Dec 09, 2021 12:34 am
by mk-soft
Fixed for Linux ...
Code: Select all
;-TOP by mk-soft
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Windows
Procedure WindowPB(Handle)
ProcedureReturn GetProp_(Handle, "pb_windowid") - 1
EndProcedure
Procedure GadgetPB(Handle)
ProcedureReturn GetProp_(Handle, "pb_id")
EndProcedure
CompilerCase #PB_OS_Linux
Procedure WindowPB(Handle)
ProcedureReturn g_object_get_data_(Handle, "pb_id" )
EndProcedure
Procedure GadgetPB(Handle)
ProcedureReturn g_object_get_data_(Handle, "pb_id" ) - 1
EndProcedure
CompilerCase #PB_OS_MacOS
Import ""
PB_Window_GetID(hWnd)
EndImport
Procedure WindowPB(Handle)
ProcedureReturn PB_Window_GetID(Handle)
EndProcedure
Procedure GadgetPB(Handle)
ProcedureReturn CocoaMessage(0, Handle, "tag")
EndProcedure
CompilerEndSelect
; ****
Global wnd,ctrl
wnd=OpenWindow(#PB_Any,0,0,400,300,"Window",#PB_Window_ScreenCentered)
ctrl=TextGadget(#PB_Any,0,0,400,300,"")
;Debug DumpObjectMethods(WindowID(wnd), 1)
Debug "Window:"
Debug "wnd = " + wnd
Debug "PB_ID = " + WindowPB(WindowID(wnd))
Debug "Gadget:"
Debug "ctrl = " + ctrl
Debug "PB_ID = " + GadgetPB(GadgetID(ctrl))
Re: GetDlgCtrlID_ behaves strange (or not?)
Posted: Thu Dec 09, 2021 12:54 am
by jacdelad
Hello mk-soft,
thanks for sharing. This is an approach I've never seen before.
I tried my snippet with PB 5.73 x64 and got handles which are lower than MaxLong, so it worked.
Edit: It works, and I feel like I've seen this somewhere before. So I assume I can attach a number of properties to a agdget/window (and PB already does it)? I read the article about the API (
https://docs.microsoft.com/en-us/window ... r-getpropa), but I can't conclude whether I'm free to use it for my own needs or not (like SetGadgetData).
Re: GetDlgCtrlID_ behaves strange (or not?)
Posted: Wed Jan 05, 2022 9:55 pm
by mestnyi
mk-soft wrote: Thu Dec 09, 2021 12:34 am
Fixed for Linux ...
Code: Select all
;-TOP by mk-soft
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Windows
Procedure WindowPB(Handle)
ProcedureReturn GetProp_(Handle, "pb_windowid") - 1
EndProcedure
Procedure GadgetPB(Handle)
ProcedureReturn GetProp_(Handle, "pb_id")
EndProcedure
CompilerCase #PB_OS_Linux
Procedure WindowPB(Handle)
ProcedureReturn g_object_get_data_(Handle, "pb_id" )
EndProcedure
Procedure GadgetPB(Handle)
ProcedureReturn g_object_get_data_(Handle, "pb_id" ) - 1
EndProcedure
CompilerCase #PB_OS_MacOS
Import ""
PB_Window_GetID(hWnd)
EndImport
Procedure WindowPB(Handle)
ProcedureReturn PB_Window_GetID(Handle)
EndProcedure
Procedure GadgetPB(Handle)
ProcedureReturn CocoaMessage(0, Handle, "tag")
EndProcedure
CompilerEndSelect
; ****
Global wnd,ctrl
wnd=OpenWindow(#PB_Any,0,0,400,300,"Window",#PB_Window_ScreenCentered)
ctrl=TextGadget(#PB_Any,0,0,400,300,"")
;Debug DumpObjectMethods(WindowID(wnd), 1)
Debug "Window:"
Debug "wnd = " + wnd
Debug "PB_ID = " + WindowPB(WindowID(wnd))
Debug "Gadget:"
Debug "ctrl = " + ctrl
Debug "PB_ID = " + GadgetPB(GadgetID(ctrl))
It works great on my MacBook, where did you get it? I've searched a lot for something like this.
Re: GetDlgCtrlID_ behaves strange (or not?)
Posted: Thu Jan 06, 2022 12:27 am
by mk-soft
Have a look at the 'SDK' of Purebasic from time to time and there are also some good tips in the forum.
Re: GetDlgCtrlID_ behaves strange (or not?)
Posted: Thu Jan 06, 2022 12:36 pm
by jacdelad
SDK?