PureBasic Forum
https://www.purebasic.fr/english/

Popup with focus
https://www.purebasic.fr/english/viewtopic.php?f=5&t=72651
Page 1 of 1

Author:  Cezary [ Mon Apr 15, 2019 10:03 pm ]
Post subject:  Popup with focus

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:
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?

Author:  RASHAD [ Tue Apr 16, 2019 9:14 am ]
Post subject:  Re: Popup with focus

Code:
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

Author:  Cezary [ Tue Apr 16, 2019 10:21 am ]
Post subject:  Re: Popup with focus

Yes, this is it. You are an inexhaustible source of knowledge about Windows API.
Thank you.

Author:  Fred [ Tue Apr 16, 2019 10:28 am ]
Post subject:  Re: Popup with focus

That's right, ten years RASHAD is giving awesome Windows API tricks, congrats !

Author:  RASHAD [ Tue Apr 16, 2019 11:50 am ]
Post subject:  Re: Popup with focus

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

Page 1 of 1 All times are UTC + 1 hour
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/