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

📄 wtl for mfc programmers, part v.mht

📁 大家知道wtl是window UI库
💻 MHT
📖 第 1 页 / 共 5 页
字号:
      <P><CODE>SubclassWindow()</CODE> is overridden to perform the =
subclassing=20
      and initialize internal data that the class keeps.</P>
      <H5>Bitmap button extended styles</H5><PRE>DWORD =
GetBitmapButtonExtendedStyle()
DWORD SetBitmapButtonExtendedStyle(DWORD dwExtendedStyle,=20
                                   DWORD dwMask =3D <SPAN =
class=3Dcpp-literal>0</SPAN>)</PRE>
      <P><CODE>CBitmapButton</CODE> supports some extended styles that =
affect=20
      the appearance or operation of the button:</P>
      <DL>
        <DT><CODE>BMPBTN_HOVER</CODE>=20
        <DD>Enables hot-tracking. When the cursor is over the button, it =
will be=20
        drawn in the focused state.=20
        <DT><CODE>BMPBTN_AUTO3D_SINGLE</CODE>, =
<CODE>BMPBTN_AUTO3D_DOUBLE</CODE>=20

        <DD>Automatically generates a 3D border around the image, as =
well as a=20
        focus rectangle when the button has the focus. In addition, if =
you do=20
        not provide an image for the pressed state, one is generated for =
you.=20
        <CODE>BMPBTN_AUTO3D_DOUBLE</CODE> produces a slightly thicker =
border.=20
        <DT><CODE>BMPBTN_AUTOSIZE</CODE>=20
        <DD>Makes the button resize itself to match the size of the =
image. This=20
        style is the default.=20
        <DT><CODE>BMPBTN_SHAREIMAGELISTS</CODE>=20
        <DD>If set, the button object does not destroy the image list =
used to=20
        hold the button images. If not set, the image list is destroyed =
by the=20
        <CODE>CBitmapButton</CODE> destructor.=20
        <DT><CODE>BMPBTN_AUTOFIRE</CODE>=20
        <DD>If set, clicking the button and holding down the mouse =
button=20
        generates repeated <CODE>WM_COMMAND</CODE> messages. </DD></DL>
      <P>When calling <CODE>SetBitmapButtonExtendedStyle()</CODE>, the=20
      <CODE>dwMask</CODE> parameter controls which styles are affected. =
Use the=20
      default of 0 to have the new styles completely replace the old =
ones.</P>
      <H5>Image list management</H5><PRE>HIMAGELIST GetImageList()
HIMAGELIST SetImageList(HIMAGELIST hImageList)</PRE>
      <P>Call <CODE>SetImageList()</CODE> to associate an image list =
with the=20
      button.</P>
      <H5>Tooltip management</H5><PRE><SPAN =
class=3Dcpp-keyword>int</SPAN>  GetToolTipTextLength()
<SPAN class=3Dcpp-keyword>bool</SPAN> GetToolTipText(LPTSTR lpstrText, =
<SPAN class=3Dcpp-keyword>int</SPAN> nLength)
<SPAN class=3Dcpp-keyword>bool</SPAN> SetToolTipText(LPCTSTR =
lpstrText)</PRE>
      <P><CODE>CBitmapButton</CODE> supports showing a tooltip when the =
mouse=20
      hovers over the button. Call <CODE>SetToolTipText()</CODE> to =
specify the=20
      text to show.</P>
      <H5>Setting the images to use</H5><PRE><SPAN =
class=3Dcpp-keyword>void</SPAN> SetImages(<SPAN =
class=3Dcpp-keyword>int</SPAN> nNormal, <SPAN =
class=3Dcpp-keyword>int</SPAN> nPushed =3D -<SPAN =
class=3Dcpp-literal>1</SPAN>,
               <SPAN class=3Dcpp-keyword>int</SPAN> nFocusOrHover =3D =
-<SPAN class=3Dcpp-literal>1</SPAN>, <SPAN =
class=3Dcpp-keyword>int</SPAN> nDisabled =3D -<SPAN =
class=3Dcpp-literal>1</SPAN>)</PRE>
      <P>Call <CODE>SetImages()</CODE> to tell the button which image in =
the=20
      image list to use for which button state. <CODE>nNormal</CODE> is=20
      required, but the others are optional. Pass -1 to indicate that =
there is=20
      no image for the corresponding state.</P>
      <H3><A name=3Dcchecklist></A>CCheckListViewCtrl</H3>
      <P><CODE>CCheckListViewCtrl</CODE>, defined in atlctrlx.h, is a=20
      <CODE>CWindowImpl</CODE>-derived class that implements a list view =
control=20
      containing check boxes. This is different from MFC's=20
      <CODE>CCheckListBox</CODE>, which uses a list box, not a list =
view.=20
      <CODE>CCheckListViewCtrl</CODE> is quite simple, since the class =
adds=20
      minimal functionality on its own. However, it does introduce a new =
helper=20
      class, <CODE>CCheckListViewCtrlImplTraits</CODE>, that is like=20
      <CODE>CWinTraits</CODE> but with a third parameter that is the =
extended=20
      list view styles to use for the control. If you don't define your =
own set=20
      of <CODE>CCheckListViewCtrlImplTraits</CODE>, the class uses these =
styles=20
      by default: <CODE>LVS_EX_CHECKBOXES | =
LVS_EX_FULLROWSELECT</CODE>.</P>
      <P>Here is a sample traits definition that uses different extended =
list=20
      view styles, plus a new class that uses those traits. (Note that =
you must=20
      include <CODE>LVS_EX_CHECKBOXES</CODE> in the extended list view =
styles,=20
      or else you will get an assert failed message.)</P><PRE><SPAN =
class=3Dcpp-keyword>typedef</SPAN> CCheckListViewCtrlImplTraits&lt;
    WS_CHILD | WS_VISIBLE | LVS_REPORT,=20
    WS_EX_CLIENTEDGE,
    LVS_EX_CHECKBOXES | LVS_EX_GRIDLINES | LVS_EX_UNDERLINEHOT |
      LVS_EX_ONECLICKACTIVATE&gt; CMyCheckListTraits;
=20
<SPAN class=3Dcpp-keyword>class</SPAN> CMyCheckListCtrl :
    <SPAN class=3Dcpp-keyword>public</SPAN> =
CCheckListViewCtrlImpl&lt;CMyCheckListCtrl, CListViewCtrl,=20
                                  CMyCheckListTraits&gt;
{
<SPAN class=3Dcpp-keyword>private</SPAN>:
    <SPAN class=3Dcpp-keyword>typedef</SPAN> =
CCheckListViewCtrlImpl&lt;CMyCheckListCtrl, CListViewCtrl,=20
                                   CMyCheckListTraits&gt; baseClass;
<SPAN class=3Dcpp-keyword>public</SPAN>:
    BEGIN_MSG_MAP(CMyCheckListCtrl)
        CHAIN_MSG_MAP(baseClass)
    END_MSG_MAP()
};</PRE>
      <H4>CCheckListViewCtrl methods</H4>
      <H5>SubclassWindow()</H5>
      <P>When you subclass an existing list view control,=20
      <CODE>SubclassWindow()</CODE> looks at the extended list view =
styles in=20
      the associated <CODE>CCheckListViewCtrlImplTraits</CODE> class and =
applies=20
      them to the control. The first two template parameters (windows =
styles and=20
      extended window styles) are not used.</P>
      <H5>SetCheckState() and GetCheckState()</H5>
      <P>These methods are actually in <CODE>CListViewCtrl</CODE>.=20
      <CODE>SetCheckState()</CODE> takes an item index and a boolean =
indicating=20
      whether to check or uncheck that item. =
<CODE>GetCheckState()</CODE> takes=20
      just an index and returns the current checked state of that =
item.</P>
      <H5>CheckSelectedItems()</H5>
      <P>This method takes an item index. It toggles the check state of =
that=20
      item, which must be selected, and changes the check state of all =
other=20
      selected items to match. You probably won't use this method =
yourself,=20
      since <CODE>CCheckListViewCtrl</CODE> handles checking items when =
the=20
      check box is clicked or the user presses the space bar.</P>
      <P>Here's how a <CODE>CCheckListViewCtrl</CODE> looks in=20
ControlMania2:</P>
      <P><IMG height=3D429 alt=3D" [Check list ctrl - 12K] "=20
      src=3D"http://www.codeproject.com/wtl/WTL4MFC5/cm2_lv.png" =
width=3D305=20
      align=3Dbottom border=3D0></P>
      <H3><A name=3Dtreeex></A>CTreeViewCtrlEx and CTreeItem</H3>
      <P>These two classes make it easier to use tree control features =
by=20
      wrapping an <CODE>HTREEITEM</CODE>. A <CODE>CTreeItem</CODE> =
object keeps=20
      an <CODE>HTREEITEM</CODE> and a pointer to the tree control that =
contains=20
      the item. You can then perform operations on that item using just=20
      <CODE>CTreeItem</CODE>; you don't have to refer to the tree =
control in=20
      every call. <CODE>CTreeViewCtrlEx</CODE> is like=20
      <CODE>CTreeViewCtrl</CODE>, however its methods deal with=20
      <CODE>CTreeItem</CODE>s instead of <CODE>HTREEITEM</CODE>s. So for =

      example, when you call <CODE>InsertItem()</CODE>, it returns a=20
      <CODE>CTreeItem</CODE> instead of an <CODE>HTREEITEM</CODE>. You =
can then=20
      operate on the newly-inserted item using the =
<CODE>CTreeItem</CODE>.=20
      Here's an example:</P><PRE><SPAN class=3Dcpp-comment>// Using =
plain HTREEITEMs:</SPAN>
HTREEITEM hti, hti2;
=20
    hti =3D m_wndTree.InsertItem ( <SPAN =
class=3Dcpp-string>"foo"</SPAN>, TVI_ROOT, TVI_LAST );
    hti2 =3D m_wndTree.InsertItem ( <SPAN =
class=3Dcpp-string>"bar"</SPAN>, hti, TVI_LAST );
    m_wndTree.SetItemData ( hti2, <SPAN class=3Dcpp-literal>100</SPAN> =
);
=20
<SPAN class=3Dcpp-comment>// Using CTreeItems:</SPAN>
CTreeItem ti, ti2;
=20
    ti =3D m_wndTreeEx.InsertItem ( <SPAN =
class=3Dcpp-string>"foo"</SPAN>, TVI_ROOT, TVI_LAST );
    ti2 =3D ti.AddTail ( <SPAN class=3Dcpp-string>"bar"</SPAN>, <SPAN =
class=3Dcpp-literal>0</SPAN> );
    ti2.SetData ( <SPAN class=3Dcpp-literal>100</SPAN> );</PRE>
      <P><CODE>CTreeItem</CODE> has a method corresponding to every=20
      <CODE>CTreeViewCtrl</CODE> method that takes an =
<CODE>HTREEITEM</CODE>,=20
      just like <CODE>CWindow</CODE> contains a method corresponding to =
every=20
      API that takes an <CODE>HWND</CODE>. Check out the ControlMania2 =
code,=20
      which demonstrates more methods of <CODE>CTreeViewCtrlEx</CODE> =
and=20
      <CODE>CTreeItem</CODE>.</P>
      <H3><A name=3Dchyperlink></A>CHyperLink</H3>
      <P><CODE>CHyperLink</CODE> is a <CODE>CWindowImpl</CODE>-derived =
class=20
      that can subclass a static text control and make it into a =
clickable=20
      hyperlink. <CODE>CHyperLink</CODE> automatically handles drawing =
the link,=20
      following the user's IE color preferences, and also supports =
keyboard=20
      navigation. The <CODE>CHyperLink</CODE> constructor takes no =
parameters,=20
      so here are the remaining public methods<CODE>.</CODE></P>
      <H4>CHyperLink methods</H4>
      <P>The class <CODE>CHyperLinkImpl</CODE> contains all the code to=20
      implement a link, but unless you need to override a method or =
message=20
      handler, you can stick with <CODE>CHyperLink</CODE> for your =
controls.</P>
      <H5>SubclassWindow()</H5><PRE>BOOL SubclassWindow(HWND hWnd)</PRE>
      <P><CODE>SubclassWindow()</CODE> is overridden to perform the =
subclassing,=20
      then initialize internal data that the class keeps.</P>
      <H5>Text label management</H5><PRE><SPAN =
class=3Dcpp-keyword>bool</SPAN> GetLabel(LPTSTR lpstrBuffer, <SPAN =
class=3Dcpp-keyword>int</SPAN> nLength)
<SPAN class=3Dcpp-keyword>bool</SPAN> SetLabel(LPCTSTR lpstrLabel)</PRE>
      <P>Gets or sets the text to use in the control. If you do not set =
the=20
      label text, the control uses the text you assign to the static =
control in=20
      the resource editor.</P>
      <H5>Hyperlink management</H5><PRE><SPAN =
class=3Dcpp-keyword>bool</SPAN> GetHyperLink(LPTSTR lpstrBuffer, <SPAN =
class=3Dcpp-keyword>int</SPAN> nLength)
<SPAN class=3Dcpp-keyword>bool</SPAN> SetHyperLink(LPCTSTR =
lpstrLink)</PRE>
      <P>Gets or sets the URL that the control will launch when it is =
clicked.=20
      If you do not set the hyperlink, the control uses the text label =
as the=20
      URL.</P>
      <H5>Navigation</H5><PRE><SPAN class=3Dcpp-keyword>bool</SPAN> =
Navigate()</PRE>
      <P>Navigates to the current hyperlink URL, either set via=20
      <CODE>SetHyperLink()</CODE>, or the default which is the window =
text.</P>
      <H5>Tooltip management</H5>
      <P>There are no methods for setting the tooltip, so you will need =
to=20
      directly access the <CODE>CToolTipCtrl</CODE> member,=20
      <CODE>m_tip</CODE>.</P>
      <P>Here is how a hyperlink control looks in the ControlMania2 =
dialog:</P>
      <P><IMG height=3D324 alt=3D" [WTL hyperlink - 12K] "=20
      src=3D"http://www.codeproject.com/wtl/WTL4MFC5/hyperlink.png" =
width=3D305=20
      align=3Dbottom border=3D0></P>
      <P>The URL is set with this call in =
<CODE>OnInitDialog()</CODE>:</P><PRE>    m_wndLink.SetHyperLink ( =
_T(<SPAN class=3Dcpp-string>"http://www.codeproject.com/"</SPAN>) =
);</PRE>
      <H2><A name=3Duiupdctrl></A>UI Updating Dialog Controls</H2>
      <P>UI updating controls in a dialog is much easier than in MFC. In =
MFC,=20
      you have to know about the undocumented <CODE>WM_KICKIDLE</CODE> =
message=20
      and how to handle it and trigger control updating. In WTL, there =
are no=20
      such tricks, although there is a bug in the AppWizard that =
requires you to=20
      add one line of code.</P>
      <P>The first thing to remember is that the dialog <B>must</B> be =
modeless.=20
      This is necessary because for <CODE>CUpdateUI</CODE> to do its =
job, your=20
      app needs to be in control of the message loop. If you make the =
dialog=20
      modal, the system handles the message loop, so idle handlers won't =
get=20
      called. Since <CODE>CUpdateUI</CODE> does its work at idle time, =
no idle=20
      processing means no UI updating.</P>
      <P>ControlMania2's dialog is modeless, and the first part of the =
class=20
      definition resembles a frame window class:</P><PRE><SPAN =
class=3Dcpp-keyword>class</SPAN> CMainDlg : <SPAN =
class=3Dcpp-keyword>public</SPAN> CDialogImpl&lt;CMainDlg&gt;, <SPAN =
class=3Dcpp-keyword>public</SPAN> CUpdateUI&lt;CMainDlg&gt;,
                 <SPAN class=3Dcpp-keyword>public</SPAN> CMessageFilter, =
<SPAN class=3Dcpp-keyword>public</SPAN> CIdleHandler
{
<SPAN class=3Dcpp-keyword>public</SPAN>:
    <SPAN class=3Dcpp-keyword>enum</SPAN> { IDD =3D IDD_MAINDLG };
=20
    <SPAN class=3Dcpp-keyword>virtual</SPAN> BOOL =
PreTranslateMessage(MSG* pMsg);
    <SPAN class=3Dcpp-keyword>virtual</SPAN> BOOL OnIdle();
=20
    BEGIN_MSG_MAP_EX(CMainDlg)
        MSG_WM_INITDIALOG(OnInitDialog)
        COMMAND_ID_HANDLER_EX(IDOK, OnOK)
        COMMAND_ID_HANDLER_EX(IDCANCEL, OnCancel)
        COMMAND_ID_HANDLER_EX(IDC_ALYSON_BTN, OnAlysonODBtn)

⌨️ 快捷键说明

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