Skip to content

Instantly share code, notes, and snippets.

@tkojitu
Created October 18, 2021 03:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tkojitu/f9703a989ea9b1eb43ca9c0ef31394f5 to your computer and use it in GitHub Desktop.
Save tkojitu/f9703a989ea9b1eb43ca9c0ef31394f5 to your computer and use it in GitHub Desktop.
#include "pch.h"
#include "framework.h"
#include "ModelessDialogDemo.h"
#include "ModelessDialogDemoDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
BEGIN_MESSAGE_MAP(CModelessDialogDemoApp, CWinApp)
ON_COMMAND(ID_HELP, &CWinApp::OnHelp)
END_MESSAGE_MAP()
CModelessDialogDemoApp::CModelessDialogDemoApp()
{
}
CModelessDialogDemoApp theApp;
BOOL CModelessDialogDemoApp::InitInstance()
{
CWinApp::InitInstance();
SetRegistryKey(_T("MyApp"));
CModelessDialogDemoDlg * dlg = new CModelessDialogDemoDlg();
m_pMainWnd = dlg;
dlg->Create(IDD_MODELESSDIALOGDEMO_DIALOG);
dlg->ShowWindow(SW_SHOW);
MSG msg;
BOOL ret;
while ((ret = GetMessage(&msg, nullptr, 0, 0)) != 0) {
if (ret == -1)
continue;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (BOOL)msg.wParam;
}
#pragma once
#include "resource.h"
class CModelessDialogDemoApp : public CWinApp
{
public:
CModelessDialogDemoApp();
virtual ~CModelessDialogDemoApp() {}
virtual BOOL InitInstance();
DECLARE_MESSAGE_MAP()
};
extern CModelessDialogDemoApp theApp;
#include "pch.h"
#include "framework.h"
#include "ModelessDialogDemo.h"
#include "ModelessDialogDemoDlg.h"
#include "afxdialogex.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
CModelessDialogDemoDlg::CModelessDialogDemoDlg(CWnd* pParent)
: CDialogEx(IDD_MODELESSDIALOGDEMO_DIALOG, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CModelessDialogDemoDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CModelessDialogDemoDlg, CDialogEx)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_CLOSE()
END_MESSAGE_MAP()
BOOL CModelessDialogDemoDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
SetIcon(m_hIcon, TRUE);
SetIcon(m_hIcon, FALSE);
return TRUE;
}
void CModelessDialogDemoDlg::OnPaint()
{
if (IsIconic()) {
CPaintDC dc(this);
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
dc.DrawIcon(x, y, m_hIcon);
}
else {
CDialogEx::OnPaint();
}
}
HCURSOR CModelessDialogDemoDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
void CModelessDialogDemoDlg::OnClose()
{
PostQuitMessage(0);
}
#pragma once
class CModelessDialogDemoDlg : public CDialogEx
{
public:
CModelessDialogDemoDlg(CWnd* pParent = nullptr);
virtual ~CModelessDialogDemoDlg() {}
virtual void OnCancel() {}
virtual void OnOK() {}
afx_msg void OnClose();
#ifdef AFX_DESIGN_TIME
enum { IDD = IDD_MODELESSDIALOGDEMO_DIALOG };
#endif
protected:
virtual void DoDataExchange(CDataExchange* pDX);
virtual BOOL OnInitDialog();
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
protected:
HICON m_hIcon;
DECLARE_MESSAGE_MAP()
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment