canvas focus/lostfocus events

Share your advanced PureBasic knowledge/code with the community.
mestnyi
Addict
Addict
Posts: 1109
Joined: Mon Nov 25, 2013 6:41 am

canvas focus/lostfocus events

Post by mestnyi »

Code: Select all

Procedure Open( ID, flag=0 )
   Static X,Y
   OpenWindow( ID, 300+X,150+Y,170,170,"window_"+Str(ID), #PB_Window_SystemMenu|flag)
   CanvasGadget( ID, 10,10,150,150, #PB_Canvas_Keyboard )
   SetActiveGadget( ID )
   X + 100
   Y + 100
EndProcedure


Open(1, #PB_Window_NoActivate)
Open(2, #PB_Window_NoActivate)
;Open(3, #PB_Window_NoActivate)

Define gadget, down
Repeat
   event = WaitWindowEvent(1)
   
   Select event
      Case #PB_Event_ActivateWindow
         Debug "["+EventWindow( )+"] active"
         
      Case #PB_Event_DeactivateWindow
         Debug " --- "
         Debug "["+EventWindow( )+"] deactive"
         
      Case #PB_Event_Gadget
         Select EventType()
            Case #PB_EventType_Focus
               Debug "["+EventGadget( )+"] focus"
               
            Case #PB_EventType_LostFocus
               Debug "["+EventGadget( )+"] lostfocus"
               
            Case #PB_EventType_LeftButtonDown
               Debug "["+EventGadget( )+"] down"
               
            Case #PB_EventType_LeftButtonUp
               Debug "["+EventGadget( )+"] up"
               
         EndSelect
         
   EndSelect
   
Until event = #PB_Event_CloseWindow
Last edited by mestnyi on Mon Nov 03, 2025 1:01 pm, edited 11 times in total.
User avatar
jacdelad
Addict
Addict
Posts: 2044
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: Fixed canvas events

Post by jacdelad »

GetDlgCtrlID_ causes problems on x64 systems an PB 6.0 Alpha 5, however, mk-soft pointed out that "GetProp_(Handle, "pb_id")" works as intended (I use it since then without problems. Just to mention, don't know if it will be relevant in the future.
https://www.purebasic.fr/english/viewto ... 62#p577962
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
mestnyi
Addict
Addict
Posts: 1109
Joined: Mon Nov 25, 2013 6:41 am

Re: Fixed canvas focus/lostfocus events

Post by mestnyi »

jacdelad wrote: Wed Jan 05, 2022 4:13 pm GetDlgCtrlID_ causes problems on x64 systems an PB 6.0 Alpha 5, however, mk-soft pointed out that "GetProp_(Handle, "pb_id")" works as intended (I use it since then without problems. Just to mention, don't know if it will be relevant in the future.
viewtopic.php?p=577962#p577962
Thank you, I re-uploaded the code, thank you, it turned out as I wanted.
Last edited by mestnyi on Mon Nov 03, 2025 1:03 pm, edited 1 time in total.
Rinzwind
Enthusiast
Enthusiast
Posts: 703
Joined: Wed Mar 11, 2009 4:06 pm
Location: NL

Re: Fixed canvas events

Post by Rinzwind »

jacdelad wrote: Wed Jan 05, 2022 4:13 pm GetDlgCtrlID_ causes problems on x64 systems an PB 6.0 Alpha 5, however, mk-soft pointed out that "GetProp_(Handle, "pb_id")" works as intended (I use it since then without problems. Just to mention, don't know if it will be relevant in the future.
https://www.purebasic.fr/english/viewto ... 62#p577962
Apparently fixed in beta 4? Can't reproduce.
mestnyi
Addict
Addict
Posts: 1109
Joined: Mon Nov 25, 2013 6:41 am

Re: canvas focus/lostfocus events

Post by mestnyi »

viewtopic.php?p=579118#p579118
When you click on the gadget in the first window

Code: Select all

 ; tested on the windows
[1] active
[1] focus
 --- 
[1] deactive
[2] active
[1] lostfocus
[2] focus
 --- 
[2] deactive
[2] lostfocus
[1] focus
[1] active
[1] lostfocus
[1] focus
[1] down
[1] up
Isn't this a mistake, shouldn't there be a different sequence of events?
Post Reply