如何重新打开使用EndDialog()关闭的对话框;在C.

时间:2017-09-07 16:04:27

标签: c visual-studio visual-c++ dialog

我正在制作一个简单的程序来通过ADB控制Android设备。 当我需要打开ADB Shell时,我需要关闭对话框。但实际上我不知道如何重新打开它。 我在打开ADB Shell之前关闭了Dialog,但是当ADB shell关闭时我需要重新打开它。 我的“代码”:

BOOL CALLBACK DlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
    switch (Message)
    {
    case WM_INITDIALOG:
        g_hbrBackground = CreateSolidBrush(RGB(255, 255, 255));

        SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(NULL,
            MAKEINTRESOURCE(IDI_APPLICATION)));
        SendMessage(hwnd, WM_SETICON, ICON_BIG, (LPARAM)LoadIcon(NULL,
            MAKEINTRESOURCE(IDI_APPLICATION)));
        break;
    case WM_CLOSE:
        EndDialog(hwnd, 0);
        break;
    case WM_CTLCOLORDLG:
        return (LONG)g_hbrBackground;
    case WM_CTLCOLORSTATIC:
    {
        HDC hdcStatic = (HDC)wParam;
        SetTextColor(hdcStatic, RGB(0, 0, 0));
        SetBkMode(hdcStatic, TRANSPARENT);
        return (LONG)g_hbrBackground;
    }
    break;
    case WM_COMMAND:
        switch (LOWORD(wParam))
        {
        case IDADBSHELL:
            if (file_exist("bin\\adb.exe"))
            {
                EndDialog(hwnd, 0);
                system("cmd /c echo 'To exit type 'exit'' & timeout /T 10 & bin\\adb.exe shell & pause");
                // Now need to open Dialog again
                break;
            }
            EndDialog(hwnd, 0);
            MessageBox(hwnd, L"adb.exe was not found!", L"Error",
                MB_OK);
            DeleteObject(MessageBox);
            exit(1);
            break;
        break;
    case WM_DESTROY:
        DeleteObject(g_hbrBackground);
        break;
    default:
        return FALSE;
    }
    return TRUE;
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    LPSTR lpCmdLine, int nCmdShow)
{
    return DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG1), NULL, DlgProc);
}

我在打开ADB Shell之前关闭了Dialog,但是当ADB shell关闭时我需要重新打开它。

P.S。删除了一些不必要的信息(例如其他按钮,什么也不做,包括)

0 个答案:

没有答案