CustomTabCtrlDemoDlg.cpp
上传用户:tang1250
上传日期:2020-10-23
资源大小:86k
文件大小:17k
源码类别:

PropertySheet

开发平台:

Visual C++

  1. // CustomTabCtrlDemoDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "CustomTabCtrlDemo.h"
  5. #include "CustomTabCtrlDemoDlg.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CAboutDlg dialog used for App About
  13. class CAboutDlg : public CDialog
  14. {
  15. public:
  16. CAboutDlg();
  17. // Dialog Data
  18. //{{AFX_DATA(CAboutDlg)
  19. enum { IDD = IDD_ABOUTBOX };
  20. //}}AFX_DATA
  21. // ClassWizard generated virtual function overrides
  22. //{{AFX_VIRTUAL(CAboutDlg)
  23. protected:
  24. virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  25. //}}AFX_VIRTUAL
  26. // Implementation
  27. protected:
  28. //{{AFX_MSG(CAboutDlg)
  29. //}}AFX_MSG
  30. DECLARE_MESSAGE_MAP()
  31. };
  32. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  33. {
  34. //{{AFX_DATA_INIT(CAboutDlg)
  35. //}}AFX_DATA_INIT
  36. }
  37. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  38. {
  39. CDialog::DoDataExchange(pDX);
  40. //{{AFX_DATA_MAP(CAboutDlg)
  41. //}}AFX_DATA_MAP
  42. }
  43. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  44. //{{AFX_MSG_MAP(CAboutDlg)
  45. // No message handlers
  46. //}}AFX_MSG_MAP
  47. END_MESSAGE_MAP()
  48. /////////////////////////////////////////////////////////////////////////////
  49. // CCustomTabCtrlDemoDlg dialog
  50. CCustomTabCtrlDemoDlg::CCustomTabCtrlDemoDlg(CWnd* pParent /*=NULL*/)
  51. : CDialog(CCustomTabCtrlDemoDlg::IDD, pParent)
  52. {
  53. //{{AFX_DATA_INIT(CCustomTabCtrlDemoDlg)
  54. //}}AFX_DATA_INIT
  55. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  56. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  57. }
  58. void CCustomTabCtrlDemoDlg::DoDataExchange(CDataExchange* pDX)
  59. {
  60. CDialog::DoDataExchange(pDX);
  61. //{{AFX_DATA_MAP(CCustomTabCtrlDemoDlg)  
  62. DDX_Control(pDX, IDC_DRAGMOVECK, m_ctrlDragmove);
  63. DDX_Control(pDX, IDC_DRAGCOPYCK, m_ctrlDragcopy); 
  64. DDX_Control(pDX, IDC_TOOLTIPSCK, m_ctrlTooltips);
  65. DDX_Control(pDX, IDC_MULTIHIGHLIGHTCK, m_ctrlMultihighlight);
  66. DDX_Control(pDX, IDC_EDITLABELSCK, m_ctrlEditlabels);
  67. DDX_Control(pDX, IDC_TAB, m_ctrlTab);
  68. //}}AFX_DATA_MAP
  69. }
  70. BEGIN_MESSAGE_MAP(CCustomTabCtrlDemoDlg, CDialog)
  71. //{{AFX_MSG_MAP(CCustomTabCtrlDemoDlg)
  72. ON_WM_SYSCOMMAND()
  73. ON_WM_PAINT()
  74. ON_WM_QUERYDRAGICON()
  75. ON_WM_SIZE()  
  76. ON_BN_CLICKED(IDC_MULTIHIGHLIGHTCK, OnMultihighlightck)
  77. ON_BN_CLICKED(IDC_TOOLTIPSCK, OnTooltipsck)
  78. ON_BN_CLICKED(IDC_EDITLABELSCK, OnEditlabelsck)
  79. ON_WM_CONTEXTMENU()
  80. ON_BN_CLICKED(IDC_DRAGMOVECK, OnDragmoveck)
  81. ON_BN_CLICKED(IDC_DRAGCOPYCK, OnDragcopyck)  
  82. ON_BN_CLICKED(IDC_RADIO3, OnRadio3)
  83. ON_BN_CLICKED(IDC_RADIO4, OnRadio4)
  84. ON_BN_CLICKED(IDC_RADIO5, OnRadio5)
  85. ON_BN_CLICKED(IDC_RADIO6, OnRadio6)
  86. ON_WM_NCPAINT()
  87. //}}AFX_MSG_MAP
  88. ON_NOTIFY(CTCN_CLICK, IDC_TAB, OnLButtonClickedTab)
  89. ON_NOTIFY(CTCN_RCLICK, IDC_TAB, OnRButtonClickedTab)
  90. ON_NOTIFY(CTCN_SELCHANGE, IDC_TAB, OnSelchangeTab)
  91. ON_NOTIFY(CTCN_HIGHLIGHTCHANGE, IDC_TAB, OnHighlightchangeTab)
  92. ON_NOTIFY(CTCN_ITEMMOVE, IDC_TAB, OnMoveitemTab)
  93. ON_NOTIFY(CTCN_ITEMCOPY, IDC_TAB, OnCopyitemTab)
  94. ON_NOTIFY(CTCN_LABELUPDATE, IDC_TAB, OnLabelupdateTab)
  95. END_MESSAGE_MAP()
  96. /////////////////////////////////////////////////////////////////////////////
  97. // CCustomTabCtrlDemoDlg message handlers
  98. BOOL CCustomTabCtrlDemoDlg::OnInitDialog()
  99. {
  100. CDialog::OnInitDialog();
  101. // Add "About..." menu item to system menu.
  102. // IDM_ABOUTBOX must be in the system command range.
  103. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  104. ASSERT(IDM_ABOUTBOX < 0xF000);
  105. CMenu* pSysMenu = GetSystemMenu(FALSE);
  106. if (pSysMenu != NULL)
  107. {
  108. CString strAboutMenu;
  109. strAboutMenu.LoadString(IDS_ABOUTBOX);
  110. if (!strAboutMenu.IsEmpty())
  111. {
  112. pSysMenu->AppendMenu(MF_SEPARATOR);
  113. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  114. }
  115. }
  116. // Set the icon for this dialog.  The framework does this automatically
  117. //  when the application's main window is not a dialog
  118. SetIcon(m_hIcon, TRUE); // Set big icon
  119. SetIcon(m_hIcon, FALSE); // Set small icon
  120. // TODO: Add extra initialization here
  121. CheckRadioButton(IDC_RADIO1,IDC_RADIO2,IDC_RADIO1);
  122. CheckRadioButton(IDC_RADIO3,IDC_RADIO6,IDC_RADIO3);
  123. m_ctrlTab.SetDragCursors(AfxGetApp()->LoadCursor(IDC_CURSORMOVE),AfxGetApp()->LoadCursor(IDC_CURSORCOPY));
  124. m_ctrlTab.InsertItem(0,"SS_BLACKRECT");
  125. m_ctrlTab.SetItemData(0,SS_BLACKRECT);
  126. m_ctrlTab.InsertItem(1,"SS_GRAY");
  127. m_ctrlTab.SetItemData(1,SS_GRAYRECT);
  128. m_ctrlTab.InsertItem(2,"SS_WHITERECT");
  129. m_ctrlTab.SetItemData(2,SS_WHITERECT);
  130. m_ctrlTab.SetCurSel(0);
  131. if(m_ctrlTab.GetStyle()&CTCS_TOOLTIPS)
  132. {
  133. m_ctrlTooltips.SetCheck(TRUE);
  134. m_ctrlTab.SetItemTooltipText(0,"Press to fill the static window background with the color used to draw window frames.");
  135. m_ctrlTab.SetItemTooltipText(1,"Press to fill the static window background with the color used to fill the screen background.");
  136. m_ctrlTab.SetItemTooltipText(2,"Press to fill the static window background with the color used to fill the the window background.");
  137. }
  138. CRect r;
  139. GetClientRect(r);
  140. Size(r.Width(),r.Height());
  141. return TRUE;  // return TRUE  unless you set the focus to a control
  142. }
  143. void CCustomTabCtrlDemoDlg::OnSysCommand(UINT nID, LPARAM lParam)
  144. {
  145. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  146. {
  147. CAboutDlg dlgAbout;
  148. dlgAbout.DoModal();
  149. }
  150. else
  151. {
  152. CDialog::OnSysCommand(nID, lParam);
  153. }
  154. }
  155. void CCustomTabCtrlDemoDlg::OnPaint() 
  156. {
  157. if (IsIconic())
  158. {
  159. CPaintDC dc(this); // device context for painting
  160. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  161. // Center icon in client rectangle
  162. int cxIcon = GetSystemMetrics(SM_CXICON);
  163. int cyIcon = GetSystemMetrics(SM_CYICON);
  164. CRect rect;
  165. GetClientRect(&rect);
  166. int x = (rect.Width() - cxIcon + 1) / 2;
  167. int y = (rect.Height() - cyIcon + 1) / 2;
  168. // Draw the icon
  169. dc.DrawIcon(x, y, m_hIcon);
  170. }
  171. else
  172. {
  173. CDialog::OnPaint();
  174. }
  175. }
  176. // The system calls this to obtain the cursor to display while the user drags
  177. //  the minimized window.
  178. HCURSOR CCustomTabCtrlDemoDlg::OnQueryDragIcon()
  179. {
  180. return (HCURSOR) m_hIcon;
  181. }
  182. void CCustomTabCtrlDemoDlg::OnSize(UINT nType, int cx, int cy) 
  183. {
  184. CDialog::OnSize(nType, cx, cy);
  185. Size(cx,cy);
  186. }
  187. void CCustomTabCtrlDemoDlg::Size(int cx, int cy)
  188. {
  189. if(m_ctrlTab.m_hWnd)
  190. {
  191. int m = 10;
  192. int h = 20;
  193. CRect rBn;
  194.  
  195. if(m_ctrlTab.IsVertical() && m_ctrlTab.GetStyle()&CTCS_TOP) // left
  196. {
  197.  
  198. m_ctrlTab.MoveWindow(m,m,h,cy-2*m);
  199. }
  200. else if(m_ctrlTab.GetStyle()&CTCS_TOP) // top
  201. m_ctrlTab.MoveWindow(m,m,cx-3*m-rBn.Width(),h);
  202. }
  203. else if(m_ctrlTab.IsVertical()) // right
  204. m_ctrlTab.MoveWindow(m+cx-3*m-rBn.Width()-h,m,h,cy-2*m);
  205. }
  206. else // bottom
  207. m_ctrlTab.MoveWindow(m,cy-h-m,cx-3*m-rBn.Width(),h);
  208. }
  209.    
  210. m_ctrlTooltips.MoveWindow(cx-m-rBn.Width(),9*m,rBn.Width(),rBn.Height());
  211. m_ctrlMultihighlight.MoveWindow(cx-m-rBn.Width(),11*m,rBn.Width(),rBn.Height());
  212. m_ctrlEditlabels.MoveWindow(cx-m-rBn.Width(),13*m,rBn.Width(),rBn.Height());
  213. m_ctrlDragmove.MoveWindow(cx-m-rBn.Width(),15*m,rBn.Width(),rBn.Height());
  214. m_ctrlDragcopy.MoveWindow(cx-m-rBn.Width(),17*m,rBn.Width(),rBn.Height()); 
  215. GetDlgItem(IDC_RADIO3)->MoveWindow(cx-m-rBn.Width(),23*m,rBn.Width(),rBn.Height());
  216. GetDlgItem(IDC_RADIO4)->MoveWindow(cx-m-rBn.Width(),25*m,rBn.Width(),rBn.Height());
  217. GetDlgItem(IDC_RADIO5)->MoveWindow(cx-m-rBn.Width(),27*m,rBn.Width(),rBn.Height());
  218. GetDlgItem(IDC_RADIO6)->MoveWindow(cx-m-rBn.Width(),29*m,rBn.Width(),rBn.Height());
  219.   RedrawWindow(NULL,NULL,RDW_ALLCHILDREN|RDW_ERASE|RDW_INVALIDATE);
  220. }
  221. }
  222. void CCustomTabCtrlDemoDlg::OnSelchangeTab(NMHDR* pNMHDR, LRESULT* pResult) 
  223. {
  224. TRACE("Notify(CTCN_SELCHANGE): nItem(%d) pszText('%s') lParam(%d) point(x=%d,y=%d) rect(l=%d,t=%d,r=%d,b=%d) bSelected(%d) bHighlighted(%d)n",
  225. ((CTC_NMHDR*)pNMHDR)->nItem,
  226. ((CTC_NMHDR*)pNMHDR)->pszText,
  227. ((CTC_NMHDR*)pNMHDR)->lParam,
  228. ((CTC_NMHDR*)pNMHDR)->ptHitTest.x,
  229. ((CTC_NMHDR*)pNMHDR)->ptHitTest.y,
  230. ((CTC_NMHDR*)pNMHDR)->rItem.left,
  231. ((CTC_NMHDR*)pNMHDR)->rItem.top,
  232. ((CTC_NMHDR*)pNMHDR)->rItem.right,
  233. ((CTC_NMHDR*)pNMHDR)->rItem.bottom,
  234. ((CTC_NMHDR*)pNMHDR)->fSelected,
  235. ((CTC_NMHDR*)pNMHDR)->fHighlighted);
  236.  
  237. *pResult = 0;
  238. }
  239. void CCustomTabCtrlDemoDlg::OnHighlightchangeTab(NMHDR* pNMHDR, LRESULT* pResult) 
  240. {
  241. TRACE("Notify(CTCN_HIGHLIGHTCHANGE): nItem(%d) pszText('%s') lParam(%d) point(x=%d,y=%d) rect(l=%d,t=%d,r=%d,b=%d) bSelected(%d) bHighlighted(%d)n",
  242. ((CTC_NMHDR*)pNMHDR)->nItem,
  243. ((CTC_NMHDR*)pNMHDR)->pszText,
  244. ((CTC_NMHDR*)pNMHDR)->lParam,
  245. ((CTC_NMHDR*)pNMHDR)->ptHitTest.x,
  246. ((CTC_NMHDR*)pNMHDR)->ptHitTest.y,
  247. ((CTC_NMHDR*)pNMHDR)->rItem.left,
  248. ((CTC_NMHDR*)pNMHDR)->rItem.top,
  249. ((CTC_NMHDR*)pNMHDR)->rItem.right,
  250. ((CTC_NMHDR*)pNMHDR)->rItem.bottom,
  251. ((CTC_NMHDR*)pNMHDR)->fSelected,
  252. ((CTC_NMHDR*)pNMHDR)->fHighlighted);
  253. *pResult = 0;
  254. }
  255. void CCustomTabCtrlDemoDlg::OnLButtonClickedTab(NMHDR* pNMHDR, LRESULT* pResult) 
  256. {  
  257. *pResult = 0;
  258. }
  259. void CCustomTabCtrlDemoDlg::OnRButtonClickedTab(NMHDR* pNMHDR, LRESULT* pResult) 
  260. {
  261. int nInsNdx;
  262. CMenu menu;
  263. menu.CreatePopupMenu();
  264.  
  265. TRACE("Notify(CTCN_RCLICK): nItem(%d) pszText('%s') lParam(%d) point(x=%d,y=%d) rect(l=%d,t=%d,r=%d,b=%d) bSelected(%d) bHighlighted(%d)n",
  266. ((CTC_NMHDR*)pNMHDR)->nItem,
  267. ((CTC_NMHDR*)pNMHDR)->pszText,
  268. ((CTC_NMHDR*)pNMHDR)->lParam,
  269. ((CTC_NMHDR*)pNMHDR)->ptHitTest.x,
  270. ((CTC_NMHDR*)pNMHDR)->ptHitTest.y,
  271. ((CTC_NMHDR*)pNMHDR)->rItem.left,
  272. ((CTC_NMHDR*)pNMHDR)->rItem.top,
  273. ((CTC_NMHDR*)pNMHDR)->rItem.right,
  274. ((CTC_NMHDR*)pNMHDR)->rItem.bottom,
  275. ((CTC_NMHDR*)pNMHDR)->fSelected,
  276. ((CTC_NMHDR*)pNMHDR)->fHighlighted);
  277. m_ctrlTab.SetCurSel(((CTC_NMHDR*)pNMHDR)->nItem);
  278. nInsNdx = ((CTC_NMHDR*)pNMHDR)->nItem;
  279. menu.AppendMenu(MF_STRING,1,_T("Insert Item"));
  280. menu.AppendMenu(MF_STRING,2,_T("Delete Item"));
  281. menu.AppendMenu(MF_STRING,3,_T("Rename")); 
  282. CPoint pt(((CTC_NMHDR*)pNMHDR)->ptHitTest);
  283. m_ctrlTab.ClientToScreen(&pt);
  284. int nRet = menu.TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD, 
  285. pt.x, pt.y, this);
  286. switch(nRet)
  287. {
  288. case 1:
  289. {
  290. if(m_ctrlTab.InsertItem(nInsNdx,_T("New SS_WHITERECT Item"),SS_WHITERECT)<0)
  291. AfxMessageBox("InsertItem(...) failed.nPossible errors:n1. Item index out of range.");
  292. }
  293. break;
  294. case 2:
  295. {
  296. if(m_ctrlTab.DeleteItem(((CTC_NMHDR*)pNMHDR)->nItem)!=CTCERR_NOERROR)
  297. AfxMessageBox("DeleteItem(...) failed.nPossible errors:n1. Item index out of range.");
  298. }
  299. break;
  300. case 3:
  301. {
  302. if(m_ctrlTab.EditLabel(((CTC_NMHDR*)pNMHDR)->nItem)!=CTCERR_NOERROR)
  303. AfxMessageBox("EditLabel(...) failed.nPossible errors:n1. Item index out of range.n2. Item not selected.n3. CTCS_EDITLABELS style not specified.");
  304. }
  305. break;
  306.    *pResult = 0;
  307. }
  308. void CCustomTabCtrlDemoDlg::OnMoveitemTab(NMHDR* pNMHDR, LRESULT* pResult) 
  309. {
  310. TRACE("Notify(CTCN_ITEMMOVE): nItem(%d) pszText('%s') lParam(%d) point(x=%d,y=%d) rect(l=%d,t=%d,r=%d,b=%d) bSelected(%d) bHighlighted(%d)n",
  311. ((CTC_NMHDR*)pNMHDR)->nItem,
  312. ((CTC_NMHDR*)pNMHDR)->pszText,
  313. ((CTC_NMHDR*)pNMHDR)->lParam,
  314. ((CTC_NMHDR*)pNMHDR)->ptHitTest.x,
  315. ((CTC_NMHDR*)pNMHDR)->ptHitTest.y,
  316. ((CTC_NMHDR*)pNMHDR)->rItem.left,
  317. ((CTC_NMHDR*)pNMHDR)->rItem.top,
  318. ((CTC_NMHDR*)pNMHDR)->rItem.right,
  319. ((CTC_NMHDR*)pNMHDR)->rItem.bottom,
  320. ((CTC_NMHDR*)pNMHDR)->fSelected,
  321. ((CTC_NMHDR*)pNMHDR)->fHighlighted);
  322. *pResult = 0;
  323. }
  324. void CCustomTabCtrlDemoDlg::OnCopyitemTab(NMHDR* pNMHDR, LRESULT* pResult) 
  325. {
  326. TRACE("Notify(CTCN_ITEMCOPY): nItem(%d) pszText('%s') lParam(%d) point(x=%d,y=%d) rect(l=%d,t=%d,r=%d,b=%d) bSelected(%d) bHighlighted(%d)n",
  327. ((CTC_NMHDR*)pNMHDR)->nItem,
  328. ((CTC_NMHDR*)pNMHDR)->pszText,
  329. ((CTC_NMHDR*)pNMHDR)->lParam,
  330. ((CTC_NMHDR*)pNMHDR)->ptHitTest.x,
  331. ((CTC_NMHDR*)pNMHDR)->ptHitTest.y,
  332. ((CTC_NMHDR*)pNMHDR)->rItem.left,
  333. ((CTC_NMHDR*)pNMHDR)->rItem.top,
  334. ((CTC_NMHDR*)pNMHDR)->rItem.right,
  335. ((CTC_NMHDR*)pNMHDR)->rItem.bottom,
  336. ((CTC_NMHDR*)pNMHDR)->fSelected,
  337. ((CTC_NMHDR*)pNMHDR)->fHighlighted);
  338. *pResult = 0;
  339. }
  340. void CCustomTabCtrlDemoDlg::OnLabelupdateTab(NMHDR* pNMHDR, LRESULT* pResult) 
  341. {
  342. TRACE("Notify(CTCN_LABELUPDATE): nItem(%d) pszText('%s') lParam(%d) point(x=%d,y=%d) rect(l=%d,t=%d,r=%d,b=%d) bSelected(%d) bHighlighted(%d)n",
  343. ((CTC_NMHDR*)pNMHDR)->nItem,
  344. ((CTC_NMHDR*)pNMHDR)->pszText,
  345. ((CTC_NMHDR*)pNMHDR)->lParam,
  346. ((CTC_NMHDR*)pNMHDR)->ptHitTest.x,
  347. ((CTC_NMHDR*)pNMHDR)->ptHitTest.y,
  348. ((CTC_NMHDR*)pNMHDR)->rItem.left,
  349. ((CTC_NMHDR*)pNMHDR)->rItem.top,
  350. ((CTC_NMHDR*)pNMHDR)->rItem.right,
  351. ((CTC_NMHDR*)pNMHDR)->rItem.bottom,
  352. ((CTC_NMHDR*)pNMHDR)->fSelected,
  353. ((CTC_NMHDR*)pNMHDR)->fHighlighted);
  354. if(CString(((CTC_NMHDR*)pNMHDR)->pszText).IsEmpty())
  355. {
  356. *pResult = 1; // Invalid label name
  357. AfxMessageBox("Invalid label name");
  358. }
  359. else
  360. *pResult = 0; // Label name OK
  361. }
  362. void CCustomTabCtrlDemoDlg::OnFixedck() 
  363. {
  364.  
  365. }
  366. void CCustomTabCtrlDemoDlg::OnFourbuttonsck() 
  367. }
  368. void CCustomTabCtrlDemoDlg::OnAutohidebuttonsck()
  369. }
  370. void CCustomTabCtrlDemoDlg::OnMultihighlightck() 
  371. {
  372. if(m_ctrlMultihighlight.GetCheck())
  373. m_ctrlTab.ModifyStyle(0,CTCS_MULTIHIGHLIGHT,0);
  374. else
  375. m_ctrlTab.ModifyStyle(CTCS_MULTIHIGHLIGHT,0,0);
  376. }
  377. void CCustomTabCtrlDemoDlg::OnTooltipsck()
  378. {
  379. if(m_ctrlTooltips.GetCheck())
  380. {
  381. m_ctrlTab.ModifyStyle(0,CTCS_TOOLTIPS,0); 
  382. for(int i=0;i<m_ctrlTab.GetItemCount();i++)
  383. {
  384. DWORD dwData;
  385. m_ctrlTab.GetItemData(i,dwData);
  386. m_ctrlTab.SetItemTooltipText(i,"测试页!");
  387. }
  388. }
  389. else
  390. m_ctrlTab.ModifyStyle(CTCS_TOOLTIPS,0,0);
  391. }
  392. void CCustomTabCtrlDemoDlg::OnEditlabelsck() 
  393. {
  394. if(m_ctrlEditlabels.GetCheck())
  395. m_ctrlTab.ModifyStyle(0,CTCS_EDITLABELS,0);
  396. else
  397. m_ctrlTab.ModifyStyle(CTCS_EDITLABELS,0,0);
  398. }
  399. void CCustomTabCtrlDemoDlg::OnDragmoveck() 
  400. {
  401. if(m_ctrlDragmove.GetCheck())
  402. m_ctrlTab.ModifyStyle(0,CTCS_DRAGMOVE,0);
  403. else
  404. m_ctrlTab.ModifyStyle(CTCS_DRAGMOVE,0,0);
  405. }
  406. void CCustomTabCtrlDemoDlg::OnDragcopyck() 
  407. {
  408. if(m_ctrlDragcopy.GetCheck())
  409. m_ctrlTab.ModifyStyle(0,CTCS_DRAGCOPY,0);
  410. else
  411. m_ctrlTab.ModifyStyle(CTCS_DRAGCOPY,0,0);
  412. }
  413. void CCustomTabCtrlDemoDlg::OnRadio1() 
  414. {
  415. // Default font
  416. m_ctrlTab.SetControlFont(m_ctrlTab.GetDefaultFont(), TRUE);
  417. }
  418. void CCustomTabCtrlDemoDlg::OnRadio2() 
  419. {
  420. //LOGFONT lf = {15, 0, 0, 0, FW_NORMAL, 0, 0, 0, DEFAULT_CHARSET, OUT_CHARACTER_PRECIS, CLIP_CHARACTER_PRECIS,DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Courier"};
  421. //m_ctrlTab.SetControlFont(lf, TRUE);
  422. }
  423. void CCustomTabCtrlDemoDlg::OnContextMenu(CWnd* /*pWnd*/, CPoint /*point*/) 
  424. {
  425. }
  426. LPCTSTR CCustomTabCtrlDemoDlg::GetTooltipText(int nStyle)
  427. {
  428. static LPCTSTR s[] = {"Sets the static window style to SS_BLACKRECT",
  429. "Sets the static window style to SS_GRAYRECT",
  430. "Sets the static window style to SS_WHITERECT"};
  431. switch(nStyle)
  432. {
  433. case SS_BLACKRECT:
  434. return s[0];
  435. case SS_GRAYRECT:
  436. return s[1];
  437. case SS_WHITERECT:
  438. return s[2];
  439. }
  440. return NULL;
  441. }
  442. void CCustomTabCtrlDemoDlg::OnClosebuttonsck() 
  443. }
  444. void CCustomTabCtrlDemoDlg::OnRtlyck() 
  445. {
  446. CRect r;
  447. GetClientRect(r);
  448. Size(r.Width(),r.Height());
  449.  
  450. }
  451. void CCustomTabCtrlDemoDlg::OnButtonsafterck() 
  452. }
  453. void CCustomTabCtrlDemoDlg::OnRadio3() 
  454. {
  455. m_ctrlTab.ModifyStyle(CTCS_LEFT,0,0);
  456. CRect r;
  457. GetClientRect(r);
  458. Size(r.Width(),r.Height());
  459. }
  460. void CCustomTabCtrlDemoDlg::OnRadio4() 
  461. {
  462. m_ctrlTab.ModifyStyle(CTCS_RIGHT,CTCS_TOP,0);
  463. CRect r;
  464. GetClientRect(r);
  465. Size(r.Width(),r.Height());
  466. }
  467. void CCustomTabCtrlDemoDlg::OnRadio5() 
  468. {
  469. m_ctrlTab.ModifyStyle(0,CTCS_LEFT,0);
  470. CRect r;
  471. GetClientRect(r);
  472. Size(r.Width(),r.Height());
  473. }
  474. void CCustomTabCtrlDemoDlg::OnRadio6() 
  475. {
  476. m_ctrlTab.ModifyStyle(CTCS_TOP,CTCS_RIGHT,0);
  477. CRect r;
  478. GetClientRect(r);
  479. Size(r.Width(),r.Height());
  480. }
  481. void CCustomTabCtrlDemoDlg::OnNcPaint() 
  482. {
  483.     //使用默认的操作先刷新
  484.     CDialog::OnNcPaint();
  485.     //计算TitleBar的坐标区域
  486.     CRect titleRect;
  487.     GetWindowRect(&titleRect); 
  488.     DWORD DialogBaseUnits = GetDialogBaseUnits();
  489.     WORD DialogBaseUnits_X = LOWORD(DialogBaseUnits)/4;
  490.     WORD DialogBaseUnits_Y = HIWORD(DialogBaseUnits)/8;
  491.     titleRect.top += GetSystemMetrics(SM_CYBORDER) * DialogBaseUnits_Y;
  492.     titleRect.left += GetSystemMetrics(SM_CXBORDER) * DialogBaseUnits_X;
  493.     titleRect.right -= GetSystemMetrics(SM_CXBORDER) * DialogBaseUnits_X;
  494.     titleRect.bottom = titleRect.top + GetSystemMetrics(SM_CYCAPTION);
  495.     //创建DC设备
  496.     CDC pDC;
  497.     pDC.CreateDC("DISPLAY", NULL, NULL,NULL);
  498.     int saveDC = pDC.SaveDC(); //保存设备
  499.     //使用自定义颜色填充
  500.     CBrush brush(RGB(255,0,0));
  501.     pDC.FillRect(&titleRect,&brush);
  502.     //正中位置显示字符串
  503.     pDC.SetBkMode(TRANSPARENT);
  504.     pDC.SetTextColor(RGB(0,128,128));
  505.     pDC.DrawText("ABCD",titleRect,DT_CENTER|DT_VCENTER|DT_SINGLELINE);
  506.     pDC.RestoreDC(saveDC); //恢复设备
  507.     pDC.DeleteDC(); //删除设备    
  508. // Do not call CDialog::OnNcPaint() for painting messages
  509. }