[英]How do I set the image of a (Win32 API) Picture Control at runtime?
測試用例非常簡單。 我想在向位圖資源(IDB_BITMAP1)按下按鈕(IDC_BUTTON2)時設置優化校准(IDC_STATIC1)的內容。 我遇到的問題是,當我按下按鈕時,優化校准不會加載圖像。 我已驗證按鈕按下是否已正確注冊,並且LoadImage的返回值不為null。
以下代碼是對話框的消息處理程序:
BOOL WINAPI DialogProc2(HWND hWindow, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_CLOSE:
EndDialog(hWindow, 0);
DestroyWindow(hWindow);
return TRUE;
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
if (LOWORD(wParam) == IDC_BUTTON2)
{
HBITMAP bmp;
bmp = (HBITMAP)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP1), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR);
if (bmp == NULL)
{
MessageBox(NULL, "Error", "ERROR", MB_OK);
return TRUE;
}
SendDlgItemMessage(hWindow, IDC_STATIC1, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)bmp);
//placing a MessageBox here proves that the button press is being registered properly and that the message is being sent, but nothing is happening...
}
return TRUE;
}
return FALSE;
}
優化校准的“名稱”屬性似乎設置為“ IDC_STATIC1”,但“ ID”屬性設置為“ IDC_STATIC”。 將其更改為“ IDC_STATIC1”可以解決此問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.