C++重绘CPropertySheet
生活随笔
收集整理的這篇文章主要介紹了
C++重绘CPropertySheet
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
CWizard類繼承自CPropertySheet,左邊的按鈕使用重繪的CListBox(CSideNav)。CPropertySheet原有的CTabCtrl被隱藏了,窗口中的按鈕使用重繪的CButton(CLexyButton)。以下代碼中OnNcPaint中的代碼是重繪非客戶區,可以不要。
1 //CWizard頭文件2 ?#pragma once
3 #include "LexyButton.h"
4 #include "SideNav.h"
5
6
7 ?// CWizard
8 ?
9 class CWizard : public CPropertySheet
10 {
11 DECLARE_DYNAMIC(CWizard)
12
13 public:
14 CWizard(UINT nIDCaption, CWnd* pParentWnd = NULL, UINT iSelectPage = 0);
15 CWizard(LPCTSTR pszCaption, CWnd* pParentWnd = NULL, UINT iSelectPage = 0);
16 virtual ~CWizard();
17 private:
18 CLexyButton mOK;
19 CLexyButton mCancel;
20 CLexyButton mApply;
21 CSideNav mTabCtrl;
22 std::vector<int> poslist;
23 int _sys_btn_idx;
24 BOOL inited;
25 void FixLocation(BOOL MovePageOnly=FALSE);
26 protected:
27 DECLARE_MESSAGE_MAP()
28 public:
29 virtual BOOL OnInitDialog();
30 virtual BOOL DestroyWindow();
31 afx_msg void OnNcPaint();
32 afx_msg BOOL OnNcActivate(BOOL bActive);
33 afx_msg void OnNcMouseMove(UINT nHitTest, CPoint point);
34 afx_msg void OnNcLButtonDown(UINT nHitTest, CPoint point);
35 afx_msg void OnTabChange();
36 afx_msg void OnPaint();
37 };
38
39
40
41 //CWizard的cpp
42 // Wizard.cpp : 實現文件
43 //
44
45 #include "stdafx.h"
46 #include "MyPIM.h"
47 #include "Wizard.h"
48 #include "LexySkin.h"
49
50 // CWizard
51
52 IMPLEMENT_DYNAMIC(CWizard, CPropertySheet)
53
54 CWizard::CWizard(UINT nIDCaption, CWnd* pParentWnd, UINT iSelectPage)
55 :CPropertySheet(nIDCaption, pParentWnd, iSelectPage){
56 m_psh.dwFlags |= PSH_NOAPPLYNOW;
57 _sys_btn_idx=-1;
58 inited=FALSE;
59 }
60
61 CWizard::CWizard(LPCTSTR pszCaption, CWnd* pParentWnd, UINT iSelectPage)
62 :CPropertySheet(pszCaption, pParentWnd, iSelectPage){
63 m_psh.dwFlags |= PSH_NOAPPLYNOW;
64 _sys_btn_idx=-1;
65 inited=FALSE;
66 }
67 CWizard::~CWizard(){}
68
69
70 BEGIN_MESSAGE_MAP(CWizard, CPropertySheet)
71 ON_WM_NCPAINT()
72 ON_WM_NCACTIVATE()
73 ON_WM_NCMOUSEMOVE()
74 ON_WM_NCLBUTTONDOWN()
75 ON_LBN_SELCHANGE(13579,OnTabChange)
76 ON_WM_PAINT()
77 END_MESSAGE_MAP()
78
79
80 // CWizard 消息處理程序
81
82 void CWizard::OnNcMouseMove(UINT nHitTest, CPoint point)
83 {
84 // TODO: 在此添加消息處理程序代碼和/或調用默認值
85 CRect rc;
86 GetWindowRect(rc);
87 CPoint pt(point.x-rc.left,point.y-rc.top);
88
89 if((poslist.size()==2)&&(pt.y<GetSystemMetrics(SM_CYCAPTION))){
90 int pos=-1;
91 if(pt.x>poslist.at(0)) pos=0;
92 if(pt.x>poslist.at(1)) pos=1;
93
94 if(pos!=_sys_btn_idx){
95 _sys_btn_idx=pos;
96 LexySkin::GetSkin()->DrawDialogNCButton(this,_sys_btn_idx);
97 //CString msg;
98 //msg.Format(L"0:%d--1:%d |pos:%d\r\n",poslist.at(0),poslist.at(1) ,pt.x);
99 //OutputDebugStringW(msg);
100 }
101 }else{
102 if(_sys_btn_idx!=-1){
103 _sys_btn_idx=-1;
104 LexySkin::GetSkin()->DrawDialogNCButton(this,_sys_btn_idx);
105 }
106 }
107 CPropertySheet::OnNcMouseMove(nHitTest, point);
108 }
109
110 void CWizard::OnNcLButtonDown(UINT nHitTest, CPoint point)
111 {
112 // TODO: 在此添加消息處理程序代碼和/或調用默認值
113 CRect rc;
114 GetWindowRect(rc);
115 CPoint pt(point.x-rc.left,point.y-rc.top);
116 if((poslist.size()==2)&&(pt.y<GetSystemMetrics(SM_CYCAPTION))){
117 int pos=-1;
118 if(pt.x>poslist.at(0)) pos=0;
119 if(pt.x>poslist.at(1)) pos=1;
120 LPARAM lp=MAKELPARAM(point.x, point.y);
121 switch(pos){
122 case 0:
123 SendMessage(WM_SYSCOMMAND, SC_MINIMIZE,lp );
124 break;
125 case 1:
126 PostMessage(WM_SYSCOMMAND,SC_CLOSE);
127 return;
128 default:
129 break;
130 }
131 }
132 CPropertySheet::OnNcLButtonDown(nHitTest, point);
133 }
134
135
136 BOOL CWizard::OnInitDialog()
137 {
138 BOOL bResult = CPropertySheet::OnInitDialog();
139 // TODO: 在此添加您的專用代碼
140 CTabCtrl* tab=this->GetTabControl();
141 tab->ShowWindow(SW_HIDE);
142 //子類化對話框按鈕
143 mCancel.SubclassDlgItem(IDCANCEL,this);
144 mOK.SubclassDlgItem(IDOK,this);
145 //初始化導航
146 mTabCtrl.Create(LBS_STANDARD|WS_CHILD|WS_VISIBLE, CRect(0,0,90,100),this,13579);
147 mTabCtrl.SetItemIcon(IDI_LI_DEF,IDI_LI_SEL);
148 for(int i=0;i<GetPageCount();i++){
149 TCITEM tcItem;
150 TCHAR buffer[256] = {0};
151 tcItem.pszText = buffer;
152 tcItem.cchTextMax = 256;
153 tcItem.mask = TCIF_TEXT;
154 tab->GetItem(i, &tcItem);
155
156 mTabCtrl.AddString(tcItem.pszText);
157 }
158
159 inited=TRUE;
160 FixLocation();
161
162 LexySkin::FixRoundWindow(this);
163 return bResult;
164 }
165
166
167 BOOL CWizard::DestroyWindow()
168 {
169 // TODO: 在此添加專用代碼和/或調用基類
170 return CPropertySheet::DestroyWindow();
171 }
172
173
174 void CWizard::OnNcPaint()
175 {
176 // TODO: 在此處添加消息處理程序代碼
177 // 不為繪圖消息調用 CPropertySheet::OnNcPaint()
178 LexySkin::GetSkin()->DrawNC(this);
179 poslist=LexySkin::GetSkin()->DrawDialogNCButton(this,_sys_btn_idx);
180 }
181
182
183 BOOL CWizard::OnNcActivate(BOOL bActive)
184 {
185 // TODO: 在此添加消息處理程序代碼和/或調用默認值
186 OnNcPaint();
187 return TRUE;
188 //return CPropertySheet::OnNcActivate(bActive);
189 }
190
191
192
193
194 void CWizard::FixLocation(BOOL MovePageOnly){
195 if(!inited) return;
196 CRect rect;
197 //整體窗體調整
198 const int addw=100;
199 if(!MovePageOnly){
200 GetWindowRect(rect);
201 this->MoveWindow(rect.left,rect.top,rect.Width()+addw,rect.Height());
202 }
203 //客戶區域調整
204 GetClientRect(rect);
205 //調整屬性頁
206 for(int i=0;i<m_pages.GetCount();i++){
207 CPropertyPage* pg=this->GetPage(i);
208 if(IsWindow(pg->m_hWnd)){
209 pg->MoveWindow(10+addw+1,11,rect.Width()-addw-20-2,rect.Height()-50-2);
210 }
211 }
212 //調整按鈕
213 mCancel.MoveWindow(rect.Width()-100,rect.Height()-30,90,24);
214 mOK.MoveWindow(rect.Width()-192,rect.Height()-30,90,24);
215 //CTabCtrl
216 mTabCtrl.MoveWindow(10,10,96,rect.Height()-50);
217 //畫邊框
218 this->InvalidateRect(rect);
219 }
220
221 void CWizard::OnTabChange(){
222 //AfxMessageBox(L"TEST");
223 int n=mTabCtrl.GetCurSel();
224 if((n>=0)&(n<mTabCtrl.GetCount())){
225 SetActivePage(mTabCtrl.GetCurSel());
226 FixLocation(TRUE);
227
228 }
229 }
230
231
232 void CWizard::OnPaint()
233 {
234 CPaintDC dc(this); // device context for painting
235 // TODO: 在此處添加消息處理程序代碼
236 // 不為繪圖消息調用 CPropertySheet::OnPaint()
237 const int addw=100;
238 Graphics g(dc.m_hDC);
239 CRect rect;
240 GetClientRect(rect);
241 Gdiplus::Pen pen(Gdiplus::Color(183,194,214));
242 g.DrawRectangle(&pen,10+addw,10,rect.Width()-addw-20,rect.Height()-50-1);
243 g.ReleaseHDC(dc.m_hDC);
244 }
轉載于:https://www.cnblogs.com/Lexy/archive/2011/05/03/2035541.html
總結
以上是生活随笔為你收集整理的C++重绘CPropertySheet的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: WCF六大步的前三步
- 下一篇: 生活随笔:态度需要端正