在一个非MFC的动态库中,如何显示一个对话框接受用户输入信息?

解决方案 »

  1.   

    1, Create the dialog resource, assign IDs to the Controls;
    suppose: IDD_WIN32_DIALOG
    2, In the appropriate location insert the following code:
    LRESULT CALLBACK DlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
    extern "C" __declspec(dllexport) void ShowDialog(HWND parentHwnd)
    {
        HWND hwnd = CreateDialog(GetModuleHandle("ThisDll.dll", MAKEINTRESOURCE(IDD_WIN32_DIALOG), parentHwnd, DlgProc);
        if(hwnd == NULL)
        {
            MessageBox(NULL, "Error creating dialog box", "ShowDialog", MB_OK);
            return;
        }
    }LRESULT CALLBACK DlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        switch(message)
        {
        case WM_COMMAND:
            switch(LOWORD(wParam))
            {
            case IDOK:
                EndDialog(hwnd, 1);
                return 1;
            }
        }
        return 0;
    }