Reprinted: MFC the MessageBox, AfxMessageBox usage

In software, we often will pop up a small window, give it a little prompt message dialog box will be used only MessageBox in Win32 API usage this kind of program, but there are three each in MFC methods: 1. API calls the MessageBox; 2. call the member function MessageBox CWnd; 3. call the global function AfxMessageBox; MFC usage in a MessageBox function prototypes and parameters function MessageBox (hWnd: HWND; Text, Caption: PChar; Type: Word): Integer; hWnd: parent window handle of the dialog box, the dialog box shown in the body of Delphi window, use the handle property of the form, 0 otherwise available, so direct as a child window of the desktop window. Text: message string to be displayed. Caption: Dialog title string. Type: box type constant. This function returns an integer value, for identifying the buttons of a dialog. 2, Type Constant Constant type dialog box may be a combination of buttons, the default button to display the icon to run four modes constant combination. (1) button combination constants MB_OK = $ 00000000; // an OK button MB_OKCANCEL = $ 00000001; // an OK button, a cancel button MB_ABORTRETRYIGNORE = $ 00000002; // an aborting button, a retry button, an Ignore button MB_YESNOCANCEL = $ 00000003 ; // is a button, a No button, a cancel button MB_YESNO = $ 00000004; // is a button, a No button MB_RETRYCANCEL = $ 00000005; // retry a button, a cancel button (2) default button MB_DEFBUTTON1 = constant $ 00000000; // The first button is the default button MB_DEFBUTTON2 = $ 00000100; hWnd is the handle of a window, or directly AfxMessageBox. Second, the value of the display variable CString string in a MessageBox; string.format ( "% d% s", m_age, m_address); // assembled into a string variable MessageBox (String, "message box header" message box type ); Win32 API MessageBox give a simple example in #include int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPre, PSTR szCmdLine, int iCmdShow) {MessageBox ( ". hello world" NULL, TEXT (), TEXT ( "Title"), 0); // TEXT now commonly in MFC _ T (), as expressed unicode character return 0;} message box function is defined as follows MessageBox (hWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType); hWnd parameter window handle, generally with less does not relate to this example. window directly write NULL. lpText parameters are parameters lpCaption content displayed message dialog box is the title parameter uType the dialog box, specify the dialog buttons, icons. these are some button type the following macro .MB defined in WinUser.h MessageBox button is short, behind the text says that there are several buttons that display what the words on the buttons, such as MB_YESNOCANCEL is to display three buttons, which are yes, no, cancel MB_OK MB_OKCANCEL MB_ABORTRETRYIGNORE MB_YESNOCANCEL MB_YESNO MB_RETRYCANCEL MB_CANCELTRYCONTINUE icon is displayed and I will often see a question mark and warning icons in the top of the dialog, you can specify the following macro MB_ICONWARNING MB_ICONERROR MB _ICONINFORMATION MB_ICONSTOP default focus now button icons may also think you have a position from left to right above the button talk button if there are several buttons that default focus is on which button you can adopt the following macro MB_DEFBUTTON1 MB_DEFBUTTON2 MB_DEFBUTTON3 MB_DEFBUTTON4 figures represent icon, the default focus of three macros, ? But how to use it together through | this symbol put them together is an example MessageBox (NULL, TEXT (), TEXT ( "Title"), MB_OKCANCEL | MB_ICONINFORMATION | MB_DEFBUTTON1 "hello world.");. Dialog box function returns the value of the last you may also want to point the user if a different button, choose how we get information about users? very simple, it is through the MessageBox function return value judgment. function will return the following value IDOK IDCANCEL IDABORT IDRETRY IDIGNORE IDYES IDNO can do so to determine if (MessageBox (NULL, TEXT ( "hello world."), TEXT ( "Title"), MB_OKCANCEL) == IDOK) {} AfxMessageBox usage AfxMessageBox MFC is encapsulation of the MessageBox. it has two different overloaded functions. 1) int AFXAPI AfxMessageBox (UINT nIDPrompt, UINT nType = MB_OK, UINT nIDHelp = (UINT) -1) where nIDPrompt string resource ID, or your string is defined in the string Table. nType with the foregoing the MessageBox exactly the same. hIDHelp is with the help of information related to it here to a (UINT) -1, put a -1 turn into an unsigned type. I really did not get to know what do you mean, I suspect it is not We were wrong. It should directly write here anyway 0. default value of 0 will use a default help document information using the example AfxMessageBox (IDS_MSG) 2) int AFXAPI AfxMessageBox (LPCTSTR lpszText, UINT nType = MB_OK, UINT nIDHelp = 0); lpszText which is to specify the content of the dialog box to be displayed.

Guess you like

Origin www.cnblogs.com/freedomworld/p/11610053.html