gpt4 book ai didi

c++ - 我的 Visual C++ Win32 中有一个无法关闭的 MessageBox!到底是怎么回事?

转载 作者:可可西里 更新时间:2023-11-01 11:07:09 26 4
gpt4 key购买 nike

我有一个无法关闭的消息框,我不确定为什么。它是在我的窗口过程中为这样创建的对话框创建的:

hwnd = CreateDialog(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_DIALOG1), NULL, WndProc);

下面是有问题的 WndProc 代码。问题出在 MessageBox 调用上,OK 按钮没有任何作用,也没有点击该消息框上的“X”。

BOOL CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
static HBRUSH bgBrush;
switch (msg)
{
case WM_INITDIALOG:
bgBrush = CreateSolidBrush(RGB(65, 65, 66));
return TRUE;

case WM_CTLCOLORDLG:
return (INT_PTR)(bgBrush);

case WM_CTLCOLORSTATIC:
SetBkMode((HDC)wParam, TRANSPARENT);
SetTextColor((HDC)wParam, RGB(200, 200, 200));
return (INT_PTR)(bgBrush);

case WM_DEVICECHANGE:
USBEnumerateDev();
break;

case WM_COMMAND:
{
switch (LOWORD(wParam))
{
case IDC_SELECTPROFILE:
switch (HIWORD(wParam))
{
case BN_CLICKED:
int res = CommonFileDialog.BasicFileOpen(hwnd);
if (res == TRUE)
{
int len = GetWindowTextLength(GetDlgItem(hwnd, IDC_EDITWLAN));
if (len > 0)
{
int i;
wchar_t* buf;

buf = (wchar_t*)GlobalAlloc(GPTR, len + 1);
GetDlgItemText(hwnd, IDC_EDITWLAN, buf, len + 1);



GlobalFree((HANDLE)buf);
}
}
break;
}
break;

case IDC_PROGRAM:
switch (HIWORD(wParam))
{
case BN_CLICKED:
int len = GetWindowTextLength(GetDlgItem(hwnd, IDC_EDITWLAN));
if (len > 0)
{
int i, fileSize;
LPSTR XMLfilename, buf;
FILE *fXMLfile;

XMLfilename = (LPSTR)GlobalAlloc(GPTR, len + 1);
GetDlgItemTextA(hwnd, IDC_EDITWLAN, XMLfilename, len + 1);
fopen_s(&fXMLfile, XMLfilename, "r");
fseek(fXMLfile, 0L, SEEK_END);
fileSize = ftell(fXMLfile);
fseek(fXMLfile, 0L, SEEK_SET);
buf = (LPSTR)GlobalAlloc(GPTR, fileSize);
fread(buf, 1, fileSize, fXMLfile);
DBG("fileSize: %d", fileSize);
if (USBSetProfile(buf, fileSize))
MessageBox(hwnd, L"Programmed!", L"PC -> USB", MB_OK | MB_ICONINFORMATION);
GlobalFree((HANDLE)XMLfilename);
GlobalFree((HANDLE)buf);
//
}
}
break;
}
}
break;

case WM_CLOSE:
DestroyWindow(hwnd);
break;

case WM_DESTROY:
PostQuitMessage(0);
break;

default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}

什么给了?我试过使用窗口句柄和 NULL 调用 MessageBox,同样的事情。

最佳答案

您的 WndProc() 正在调用 DefWindowProc(),但是 documentation特别指出不要那样做:

Although the dialog box procedure is similar to a window procedure, it must not call the DefWindowProc function to process unwanted messages. Unwanted messages are processed internally by the dialog box window procedure.

关于c++ - 我的 Visual C++ Win32 中有一个无法关闭的 MessageBox!到底是怎么回事?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29359365/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com