Method for generating a dialog box in a DLL (MFC Regular DLL)

Source: Internet
Author: User
Tags win32

Creating the modal dialog box in the MFC Regular DLLCreating a modal dialog box in an MFC Regular DLL is very simple, CDialog the base class provides a method DoModal () that can create a modal dialog box, so you create a Regular dialog box in the MFC modal DLL, Just need to inherit the dialog base class yourself, call DoModal in the export function.Create the modeless dialog box in the MFC Regular Dll.Because the MFC application framework is just encapsulation of the WIN32 function, creating a modeless dialog box in an MFC Regular DLL actuallymethod One (Win32 DLL) that generates a dialog box in a DLLThe internal principle of the generated modeless dialog is consistent, and the difference is that only a little bit of skill is needed in the MFC framework. We know that in Win32 SDK programming, there is a main window handle HWND, also in MFC, there is a variable, but it is now encapsulated in the Cwindthread, we can see in the AFXWIN.H that the definition: ...   cwnd* m_pMainWnd; main window (usually same afxgetapp ()->m_pmainwnd) ...     And we know that CWinApp is inherited from CWinThread.     Let's look at the encapsulation of the window process, in MFC, the CFrameWnd category can be used to create Windows, and internally define window procedures, specifically, that is, the CREATEWINDOW,MESSAGELOOP mechanism is implemented in that category. With the ground above, we'll see.method One (Win32 DLL) that generates a dialog box in a DLLThe steps in this article to generate the modeless dialog: 1: We first set up a main window, but do not display the window, what we really need is the Windows handle HWND. 2: Creates a dialog box that sets the owner handle of the dialog box to HWND. 3: The message is diverted.     behind the steps above actually hides a trick inside: we can discard the hwnd, that is, we can set the dialog handle to the HWND, so we can omit the third step, do not have to do in the message loop where the message shunt, So our code looks like this ...      hwnd = CreateWindow (Szappname, TEXT ("Modeless_dialog"),                             Ws_overlappedwindow | Ws_clipchildren,                            cw_usedefault, Cw_usedefault,                             Cw_usedefault, Cw_usedefault,                            null, NULL, HINSTANCE, NULL);         //ShowWindow (hwnd, Icmdshow);      // The main window is not shown here    //UpdateWindow (HWND);   hwnd = Createdialog (HINSTANCE, Makeintresource (IDD_DIALOG1), NULL, Dlgproc);           while (GetMessage (&msg, NULL, 0, 0))      {& nbsp;         TranslateMessage (&msg);           DispatchMessage (&msg);     }...     Ok here we can follow the above steps to generate a dialog box in the MFC Regular DLL 1: Build an MFC Regular DLL with AppWizard. 2: Derive a new class Cmyframewnd class from CFrameWnd, because we just need to produce a window that does not display, so all actions take the default action. Class Cmyframe:public CFrameWnd {Public:cmyframe (); Declare_message_map ()}; 3: Derive a new CMyDialog class from CDialog. 4: Because CWinApp's InitInstance () is used to initialize the application.     So we add the following code to the CMyWinApp InitInstance method: m_pMainWnd = new Cmyframe ();   m_pMainWnd = Pdlg; Pdlg is a pointer to a Cmydialg object. 5: Write export function: extern "C" void __declspec (dllexport) show () {pdlg->domodal ();//Display Dialog} from the above steps we can see that in MFC Regular D The way to show the modeless dialog box in ll is to follow the methods in the Win32 DLL, of course, because MFC's object-oriented features, as long as we follow this approach, we can have more ways to achieve, but the introduction here should be the simplest and most direct way.

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.