Skip to content

Instantly share code, notes, and snippets.

@tkojitu
Created March 1, 2022 00:42
Show Gist options
  • Save tkojitu/a43a5c955589690cac96359e8064193a to your computer and use it in GitHub Desktop.
Save tkojitu/a43a5c955589690cac96359e8064193a to your computer and use it in GitHub Desktop.
#include "pch.h"
#include "framework.h"
#include "ChildProc.h"
#include "ChildProcDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
BEGIN_MESSAGE_MAP(CChildProcApp, CWinApp)
ON_COMMAND(ID_HELP, &CWinApp::OnHelp)
END_MESSAGE_MAP()
CChildProcApp::CChildProcApp()
{
}
CChildProcApp theApp;
BOOL CChildProcApp::InitInstance()
{
CWinApp::InitInstance();
SetRegistryKey(L"ChildProc");
CChildProcDlg * dlg = new CChildProcDlg();
m_pMainWnd = dlg;
dlg->Create(IDD_CHILDPROC_DIALOG);
dlg->ShowWindow(SW_SHOW);
MSG msg;
BOOL ret;
while ((ret = GetMessage(&msg, nullptr, 0, 0)) != 0) {
if (ret == -1)
continue;
TranslateMessage(&msg);
DispatchMessage(&msg);
if (msg.message == WM_APP + 1) {
AfxMessageBox(L"Gatcha!");
dlg->DestroyWindow();
return FALSE;
}
}
return (BOOL)msg.wParam;
}
#include "pch.h"
#include "framework.h"
#include "WndMsgComm.h"
#include "WndMsgCommDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
BEGIN_MESSAGE_MAP(CPostThreadMessageDemo, CWinApp)
ON_COMMAND(ID_HELP, &CWinApp::OnHelp)
END_MESSAGE_MAP()
CPostThreadMessageDemo::CPostThreadMessageDemo()
{
}
CPostThreadMessageDemo theApp;
BOOL CPostThreadMessageDemo::InitInstance()
{
CWinApp::InitInstance();
SetRegistryKey(L"WndMsgComm");
wchar_t path[] = L"C:\\Users\\b05l5008\\source\\repos\\WndMsgComm\\x64\\Debug\\ChildProc.exe";
STARTUPINFO si;
::GetStartupInfo(&si);
if (!::CreateProcess(NULL, path, NULL, NULL, FALSE, NULL, NULL, NULL, &si, &m_pi)) {
AfxMessageBox(L"CreateProcess failed");
return FALSE;
}
CWndMsgCommDlg dlg;
m_pMainWnd = &dlg;
INT_PTR nResponse = dlg.DoModal();
if (nResponse == IDOK) {
BOOL ret = ::PostThreadMessage(m_pi.dwThreadId, WM_APP + 1, 0, 0);
if (!ret) {
AfxMessageBox(L"PostThreadMessage failed");
}
}
else if (nResponse == IDCANCEL) {
}
else if (nResponse == -1) {
}
return FALSE;
}
BOOL CPostThreadMessageDemo::ExitInstance()
{
CloseHandle(m_pi.hThread);
CloseHandle(m_pi.hProcess);
return TRUE;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment