VC Tips Summary of the dialog box skills _c language

Source: Internet
Author: User
Tags function prototype

This paper collects and summarizes the VC in the dialog box commonly used in some of the skills for VC development due to a certain reference value.

1. How to modify the background color of the dialog box:

In the OnPaint () function of the dialog box, add the following statement:

CRect rect;
GetClientRect (&rect);   Calculates the size of the dialog box
DC. Fillsolidrect (&rect,rgb (192,248,202));  Draw a dialog box background color

2. How to make the pop-up dialog box have a unified background color:

Add the following statement to the InitInstance () function of the application class Cxxxapp:

SetDialogBkColor (RGB (192,248,202));

All user-defined pop-up dialogs have a background color of RGB (192,248,202) and do not need to be set individually.

3. How to open a file dialog box to make a number of choices:

When you customize the Open File dialog box, you can add the Ofn_allowmultiselect property to the Open File dialog box to make multiple selections.
Such as:

CFileDialog M_dlg (TRUE, NULL, NULL, OFN_HIDEREADONLY | Ofn_overwriteprompt
    | Ofn_allowmultiselect, NULL, NULL);
After that, use the getstartposition () function to get the selected starting file location and use the Getnextpathname () function to get the file names at each location.
such as:
if (m_dlg.domodal () = = Idok)
{
   POSITION pos;
   pos = M_dlg.getstartposition ();
   while (POS)
   {
     M_path = M_dlg.getnextpathname (POS);
     ......
   }

4. Why does the file not open when you select multiple files to a certain number with the Open File dialog box?

CFileDialog sets a buffer for the file list, and when too many files are selected, a buffer overflow occurs, causing some files to not be opened. Can be solved by using a custom large buffer instead of a system buffer.
Such as:

CFileDialog M_dlg (TRUE, NULL, NULL, OFN_HIDEREADONLY | Ofn_overwriteprompt
    | Ofn_allowmultiselect, NULL, NULL);/Custom Open File dialog box
char* pBuf = new char[20480];    Application buffer
m_Dlg.m_ofn.nMaxFile = 20480;    Let PBuf replace CFileDialog buffer
m_Dlg.m_ofn.lpstrFile = PBuf;
M_dlg.m_ofn.lpstrfile[0] = NULL;
....... delete []pbuf;    Reclaim buffers

5. Prompt dialog box (MessageBox)

You can use the MessageBox () function pop-up prompt dialog box in the View class and dialog class using the MFC function. This function prototype is:

int MessageBox (LPCTSTR lpsztext,lpctstr lpscaption=null,uint NTYPE=MB_OK);

Parameters:
Lpsztext Displays the string
Lpscaption dialog box title
Ntype style, which can be a combination of the following values:
Specifies one of the following flags to display a button in a message box, which has the following meaning.
Mb_abortretryignore: The message box contains three buttons: Abort,retry and ignore.
MB_OK: Message box contains a button: OK. This is the default value.
Mb_okcancel: Message box contains two buttons: OK and cancel.
Mb_retrycancel: The message box contains two buttons: Retry and Cancel.
Mb_yesno: Message box contains two buttons: Yes and No.
Mb_yesnocancel: The message box contains three buttons: Yes,no and Cancel. The
specifies one of the following flags to display the icon in the message box: The meaning of the flag is as follows.
Mb_iconexclamation:
mb_iconwarning: An exclamation point appears in a message box.
Mb_iconinformation:
Mb_iconasterisk: An icon in a circle that writes the letter I appears in a message box.
Mb_iconouestion: An issue flag icon appears in the message box.
Mb_iconstop:
Mb_iconerror:
Mb_iconhand: A Stop message icon appears in a message box. The

Specifies one of the following flags to specify the default button: The meaning of the flag is as follows.

Mb_defbutton1: The first button is the default button. If Mb_defbutton2,mb_defbutton3,mb_defbutton4 is not specified, the Mb_defbutton1 is the default value. The
Mb_defbutton2, and the second button is the default button.
Mb_defbutton3: The third button is the default button.
Mb_defbutton4: The fourth button is the default button.

Example: Prompt file for disk:

int t;
The text of T=messagebox (m_pathname+) has changed, do you want to save it? "," Warning ", Mb_yesnocancel | mb_iconwarning);
if (t==0 | | t==idcancel) return
  ;
if (t==idyes)
  onfilesave ();

You cannot use the MessageBox () function in MFC in other classes, such as document classes, and you can only use the MessageBox () function in an API function:

int MessageBox (HWND hwnd,lpctstr lpsztext,lpctstr lpcaption,uint utype);

HWnd: Identifies the owning window of the message box that will be created. If this parameter is NULL, the message box does not have a window.
The latter three parameters are the same as the MessageBox of the view class, but there is no default value and must be set.
Cases:

:: MessageBox (null,m_pathname+) text has changed, to save it? "," Warning ", Mb_yesnocancel | mb_iconwarning);

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.