tmsgboxynac.cpp

来自「mpq文件的格式就是一种压缩格式」· C++ 代码 · 共 126 行

CPP
126
字号
/*****************************************************************************/
/* TMsgBoxYNAC.cpp                        Copyright (c) Ladislav Zezula 2003 */
/*---------------------------------------------------------------------------*/
/* Implementation for the message box with Yes, No, All, Cancel buttons      */
/*---------------------------------------------------------------------------*/
/*   Date    Ver   Who  Comment                                              */
/* --------  ----  ---  -------                                              */
/* 08.04.03  1.00  Lad  The first version of TMsgBoxYNAC.cpp                 */
/*****************************************************************************/

#include "stdafx.h"
#include "resource.h"
#include "TMsgBoxYNAC.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

BEGIN_MESSAGE_MAP(TMsgBoxYNAC, CDialog)
	//{{AFX_MSG_MAP(TMsgBoxYNAC)
	ON_BN_CLICKED(IDYES, OnYesClick)
	ON_BN_CLICKED(IDC_NOBTN, OnNoClick)
	ON_BN_CLICKED(IDC_ALLBTN, OnAllClick)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

//-----------------------------------------------------------------------------
// Constructor and destructor

TMsgBoxYNAC::TMsgBoxYNAC(CWnd* pParent /*=NULL*/)
	: CDialog(TMsgBoxYNAC::IDD, pParent)
{
	//{{AFX_DATA_INIT(TMsgBoxYNAC)
	//}}AFX_DATA_INIT
}

//-----------------------------------------------------------------------------
// TMsgBoxYNAC message handlers

BOOL TMsgBoxYNAC::OnInitDialog() 
{
    char * szIDIcon = NULL;

    CDialog::OnInitDialog();

    // Set the title
    SetWindowText(m_strCaption);

	// Load the icon
    switch(m_uType & 0x00F0)
    {
        case MB_ICONASTERISK    : szIDIcon = IDI_ASTERISK; break;
        case MB_ICONQUESTION    : szIDIcon = IDI_QUESTION; break;
        case MB_ICONWARNING     : szIDIcon = IDI_WARNING; break;
        case MB_ICONERROR       : szIDIcon = IDI_ERROR; break;
    }
 
    if(szIDIcon != NULL)
    {
        CStatic * pStatic = (CStatic *)GetDlgItem(IDC_MSGBOXICON);
        HICON     hIcon = LoadIcon(NULL, szIDIcon);
        pStatic->SetIcon(hIcon);
    }

    // Set the text
    SetDlgItemText(IDC_TEXT, m_strText);
	return TRUE;
}

//-----------------------------------------------------------------------------
// Public functions

int MessageBoxYNAC(CWnd * pParent, const TCHAR * szText, const TCHAR * szCaption, UINT uType, BOOL * pbAll)
{
    // If the "All" answer is already on, return "Yes" answer
    if(pbAll != NULL && *pbAll == TRUE)
        return IDYES;
    
    TMsgBoxYNAC dlg(pParent);
    dlg.m_strCaption = szCaption;
    dlg.m_strText = szText;
    dlg.m_uType = uType;
    dlg.m_pbAll = pbAll;
    return dlg.DoModal();
}

int MessageBoxYNAC(CWnd * pParent, UINT nIDText, UINT nIDCaption, UINT uType, BOOL * pbAll, ...)
{
    HINSTANCE hInst = AfxGetResourceHandle();
    TCHAR szCaption[256];
    TCHAR szText[256];
    TCHAR szMsg[512];
    va_list argList;

    // Load the strings from resources
    LoadString(hInst, nIDCaption, szCaption, sizeof(szCaption) / sizeof(TCHAR));
    LoadString(hInst, nIDText, szText, sizeof(szText) / sizeof(TCHAR));

    // Format the string
    va_start(argList, pbAll);
    _vstprintf(szMsg, szText, argList);
    va_end(argList);

    // Call the text version
    return MessageBoxYNAC(pParent, szMsg, szCaption, uType, pbAll);
}

void TMsgBoxYNAC::OnYesClick() 
{
    EndDialog(IDYES);
}

void TMsgBoxYNAC::OnNoClick() 
{
    EndDialog(IDNO);
}

void TMsgBoxYNAC::OnAllClick() 
{
    if(m_pbAll != NULL)
        *m_pbAll = TRUE;
    EndDialog(IDYES);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?