Page 1 of 1

Popup with focus

Posted: Mon Apr 15, 2019 10:03 pm
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?

Re: Popup with focus

Posted: Tue Apr 16, 2019 9:14 am
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

Re: Popup with focus

Posted: Tue Apr 16, 2019 10:21 am
by Cezary
Yes, this is it. You are an inexhaustible source of knowledge about Windows API.
Thank you.

Re: Popup with focus

Posted: Tue Apr 16, 2019 10:28 am
by Fred
That's right, ten years RASHAD is giving awesome Windows API tricks, congrats !

Re: Popup with focus

Posted: Tue Apr 16, 2019 11:50 am
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