Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
(First, I'm worry about my suck English. If you can understand, could you help me?)

C++
#include <Windows.h>
#include "resource.h"

HINSTANCE hInst;
HWND hDigMain;

BOOL CALLBACK MainDigProc(HWND, UINT, WPARAM, LPARAM);
BOOL CALLBACK testProc(HWND, UINT, WPARAM, LPARAM);

int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
	_In_opt_ HINSTANCE hPrevInstance,
	_In_ LPWSTR    lpCmdLine,
	_In_ int       nCmdShow)
{
	hInst = hInstance;
	DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG1), HWND_DESKTOP, MainDigProc);
	return 0;
}

BOOL CALLBACK MainDigProc(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam)
{
	//Search Files ..
	switch (iMessage) {
	case WM_INITDIALOG:
		return TRUE;
	case WM_COMMAND:
		switch (LOWORD(wParam)) {
		case IDSTART:
			if (!IsWindow(hDigMain)) {
				hDigMain = CreateDialog(hInst, MAKEINTRESOURCE(IDD_DIALOG2), HWND_DESKTOP, testProc);
				ShowWindow(hDigMain, SW_SHOW);
			}
			//EndDialog(hWnd, IDSTART);
			return TRUE;
		case IDLOAD:
			EndDialog(hWnd, IDLOAD);
			return TRUE;
		case ID_OPTION:
			EndDialog(hWnd, ID_OPTION);
			return TRUE;
		case IDCANCEL:
			EndDialog(hWnd, IDLOAD);
			return TRUE;
		}
		break;
	}
	return FALSE;
}

BOOL CALLBACK testProc(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam)
{
	switch (iMessage) {
	case WM_INITDIALOG:
		return TRUE;
	case WM_COMMAND:
		switch (LOWORD(wParam)) {
		case IDOK:
		case IDCANCEL:
			EndDialog(hWnd, IDLOAD);
			return TRUE;
		}
		break;
	}
	return FALSE;
}


I tried popup new window(IDD_DIALOG2) when clicked button ':IDSTART', and close (automatic) old window(IDD_DIALOG1).

What I have tried:

In MainDigProc - WM_COMMAND, EndDialog make close total program. (now I think 'IsWindow' is unnecessary, isn't it?) Did I tried close Parent window, so it make to shut-down program? I'm not sure. Opinion please.
Posted
Updated 22-Feb-16 7:23am
v2
Comments
Richard MacCutchan 23-Feb-16 3:49am    
It is not clear exactly what you are trying to do in the above code. It looks like, you have a modal dialog as your main window, and on the press of a button you create a modeless dialog. All other options try to close the dialogs, and in the case of the main dialog, that will terminate the program.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900