- React on #WM_ACTIVATEAPP when wParam is #True
- lParam now has the previous threadid so enumerate all windows using EnumThreadWindows_()
- Check if WINDOWINFO structure has dwWindowStatus set to #WS_ACTIVECAPTION
- Assume that the found hWnd is the previously activated window...
Can anyone help?
Here is the code I'm using right now:
Code: Select all
EnableExplicit
Enumeration
#Window
#GadgetText
#GadgetList
EndEnumeration
Global EnumThreadWndProcWindowID
#WS_ACTIVECAPTION = $1
Macro ListGadgetScrollEnd(GadgetNr)
SendMessage_(GadgetID(GadgetNr), #WM_VSCROLL, #SB_BOTTOM, #Null)
EndMacro
Macro ListIconGadgetAutoTooltip(GadgetNr)
SendMessage_(GadgetID(GadgetNr), #LVM_SETEXTENDEDLISTVIEWSTYLE, 0, SendMessage_(GadgetID(GadgetNr), #LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0) | #LVS_EX_LABELTIP)
EndMacro
Procedure.s WindowTitle(WindowID)
Protected Length
Protected Title.s = Space(#MAX_PATH)
Length = GetWindowText_(WindowID, @Title, #MAX_PATH)
Title = Left(Title, Length)
ProcedureReturn Title
EndProcedure
Procedure GadgetListAdd(WindowID)
Protected Text.s
; Time:
Text + FormatDate("%hh:%ii:%ss", Date()) + #LF$
; ID:
Text + RSet(Hex(WindowID, #PB_Long), 8, "0") + #LF$
; Title:
Text + WindowTitle(WindowID) + #LF$
; Add new list item and show it:
AddGadgetItem(#GadgetList, -1, Text)
ListGadgetScrollEnd(#GadgetList)
EndProcedure
Procedure EnumThreadWndProc(hWnd, lParam)
Protected wi.WINDOWINFO
Protected Result = #True
Debug "EnumThreadWndProc: " + RSet(Hex(hWnd, #PB_Long), 8, "0") + " - " + WindowTitle(hWnd)
wi\cbSize = SizeOf(WINDOWINFO)
If GetWindowInfo_(hWnd, @wi)
If wi\dwWindowStatus = #WS_ACTIVECAPTION ; Is it active?
EnumThreadWndProcWindowID = hWnd
Result = #False ; Abort enumeration
EndIf
EndIf
ProcedureReturn Result
EndProcedure
Procedure WindowCallback(hWnd, Msg, wParam, lParam)
Protected Result = #PB_ProcessPureBasicEvents
Select Msg
Case #WM_ACTIVATEAPP ; http://msdn.microsoft.com/en-us/library/ms632614(v=vs.85).aspx
If wParam = #True
Debug "EnumThreadWndProc: --------------------"
EnumThreadWindows_(lParam, @EnumThreadWndProc(), #Null) ; Get WindowID from ThreadID
GadgetListAdd(EnumThreadWndProcWindowID) ; Returned WindowID from EnumThreadWndProc()
EndIf
Result = #False
EndSelect
ProcedureReturn Result
EndProcedure
If OpenWindow(#Window, #PB_Ignore, #PB_Ignore, 300, 200, "My Own Window", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
;StickyWindow(#Window, #True)
SetWindowCallback(@WindowCallback(), #Window)
TextGadget(#GadgetText, 10, 10, 280, 20, "Previously activated window:")
ListIconGadget(#GadgetList, 10, 40, 280, 150, "Time", 55, #PB_ListIcon_GridLines | #PB_ListIcon_FullRowSelect | #PB_ListIcon_AlwaysShowSelection)
ListIconGadgetAutoTooltip(#GadgetList)
AddGadgetColumn(#GadgetList, 1, "ID", 65)
AddGadgetColumn(#GadgetList, 2, "Title", 135)
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
