BITBLT.C
/*---------------------------------------
   BITBLT.C -- BitBlt Demonstration
               (c) Charles Petzold, 1998
  ---------------------------------------*/#include <windows.h>LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                    PSTR szCmdLine, int iCmdShow)
{
     static TCHAR szAppName [] = TEXT ("BitBlt") ;
     HWND         hwnd ;
     MSG          msg ;
     WNDCLASS     wndclass ;     wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
     wndclass.lpfnWndProc   = WndProc ;
     wndclass.cbClsExtra    = 0 ;
     wndclass.cbWndExtra    = 0 ;
     wndclass.hInstance     = hInstance ;
     wndclass.hIcon         = LoadIcon (NULL, IDI_INFORMATION) ;
     wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
     wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
     wndclass.lpszMenuName  = NULL ;
     wndclass.lpszClassName = szAppName ;
     
     if (!RegisterClass (&wndclass))
     {
          MessageBox (NULL, TEXT ("This program requires Windows NT!"),
                      szAppName, MB_ICONERROR) ;
          return 0 ;
     }
     
     hwnd = CreateWindow (szAppName, TEXT ("BitBlt Demo"), 
                          WS_OVERLAPPEDWINDOW, 
                          CW_USEDEFAULT, CW_USEDEFAULT,
                          CW_USEDEFAULT, CW_USEDEFAULT,
                          NULL, NULL, hInstance, NULL) ;     ShowWindow (hwnd, iCmdShow) ;
     UpdateWindow (hwnd) ;     while (GetMessage (&msg, NULL, 0, 0))
     {
          TranslateMessage (&msg) ;
          DispatchMessage (&msg) ;
     }
     return msg.wParam ;
}LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
     static int  cxClient, cyClient, cxSource, cySource ;
     HDC         hdcClient, hdcWindow ;
     int         x, y ;
     PAINTSTRUCT ps ;
     
     switch (message)
     {
     case WM_CREATE:
          cxSource = GetSystemMetrics (SM_CXSIZEFRAME) +
                     GetSystemMetrics (SM_CXSIZE) ;          cySource = GetSystemMetrics (SM_CYSIZEFRAME) + 
                     GetSystemMetrics (SM_CYCAPTION) ;
          return 0 ;     case WM_SIZE:
          cxClient = LOWORD (lParam) ;
          cyClient = HIWORD (lParam) ;
          return 0 ;     case WM_PAINT:
          hdcClient = BeginPaint (hwnd, &ps) ;
          hdcWindow = GetWindowDC (hwnd) ;          for (y = 0 ; y < cyClient ; y += cySource)
          for (x = 0 ; x < cxClient ; x += cxSource)
          {
               BitBlt (hdcClient, x, y, cxSource, cySource,
                       hdcWindow, 0, 0, SRCCOPY) ;
          }          ReleaseDC (hwnd, hdcWindow) ;
          EndPaint (hwnd, &ps) ;
          return 0 ;
     case WM_DESTROY:
          PostQuitMessage (0) ;
          return 0 ;
     }
     return DefWindowProc (hwnd, message, wParam, lParam) ;
}这是书上源码,完全一样,照理说应该显示窗口左上角的图标,书上也是这个效果,可是为什么我用VS2008运行时,总是显示的总是窗口下面的编译器上的某个地方的图?
请指教!

解决方案 »

  1.   

    GetWindowDC 本来想加颜色的,结果失败了,前后都有color,拷贝代码时请注意
      

  2.   

    BitBlt (hdcClient, x, y, cxSource, cySource,
                           hdcWindow, 0, 0, SRCCOPY) ;
    ======================================================
    有误,你往 客户区贴图了。
      

  3.   

    可是我在vs2008里满屏都是vs2008上的某个图啊,也就是说我的窗口标题在vs2008的哪个部分上面,就显示哪个部分...我是win7..
      

  4.   

    我的是XP+VC6
    显示的是系统信息那个图吧,就是那个白色的"i"
      

  5.   

    显示的应该是这个图标
    wndclass.hIcon         = LoadIcon (NULL, IDI_INFORMATION) ;
    难道你Win7下面的IDI_INFORMATION图标没有?
      

  6.   

    完全拷贝的windows程序设计第五版...
    话说怎么贴图?我贴个图来
      

  7.   

    你先看下getwindowdc是否成功了,或者简单测试下 getwindowdc(NULL)看是否获得系统左上角。
    另也有可能是系统的缘故,毕竟没WIN7上测试过。
      

  8.   

    WIN7 总是问题多~~~~也可能是WIN7 做了系统保护吧!!!有的函数调用需要管理员权限~~~