📄 readme.wzd
字号:
/////////////////////////////////////////////////////////////////////
// Example files.
/////////////////////////////////////////////////////////////////////
clrpage.cpp -- a property page class that allows a user to move slide bars
clrpage.h to pick an exact on-diffused color
WzdPrjct.h -- system registry keys to save custom color values
/////////////////////////////////////////////////////////////////////
// Modify the project resource file.
/////////////////////////////////////////////////////////////////////
// 1) add the following dialog box template to your resources
IDD_COLOR_PAGE DIALOG DISCARDABLE 0, 0, 175, 108
STYLE WS_CHILD | WS_CAPTION
CAPTION "Color"
FONT 8, "MS Sans Serif"
BEGIN
CONTROL "",IDC_COLOR1_DISPLAY,"Static",SS_BLACKFRAME | SS_SUNKEN |
NOT WS_VISIBLE,32,18,30,26
CONTROL "Slider1",IDC_RED_SLIDER1,"msctls_trackbar32",TBS_VERT |
TBS_BOTH | TBS_NOTICKS | WS_TABSTOP,83,15,19,26
CONTROL "Slider1",IDC_GRN_SLIDER1,"msctls_trackbar32",TBS_VERT |
TBS_BOTH | TBS_NOTICKS | WS_TABSTOP,109,15,19,26
CONTROL "Slider1",IDC_BLUE_SLIDER1,"msctls_trackbar32",TBS_VERT |
TBS_BOTH | TBS_NOTICKS | WS_TABSTOP,131,15,19,26
GROUPBOX "Color 1",IDC_STATIC,22,7,132,45
CONTROL "",IDC_COLOR2_DISPLAY,"Static",SS_BLACKFRAME | SS_SUNKEN |
NOT WS_VISIBLE,31,67,30,26
CONTROL "Slider1",IDC_RED_SLIDER2,"msctls_trackbar32",TBS_VERT |
TBS_BOTH | TBS_NOTICKS | WS_TABSTOP,83,67,19,26
CONTROL "Slider1",IDC_GRN_SLIDER2,"msctls_trackbar32",TBS_VERT |
TBS_BOTH | TBS_NOTICKS | WS_TABSTOP,109,67,19,26
CONTROL "Slider1",IDC_BLUE_SLIDER2,"msctls_trackbar32",TBS_VERT |
TBS_BOTH | TBS_NOTICKS | WS_TABSTOP,131,66,19,26
GROUPBOX "Color 2",IDC_STATIC,21,57,132,47
LTEXT "Red",IDC_STATIC,83,41,14,8
LTEXT "Red",IDC_STATIC,81,92,14,8
LTEXT "Green",IDC_STATIC,105,41,20,8
LTEXT "Green",IDC_STATIC,105,92,20,8
LTEXT "Blue",IDC_STATIC,131,41,15,8
LTEXT "Blue",IDC_STATIC,131,92,15,8
END
/////////////////////////////////////////////////////////////////////
// Modify the Mainframe Class.
/////////////////////////////////////////////////////////////////////
// 1) add the following functions and variables to this class's include file
// Operations
public:
void LoadOptions();
void SaveOptions();
void SetColorRef(int id,COLORREF rgb){m_rgbColors[id]=rgb;};
CPalette *GetPalette(){return m_pPalette;};
/////////////////
private:
COLORREF m_rgbColors[NUM_COLORS];
CColorPage *m_pColorPage;
CPalette *m_pPalette;
void CreatePalette();
// 2) initialize the color values in the constructor
CMainFrame::CMainFrame()
{
m_rgbColors[COLOR1_COLOR]=RGB(200,20,150);
m_rgbColors[COLOR2_COLOR]=RGB(0,200,100);
m_pPalette=NULL;
}
// 3) destroy the palette we are about o make in the destructor
CMainFrame::~CMainFrame()
{
m_pPalette->DeleteObject();
delete m_pPalette;
m_pPalette=NULL;
}
// 4) load custom color values from system registry and create
// a palette using two helper functions:
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
LoadOptions(); //<<<<<
CreatePalette(); //<<<<
return 0;
}
// 5) save custom color values using one helper function
void CMainFrame::OnClose()
{
SaveOptions();
CMDIFrameWnd::OnClose();
}
// 6) the helper function that loads color values from system registry:
void CMainFrame::LoadOptions()
{
BYTE *p;
UINT size;
if (AfxGetApp()->GetProfileBinary(SETTINGS_KEY,COLORS_KEY,&p,&size))
{
memcpy(m_rgbColors,p,size);
delete []p;
}
}
// 7) the helper function that saves color values to system registry:
void CMainFrame::SaveOptions()
{
UINT size=sizeof(m_rgbColors);
AfxGetApp()->WriteProfileBinary(SETTINGS_KEY,COLORS_KEY,(BYTE*)m_rgbColors,size);
}
// 8) initialize the color propery page and add to application's preferences
void CMainFrame::OnOptionsPreferences()
{
CPropertySheet sheet(_T("Preferences"),this);
m_pColorPage=new CColorPage;
sheet.AddPage(m_pColorPage);
m_pColorPage->m_rgbColors[COLOR1_COLOR] = m_rgbColors[COLOR1_COLOR];
m_pColorPage->m_rgbColors[COLOR2_COLOR] = m_rgbColors[COLOR2_COLOR];
sheet.DoModal();
delete m_pColorPage;
}
// 9) the helper function that creates a custom palette
void CMainFrame::CreatePalette()
{
LOGPALETTE *lp = (LOGPALETTE *)calloc( 1, sizeof(LOGPALETTE) +
(NUM_COLORS * sizeof(PALETTEENTRY)) );
lp->palVersion = 0x300;
lp->palNumEntries = NUM_COLORS;
for (int i=0; i<NUM_COLORS; i++)
{
lp->palPalEntry[i].peRed=GetRValue(m_rgbColors[i]);
lp->palPalEntry[i].peGreen=GetGValue(m_rgbColors[i]);
lp->palPalEntry[i].peBlue=GetBValue(m_rgbColors[i]);
// reserve for animation
lp->palPalEntry[i].peFlags = PC_RESERVED;
}
if (m_pPalette) delete m_pPalette;
m_pPalette = new CPalette;
m_pPalette->CreatePalette(lp);
free(lp);
}
/////////////////////////////////////////////////////////////////////
// Modify any class that can draw to a window.
/////////////////////////////////////////////////////////////////////
// 1) select palette into device context and realize colors
CPalette *pOPalette=pDC->SelectPalette(((CMainFrame*)AfxGetMainWnd())->GetPalette(),FALSE);
pDC->RealizePalette();
// 2) create our objects and select into device context
CPen pen(PS_SOLID,3,PALETTEINDEX(COLOR1_COLOR));
CPen *pOPen=pDC->SelectObject(&pen);
CBrush brush(PALETTEINDEX(COLOR2_COLOR));
CBrush *pOBrush=pDC->SelectObject(&brush);
// 3) draw object(s)
pDC->Rectangle(10,10,200,200);
// 4) unselect everything
pDC->SelectObject(pOPen);
pDC->SelectObject(pOBrush);
pDC->SelectPalette(pOPalette,FALSE);
/////////////////////////////////////////////////////////////////////
// From: Visual C++ MFC Programming by Example by John E. Swanke
// Copyright (C) 1999 jeswanke. All rights reserved.
/////////////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -