首页 > 其他分享 >CreateDialog 与 DialogBox

CreateDialog 与 DialogBox

时间:2023-12-11 18:44:52浏览次数:34  
标签:DialogProc lpParam HWND CreateDialog hParentWnd DialogBox NULL

DWORD WINAPI UploadThread(LPVOID lpParam)
{
    HWND hParentWnd = (HWND)lpParam;

    HWND hDialog = CreateDialog(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_UPLOAD_DIALOG), hParentWnd, DialogProc);
    ShowWindow(hDialog, SW_SHOW);

    for (int i = 0; i <= 100; i++)
    {
        SendMessage(g_hProgressBar, PBM_SETPOS, i, 0); // 更新进度
        Sleep(100); // 模拟上传延迟
    }

    DestroyWindow(hDialog);

    return 0;
}
DialogBox(hInstance, MAKEINTRESOURCE(IDD_UPLOAD_DIALOG), NULL, DialogProc);

include <windows.h>

HWND g_hProgressBar; // 进度条控件句柄

BOOL CALLBACK DialogProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)
    {
        case WM_INITDIALOG:
            // 创建进度条控件
            g_hProgressBar = CreateWindowEx(0, PROGRESS_CLASS, NULL, WS_CHILD | WS_VISIBLE, 10, 10, 200, 20, hWnd, NULL, GetModuleHandle(NULL), NULL);
            SendMessage(g_hProgressBar, PBM_SETPOS, 0, 0); // 初始化进度为0
            break;

        case WM_COMMAND:
            if (LOWORD(wParam) == IDCANCEL)
            {
                EndDialog(hWnd, 0);
            }
            break;

        default:
            return FALSE;
    }

    return TRUE;
}

DWORD WINAPI UploadThread(LPVOID lpParam)
{
    HWND hParentWnd = (HWND)lpParam;

    HWND hDialog = CreateDialog(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_UPLOAD_DIALOG), hParentWnd, DialogProc);
    ShowWindow(hDialog, SW_SHOW);

    for (int i = 0; i <= 100; i++)
    {
        SendMessage(g_hProgressBar, PBM_SETPOS, i, 0); // 更新进度
        Sleep(100); // 模拟上传延迟
    }

    DestroyWindow(hDialog);

    return 0;
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    HWND hParentWnd = NULL; // 设置为上传文件的父窗口句柄

    HANDLE hThread = CreateThread(NULL, 0, UploadThread, (LPVOID)hParentWnd, 0, NULL);
    if (hThread != NULL)
    {
        // 等待上传线程结束
        WaitForSingleObject(hThread, INFINITE);
        CloseHandle(hThread);
    }

    return 0;
}

 

 

标签:DialogProc,lpParam,HWND,CreateDialog,hParentWnd,DialogBox,NULL
From: https://www.cnblogs.com/hshy/p/17895120.html

相关文章