📄 skinshowdlg.cpp
字号:
// SkinShowDlg.cpp : implementation file
//
#include "stdafx.h"
#include "SkinShow.h"
#include "SkinShowDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSkinShowDlg dialog
CSkinShowDlg::CSkinShowDlg(CWnd* pParent /*=NULL*/)
: CDialog(CSkinShowDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CSkinShowDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CSkinShowDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSkinShowDlg)
DDX_Control(pDX, IDC_ST_OK, m_ok);
DDX_Control(pDX, IDC_ST_BACK, m_back);
DDX_Control(pDX, IDC_ST_PICTURE, m_pic);
DDX_Control(pDX, IDC_COMBO_FA, m_falist);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSkinShowDlg, CDialog)
//{{AFX_MSG_MAP(CSkinShowDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BTN_CHANGE, OnBtnChange)
ON_WM_CTLCOLOR()
ON_WM_LBUTTONUP()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSkinShowDlg message handlers
BOOL CSkinShowDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
m_falist.AddString("方案1(蓝色)");
m_falist.AddString("方案2(粉红色)");
m_falist.AddString("方案3(黄色)");
m_falist.AddString("方案4(紫色)");
m_falist.AddString("方案5(绿色)");
char AppPathName[100];
GetModuleFileName(NULL,AppPathName,100);
CString PathName=(CString)AppPathName;
CString FileName = "";
if(PathName.ReverseFind('\\')>0)
PathName=PathName.Left(PathName.ReverseFind('\\')+1);
FileName = PathName + "\\Pic\\back.bmp";
backmap=(HBITMAP)LoadImage(AfxGetInstanceHandle(), FileName,IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION);
m_back.SetBitmap(backmap);
GetDlgItem(IDC_ST_BACK)->MoveWindow(CRect(9,11,572,289));
FileName = PathName + "\\Pic\\ok.bmp";
okmap=(HBITMAP)LoadImage(AfxGetInstanceHandle(), FileName,IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION);
GetDlgItem(IDC_BTN_CHANGE)->GetWindowRect(&ret);
ScreenToClient(&ret);
m_ok.SetBitmap(okmap);
GetDlgItem(IDC_ST_OK)->MoveWindow(ret);
return TRUE; // return TRUE unless you set the focus to a control
}
void CSkinShowDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CSkinShowDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
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;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CSkinShowDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CSkinShowDlg::OnBtnChange()
{
int nSel = m_falist.GetCurSel();
char AppPathName[100];
GetModuleFileName(NULL,AppPathName,100);
CString FileName=(CString)AppPathName;
if(FileName.ReverseFind('\\')>0)
FileName=FileName.Left(FileName.ReverseFind('\\')+1);
switch(nSel){
case 0:
m_pbbrush=CreateSolidBrush(RGB(191,223,255));
FileName = FileName + "\\Pic\\01.bmp";
break;
case 1:
m_pbbrush=CreateSolidBrush(RGB(255,208,232));
FileName = FileName + "\\Pic\\02.bmp";
break;
case 2:
m_pbbrush=CreateSolidBrush(RGB(255,255,210));
FileName = FileName + "\\Pic\\03.bmp";
break;
case 3:
m_pbbrush=CreateSolidBrush(RGB(190,125,255));
FileName = FileName + "\\Pic\\04.bmp";
break;
case 4:
m_pbbrush=CreateSolidBrush(RGB(210,255,222));
FileName = FileName + "\\Pic\\05.bmp";
break;
}
HBITMAP bitmap;
bitmap=(HBITMAP)LoadImage(AfxGetInstanceHandle(), FileName,IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION);
BITMAP bm;
GetObject(bitmap, sizeof(bm), &bm);
GetDlgItem(IDC_ST_PICTURE)->MoveWindow(CRect(10,15,bm.bmWidth,bm.bmHeight));
m_pic.SetBitmap(bitmap);
this->RedrawWindow();
}
HBRUSH CSkinShowDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
switch(nCtlColor){
case CTLCOLOR_LISTBOX:
case CTLCOLOR_STATIC:
case CTLCOLOR_DLG:
case CTLCOLOR_MSGBOX :
pDC->SetBkMode(TRANSPARENT);
pDC->SetTextColor(RGB(0,0,0));
return m_pbbrush;
break;
default:
return CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
break;
}
// TODO: Return a different brush if the default is not desired
return hbr;
}
void CSkinShowDlg::OnLButtonUp(UINT nFlags, CPoint point)
{
if(ret.PtInRect(point)){
OnBtnChange();
}
CDialog::OnLButtonUp(nFlags, point);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -