I am having an issue with trying to receive a callback when switching to a popup window that gets created in a new thread within a Maya plugin. I spawn the new thread, then create a window, like so:
hWnd = CreateWindow(
"Sample", "Sample", WS_POPUP | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, NULL, NULL, hInstance, NULL);
Then I have what seems like it should be a pretty straightforward window procdure to determine if the created window has gotten a foreground event:
windowsEventHook = SetWinEventHook(
EVENT_SYSTEM_FOREGROUND, EVENT_SYSTEM_FOREGROUND, // Range of events (4 to 5).
NULL, // Handle to DLL.
selectMayaObjectOnActiveWindowCallback, // The callback.
0, 0, // Process and thread IDs of interest (0 = all)
WINEVENT_OUTOFCONTEXT | WINEVENT_SKIPOWNPROCESS); // Flags.
This procedure runs as expected whenever a window is selected via the thumbnail:
void CALLBACK selectMayaObjectOnActiveWindowCallback(HWINEVENTHOOK hook, DWORD event, HWND hwnd,
LONG idObject, LONG idChild,
DWORD dwEventThread, DWORD dwmsEventTime)
The issue, however, is that idObject
, idChild
, and dwEventThread
are the same if I click on the original thumbnail window containing Maya, or the Thumbnail containing the window I have created.
In addition, I am able to find the created window by title, but when comparing it to the HWND
instance that is passed in, they are not the same when clicking on my window.
I have tried limiting the callback to my process ID by passing in the process ID via GetCurrentThreadId()
, as well as compare them using the title. However, the title appears to be listed as TaskListThumbnailWnd
.
I have also tried several variations of getActiveWindow()
, getForegroundWindow()
, GetWindow(hwnd, GW_ENABLEDPOPUP)
, and getFocus()
.
Is there a way I can directly set an onClick
listener from an HWND
instance, or determine if a popup window has been clicked?
The flags you pass to SetWinEventHook() are surely wrong, if the add-in is built as a DLL and loaded into the Maya process. You shouldn’t get any callback at all, TaskListThumbnailWnd belongs to Explorer. Use WINEVENT_INCONTEXT.
hmmm no the plugin is built as an .mll. Switching the flag to incontext I get no alert at all when switching between the two.
The file extension doesn’t make a difference. This is still presumably a DLL, and you must pass that module’s base address into
SetWinEventHook()
. You can store it from yourDllMain()
implementation, discover it usingGetModuleHandleExW
with theGET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS
flag, or make use of the__ImageBase
linker pseudovariable.