Page 1 of 1

Receive notice that a window was minimzied?

Posted: Sun Jun 16, 2013 6:40 pm
by jassing
Is there a way to hook into a window that is not your own to know it was minimized? Sort of adding a callback to a window that is not your own?

Code: Select all

global ptr
Procedure SetWinCB(hWnd)
 	If IsWindow_(hwnd)
 		ptr=GetWindowLong_(hwnd,#GWL_WNDPROC) ; capture the old callback ptr
 		Debug "ORG PTR "+Str(ptr)
   Debug "SWCB"
   Debug SetWindowLong_(hwnd,#GWL_WNDPROC,@WinCallback()) ; set the new callback ptr
 Else
 	Debug "not a window"
 EndIf
EndProcedure
I call SetwinCB() with a valid window handle, and wincallback is defined, but it never gets called and SetWindowLog_() always returns 0

Re: Receive notice that a window was minimzied?

Posted: Sun Jun 16, 2013 7:15 pm
by RASHAD
You can try

Code: Select all

Procedure AlertThread(Parameter)
  Repeat
      hWnd = FindWindow_("??????",0)
  Until hWnd
  Repeat
    If IsIconic_(hWnd)
       MessageRequester("Info", "Window Minimized", 0)
    EndIf
    Delay(100)
  ForEver
EndProcedure

CreateThread(@AlertThread(), 154)

Re: Receive notice that a window was minimzied?

Posted: Sun Jun 16, 2013 8:17 pm
by jassing
thanks -- but I was hoping for a callback solution, mostly to avoid tight loops. I already have a similar version running.
Cheers
-josh

Re: Receive notice that a window was minimzied?

Posted: Sat Jul 20, 2013 10:08 am
by JHPJHP
*** post was a little bloated (I kept adding to it) :) so I edited it down to a very basic example ***

Code: Select all

Global WM_SHELLHOOKMESSAGE

Prototype.b protoDeregisterShellHookWindow(hWnd)
Global DeregisterShellHookWindow.protoDeregisterShellHookWindow

Structure SHELLHOOKINFO
  hWnd.l
  rc.RECT
EndStructure

Procedure WindowProc(hWnd, Msg, wParam, lParam)
  If Msg And Msg = WM_SHELLHOOKMESSAGE 
    If wParam = #HSHELL_GETMINRECT
      sHook.SHELLHOOKINFO
      CopyMemory(lParam, sHook, SizeOf(sHook))
      hWindow = sHook\hWnd
    Else
      hWindow = lParam
    EndIf
    lpwndpl.WINDOWPLACEMENT
    lpwndpl\Length = SizeOf(lpwndpl)
    GetWindowPlacement_(hWindow, @lpwndpl)
    
    Select lpwndpl\showCmd
      Case 0
        Debug Str(hWindow) + ": Hidden"
      Case 1
        Debug Str(hWindow) + ": Restored"
      Case 2
        Debug Str(hWindow) + ": Minimized"
      Case 3
        Debug Str(hWindow) + ": Maximized"
      Default
        Debug Str(hWindow) + ": Other: " + Str(lpwndpl\showCmd)
    EndSelect
  EndIf
  ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure

If OpenWindow(0, 0, 0, 200, 100, "Shell Hook Window", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  user32 = OpenLibrary(#PB_Any, "user32.dll")
  
  If IsLibrary(user32)
    DeregisterShellHookWindow = GetFunction(user32, "DeregisterShellHookWindow")
    
    If DeregisterShellHookWindow
      If RegisterShellHookWindow_(WindowID(0))
        WM_SHELLHOOKMESSAGE = RegisterWindowMessage_("SHELLHOOK")
        SetWindowCallback(@WindowProc())
        Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
        DeregisterShellHookWindow(WindowID(0))
      EndIf
    EndIf
    CloseLibrary(user32)
  EndIf
EndIf

Re: Receive notice that a window was minimzied?

Posted: Sat Jul 20, 2013 10:15 am
by PB
> to avoid tight loops

As long as you don't hog the CPU or other system resources,
there's nothing wrong with tight loops. It's what PCs do. ;)