It is currently Wed Sep 18, 2019 8:59 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Popup with focus
PostPosted: Mon Apr 15, 2019 10:03 pm 
Offline
User
User

Joined: Sun Feb 12, 2017 2:31 pm
Posts: 38
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?


Top
 Profile  
Reply with quote  
 Post subject: Re: Popup with focus
PostPosted: Tue Apr 16, 2019 9:14 am 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3395
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

_________________
Egypt my love


Top
 Profile  
Reply with quote  
 Post subject: Re: Popup with focus
PostPosted: Tue Apr 16, 2019 10:21 am 
Offline
User
User

Joined: Sun Feb 12, 2017 2:31 pm
Posts: 38
Yes, this is it. You are an inexhaustible source of knowledge about Windows API.
Thank you.


Top
 Profile  
Reply with quote  
 Post subject: Re: Popup with focus
PostPosted: Tue Apr 16, 2019 10:28 am 
Offline
Administrator
Administrator

Joined: Fri May 17, 2002 4:39 pm
Posts: 13612
Location: France
That's right, ten years RASHAD is giving awesome Windows API tricks, congrats !


Top
 Profile  
Reply with quote  
 Post subject: Re: Popup with focus
PostPosted: Tue Apr 16, 2019 11:50 am 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3395
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


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye