Aero Snap

Windows specific forum
cas
Enthusiast
Enthusiast
Posts: 597
Joined: Mon Nov 03, 2008 9:56 pm

Aero Snap

Post by cas »

http://blogs.msdn.com/e7/archive/2009/0 ... -snap.aspx

With purebasic application all features of aero snap work except this one:
  • Vertically maximize a window with Aero Snap by resizing the window to the edge of the screen
My question: How to make vertical maximize to work with purebasic application? I'm guessing that i will need callback to detect resize to edge of the screen and then return something to OS that will handle this feature...
It's not working with default window created like this:

Code: Select all

If OpenWindow(0, 100, 200, 195, 260, "PureBasic Window", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget)
  
  Repeat
    Event = WaitWindowEvent()
    
    If Event = #PB_Event_CloseWindow
      Quit = 1
    EndIf
    
  Until Quit = 1
  
EndIf
Thanks for any help
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4997
Joined: Sun Apr 12, 2009 6:27 am

Post by RASHAD »

Hello cas

Sol. #1

Code: Select all

Global wr.RECT

Procedure WinProc(hwnd, msg, wparam, lparam)
 GetWindowRect_(WindowID(0), wr)
  result=#PB_ProcessPureBasicEvents
  Select msg
    Case #WM_SIZE,#WM_SIZING
      If wr\top = 0
        mouse_event_(#MOUSEEVENTF_LEFTDOWN,0,0,0,0)
        mouse_event_(#MOUSEEVENTF_LEFTUP	,0,0,0,0)
      EndIf
  EndSelect
  ProcedureReturn result
EndProcedure


hwnd = OpenWindow(0, 100, 200, 195, 260, "PureBasic Window", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget)
SetWindowCallback(@WinProc(),0) 
  
  Repeat 
    Event = WaitWindowEvent() 
    
    If Event = #PB_Event_CloseWindow 
      Quit = 1 
    EndIf 
    
  Until Quit = 1
Sol. #2

Code: Select all

Procedure WindowCallback(Window, Message, wParam, lParam) 
  Select Message
    Case #WM_DESTROY 
      PostQuitMessage_(0) 
      Result  = 0 
    Default 
      Result  = DefWindowProc_(Window, Message, wParam, lParam) 
  EndSelect 
  ProcedureReturn Result 
EndProcedure 

#Style  = #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget
#StyleEx  = #WS_EX_ACCEPTFILES    

WinClass.s  = "Default" 
w.WNDCLASSEX
w\cbsize  = SizeOf(WNDCLASSEX) 
w\lpfnWndProc  = @WindowCallback()
w\hCursor  = LoadCursor_(0, #IDC_ARROW)
w\hbrBackground  = #COLOR_WINDOW
w\lpszClassName  = @WinClass 
RegisterClassEx_(@w) 

hwnd  = CreateWindowEx_(#StyleEx, WinClass, "Aero Snap Test",#Style, (GetSystemMetrics_(#SM_CXSCREEN)-640)/2,(GetSystemMetrics_(#SM_CYSCREEN)-480)/2, 640, 480, 0, 0, 0, 0)

ShowWindow_(hwnd,  #SW_SHOWDEFAULT) 

While GetMessage_(msg.MSG, #Null, 0, 0 ) 
  TranslateMessage_(msg) 
  DispatchMessage_(msg) 
Wend
Please check

Have a good day
RASHAD
cas
Enthusiast
Enthusiast
Posts: 597
Joined: Mon Nov 03, 2008 9:56 pm

Post by cas »

Second one is working. The only way is to create window with CreateWindowEx_() like you did in second example.
Thanks
:wink:
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4997
Joined: Sun Apr 12, 2009 6:27 am

Post by RASHAD »

You mean it does not work at all or what?
It is not perfect I know(not according to ms planned) but it works here somehow
Win 7 RTM x64
PB v4.31 x64

and again with some modifications

Code: Select all

Global wr.RECT,desk.RECT

Procedure WinProc(hwnd, msg, wparam, lparam)
  GetWindowRect_(WindowID(0), wr)  
  result=#PB_ProcessPureBasicEvents
  Select msg
    Case #WM_SIZE,#WM_SIZING
      If wr\top = 0 Or wr\bottom = desk\bottom - 20
        mouse_event_(#MOUSEEVENTF_LEFTDOWN,0,0,0,0)
        mouse_event_(#MOUSEEVENTF_LEFTUP	,0,0,0,0)
      EndIf
      
    Case #WM_MOUSELEAVE
        mouse_event_(#MOUSEEVENTF_LEFTDOWN,0,0,0,0)
        mouse_event_(#MOUSEEVENTF_LEFTUP	,0,0,0,0)
  
  EndSelect
  ProcedureReturn result
EndProcedure

hwnd = OpenWindow(0, 100, 200, 195, 260, "PureBasic Window", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget)
SystemParametersInfo_(#SPI_GETWORKAREA, 0, @desk.RECT, 0)
SetWindowCallback(@WinProc(),0) 
  
  Repeat 
    Event = WaitWindowEvent() 
    
    If Event = #PB_Event_CloseWindow 
      Quit = 1 
    EndIf 
    
  Until Quit = 1
Let me know cas if it is not working totally or what
cas
Enthusiast
Enthusiast
Posts: 597
Joined: Mon Nov 03, 2008 9:56 pm

Post by cas »

It's working but it is instantaneously resizing window. It should wait for me to release mouse button and give aero outline preview of resized window.
Your snippet with CreateWindowEx_() works perfectly.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4997
Joined: Sun Apr 12, 2009 6:27 am

Post by RASHAD »

Thank you cas
I know it is not perfect but I was worry @ simulating Mouse click code


Have a good day mate

RASHAD
Post Reply