下面是一個示例。基本上,你需要發送STM_SETIMAGE消息到圖片控件,以及你想要顯示的圖片的句柄。
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include "resource.h"
HINSTANCE hInst;
BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
static HBITMAP bmp1, bmp2;
static bool isImg1 = true;
switch(uMsg)
{
case WM_INITDIALOG:
bmp1 = (HBITMAP)SendDlgItemMessage(hwndDlg, IDC_STATIC1, STM_GETIMAGE, IMAGE_BITMAP, 0);
bmp2 = (HBITMAP)LoadImage(NULL, "bitmap2.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
return TRUE;
case WM_DESTROY:
DeleteObject(bmp1);
DeleteObject(bmp2);
return true;
case WM_CLOSE:
EndDialog(hwndDlg, 0);
return TRUE;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDC_BTN_QUIT:
EndDialog(hwndDlg, 0);
return TRUE;
case IDC_BTN_TEST:
if (isImg1)
SendDlgItemMessage(hwndDlg, IDC_STATIC1, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)bmp2);
else
SendDlgItemMessage(hwndDlg, IDC_STATIC1, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)bmp1);
isImg1 = !isImg1;
return TRUE;
}
}
return FALSE;
}
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
hInst = hInstance;
// The user interface is a modal dialog box
return DialogBox(hInstance, MAKEINTRESOURCE(DLG_MAIN), NULL, (DLGPROC)DialogProc);
}
如果你能證明你目前的代碼,然後它會更容易建議變化。 – Ram