我有一个进度对话框,其中包含进度条上方的图像。该对话框位于C ++项目资源文件中。这个对话框有" CONTROL"用于图像控制。 现在,当最初显示对话框时,不显示此图像,但在几秒钟后出现图像和按钮
首次加载时如何加载图片和按钮?
RESOURCE.RC
IDD_TESTDIALOG DIALOGEX 0, 0, 335, 74
STYLE DS_SETFONT | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION
EXSTYLE WS_EX_DLGMODALFRAME | WS_EX_TOPMOST
CAPTION "Connecting.."
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
PUSHBUTTON "Cancel",IDCANCEL,277,54,50,15
CONTROL "",IDC_PROGRESS1,"msctls_progress32",WS_BORDER,12,61,254,6
LTEXT "Waiting for server connection...",IDC_PROGRESS_MESSAGE,13,44,181,14
CONTROL IDS_APP_TITLE,IDC_BITMAP1,"Static",SS_BITMAP,0,0,333,34
END
Main.cpp的
INT_PTR CALLBACK DialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
switch (message)
{
case WM_INITDIALOG:
return DefWindowProc(hWnd, message, wParam, lParam);
//return (INT_PTR)TRUE;
case WM_PAINT:
return DefWindowProc(hWnd, message, wParam, lParam);
case WM_CLOSE:
ShowWindow(hDlg, SW_HIDE);
return (INT_PTR)TRUE;
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
switch (wmId)
{
case IDCANCEL:
//DestroyWindow(hWnd);
ShowWindow(hDlg, SW_HIDE);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return (INT_PTR)FALSE;
}
// Creating Dialog
g_hToolbar = CreateDialog(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_TESTDIALOG), hWnd, DialogProc);
答案 0 :(得分:0)
问题在于资源文件。
http://winapi.freetechsecrets.com/win32/WIN32Visibility.htm
我们需要在资源对话框中添加 WS_VISIBLE 标志。默认情况下,Windows会创建一个隐藏窗口,除非应用程序指定WS_VISIBLE样式。通常,应用程序在创建窗口后设置WS_VISIBLE样式,以保持创建过程的详细信息对用户隐藏。
<强> RESOURCE.RC 强>
IDD_TESTDIALOG DIALOGEX 0, 0, 335, 74
STYLE DS_SETFONT | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_VISIBLE
EXSTYLE WS_EX_DLGMODALFRAME | WS_EX_TOPMOST
CAPTION "Connecting.."
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
PUSHBUTTON "Cancel",IDCANCEL,277,54,50,15
CONTROL "",IDC_PROGRESS1,"msctls_progress32",WS_BORDER,12,61,254,6
LTEXT "Waiting for server connection...",IDC_PROGRESS_MESSAGE,13,44,181,14
CONTROL IDS_APP_TITLE,IDC_BITMAP1,"Static",SS_BITMAP|WS_VISIBLE,0,0,333,34
END