The code:
Note that either of two dialogs can be called: first one, and then when it exits, another. The problem is the first dialog: the program processes until it enters the CreateDialog statement, and the program quietly dies inside it. Several calls are made on the dialog handler, but the window never appears. Note that it is the only window being used; there is no normal "main" window. This does not happen on my development machine; it works fine. It only happens on a clean install. I'm using Windows XP Pro, and MSVS.net as a compiler. Any ideas?
Code:
#include "stdafx.h"
#include "GroundZero.h"
#include <stdio.h>
#include <commctrl.h>
#include <htmlhelp.h>
#define MAX_LOADSTRING 100
// Global Variables:
static HWND hDlg = NULL;
HINSTANCE hInst;
TCHAR szTitle [MAX_LOADSTRING];
TCHAR szWindowClass [MAX_LOADSTRING];
TCHAR szVersion [MAX_LOADSTRING];
Options opts;
// Forward declarations of functions included in this code module:
BOOL CALLBACK Wnd1Proc(HWND, UINT, WPARAM, LPARAM);
BOOL CALLBACK Wnd2Proc(HWND, UINT, WPARAM, LPARAM);
int APIENTRY _tWinMain (
HINSTANCE hInstance,
HINSTANCE PrevInstance,
LPTSTR lpCmdLine,
int nCmdShow
)
{
MSG msg;
HACCEL hAccelTable;
WNDCLASSEX wcex;
// Initialize global strings
LoadString (hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString (hInstance, IDC_GROUNDZERO, szWindowClass, MAX_LOADSTRING);
LoadString (hInstance, IDS_VERSION, szVersion, MAX_LOADSTRING);
sprintf (szTitle, "%s v%s", szTitle, szVersion);
// Set up the class:
wcex.cbSize = sizeof (WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC) Wnd1Proc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon (hInstance, (LPCTSTR) IDI_GROUNDZERO);
wcex.hCursor = LoadCursor (NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH) (COLOR_WINDOW+1);
wcex.lpszMenuName = (LPCTSTR) IDC_GROUNDZERO;
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon (wcex.hInstance, (LPCTSTR) IDI_SMALL);
RegisterClassEx (&wcex);
// Perform application initialization:
hInst = hInstance;
hAccelTable = LoadAccelerators (hInstance, (LPCTSTR) IDC_GROUNDZERO);
InitOpts (&opts);
for (bool phase = true; true; phase = !phase) {
opts.back = false;
if ((hDlg = [red]CreateDialog[/red] (hInst, MAKEINTRESOURCE (phase ? IDD_DLG1 : IDD_DLG2),
NULL, (DLGPROC) (phase ? Wnd1Proc : Wnd2Proc))) == NULL) {
ErrBox (MB_OK, "Error creating dialog %d.", phase);
exit (0);
}
ShowWindow (hDlg, SW_SHOW);
ErrBox (MB_OK, "Dialog should have shown by now.");
while (GetMessage (&msg, NULL, 0, 0)) {
if (!IsWindow (hDlg) || !IsDialogMessage (hDlg, &msg)) {
if (!TranslateAccelerator (msg.hwnd, hAccelTable, &msg)) {
TranslateMessage (&msg);
DispatchMessage (&msg);
}
}
}
if ((phase && opts.immediate) ||
(!phase && (opts.immediate || !opts.back))) break;
}
ExitOut (&opts);
return (int) msg.wParam;
}
Note that either of two dialogs can be called: first one, and then when it exits, another. The problem is the first dialog: the program processes until it enters the CreateDialog statement, and the program quietly dies inside it. Several calls are made on the dialog handler, but the window never appears. Note that it is the only window being used; there is no normal "main" window. This does not happen on my development machine; it works fine. It only happens on a clean install. I'm using Windows XP Pro, and MSVS.net as a compiler. Any ideas?