属性对话框如何去掉按钮_第1页
属性对话框如何去掉按钮_第2页
属性对话框如何去掉按钮_第3页
属性对话框如何去掉按钮_第4页
属性对话框如何去掉按钮_第5页
已阅读5页,还剩7页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、属性对话框如何去掉 自动生成的 “确定” “取消” “帮助” 按钮? 问题点数:50、回复次数:7Top 1 楼goodboyws(深夜不眠者(VCMVP))回复于 2005-08-23 10:30:38 得分 5Top2 楼happyparrot(快乐鹦鹉)回复于 2005-08-23 10:33:31 得分 10在属性页的OnInitDialog中: /隐藏应用和帮助按钮, GetDlgItem(ID_APPLY_NOW)-ShowWindow(SW_HIDE); GetDlgItem(IDHELP)-ShowWindow(SW_HIDE); Top3 楼lixiaosan(小三)回复于

2、2005-08-23 11:01:15 得分 10CMySheet:OnInitDialog() . GetDlgItem(IDOK)-ShowWindow(SW_HIDE); GetDlgItem(IDCANCEL)-ShowWindow(SW_HIDE); GetDlgItem(IDHELP)-ShowWindow(SW_HIDE); . Top4 楼KennyLiu(大星)回复于 2005-08-23 11:17:31 得分 5同意 lixiaosan(小三)!Top5 楼vcmute(淡入淡出)回复于 2005-08-23 12:39:51 得分 10 或 P.S.小三的代码可能会非法

3、,不严谨,最好加判断Top6 楼vcmute(淡入淡出)回复于 2005-08-23 13:02:52 得分 5只要在重载的OnInitDialog中 BOOL CPropSheet:OnInitDialog() m_bModeless = TRUE; BOOL bResult = CPropertySheet:OnInitDialog(); m_bModeless = FALSE; return bResult; IntroductionIn my applications, I usually need to change the default look and feel and the

4、 behavior of Property Sheets. Working with property sheets and pages is really a pain and you must do most of the work on yourself for non-standard operations (such as changing the coordinates of the buttons, adding new controls to the property sheet, .etc). In this article, I tried to give as many

5、tips and tricks as I can do.Before going in to the details, you should first create a CPropertySheet derived class - say CMyPropSheet.Lets begin with some simple things:Hiding Standards ButtonsWhen our property sheet shows up, by default it has all the buttons visible and the Apply button is disable

6、d. In general we dont need to use Apply button. To hide the apply button, you can simply use the following code:propsheet.m_psh.dwFlags |= PSH_NOAPPLYNOW;However, this does not work for all buttons. A better approach is to get a handle to the specified button and then threat the button as a normal w

7、indow. Here is a sample code that hides the cancel button:CWnd *pWnd = GetDlgItem( IDCANCEL );pWnd-ShowWindow( FALSE );When we hide the controls using the ShowWindow function all the other controls remain whereever they were. This may give the property sheet and unappealing look. To avoid this, we s

8、hould reposition the controls manually. Next subsections shows how to move the controls.Moving the Standard ButtonsAs I mentioned before, once we get the handle to the standard buttons, we can treat them like any other window. The code below first hides Apply and Help buttons, then moves OK and Canc

9、el buttons right.CollapseBOOL CMyPropSheet:OnInitDialog () BOOL bResult = CPropertySheet:OnInitDialog(); int ids = IDOK, IDCANCEL;/, ID_APPLY_NOW, IDHELP ; / Hide Apply and Help buttons CWnd *pWnd = GetDlgItem (ID_APPLY_NOW); pWnd-ShowWindow (FALSE); pWnd = GetDlgItem (IDHELP); pWnd-ShowWindow (FALS

10、E); CRect rectBtn; int nSpacing = 6; / space between two buttons. for( int i =0; i GetWindowRect (rectBtn); ScreenToClient (&rectBtn); int btnWidth = rectBtn.Width(); rectBtn.left = rectBtn.left + (btnWidth + nSpacing)* 2; rectBtn.right = rectBtn.right + (btnWidth + nSpacing)* 2; GetDlgItem (ids i)-

11、MoveWindow(rectBtn); return bResult;The following code moves all standard buttons to the right and resizes the property sheet appropriately.CollapseBOOL CMyPropSheet:OnInitDialog () BOOL bResult = CPropertySheet:OnInitDialog(); int ids = IDOK, IDCANCEL, ID_APPLY_NOW ; CRect rectWnd; CRect rectBtn; G

12、etWindowRect (rectWnd); GetDlgItem (IDOK)-GetWindowRect (rectBtn); int btnWidth = rectBtn.Width(); int btnHeight = rectBtn.Height(); int btnOffset = rectWnd.bottom - rectBtn.bottom; int btnLeft = rectWnd.right - rectWnd.left; rectWnd.bottom = rectBtn.top; rectWnd.right = rectWnd.right + btnWidth + b

13、tnOffset; MoveWindow(rectWnd); rectBtn.left = btnLeft; rectBtn.right = btnLeft + btnWidth; for (int i = 0; i MoveWindow (rectBtn); return bResult;Changing the Tab LabelTo change the labels at runtime, we just need to get a pointer to the tab control and then use SetItem functions of the tab control.

14、 Here is an example:TC_ITEM item;item.mask = TCIF_TEXT;item.pszText = New Label;/Change the label of the first tab (0 is the index of the first tab).GetTabControl ()-SetItem (0, &item);Changing the Tab Label FontThis is also similar to changing the label of the tab. Here is an example code: m_NewFon

15、t.CreateFont (14, 0, 0, 0, 800, TRUE, 0, 0, 1, 0, 0, 0, 0, _T(Arial) ); GetTabControl()-SetFont (&m_NewFont);Using Images with Tab LabelsIn order to use images with the tab labels, first you have to create a CImageList class with the images you want to use in the tab control. The using SetItem metho

16、d of CTabCtrl class, you should set the images of the items. Here is an example:BOOL CMyPropSheet:OnInitDialog () BOOL bResult = CPropertySheet:OnInitDialog(); m_imageList.Create (IDB_MYIMAGES, 13, 1, RGB(255,255,255); CTabCtrl *pTabCtrl = GetTabControl (); pTabCtrl-SetImageList (&m_imageList); TC_I

17、TEM item; item.mask = TCIF_IMAGE; for (int i = 0; i SetItem (i, &item ); return bResult;Placing a Bitmap in the Property SheetThe following code places a bitmap in the left-bottom corner of the property sheet.Collapsevoid CMyPropSheet:OnPaint () CPaintDC dc(this); / device context for painting int n

18、Offset = 6; / load IDB_BITMAP1 from our resources CBitmap bmp; if (bmp.LoadBitmap (IDB_BITMAP1) / Get the size of the bitmap BITMAP bmpInfo; bmp.GetBitmap (&bmpInfo); / Create an in-memory DC compatible with the / display DC were using to paint CDC dcMemory; dcMemory.CreateCompatibleDC (&dc); / Sele

19、ct the bitmap into the in-memory DC CBitmap* pOldBitmap = dcMemory.SelectObject (&bmp); / Find a bottom-left point for the bitmap in the client area CRect rect; GetClientRect (&rect); int nX = rect.left + nOffset; int nY = rect.top + (rect.Height () - bmpInfo.bmHeight) - nOffset; / Copy the bits fro

20、m the in-memory DC into the on- / screen DC to actually do the painting. Use the centerpoint / we computed for the target offset. dc.BitBlt (nX, nY, bmpInfo.bmWidth, bmpInfo.bmHeight, &dcMemory, 0, 0, SRCCOPY); dcMemory.SelectObject (pOldBitmap); / Do not call CPropertySheet:OnPaint() for painting m

21、essagesAdding a Control to the Property Sheet To add your own control to the property sheet, first add a member variable to your header class. The following steps shows you adding an Edit conrol to your property sheet (to the bottom-left corner):In MyPropSheet.h:public: CEdit m_edit;In MyPropSheet.c

22、pp:BOOL CMyPropSheet:OnInitDialog () BOOL bResult = CPropertySheet:OnInitDialog (); CRect rect; int nHeight = 24; int nWidth = 120; int nOffset = 6; GetClientRect (&rect); / Find a bottom-left point for the edit control in the client area int nX = rect.left + nOffset; int nY = rect.top + (rect.Heigh

23、t() - nHeight) - nOffset; / finally create the edit control m_Edit.CreateEx (WS_EX_CLIENTEDGE, _T(EDIT), NULL, WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER, nX, nY, nWidth, nHeight, m_hWnd, 0, 0 ); return bResult;A More Complex ScenarioNow we are ready for a more complex operation on these stupid

24、property sheets. Suppose you want to add a header on top of your property sheet. At first, this seems to be an easy task, but when you implement the first thing in your mind, you would mostly be disappointed.You need a free space on top of the property sheet. Thus you need to increase the size of th

25、e property sheet, then move all the buttons and tab control. However this is not enough. The problem is that, when you move your Tab Control, your property pages in the Tab Control will not be moved appropriately. They will remain on the same coordinates (even though the tab control is moved). So, y

26、ou also have to move the first property page on your tab control. You dont have to move the other property pages, because when you change the active tab, tab control will get the new coordinates automatically and place the property pages correctly. The problem occurs only when the property sheet is

27、created and firstly shown. The code below creates an area on top of the property sheet and moves all the controls and property pages accordingly. You just need to add your header control.CollapseBOOL CMyPropSheet:OnInitDialog () BOOL bResult = CPropertySheet:OnInitDialog (); int _PropSheetButtons =

28、IDOK, IDCANCEL, ID_APPLY_NOW, IDHEL ; int m_nHeaderHeight = 70; /The height of the header control CRect rectWnd; GetWindowRect (rectWnd); ScreenToClient (rectWnd); SetWindowPos (NULL, 0, 0, rectWnd.Width(), rectWnd.Height() + m_nHeaderHeight, SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE); / create you

29、r header control here /m_HeaderCtrl.CreateEx (NULL, NULL, NULL, / WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER, / -1, -1, rectWnd.Width (), m_nHeaderHeight - 5, m_hWnd, 0, 0); /m_HeaderCtrl.SetTitle (m_sTitle); /m_HeaderCtrl.SetIcon (m_nIcon); /m_HeaderCtrl.SetDesc (m_sDesc);*/ HWND hWnd = (HWND)G

30、etTabControl ()-m_hWnd; ASSERT (hWnd != NULL); CRect rectOld; :GetWindowRect (hWnd, &rectOld); ScreenToClient (&rectOld); :SetWindowPos (hWnd, NULL, rectOld.left, rectOld.top + m_nHeaderHeight, rectOld.Width (), rectOld.Height (), SWP_NOZORDER | SWP_NOACTIVATE); hWnd = (HWND)m_Page1.m_hWnd; / m_Page

31、1 is assumed to be the first page / in your property sheet. de corrections accordingly ASSERT (hWnd != NULL); :GetWindowRect (hWnd, &rectOld); ScreenToClient (&rectOld); :SetWindowPos (hWnd, NULL, rectOld.left, rectOld.top + m_nHeaderHeight, rectOld.Width (), rectOld.Height (), SWP_NOZORDER | SWP_NO

32、ACTIVATE); / move buttons by similar amount for (int i = 0; i sizeof (_PropSheetButtons) / sizeof (int); i+) hWnd = :GetDlgItem (m_hWnd, _PropSheetButtons i); if (hWnd != NULL) :GetWindowRect (hWnd, &rectOld); ScreenToClient (&rectOld); :SetWindowPos (hWnd, NULL, rectOld.left, rectOld.top + m_nHeade

33、rHeight, rectOld.Width (), rectOld.Height (), SWP_NOZORDER | SWP_NOACTIVATE); / Enable Apply Now button hWnd = :GetDlgItem(m_hWnd, ID_APPLY_NOW); if (hWnd != NULL) :ShowWindow (hWnd, SW_SHOW); :EnableWindow (hWnd, TRUE); CenterWindow (); return bResult;So far so good. Now, I want to change the behav

34、ior for the OK, Cancel and Apply buttons. For example, when the user clicks on OK or Cancel button, you may want to do something different rather than closing the property sheet. Here is a general template that can be used to do this kind of stuff:CollapseBOOL CMyPropSheet:OnCommand (WPARAM wParam,

35、LPARAM lParam) / allow message map override if (CWnd:OnCommand (wParam, lParam) return TRUE; / crack message parameters UINT nID = LOWORD(wParam); HWND hWndCtrl = (HWND)lParam; int nCode = HIWORD(wParam); / set m_nModalResult to ID of button, whenever button is clicked if (hWndCtrl != NULL & nCode = BN_CLICKED) if (:SendMessage(hWndCtrl, WM_GETDLGCODE, 0, 0) & (DLGC_BUTTON|DLGC_DEFPUSHBUTTON) LONG lStyle = :GetWindowLong(hWndCtrl, GWL_STYLE) & 0x0F; if (lStyle = BS_PUSHBUTTON | lStyle = BS_DEFPUSHBUTTON | lStyle = BS_USERBUTT

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论