Deeper Shallow CPROPERTYSHEET Translator: Xu Jingzhou (original: Mustafa Demirhan)
In order to maximize the utility of the property page, let us first inherit a new class from CpropertySheet, named CMYPropsheet.
Next, you can do the following:
l Hide Properties Page Default button
Hide an Apply Application button:
PropSheet.m_psh.dwflags | = psh_noapplynow;
Or hide the CANCEL cancel button:
CWND * PWND = getdlgitem (IDCANCEL);
PWND-> ShowWindow (False);
l Move property page button
First, you have to get the click handle, then you can handle them like the form. The following code hides the Apply and Help ammonium butt, then move OK and CANCEL to the right.
Bool cmypropsheet :: oninitdialog ()
{
Bool Bresult = CPROPERTYSHEET :: OnInitdialog ();
INT IDS [] = {IDOK, IDCANCEL}; //, id_apply_now, idhelp};
// hide apply and help button
CWND * PWND = getdlgitem (id_apply_now);
PWND-> ShowWindow (False);
PWnd = getdlgitem (idhelp);
PWND-> ShowWindow (False);
CRECT RECTBTN;
INT nspacing = 6; // Space Between Two Buttons ...
For (int i = 0; i { Getdlgitem (IDS [i]) -> getWindowRect (RectBTN); ScreenToClient (& RectB); Int btnWidth = Rectn.width (); RectBtn.Left = Rectn.Left (btnwidth nspacing) * 2; Rectn.right = Rectn.right (btnwidth nspacing) * 2; Getdlgitem (IDS [I]) -> MoveWindow (RectBTN); } Return BRESULT; } The following code moves all buttons to the right and re-resets the attribute page as the appropriate size. Bool cmypropsheet :: oninitdialog () { Bool Bresult = CPROPERTYSHEET :: OnInitdialog (); INT IDS [] = {IDOK, IDCANCEL, ID_APPLY_NOW}; CRECT RECTWND; CRECT RECTBTN; GetWindowRect (RectWnd); Getdlgitem (IDOK) -> GetWindowRect (RectBTN); Int btnWidth = Rectn.width (); INT btnheight = Rectn.height (); Int btnoffset = RectWnd.bottom - RectBtn.bottom INT btnleft = RectWnd.right - RectWnd.Left; RectWnd.Bottom = RectBtn.top; RectWnd.right = RectWnd.right btnwidth btnoffset; MoveWindow (RECTWND); Rectbtn.Left = btnLeft; Rectbtn.right = btnleft btnwidth; For (int i = 0; i { Rectbtn.top = (i 1) * btnoffset btnheight * i; Rectn.bottom = RectBtn.top btnHeight; Getdlgitem (IDS [I]) -> MoveWindow (RectBTN); } Return BRESULT; } l Change the label text on the property page First modify the TC_Item structure, then use setItem to modify the tag text, as follows: Tc_Item item; Item.mask = tcif_text; Item.psztext = "new label"; // Change the lael of the first tab (0 is the index of the first tab) ... GetTabControl () -> setItem (0, & item); l Change the font properties of the property page label text As follows: M_newfont.createfont (14, 0, 0, 0, 800, true, 0, 0, 1, 0, 0, 0, 0, _t ("arial")); GetTabControl () -> setfont (& m_newfont); l Display bitmap on the property page label You can create images with CIMAGELIST. Set with setItem, as shown below: 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_Item item; Item.mask = tcif_image; For (int i = 0; i { Item.iimage = i; PTABCTRL-> SetItem (i, & item); } Return BRESULT; } l Display bitmap at the lower left corner of the property page The following code shows: Void CMYPROPSHEET :: OnPaint () { CPAINTDC DC (this); // Device Context for Painting INT Noffset = 6; // load idb_bitmap1 from ot 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 We're Using to PaintCDC DCMEMORY; DcMemory.createCompaMPALDC (& DC); // SELECT 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 from the in-memory dc inteo 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 Messages } l Display 3D text logo at the lower right corner of the property page As follows: Void CMYPROPSHEET :: OnPaint () { / // Show 3D text prompt next to the Tab button, Jingzhou Xu CString M_Logoname = "Properties page"; // if (m_logoname == "") // Return; GetWindowRect (Rect); ScreenToClient (Rect); Logfont logfont; ZeromeMory ((void *) & logfont, sizeof (logfont)); STRCPY (logfont.lffacename, "Song"); Logfont.lfheight = -12; Logfont.lfWeight = 400; Logfont.lfcharset = GB2312_CHARSET; Logfont.lfoutPrecision = 3; Logfont.lfclipprecision = 2; Logfont.lfquality = 1; Logfont.lfpitchandfamily = 2; m_font.createfontindirect (& logfont); SetFont (& m_font); CFont * PoldFont = PDC-> SelectObject (& M_Font); Rect.Left = 6; RECT.RIGHT - = 6; Rect.bottom - = 1; Rect.top = Rect.Bottom - itembutton_height 1; CFONT M_LOGOFONT; CString slogostring; M_Logofont.createFont (Rect.height () * 4/5, 0, 0, 0, FW_BOLD, 1, FALSE, FALSE, Default_charset, out_default_precis, clip_default_precis, default_quality, fixed_pitch | ff_roman, "体 _GB2312"); Slogostring = m_logoname; Rect M_RDATABOX; CopyRect (& M_RDATABOX, & REC); TextMetric TM; PDC-> GetTextMetrics; & TM CFont * OldFont = PDC-> SelectObject (& M_LOGOFONT); CSIZE SZ = PDC-> GetTextExtent (slogostring, slogostring.getLength ()); // Calculate the font logo size with gettextextent, rely on the device environment, use logo to be in the lower right corner M_RDATABOX.LEFT = M_RDATABOX.RIGHT - SZ.CX - TM.TMAVECHARWIDTH / 2; M_RDATABOX.TOP = M_RDATABOX.BOTTOM - SZ.CY - TM.TMHEIGHT / 5; PDC-> setbkmode (transparent); // Display 3D font, first black, and finally use the default color ColorRef OldColor = PDC-> SetTextColor (GetsysColor (Color_3ddkshadow); PDC-> DrawText (slogostring, slogostring.getLength (), & m_rdatabase, dt_vcenter | dt_singeline | dt_center; M_RDATABOX.LEFT - = TM.TMAVECHARWIDTH; PDC-> SetTextColor (color_3dhilight); PDC-> DrawText (slogostring, slogostring.getLength (), & m_rdatabase, dt_vcenter | dt_singeline | dt_center; M_RDATABOX.EFT = 3 * tm.tmavecharwidth / 5; PDC-> setTextColor (RGB (0, 0, 255)); PDC-> DrawText (slogostring, slogostring.getLength (), & m_rdatabase, dt_vcenter | dt_singeline | dt_center; / / Release Resources PDC-> SelectObject (OldFont); PDC-> SetTextColor (OldColor); m_logofont.deleteObject (); / } l Dog in the property page to add other controls The following demonstrates how to join an Edit control in the lower left corner: In mypropsheet.h: PUBLIC: Cedit m_edit; In mypropsheet.cpp: 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 Areaint Nx = Rect.Left Noffset INT NY = Rect.top (Rect.height () - 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; }