Skip to main content
gamedev.net
🔒 Locked

Dialog Box Problems

Started by bower12345 Feb 20, 2003 at 12:17 PM 4 replies 200+ views
Original Post
bower12345
bower12345
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;
}
  
Mikehttp://cs.wpunj.edu/~bowersom
Nytegard
Nytegard
What style are you using, Overlapped, Popup, or child? Thats my first guess as what is wrong.

Also, you should try checking the WM_COMMAND by the LOWORD(wParam), rather than just the wParam.

[edited by - Nytegard on February 20, 2003 1:22:44 PM]
bower12345
bower12345
Hey,

I added in the LOWORD(wParam) macro just now, but it still doesn''t work. My main window for the application is using WS_OVERLAPPEDWINDOW and WS_POPUPWINDOW. I didn''t fill a WINCLASS structure for the about box window though so there are no styles for that. Again, any help is appreciated!
Mikehttp://cs.wpunj.edu/~bowersom
sphinx23
sphinx23
You must return TRUE in your AboutDlgProc procedure when you receive the WM_INITDIALOG message:

... AboutDlgProc (...)
{
......

case WM_INITDIALOG:
return TRUE;

......
}
bower12345
bower12345
Hey Again,

Using the switch(Msg)/case WM_INITDIALOG: return TRUE; did not work for me. I''m still wondering about this. I did check on the dialog box settings and it is a Popup Window. Any help is greatly appreciated yet again.

Mike
Mikehttp://cs.wpunj.edu/~bowersom
Nytegard
Nytegard
OK, a couple fixes & suggestions:

Don''t mix WS_OVERLAPPEDWINDOW & WS_POPUPWINDOW. It''s redundant. Just add WS_POPUP to the WS_OVERLAPPEDWINDOW to get the same effect.

Here''s my about:


  
LRESULT CALLBACK AboutDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam){
switch (message){
case WM_INITDIALOG:
return TRUE;
break;

case WM_COMMAND:
if (LOWORD(wParam) == IDOK){
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
break;
}
return FALSE;
}


When I mean, were you using overlapped, popup, or child, I was talking about the actual dialog window. Go into the resource editor, and go under properties. You probably have it set to child. Change it to overlapped and things should work fine.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.