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 }
posted @ 2011-05-03 17:35  Lexy  阅读(3374)  评论(5编辑  收藏  举报