lundi 30 mars 2015

I have a MessageBox in my Visual C++ Win32 that cannot be closed! What is going on?

So I have a message box that simply cannot be closed, and I am not sure why. It is created within my window procedure for a dialog box which was created like so:



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


Below is the snippet of code with the problem. It is the MessageBox call that has the problem, the OK button does nothing, nor does hitting the "X" on that message box.



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 Device", MB_OK | MB_ICONINFORMATION);
GlobalFree((HANDLE)XMLfilename);
GlobalFree((HANDLE)buf);
//
}
}
break;


What gives? I have tried both calling MessageBox with the window handle and with NULL, same thing.


Aucun commentaire:

Enregistrer un commentaire