C ++,位图将不显示? [英] c++,bitmap won't show?

查看:160
本文介绍了C ++,位图将不显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

点击鼠标左键时,位图将不会显示。
我在使用Visual C ++前preSS

The bitmap will not display when the left mouse button is clicked. I'm using visual c++ express

HDC DC, memDC;

switch(message) {
case WM_CREATE:
        hBit1 = LoadBitmap(hInst, "C:\New folder (2)\MyBP1.bmp");
        break;

case WM_LBUTTONDOWN:
            DC = GetDC(hwnd);
            memDC = CreateCompatibleDC(DC);
        SelectObject (memDC, hBit1);
        BitBlt(DC, LOWORD(lParam), HIWORD(lParam), 27, 59, memDC, 0, 0, SRCCOPY);
        ReleaseDC(hwnd, DC);
        DeleteDC(memDC);
        break;

我不知道究竟什么是错的code。
即使世界显示在Visual C ++前preSS没有错误
如果code是完全错了会有人点我在正确的方向

I'm not sure exactly whats wrong with the code. Theres no errors displayed in visual c++ express If the code is all wrong would someone point me in the right direction

推荐答案

LoadBitmap 仅适用于存储在您的可执行文件或DLL资源加载位图。

LoadBitmap is only for loading bitmaps that are stored as resources in your executable or a DLL.

要从一个BMP文件中加载位图,你想用的LoadImage LR_LOADFROMFILE 标记,像这样的:

To load a bitmap from a BMP file, you want to use LoadImage with the LR_LOADFROMFILE flag, something like this:

bmp = (HBITMAP)LoadImage(0, filename, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);

顺便说一句,你可能真的不希望做直接回应 WM_LBUTTONDOWN 显示。相反,你通常要录制的位置,可能设置一个标志,表明该位应该被显示,并调用 InvalidateRect 无效您的客户端矩形 - 然后做实际的针对绘图 WM_PAINT

As an aside, you probably don't really want to do the displaying directly in response to WM_LBUTTONDOWN. Instead, you normally want to record the position, possibly set a flag to indicate that the bitmap should be displayed, and call InvalidateRect to invalidate your client rectangle -- then do the actual drawing in response to WM_PAINT.

这篇关于C ++,位图将不显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆