Add a new block in the status bar of an AppWizard application, add the following statements in Mainfrm.cpp
//Mainfrm.cpp
Static uint indeicators [] = {id_separator, // status line indeicator id_indicator_bitmap, // bitmap status bar ID_INDICATOR_CAPS, ID_INDICATOR_NUM, ID_IDICATOR_SCRL,};
Delicate a new class (for example, cbitmapstatusbar) from CSTATUSBAR, and replaces CSTATUSBAR (Mainfrm.h) in CMAINFRAME with this new class.
//Mainfrm.h
// cstatusbar m_wndstatusbar; cbitmapstatusbar m_wndstatusbar;
Add the declarations and definitions of the following two functions in the new class .h and .cpp
//Bitmapstatusbar.h
Class CMYSTATUSBAR: PUBLIC CSTATUSBAR {... #i_mfc_ver <0x400 Virtual Void DopAint (CDC * PDC); #ELSE Virtual Void DrawItem (LPDrawItemstruct LPDrawItemstructure); #ENDIF ...}
//Bitmapstatusbar.cpp
#IF _MFC_VER <0x400 Void CBitmapStatusbar :: DopAint (CDC * PDC) {CRECT Rect; GetItemRect (1, & Re); // Get PANE size PDC-> ExcludeClipRect (& Re); // Create a new cut zone CSTATUSBAR :: DopAint (PDC); // Status Bar's remaining part of the remaining part of the CRGN PANERGN; PANERGN.CREATERECTRGNIRECT (Rect); PDC-> SelectClipRGN (& PANERGN); // Select Cutting Area CBitmap Pbitmap; // Load Bitmap IMPORT loads resources from the file, you can limit Pbitmap.LoadBitmap (IDB_bitmap1) without password panels; // put the current bitmap in a compatible CDC CDC Sourcedc; SourceDc.createCompatibleDC (NULL); // Generate compatible CDC cBitmap * Poldbitmap = SourceDc.selectObject (& Pbitmap); // Select bitmap PDC-> Bitblt (Rect.Left, Rect.top, Rect.width (), Rect.Height (), & Soucedc, 0, 0, Srccopy; // Bitblt Sourcedc .SelectObject (pOldBitmap); // bitmap pBitmap.DeleteObject CDC delete the selected (); // delete the bitmap} #else void CBitmapStatusBar :: DrawItem (lPDRAWITEMSTRUCT lpDrawItemStruct) {switch (lpDrawItemStruct-> itemID) {case 1 : // Select a bitmap from the resource CBITMAP PBITMAP; / / Load bitmap, use IMPORT to load resources from file, you can limit PbitMap.LoadBitmap (IDB_bitmap1) without being controlled by the palette; // Statusbar is attached to a CDC object CDC DC, SourceDC; DC. ATTACH (LPDRAWITEMSTRUCT-> HDC); // Get the size of the PANE and the coordinate CRECT Rect (& lpdrawItemStruct-> rcitem); // put the current bitmap in a compatible CDC Sourcedc.createCompAMPALDC (NULL); // Generate compatible CDC cBitmap * PoldbitMap = SourceDc.selectObject (& Pbitmap); // Select bitmap Dc.bitblt (Rect] .left, rect.top, reference.width (), Rect.Height (), & sourcedc, 0, 0, srcopy; // Bitblt Sourcedc.selectObject (Poldbitmap); // Deletes the bitmap pbitmap.deleteObject () selected in the CDC;
// Delete bitmap // Separate the status bar with the CDC object, otherwise the HDC will be deleted when the CDC is discarded (); return;} cstatusbar :: DrawItem (lpdrawItemstructure);} #ENDIF in mainfrm Add the following code to CMAINFRAME :: OnCreate ()
//Mainfrm.cpp
int CMainFrame :: OnCreate (LPCREATESTRUCT lpCreateStruct) {... if (! m_wndStatusBar.Create (this) ||! m_wndStatusBar.SetIndicators (indicators, sizeof (indicators) / sizeof (UINT))) {TRACE0 ( "Failed to create status BAR / N "); return -1; // fail to create} // Add the following code #IF _MFC_VER> = 0x400 uint NID, NStyle; int CxWidth; M_WndstatusBar.getPaneInfo (1, NID, NStyle, CxWidth); m_wndstatusbar. SetPaneInfo (1, NID, NStyle | SBT_OWNERDRAW, CXWIDTH); #ENDIF ...}