测试用例非常简单。我想在按下按钮(IDC_BUTTON2)到位图资源(IDB_BITMAP1)时设置优化校准(IDC_STATIC1)的内容。我遇到的问题是,当我按下按钮时,优化校准不会加载图像。我已经验证按钮正在正确注册,并且LoadImage的返回值不为空。
以下代码是对话框的消息处理程序:
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;
}
答案 0 :(得分:1)
这似乎是"姓名"优化校准的属性设置为" IDC_STATIC1"但是" ID"属性设置为" IDC_STATIC"。将其更改为" IDC_STATIC1"解决了这个问题。