⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 colourpicker.shtml.htm

📁 mfc资料集合5
💻 HTM
字号:
<HTML>
<HEAD>
   <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
   <META NAME="Author" CONTENT="Zafir Anjum">
   <TITLE>Controls - Office 97 style Colour Picker control</TITLE>
</HEAD>
<body background="../fancyhome/back.gif" tppabs="http://www.codeguru.com/fancyhome/back.gif" bgcolor="#FFFFFF" link="#B50029" vlink="#8E2323" alink="#FF0000">
<table WIDTH="100%">
<tr WIDTH="100%">
<td><td>
</tr>
</table>


<CENTER>
<H3>
<FONT COLOR="#AOAO99">Office 97 style Colour Picker control</FONT></H3></CENTER>
<HR>


This sample was contributed by <A HREF="mailto:Chris.Maunder@cbr.clw.csiro.au">Chris Maunder</A>,
and extended by <A HREF="mailto:bischofb@informatik.tu-muenchen.de">Alexander Bischofberger</A>.

<p>
<img src="ColourPicker.gif" tppabs="http://www.codeguru.com/controls/ColourPicker.gif" border=0 alt="Colour Picker image" align="bottom">
Download <A HREF="ColourPicker.zip" tppabs="http://www.codeguru.com/controls/ColourPicker.zip">source files</A> (11.4 Kb) or 
<A HREF="ColourPickDemo.zip" tppabs="http://www.codeguru.com/controls/ColourPickDemo.zip">sample project</a> (44 Kb).
</p>

<p>
<strong>If you have read this before, then you can read about version 1.1
<a href="ColourPicker.shtml.htm#Version11" tppabs="http://www.codeguru.com/controls/ColourPicker.shtml#Version11">here.</a></strong>
</p>

<p>In an effort to have the latest and greatest wizz-bang features in
my programs I unashamedly ripped of the colour picker from Office 97.

<p>Initially I tried to modify an owner drawn combo box and combine
that with a multicolumn combobox, but current multicolumn combo
boxes are really just a single column with dividing lines drawn in.
I then decided to write the whole thing from scratch based on a button,
since it would at least give me a BN_CLICKED notification to get
things started.

<p>The colour picker is in two parts: an owner drawn button that
reflects the currently selected colour, and a popup colour chooser
window to select this colour. When the user clicks on the button
the popup window appears and all mouse messages are captured until
the left mouse button is clicked, or until the Enter or Escape keys
are pressed. The popup window can be navigated using the mouse or
the keyboard and includes tooltips explaining what each colour is.

<p>The control can be incorporated into a project like any other
Cbutton derived control. Either Create the control manually, subclass
an existing CButton or DDX_control it. The control also comes with
a <strong>DDX_ColourPicker</strong> routine to get/set the colour of 
the control using a variable of type <FONT COLOR="blue">COLORREF</Font>.

<p>The Colour Picker is contained in the class <strong>CColourPicker</strong>.
It uses the class <strong>CColourPopup</strong> for the popup window.
These classes are contained in the file <A HREF="ColourPicker.zip" tppabs="http://www.codeguru.com/controls/ColourPicker.zip">
ColourPicker.zip</a>, and a sample project is contained in
<A HREF="ColourPickDemo.zip" tppabs="http://www.codeguru.com/controls/ColourPickDemo.zip">ColourPickDemo.zip</a>. 

<p>CColourPicker only has the following public member functions:
<PRE><TT><FONT COLOR="#990000">		void     SetColour(COLORREF crColour);
		COLORREF GetColour();

		void     SetSelectionMode(UINT nMode); // Either CP_MODE_TEXT or CP_MODE_BK
		UINT     GetSelectionMode();

		void     SetBkColour(COLORREF crColourBk);
		COLORREF GetBkColour();
    
		void     SetTextColour(COLORREF crColourText);
		COLORREF GetTextColour();
</FONT></TT></PRE>

<p>(These last 6 are new as of version 1.1)

<p>You can choose whether the colour chosen using the dropdown colour chooser will
affect the text or the background colour using the new member function
<b>SetSelectionMode(int nMode)</b>. Possible values for nMode are CP_MODE_TEXT
to make colour changes affect the text colour, and CP_MODE_BK to make changes
affect the background (default). 

<p><b>SetColour</b>, <b>GetColour</b> and the the DDX-function
will set and get the colour according to the current selection mode. To access
the text colour and the background colour directly use the Set/GetTextColour
and Set/GetBkColour functions.

<p>There are also a number of user messages that may be handled to
get more information from the control. These are:

<BR>&nbsp;
<CENTER><TABLE BORDER WIDTH="90%" BGCOLOR="#FFFFCC" >
<TR>
<TH ALIGN=LEFT WIDTH="20%">Message</TH>
<TH ALIGN=LEFT>Description</TH>
</TR>

<TR><TD WIDTH="30%">CPN_SELCHANGE</TD>     <TD>Colour Picker Selection change</TD></TR>
<TR><TD WIDTH="30%">CPN_DROPDOWN</TD>      <TD>Colour Picker drop down</TD></TR>
<TR><TD WIDTH="30%">CPN_CLOSEUP</TD>       <TD>Colour Picker close up</TD></TR>
<TR><TD WIDTH="30%">CPN_SELENDOK</TD>      <TD>Colour Picker end OK</TD></TR>
<TR><TD WIDTH="30%">CPN_SELENDCANCEL</TD>  <TD>Colour Picker end (cancelled)</TD></TR>

</TABLE></CENTER>

<p>These messages can be handled using <strong>ON_MESSAGE(&lt MESSAGE&gt, <em>MessageFn</em>)
</strong> in you message map entries, where <strong>MessageFn</strong> is of
the form<br>

<PRE><TT><FONT COLOR="#990000">
    afx_msg LONG MessageFn(UINT lParam, LONG wParam);
</FONT></TT></PRE>

<p>The demo program gives an example of how to do this.

<br><br><HR><br><br>

<H3><a name="Version11">New in Version 1.1</a></H3>

<p>
The following changes have been made by <A HREF="mailto:bischofb@informatik.tu-muenchen.de">Alexander Bischofberger</a>.

<p>
The original version did not display a text inside the combo box. The current version
now displays the button text (as set in the dialog resource, or via SetWindowText).

You can choose whether the colour chosen using the dropdown colour chooser will
affect the text or the background colour using the new member function
<b>SetSelectionMode</b>:

<PRE><TT><FONT COLOR="#990000">		#define CP_MODE_TEXT 1		// Colour selection affects text colour
		#define CP_MODE_BK   2		// Colour selection affects background colour (default)

		void     SetSelectionMode(UINT nMode);
		UINT     GetSelectionMode();
</FONT></TT></PRE>

Two new member functions have been introduced to set the text colour and the
background colour directly:

<PRE><TT><FONT COLOR="#990000">		void     SetBkColour(COLORREF crColourBk);
		COLORREF GetBkColour();
    
		void     SetTextColour(COLORREF crColourText);
		COLORREF GetTextColour();
</FONT></TT></PRE>

<p><b>SetColour</b>, <b>GetColour</b> and the the DDX-function
will set and get the colour according to the current selection mode.
<p>
Some minor changes were made in the drawing routine (now faster and able to show a
pressed combo box button), the messaging (CPN_SELCHANGE now sent to the parent).

<p>
The following changes have been made by <A HREF="mailto:Chris.Maunder@cbr.clw.csiro.au">
Chris Maunder</a>.

<p>The button now stays pressed while colour choosing is in progress, and the initial
colour sent to the drop down colour chooser is highlighted as in Office 97. Oh - and 
a line now separates the Custom Text area from the colours. weee!

<p>Palette support is now included so things don't look so bad in 256 colours.

<br><br>
<p>See the updated <A HREF="ColourPickDemo.zip" tppabs="http://www.codeguru.com/controls/ColourPickDemo.zip">sample</A> how to use the new
functionality. 


<p>Updated 27 March 1998


<P>
<HR>
<TABLE BORDER=0 WIDTH="100%" >
<TR>
<TD WIDTH="33%"><FONT SIZE=-1><A HREF="../index.htm" tppabs="http://www.codeguru.com/">Goto HomePage</A></FONT></TD>

<TD WIDTH="33%">
<CENTER><FONT SIZE=-2>&copy; 1997 Zafir Anjum</FONT>&nbsp;</CENTER>
</TD>

<TD WIDTH="34%">
<DIV ALIGN=right><FONT SIZE=-1>Contact me: <A HREF="mailto:zafir@home.com">zafir@home.com</A>&nbsp;</FONT></DIV>
</TD>
</TR>
</TABLE>
<CENTER><FONT SIZE=-2>5368</FONT></CENTER>
</BODY>
</HTML>

⌨️ 快捷键说明

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