[英]How do I set the image of a (Win32 API) Picture Control at runtime?
The test case is very simple. 测试用例非常简单。 I want to set the contents of a Picture Control (IDC_STATIC1) upon the pressing of a button (IDC_BUTTON2) to a bitmap resource (IDB_BITMAP1).
我想在向位图资源(IDB_BITMAP1)按下按钮(IDC_BUTTON2)时设置优化校准(IDC_STATIC1)的内容。 The problem I'm encountering is that when I press the button, the Picture Control doesn't load the image.
我遇到的问题是,当我按下按钮时,优化校准不会加载图像。 I have verified that the button press IS being registered properly and the return value from LoadImage is NOT null.
我已验证按钮按下是否已正确注册,并且LoadImage的返回值不为null。
The following code is the message handler for the dialog: 以下代码是对话框的消息处理程序:
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;
}
It would seem the "Name" property of the Picture Control was set to "IDC_STATIC1" but the "ID" property was set to "IDC_STATIC". 优化校准的“名称”属性似乎设置为“ IDC_STATIC1”,但“ ID”属性设置为“ IDC_STATIC”。 Changing it to "IDC_STATIC1" solved the issue.
将其更改为“ IDC_STATIC1”可以解决此问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.