1

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

 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;
   //**
4

1 回答 1

0

您没有向我们展示不起作用的代码,因此我们无法告诉您您做错了什么。

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

于 2013-07-03T21:35:20.423 回答