I have an win32 app which places a dialog on the screen - no "main window", just a dialog. If I call any other common control (such as message box or an open dialog) The main dialog loses focus, but the new subdialog never gains it; it remains inert, and the main dialog is likewise dead - I have to kill the program. So what is going wrong with the subdialog?
I include here a part of the main program which shows what I'm doing - there are two dialogs which cycle, but otherwise the main routine is pretty generic. BTW, I'm using VC++ .NET:
#include "stdafx.h"
#include <commctrl.h>
#include "GroundZero.h"
#define MAX_LOADSTRING 100
// Global Variables:
static HWND hDlg = NULL;
HINSTANCE hInst; // current instance
TCHAR szTitle [MAX_LOADSTRING]; // The title bar text
Options opts;
// Forward declarations of functions included in this code module:
LRESULT CALLBACK Wnd1Proc (HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK Wnd2Proc (HWND, UINT, WPARAM, LPARAM);
int APIENTRY _tWinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPTSTR lpCmdLine, int nCmdShow)
{
MSG msg;
HACCEL hAccelTable;
// Initialize global strings
LoadString (hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
// Perform application initialization:
hInst = hInstance; // Store instance handle in our global variable
hAccelTable = LoadAccelerators (hInstance, (LPCTSTR) IDC_ON_THE_FLOOR);
bool phase = true;
while (true) {
opts.back = false;
if ((hDlg = CreateDialog (hInst, (LPCTSTR) (phase ? IDD_DLG1 : IDD_DLG2),
NULL, (DLGPROC) (phase ? Wnd1Proc : Wnd2Proc))) == NULL) {
ErrBox (MB_OK, "Error creating dialog %d.", phase);
exit (0);
}
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;
phase = !phase;
}
return (int) msg.wParam;
}
I include here a part of the main program which shows what I'm doing - there are two dialogs which cycle, but otherwise the main routine is pretty generic. BTW, I'm using VC++ .NET:
#include "stdafx.h"
#include <commctrl.h>
#include "GroundZero.h"
#define MAX_LOADSTRING 100
// Global Variables:
static HWND hDlg = NULL;
HINSTANCE hInst; // current instance
TCHAR szTitle [MAX_LOADSTRING]; // The title bar text
Options opts;
// Forward declarations of functions included in this code module:
LRESULT CALLBACK Wnd1Proc (HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK Wnd2Proc (HWND, UINT, WPARAM, LPARAM);
int APIENTRY _tWinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPTSTR lpCmdLine, int nCmdShow)
{
MSG msg;
HACCEL hAccelTable;
// Initialize global strings
LoadString (hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
// Perform application initialization:
hInst = hInstance; // Store instance handle in our global variable
hAccelTable = LoadAccelerators (hInstance, (LPCTSTR) IDC_ON_THE_FLOOR);
bool phase = true;
while (true) {
opts.back = false;
if ((hDlg = CreateDialog (hInst, (LPCTSTR) (phase ? IDD_DLG1 : IDD_DLG2),
NULL, (DLGPROC) (phase ? Wnd1Proc : Wnd2Proc))) == NULL) {
ErrBox (MB_OK, "Error creating dialog %d.", phase);
exit (0);
}
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;
phase = !phase;
}
return (int) msg.wParam;
}