我看错地方了。该消息显示在对话框的父窗口的窗口过程中,这是工作代码:
#include <windows.h>
#include <iostream>
UINT uFindReplaceMsg = RegisterWindowMessageW(FINDMSGSTRINGW);
LRESULT CALLBACK MyWndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
if (Msg == uFindReplaceMsg) std::cout << "uFindReplaceMsg catched" << std::endl;
return DefWindowProcW(hWnd, Msg, wParam, lParam);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPTSTR, int nCmdShow) {
using namespace std;
WNDCLASSEXW wc;
wc.cbSize = sizeof(WNDCLASSEXW);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = &MyWndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = sizeof(PVOID);
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hIconSm = NULL;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_BACKGROUND);
wc.lpszMenuName = L"MainMenu";
wc.lpszClassName = L"window";
ATOM class_atom = RegisterClassExW(&wc);
HWND hWnd = CreateWindowExW(
0,
reinterpret_cast<LPCWSTR>(class_atom),
L"window title",
WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPCHILDREN | WS_THICKFRAME,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL
);
WCHAR szFindWhat[MAX_PATH] = {0};
FINDREPLACEW fr;
ZeroMemory(&fr, sizeof(fr));
fr.lStructSize = sizeof(fr);
fr.hwndOwner = hWnd;
fr.lpstrFindWhat = szFindWhat;
fr.wFindWhatLen = MAX_PATH;
fr.Flags = 0;
HWND hdlg = FindTextW(&fr);
MSG msg;
for (;;) {
GetMessageW(&msg, 0, 0, 0);
TranslateMessage(&msg);
DispatchMessageW(&msg);
}
}