I have made a simple Pane class so that I can encapsulate a winapi Dialog.
I call it as:
Here the code I have, but it displays no dialog.
Here is what I do in main:
Code:
Pane(&hDlg, hInstance, nCmdShow);
while((ret = GetMessage(&msg, 0, 0, 0)) != 0)
{
if(ret == -1)
return -1;
if(!IsDialogMessage(hDlg, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}//while
Pane.h
Code:
#pragma once
#include "stdafx.h"
#include "resource.h"
#pragma comment(linker, \
"\"/manifestdependency:type='Win32' "\
"name='Microsoft.Windows.Common-Controls' "\
"version='6.0.0.0' "\
"processorArchitecture='*' "\
"publicKeyToken='6595b64144ccf1df' "\
"language='*'\"")
#pragma comment(lib, "ComCtl32.lib")
class Pane
{
public:
static HWND m_hDlg;
MSG msg;
HINSTANCE hInstance;
int nCmdShow;
Pane(HWND *hDlg, HINSTANCE hINstance, int ncmdshow);
~Pane(void);
static void onRestartNow();
static void onRestartLater();
static void onClose();
static BOOL CALLBACK DialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
};
Pane.cpp
Code:
#include "StdAfx.h"
#include "Pane.h"
HWND Pane::m_hDlg = 0;
Pane::Pane(HWND *hDlg, HINSTANCE hINstance, int nCmdShow)
{
InitCommonControls();
m_hDlg = CreateDialogParam(hInstance, MAKEINTRESOURCE(IDD_DIALOG1), 0, DialogProc, 0);
*hDlg = m_hDlg;
HICON hIcon = LoadIcon(NULL, IDI_EXCLAMATION);
HWND hImageCtl = GetDlgItem(*hDlg, IDC_STATIC_ICON);
::SendMessage(hImageCtl, STM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon);
ShowWindow(m_hDlg, nCmdShow);
}
void Pane::onRestartNow()
{
SendMessage(m_hDlg, WM_CLOSE, 0, 0);
}
void Pane::onRestartLater()
{
SendMessage(m_hDlg, WM_CLOSE, 0, 0);
}
void Pane::onClose()
{
DestroyWindow(m_hDlg);
}
INT_PTR CALLBACK Pane::DialogProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg) /* more compact, each "case" through a single line, easier on the eyes */
{
case WM_COMMAND:
switch(LOWORD(wParam))
{
case ID_RESTART_NOW: onRestartNow(); return TRUE;
case ID_RESTART_LATER: onRestartLater(); return TRUE;
}
break;
case WM_CLOSE: onClose(); return TRUE;
case WM_DESTROY: PostQuitMessage(0); return TRUE;
}
return FALSE;
}
Pane::~Pane(void)
{
}