Einzelnen Beitrag anzeigen

v2afrank

Registriert seit: 9. Mai 2005
Ort: Bocholt
573 Beiträge
 
Delphi XE2 Professional
 
#5

AW: Click auf Taskbarbutton löst onDeactivate onActivate aus

  Alt 22. Nov 2022, 08:10
Ich habe das Ganze noch einmal mit C# nachgebildet (das Gleiche Verhalten) und daraufhin hier folgendes gefunden
You should be using WM_SETFOCUS and WM_KILLFOCUS to determine if your window has the focus.

With regard to WM_ACTIVEATEAPP, both wParam (TRUE/FALSE) and lParam (thread id) are important to the interpretation of that message. Review the docs, which also state "The message is sent to the application whose window is being activated and to the application whose window is being deactivated." So, under certain circumstances, you can expect to receive two WM_ACTIVATEAPP messages - but only one applicable to your thread.

Under certain circumstances, WM_ACTIVATE may also be sent twice, but, similar to WM_ACTIVATEAPP, you must look at all applicable parameters, i.e., wParam AND lParam, to determine the applicability to your app. EDIT: wParam and lParam do NOT have the same meaning for those messages.

As an example, I was able to duplicate the situation by having both App1 and notepad open on the desktop. App1 has the focus. Following a click of the taskbar icon, App1 is minimized and receives:

[columns = message, wParam, lParam]

WM_ACTIVATEAPP False 6856 // window in thread 6856 deactivated. I.e., App1
WM_KILLFOCUS
WM_ACTIVATEAPP True 0 // window in thread 0 activated - I assume notepad. In any case, not applicable to App1??

EDIT: I think the docs are confused (or, at least, confusing). They state: wParam is TRUE if the window is being activated; FALSE if deactivated. That part appears correct.

However, for lParam, the docs say if wParam is TRUE, lParam is the thread that owns the window being deactivated; and if wParam is FALSE, lParam is the thread that owns the window being activated. It appears that the interpretation of lParam should be the thread owner. Period. Without regard to wParam.
  Mit Zitat antworten Zitat