我写了一个dll,里面registerclass->createwindow->show->update->getmessage->transtlate->dispatch。
将这个dll注入到notebook.exe后,出现想要的窗口,然后原来程序窗口失去反映了(新创建的窗口仍然有反映),关掉新窗口,程序窗口又有反映了。
以前逛论坛的时候好像碰到有人问这个问题,但今天翻了好久没有找到,本想自己研究一下,但看看外面天色已晚,只有请教大家了!
关键代码:
DLLMAIN:
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch(ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
{
static TCHAR szAppName[] = TEXT ("HelloWin") ;
HWND hwnd ;
MSG msg ;
WNDCLASS wndclass ;
//填充 wndclass
if (!RegisterClass (&wndclass))
{
MessageBox (NULL, TEXT ("This program requires Windows NT!"),
szAppName, MB_ICONERROR) ;
return 0 ;
}
hwnd = CreateWindow (szAppName, // window class name
TEXT ("The Hello Program"), // window caption
WS_OVERLAPPEDWINDOW, // window style
CW_USEDEFAULT, // initial x position
CW_USEDEFAULT, // initial y position
CW_USEDEFAULT, // initial x size
CW_USEDEFAULT, // initial y size
NULL, // parent window handle
NULL, // window menu handle
GetModuleHandle(NULL),//hInstance, // program instance handle
NULL) ; // creation parameters
ShowWindow (hwnd, 1);//iCmdShow) ;
UpdateWindow (hwnd) ;
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
break;
}
}
return TRUE;
}
CALLBACK WndProc:
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc ;
PAINTSTRUCT ps ;
RECT rect ;
switch (message)
{
case WM_CREATE:
return 0 ;
case WM_PAINT:
hdc = BeginPaint (hwnd, &ps) ;
GetClientRect (hwnd, &rect) ;
DrawText (hdc, TEXT ("Hello, Windows 98!"), -1, &rect,
DT_SINGLELINE | DT_CENTER | DT_VCENTER) ;
EndPaint (hwnd, &ps) ;
return 0 ;
case WM_DESTROY:
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
我的观点:
好像是消息处理的问题,如果是的话不知如何解决?PostMessage/SendMessage?
[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!