11.04.2014 Views

Advanced MFC Programming

Advanced MFC Programming

Advanced MFC Programming

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 7. Common Dialog Boxes<br />

DWORD Flags;<br />

LPARAM lCustData;<br />

LPCCHOOKPROC lpfnHook;<br />

LPCTSTR lpTemplateName;<br />

} CHOOSECOLOR;<br />

We can change the custom colors by assigning the address of a COLORREF type array with size of 16 to<br />

member lpCustColors of this structure. The colors in the array will be used to initialize the custom colors.<br />

After the dialog box is closed, we can call function CColorDialog::GetColor() to retrieve the<br />

selected color. Also, if we’ve initialized custom colors, we can obtain the updated values by accessing<br />

member lpCustColors.<br />

Sample<br />

Sample 7.5\CDB demonstrates how to use color dialog box. First a function ColorDialog(…) is added<br />

to class CCDBDoc, which will implement a color dialog box whose default selected color and custom colors<br />

are customized. The following is its definition:<br />

……<br />

……<br />

class CCDBDoc : public CDocument<br />

{<br />

public:<br />

void ColorDialog(COLORREF colorInit, DWORD dwFlags=0);<br />

}<br />

This function has two parameters, the first one specifies the initially selected color, and the second one<br />

specifies the style flags. We will show how to use different style flags later, for the time being we just set<br />

all bits to 0. The function is implemented as follows:<br />

void CCDBDoc::ColorDialog(COLORREF colorInit, DWORD dwFlags)<br />

{<br />

CColorDialog dlg(colorInit);<br />

COLORREF color[16];<br />

COLORREF colorRlt;<br />

CString szStr;<br />

CString szStrRGB;<br />

int i;<br />

dlg.m_cc.Flags|=dwFlags;<br />

for(i=0; i

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!