#include "stdafx.h"
#include "resource.h"
// Global Variables:
HINSTANCE hInst; // current instance
HBITMAP bmp;
HDC mdc;//内存DC
// Foward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
  // TODO: Place code here.
MSG msg; MyRegisterClass(hInstance); // Perform application initialization:
if (!InitInstance (hInstance, nCmdShow)) 
{
return FALSE;
} // Main message loop:
while (GetMessage(&msg, NULL, 0, 0)) 
{

TranslateMessage(&msg);
DispatchMessage(&msg);
} return msg.wParam;
}//
//  FUNCTION: MyRegisterClass()
//
//  PURPOSE: Registers the window class.
//
//  COMMENTS:
//
//    This function and its usage is only necessary if you want this code
//    to be compatible with Win32 systems prior to the 'RegisterClassEx'
//    function that was added to Windows 95. It is important to call this function
//    so that the application will get 'well formed' small icons associated
//    with it.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex; wcex.cbSize = sizeof(WNDCLASSEX);  wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = NULL;
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = "GameBmp";
wcex.hIconSm = NULL; return RegisterClassEx(&wcex);
}
//绘图函数
void MyPaint(HDC hdc)
{
SelectObject(mdc,bmp);
BitBlt(hdc,0,0,800,500,mdc,0,0,SRCCOPY);
}//
//   FUNCTION: InitInstance(HANDLE, int)
//
//   PURPOSE: Saves instance handle and creates main window
//
//   COMMENTS:
//
//        In this function, we save the instance handle in a global variable and
//        create and display the main program window.
//BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
   HWND hWnd;
   HDC hdc;
   hInst = hInstance; // Store instance handle in our global variable   hWnd = CreateWindow("GameBmp", "第一个游戏窗口", WS_OVERLAPPEDWINDOW,
      CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);   if (!hWnd)
   {
      return FALSE;
   }
   MoveWindow(hWnd,30,10,800,500,true);
   ShowWindow(hWnd, nCmdShow);
   UpdateWindow(hWnd);   hdc=GetDC(hWnd);
   mdc=CreateCompatibleDC(hdc);   bmp=(HBITMAP)LoadImage(NULL,"C:\Documents and Settings\Administrator\桌面\B6.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);   MyPaint(hdc);
   ReleaseDC(hWnd,hdc);   return TRUE;
}//
//  FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
//
//  PURPOSE:  Processes messages for the main window.
//
//  WM_COMMAND - process the application menu
//  WM_PAINT - Paint the main window
//  WM_DESTROY - post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
switch (message) 
{
case WM_PAINT:
hdc=BeginPaint(hWnd,&ps);
MyPaint(hdc);
EndPaint(hWnd,&ps);
break;
case WM_DESTROY:
DeleteDC(mdc);
DeleteObject(bmp);
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
   }
   return 0;
}位图大小144K
怎么看不到加载的位图啊?大侠指点下

解决方案 »

  1.   

    MyPaint(hdc); 
    ==========
    这个函数写在哪儿啊?没找到啊
      

  2.   

    不好意思,看到了,首先有个错误:
    bmp=(HBITMAP)LoadImage(NULL,L"C:\Documents and Settings\Administrator\桌面\B6.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE); 这里的路径中的"\"应该改为“\\”
      

  3.   

    问题解决  就是上面的原因  用什么方法把图片加载到工程中  直接用文件名代替路径名? wltg2001谢谢你
      

  4.   

    可以在资源中,先插入一个bmp,然后,将对应的文件给换掉,最后,你装载的时候,直接装载对应的ID!CBitmap
      

  5.   

    CBitmap支持的直接装载资源ID的!
      

  6.   

    将图片当作资源载入,不过这时LoadImage的参数就不是文件名而资源ID了,应该说如果你的程序不用动态加载图片的话,用资源比较方便。