Popup with focus

Windows specific forum
Cezary
User
User
Posts: 89
Joined: Sun Feb 12, 2017 2:31 pm

Popup with focus

Post by Cezary »

Dear forum users,

I need in my code to get popup dialog with focus as result of selected key sequence. The focus is important because I want the dialog to disappear when it loses focus I tried something like this (a left Shift + left WinKey recalls popup):

Code: Select all

Procedure PopupDlg()
  
  If #False = OpenWindow(0,
                         300, 300, 
                         150, 150, 
                         "Popup test",
                         #PB_Window_Tool)
    ProcedureReturn
  EndIf
  
  SetWindowPos_(WindowID(0),
                #HWND_TOPMOST,
                0, 0, 0, 0,
                #SWP_NOMOVE |
                #SWP_NOSIZE); 
  SetActiveWindow_(WindowID(0))
  
  Repeat
  Until #PB_Event_DeactivateWindow = WaitWindowEvent()
  
  CloseWindow(0)
  
EndProcedure

cnt = 0

Repeat
  Delay(100)
  cnt = cnt + 1
  If GetKeyState_(#VK_LWIN) & $8000
    If #False = KeyPrev
    ; Left WinKey pressed
      KeyPrev = #True
      If GetKeyState_(#VK_LSHIFT) & $8000
        ; With Shift
        PopupDlg()
      ElseIf GetKeyState_(#VK_LCONTROL) & $8000
        ; With Ctrl
        End
      EndIf
    EndIf
  Else
    KeyPrev = #False
  EndIf  
Until cnt = 600 ; One minute limit
Unfortunately I can't get the popup with focus in this way. Can anyone help me with this, please?
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4636
Joined: Sun Apr 12, 2009 6:27 am

Re: Popup with focus

Post by RASHAD »

Code: Select all

Procedure PopupDlg()
 
  If #False = OpenWindow(0,
                         300, 300,
                         150, 150,
                         "Popup test",
                         #PB_Window_Tool)
    ProcedureReturn
  EndIf
 
  SetWindowPos_(WindowID(0),
                #HWND_TOPMOST,
                0, 0, 0, 0,
                #SWP_NOMOVE |
                #SWP_NOSIZE)
                SendMessage_(#HWND_BROADCAST, #WM_SYSCOMMAND, #SC_HOTKEY, WindowID(0))
  Repeat
  Until #PB_Event_DeactivateWindow = WaitWindowEvent()
 
  CloseWindow(0)
 
EndProcedure

cnt = 0

Repeat
  Delay(100)
  cnt = cnt + 1
  If GetKeyState_(#VK_LWIN) & $8000
    If #False = KeyPrev
    ; Left WinKey pressed
      KeyPrev = #True
      If GetKeyState_(#VK_LSHIFT) & $8000
        ; With Shift
        PopupDlg() 
   
      ElseIf GetKeyState_(#VK_LCONTROL) & $8000
        ; With Ctrl
        End
      EndIf
    EndIf
  Else
    KeyPrev = #False
  EndIf 
Until cnt = 600 ; One minute limit
Egypt my love
Cezary
User
User
Posts: 89
Joined: Sun Feb 12, 2017 2:31 pm

Re: Popup with focus

Post by Cezary »

Yes, this is it. You are an inexhaustible source of knowledge about Windows API.
Thank you.
Fred
Administrator
Administrator
Posts: 16617
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Popup with focus

Post by Fred »

That's right, ten years RASHAD is giving awesome Windows API tricks, congrats !
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4636
Joined: Sun Apr 12, 2009 6:27 am

Re: Popup with focus

Post by RASHAD »

Thanks Cezary
Thanks Fred & Team for the wonderful PureBasic project
I always have 2 to 4 ways to solve the problem
With PB I test which one will do and which one is the best in no time
Can not do that with any other programming language
Thanks again Fred
Egypt my love
Post Reply