如何在C窗口上显示两个位图图像

时间:2013-07-03 21:21:56

标签: c winapi bitmap win32gui

我可以在窗口上成功显示单个图像,我不知道如何在窗口上显示两个图像。我为差异图像重复相同的代码,但它不起作用。这是一个显示单个图像的代码。

 static HBITMAP bmpSource = NULL;
 static HDC hdcSource = NULL;
 PAINTSTRUCT ps;
 HDC hdcDestination;

 //* inside the WndProc()

    case WM_PAINT:

    bmpSource = (HBITMAP)LoadImage(NULL,file_path,IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
    hdcSource = CreateCompatibleDC(GetDC(0));
    SelectObject(hdcSource, bmpSource);
    hdcDestination = BeginPaint(hwnd, &ps);
    BitBlt(hdcDestination,img_x, img_y, 300, 300, hdcSource, 0, 0, SRCCOPY);
    EndPaint(hwnd, &ps);

    breaks;
   //**

这是我正在做的事情,我有窗口gui的经验。

     static HBITMAP bmpSource = NULL,bmpSource2 = NULL;
 static HDC hdcSource = NULL,hdcSource2 = NULL;
 PAINTSTRUCT ps;
 HDC hdcDestination;

 //* inside the WndProc()

    case WM_PAINT:

    bmpSource = (HBITMAP)LoadImage(NULL,file_path,IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
    hdcSource = CreateCompatibleDC(GetDC(0));
    SelectObject(hdcSource, bmpSource);
     bmpSource2 = (HBITMAP)LoadImage(NULL,file2_path,IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
    hdcSource2 = CreateCompatibleDC(GetDC(0));
    SelectObject(hdcSource2, bmpSource2);
    hdcDestination = BeginPaint(hwnd, &ps);
    BitBlt(hdcDestination,img_x, img_y, 300, 300, hdcSource, 0, 0, SRCCOPY);
    BitBlt(hdcDestination,img2_x, img2_y, 300, 300, hdcSource2, 0, 0, SRCCOPY);
    EndPaint(hwnd, &ps);

    breaks;
   //**

1 个答案:

答案 0 :(得分:0)

您没有向我们展示无效的代码,因此我们无法告诉您错误的行为。

在BeginPaint之后和EndPaint之前进行所有绘画(即BitBlt调用)。这些函数必须只调用一次,所以不要复制它们。