Jump to content
  • Advertisement
Sign in to follow this  
corrington_j

why won't my dialog close

This topic is 4976 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to use a dialog for my main window in a c++ win32 application and i can't get it to close when the x is clicked. Here is my code, I got it from charles petzolds programming windows book, so i can't see why it doesn't work. Oh also i am trying to do this with visual studio .net 2003. Do i need to change some of the dialog properties in the dialog editor.
#include <windows.h>

#include "resource.h"

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, PSTR cmdLine, INT cmdShow)
{
	char appName[] = "dialog";
	HWND hWnd;
	MSG msg;
	WNDCLASS wndClass;

	wndClass.style = CS_HREDRAW | CS_VREDRAW;
	wndClass.lpfnWndProc = WndProc;
	wndClass.cbClsExtra = 0;
	wndClass.cbWndExtra = DLGWINDOWEXTRA;
	wndClass.hInstance = hInst;
	wndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
	wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
	wndClass.lpszMenuName = NULL;
	wndClass.lpszClassName = appName;

	RegisterClass(&wndClass);

	hWnd = CreateDialog(hInst, MAKEINTRESOURCE(IDD_DIALOG1), 0, NULL);

	ShowWindow(hWnd, cmdShow);

	while (GetMessage(&msg, NULL, 0, 0))
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}

	return msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch (msg)
	{
	case WM_DESTROY:
		PostQuitMessage(0);
		return 0;
	}

	return DefWindowProc(hWnd, msg, wParam, lParam);
}
Thanks for the help

Share this post


Link to post
Share on other sites
Advertisement
Add this to your dialog procedure:

case WM_SYSCOMMAND:
{
if(wparam == SC_CLOSE))
{
EndDialog(hwnd);

return TRUE;
}

break;
}


Also, you should NOT be calling DefWindowProc() with a dialog box. Return TRUE for messages that you handle, FALSE otherwise.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!