Skip to content

Instantly share code, notes, and snippets.

@tkojitu
Last active July 14, 2022 05:57
Show Gist options
  • Save tkojitu/1c569e4d5f7fd2b5e315630b56d74626 to your computer and use it in GitHub Desktop.
Save tkojitu/1c569e4d5f7fd2b5e315630b56d74626 to your computer and use it in GitHub Desktop.
How to hook EVENT_SYSTEM_FOREGROUND
#include "pch.h"
#include "framework.h"
#include "PopupDemo.h"
#include "MyWnd.h"
#include "PopupDemoDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
BEGIN_MESSAGE_MAP(CPopupDemoApp, CWinApp)
ON_COMMAND(ID_HELP, &CWinApp::OnHelp)
END_MESSAGE_MAP()
CPopupDemoApp::CPopupDemoApp()
{
}
CPopupDemoApp theApp;
static void eventProc(
HWINEVENTHOOK hWinEventHook,
DWORD event,
HWND hwnd,
LONG idObject,
LONG idChild,
DWORD idEventThread,
DWORD dwmsEventTime
) {
OutputDebugString(L"oops!");
}
BOOL CPopupDemoApp::InitInstance()
{
CWinApp::InitInstance();
SetRegistryKey(L"PopupDemo");
SetWinEventHook(
EVENT_SYSTEM_FOREGROUND,
EVENT_SYSTEM_FOREGROUND,
NULL,
eventProc,
0,
0,
WINEVENT_OUTOFCONTEXT | WINEVENT_SKIPOWNPROCESS);
CPopupDemoDlg dlg;
m_pMainWnd = &dlg;
INT_PTR nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
}
else if (nResponse == IDCANCEL)
{
}
else if (nResponse == -1)
{
}
return FALSE;
}
void CPopupDemoApp::ShowPopup()
{
MyWnd* wnd = new MyWnd();
if (!wnd->CreateMe())
return;
wnd->ShowWindow(SW_SHOW);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment