Original Post
Hi Folks,
I have a simple question. In my program, I want to create an "About Box" dialog. I designed it in the resources and included everything. But, when the box loads up, I can''t click on the "OK" button to close the box. The program pretty much freezes. I''m going to post my code and if Anyone can help me, it would be greatly appreciated. Thanks.
// Our Includes
#include <windows.h>
#include <windowsx.h>
#include <fstream.h>
#include <iostream.h>
#include "resource.h"
// Our Defines
#define WIN32_LEAN_AND_MEAN
// Our Globals
char strFileName[260]; // Our Location of the ROM Image we are opening
bool EmulationRunning = true; // Is the Emulator Translating?
HINSTANCE WindowInstance; // Global Instance
// Our About Box Dialog Procedure
BOOL CALLBACK AboutDlgProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
switch(Msg)
{
case WM_COMMAND:
{
switch(wParam)
{
case IDOK:
{
EndDialog(hWnd, IDOK);
return TRUE;
}
break;
}
}
break;
}
return FALSE;
}
// Our MsgHandler() Function
LRESULT CALLBACK MsgHandler(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
switch(Msg)
{
case WM_CLOSE:
{
PostQuitMessage(0);
EmulationRunning = false;
return 0;
}
break;
case WM_QUIT:
{
PostQuitMessage(0);
EmulationRunning = false;
return 0;
}
break;
case WM_DESTROY:
{
PostQuitMessage(0);
EmulationRunning = false;
return 0;
}
break;
case WM_COMMAND:
{
switch(wParam)
{
case ID_FILE_EXIT:
{
PostQuitMessage(0);
EmulationRunning = false;
return 0;
}
break;
case ID_FILE_OPENROMIMAGE:
{
OPENFILENAME ofn;
ZeroMemory(&ofn, sizeof(ofn));
ofn.lpstrFilter = "NES Roms (*.NES)\0*.NES\0All Files (*.*)\0*.*\0";
ofn.nFilterIndex = 1;
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = hWnd;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = NULL;
ofn.lpstrFile = NULL;
GetOpenFileName(&ofn);
}
break;
case ID_HELP_ABOUT:
{
DialogBox(WindowInstance, MAKEINTRESOURCE(ABOUT_DIALOG), hWnd,
(DLGPROC)AboutDlgProc);
}
break;
}
}
break;
}
return DefWindowProc(hWnd, Msg, wParam, lParam);
}
// WinMain
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
MSG Msg;
HWND MainWindow;
WNDCLASSEX NesPC;
ifstream RomImage;
// Initialize our Main Window Class
NesPC.cbSize = sizeof(WNDCLASSEX);
NesPC.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC | CS_DBLCLKS;
NesPC.lpfnWndProc = MsgHandler;
NesPC.cbClsExtra = 0;
NesPC.cbWndExtra = 0;
NesPC.hInstance = hInstance;
NesPC.hIcon = LoadIcon(NULL, IDI_WINLOGO);
NesPC.hCursor = LoadCursor(NULL, IDC_ARROW);
NesPC.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
NesPC.lpszMenuName = NULL;
NesPC.lpszClassName = "NesPC";
NesPC.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
RegisterClassEx(&NesPC);
MainWindow = CreateWindowEx(NULL,
"NesPC",
"NesPC Version 0.01 Alpha",
WS_POPUPWINDOW | WS_OVERLAPPEDWINDOW | WS_VISIBLE,
100,
100,
320,
240,
NULL,
NULL,
hInstance,
NULL);
WindowInstance = hInstance;
SetMenu(MainWindow, LoadMenu(hInstance, MAKEINTRESOURCE(NESPC)));
ShowWindow(MainWindow, SW_SHOWNORMAL);
while(EmulationRunning == true)
{
// Draw Our Emulation Screen Here
if(GetMessage(&Msg, NULL, 0, 0))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
}
return Msg.wParam;
}