Minimize when focus is lost ?

Just starting out? Need help? Post your questions and find answers here.
colguetti
User
User
Posts: 11
Joined: Wed Feb 27, 2013 5:03 am

Minimize when focus is lost ?

Post by colguetti »

Hello everyone! After 3 days of reading, searching and experimenting I´ve decided to give up and ask...

I use a fragment of code made by FSW updated by blbltheworm, that makes a borderless window fullscreen, but when I Alt+Tab my window goes to background, I want it to minimize whenever Alt+Tab is pressed, and if possible to minimize it when the windows key is pressed or Ctrl+Shift+Esc...

Code: Select all

If OpenWindow(0, 0, 0, GetSystemMetrics_(#SM_CXSCREEN), GetSystemMetrics_(#SM_CYSCREEN), "Borderless Screen", #PB_Window_BorderLess | #PB_Window_ScreenCentered) 

  InitSprite() 

  OpenWindowedScreen(WindowID(0), 0, 0, GetSystemMetrics_(#SM_CXSCREEN), GetSystemMetrics_(#SM_CYSCREEN), 1, 0, 0) 

  AddKeyboardShortcut(0, #PB_Shortcut_Escape, 1) 
  
  Repeat
    WaitWindowEvent()
    FlipBuffers()
  Until EventMenu() = 1
EndIf
Thanks in advance !!!
colguetti
User
User
Posts: 11
Joined: Wed Feb 27, 2013 5:03 am

Re: Minimize when focus is lost ?

Post by colguetti »

Sorry, just found the solution !!! I´ll add it here:

Code: Select all

If OpenWindow(0, 0, 0, GetSystemMetrics_(#SM_CXSCREEN), GetSystemMetrics_(#SM_CYSCREEN), "Borderless Screen", #PB_Window_BorderLess | #PB_Window_ScreenCentered) 

  InitSprite() 

  OpenWindowedScreen(WindowID(0), 0, 0, GetSystemMetrics_(#SM_CXSCREEN), GetSystemMetrics_(#SM_CYSCREEN), 1, 0, 0) 

  AddKeyboardShortcut(0, #PB_Shortcut_Escape, 1) 
  
  Repeat
    WaitWindowEvent()
    FlipBuffers()
    If IsScreenActive() = 0
      ShowWindow_(WindowID(0), #SW_SHOWMINIMIZED)
    EndIf
  Until EventMenu() = 1
EndIf
The new cool part is this:

Code: Select all

If IsScreenActive() = 0
      ShowWindow_(WindowID(0), #SW_SHOWMINIMIZED)
    EndIf
This way, whenever you key in a windows shortcut like Alt+Tab, Ctrl+Esc or even the Windows key the application minimizes itself...

Special thanks goes to djes and AndyMK who nailed the problem in such a wonderful way!

Thank you all !!!
Post Reply