我正在創建一個DLL來檢查用戶何時按下應用程序窗口上的關閉按鈕,它工作正常,然後我想這樣做,以便當_text全局變量爲空時,沒有消息將被顯示。 我不明白爲什麼一個簡單的if(_text!=「」)不起作用...我做錯了什麼?簡單如果比較不適用於char
#include <windows.h>
#define export extern "C" __declspec (dllexport)
WNDPROC GameWndProc = NULL;
HWND GameHwnd = NULL;
double _button_result = 0;
char* _text;
char* _title;
LRESULT CALLBACK SubClassWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg) {
case WM_CLOSE:
if (_text != "") {
if (MessageBox(GameHwnd, (LPSTR)_text, (LPSTR)_title, MB_YESNO|MB_APPLMODAL) == IDYES) {
_button_result = 1;
return 0;
} else {
return 0;
}
}
_button_result = 1;
return 0;
break;
}
return CallWindowProc(GameWndProc, hwnd, uMsg, wParam, lParam);
}
export double _window_check_close_init(double window_handle, char* _msg_text, char* _msg_title)
{
GameHwnd = (HWND)(int)window_handle;
GameWndProc = (WNDPROC)SetWindowLongPtr(GameHwnd, GWL_WNDPROC, (LONG)SubClassWndProc);
_text = _msg_text;
_title = _msg_title;
if (!GameWndProc) {
return 0;
}
return 1;
}
export double _window_check_close()
{
if (_button_result == 1) {
_button_result = 0;
return 1;
} else {
return 0;
}
}
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
if (fdwReason == DLL_PROCESS_DETACH) {
if (IsWindow(GameHwnd) && GameWndProc) {
SetWindowLongPtr(GameHwnd, GWL_WNDPROC, (LONG)GameWndProc);
}
}
return TRUE;
}
謝謝,我會一起去的。它很好地工作。 :) – user780756