MFC's Form Changes Toolbar programming status bar Programming program Start screen

Source: Internet
Author: User

1 changes in form appearance

(1) Change in CMainFrame::p Recreatewindow (createstruct& CS)

Change title:cs.style&=fws_addtotitle;

cs.lpsznamw= "new title";

(2) Change appearance after form creation

Call SetWindowLong (HWND hwnd,.....) in Cmainframe::create () Change the specified item according to the number of parameters

All classes derived from CWnd are form classes that have a public member variable in the form class that holds the form handle associated with a form object m_hwnd

Gets the form's existing type and changes it on the existing type: SetWindowLong (M_hwnd,gwl_style,getwindowlong (M_hwnd,gwl_style) &~ws_maximizebox);

(3) Change icon cursor background (i.e. change Form Class) before form generation

Create your own form class and register it in bool CMainFrame::P Recreatewindow (createstruct& CS)

BOOL CMainFrame::P Recreatewindow (createstruct& CS)
{
if (! CFrameWnd::P Recreatewindow (CS))
return FALSE;
Wndclass Wclass;
wclass.cbclsextra=0;
wclass.cbwndextra=0;
Wclass.hbrbackground= (Hbrush) getstockobject (Black_brush);
Wclass.hcursor=loadcursor (Null,idc_hand);
Wclass.hicon=loadicon (Null,idi_error);
Wclass.hinstance=afxgetinstancehandle ();//Use the global function to get the application instance handle
wclass.lpfnwndproc=: A global default function for the:D efwindowproc;//
wclass.lpszclassname=_t ("www.csdn.net/luguifang2011");
wclass.lpszmenuname=null;//does not affect the menu that you actively create
Wclass.style=cs_hredraw|cs_vredraw;
RegisterClass (&wclass);
cs.lpszclass=_t ("www.csdn.net/luguifang2011");//j apply the class of his own design to the production form
return TRUE;
}

Note: in CMainFrame only can change the icon cursor background cannot change, want to change the background and the cursor need again in bool Cmenuview::P Recreatewindow (createstruct& CS) cs.lpszclass=_t ("www.csdn.net/luguifang2011");

Another way to return a form class with the global function Afxwndregisterwndclass ()

Cs.lpszclass=afxregisterwndclass (cs_hredraw|cs_vredraw,0,0, LoadIcon (null,idi_warning));

(4) Change icon cursor background, etc. after form creation

Use global function Setclasslong () for related changes

(5) Three ways to get application instance handles:


MAKEINTRESOURCE macro

2 Programming of toolbars

(1) Create a toolbar

if (cframewnd::oncreate (lpcreatestruct) = =-1)
return-1;


if (!m_wndtoolbar.createex (this, Tbstyle_flat, Ws_child | ws_visible | Cbrs_top | Cbrs_gripper | Cbrs_tooltips | cbrs_flyby | Cbrs_size_dynamic) | |
!m_wndtoolbar.loadtoolbar (IDR_MAINFRAME))
{
TRACE0 ("Failed to create toolbar \ n");
return-1; Failed to create
}


if (!m_wndstatusbar.create (this))
{
TRACE0 ("Failed to create status bar \ n");
return-1; Failed to create
}
M_wndstatusbar.setindicators (indicators, sizeof (indicators)/sizeof (UINT));
M_wndtoolbar.enabledocking (Cbrs_align_any);
EnableDocking (Cbrs_align_any);
DockControlBar (&m_wndtoolbar);

(2) hiding and displaying toolbars


DockControlBar (&m_newtoolbar);

Another way to show and hide with Cfreamwnd::showcontrolbar ()



3 Programming the status bar

(1) Create

Static UINT indicators[] =
{
Id_separator,//Status line indicator
Id_indicator_caps,
Id_indicator_num,
ID_INDICATOR_SCRL,
};//by adding the contents of the status indicator? Number of status bars

if (!m_wndstatusbar.create (this))
{
TRACE0 ("Failed to create status bar \ n");
return-1; Failed to create
}

(2) Set the status bar to display the information

Cstatusbar::setpanetext ()

Cstatusbar::commandtoindex ();//get Index by ID

Cstatusbar::setpaneinfo ();//Change indicator information contains the status bar width, and type

CSize SZ=DC. GetTextExtent (str)//Get text width

(3) Progress bar

CProgressCtrl class

member function: SetPos ()//Set Progress position

Set the progress bar to the status bar

Cstatusbar::getitemrect ()//Get the status bar a rectangular area of an indicator

Note: For the rectangular area that gets the status bar, after the form has been generated, the CMainFrame::OnCreate () function has finished running, so we define the message beforehand in cmainframe::o The Ncreate () function posts its own defined message through PostMessage () to the message queue in the message's response function to get the indicator rectangle area (not with SendMessage (), since the function immediately runs the response function. Instead of waiting for OnCreate () to run out)

Another way to respond to the WM_PAINT message function is to process


4cframewnd::setmessagetext ()

Place text into the longest status bar (four methods)


Getdescendantwindow () is a member function of CWnd

5 Add to Program start screen

Using the Csplaswnd in the VC + + component library

MFC's Form Changes Toolbar programming status bar Programming program Start screen

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.