程序只是化些字体上去,只是我发现用GetDC画的会不断闪烁,好象在不断重画一样,
而BeginPaint就没有这样的问题,
==========================================================
case WM_PAINT:

// hdc=GetDC(hwnd);
 hdc=BeginPaint(hwnd,&ps);
  for (i = 0 ; i < NUMLINES ; i++)
          {
              TextOut(hdc,0,i*15,devcaps[i].szLabel,strlen (devcaps[i].szLabel));
  TextOut(hdc,150,i*15,devcaps[i].szDesc,strlen (devcaps[i].szDesc));              TextOut(hdc,400,i*15,szBuffer,wsprintf (szBuffer, TEXT ("%5d"),
                             GetDeviceCaps (hdc, devcaps[i].iIndex)));
          }
TextOut(hdc,600,600,szBuffer,wsprintf (szBuffer, TEXT ("%5d"),i2));//另外为什么我这句执行
的时候看不出来,我是想严整是否被重画
  i2++;
 EndPaint(hwnd,&ps);
// ReleaseDC(hwnd,hdc);
 return 0;

解决方案 »

  1.   

    贴上完整代码
    #include<windows.h>
    #include<stdio.h>
    #include<fstream>
    #include<string>
    using namespace std;
    #define NUMLINES ((int) (sizeof devcaps / sizeof devcaps [0]))
    struct
    {
         int     iIndex ;
         TCHAR * szLabel ;
         TCHAR * szDesc ;
    }
    devcaps [] =
    {
         HORZSIZE,       "HORZSIZE",      "Width in millimeters:",
         VERTSIZE,       "VERTSIZE",      "Height in millimeters:",
         HORZRES,        "HORZRES",       "Width in pixels:",
         VERTRES,        "VERTRES",       "Height in raster lines:",
         BITSPIXEL,      "BITSPIXEL",     "Color bits per pixel:",
         PLANES,         "PLANES",        "Number of color planes:",
         NUMBRUSHES,     "NUMBRUSHES",    "Number of device brushes:",
         NUMPENS,        "NUMPENS",       "Number of device pens:",
         NUMMARKERS,     "NUMMARKERS",    "Number of device ers:",
         NUMFONTS,       "NUMFONTS",      "Number of device fonts:",
         NUMCOLORS,      "NUMCOLORS",     "Number of device colors:",
         PDEVICESIZE,    "PDEVICESIZE",   "Size of device structure:",
         ASPECTX,        "ASPECTX",       "Relative width of pixel:",
         ASPECTY,        "ASPECTY",       "Relative height of pixel:",
         ASPECTXY,       "ASPECTXY",      "Relative diagonal of pixel:",
         LOGPIXELSX,     "LOGPIXELSX",    "Horizontal dots per inch:",
         LOGPIXELSY,     "LOGPIXELSY",    "Vertical dots per inch:",
         SIZEPALETTE,    "SIZEPALETTE",   "Number of palette entries:",
         NUMRESERVED,    "NUMRESERVED",   "Reserved palette entries:",
         COLORRES,       "COLORRES",      "Actual color resolution:"
    } ;
    LRESULT CALLBACK WindowProc(
      HWND hwnd,      // handle to window
      UINT uMsg,      // message identifier
      WPARAM wParam,  // first message parameter
      LPARAM lParam   // second message parameter
    );
    int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)
    {
    //填写窗口类
    WNDCLASS wndobj;
    wndobj.hInstance=(HINSTANCE)1;
    wndobj.lpszClassName="NO_1";
    wndobj.lpszMenuName =NULL;
    wndobj.cbClsExtra =NULL;
    wndobj.cbWndExtra =NULL;
    wndobj.lpfnWndProc=WindowProc;
    wndobj.style =CS_HREDRAW|CS_VREDRAW;
    wndobj.hIcon =LoadIcon(NULL,IDI_APPLICATION);
    wndobj.hCursor = LoadCursor(NULL,IDC_CROSS);
    wndobj.hbrBackground =(HBRUSH)GetStockObject(WHITE_BRUSH);
    //申请注册窗口类
    if (!RegisterClass(&wndobj))
    {
    MessageBox(NULL,"Register Error!","information",MB_ICONSTOP);
    return 0;
    }
    //实例化窗口类
    HWND hwnd;
    hwnd=0;
    hwnd=CreateWindow(
    "NO_1",
    "First Window",
    WS_OVERLAPPEDWINDOW,
    CW_USEDEFAULT,
    CW_USEDEFAULT,
    200,200,
    NULL,NULL,
    (HINSTANCE)1,NULL);
        if (!hwnd)
    {
    MessageBox(NULL,"CreateWindow Error!","information",MB_ICONSTOP);
    return 0;
    }
    //显示窗体
    ShowWindow(hwnd,SW_SHOWDEFAULT);
    UpdateWindow(hwnd);
    //处理Windows消息
    MSG msg;
    while(GetMessage(&msg,NULL,0,0))
    { TranslateMessage (&msg);
            DispatchMessage (&msg); }
    return 0;
    }//======================回调函数定义==============================
    LRESULT CALLBACK WindowProc(
      HWND hwnd,      // handle to window
      UINT uMsg,      // message identifier
      WPARAM wParam,  // first message parameter
      LPARAM lParam   // second message parameter
    )
    {
     int i=0,i2=0;
         HDC         hdc ;//设备句柄
         PAINTSTRUCT ps ;//数据结构
         RECT        rect ;//数据结构
     char szBuffer[50]={0};
        
    switch  (uMsg)
    {
    case WM_CREATE:
     
    case WM_PAINT:

    // hdc=GetDC(hwnd);
     hdc=BeginPaint(hwnd,&ps);
      for (i = 0 ; i < NUMLINES ; i++)
              {
                  TextOut(hdc,0,i*15,devcaps[i].szLabel,strlen (devcaps[i].szLabel));
      TextOut(hdc,150,i*15,devcaps[i].szDesc,strlen (devcaps[i].szDesc));              TextOut(hdc,400,i*15,szBuffer,wsprintf (szBuffer, TEXT ("%5d"),
                                 GetDeviceCaps (hdc, devcaps[i].iIndex)));
              }
          TextOut(hdc,600,600,szBuffer,wsprintf (szBuffer, TEXT ("%5d"),i2));
      i2++;
     EndPaint(hwnd,&ps);
    // ReleaseDC(hwnd,hdc);
     return 0;
    case WM_DESTROY:
     PostQuitMessage (0) ;
             return 0;
    }
    return DefWindowProc(hwnd,uMsg,wParam,lParam);

    }
      

  2.   

    <windows程序设计>第四章说如果收到WM_PAINT后不调用BeginPaint和EndPaint的话无效区不会变为有效,因而windows会一直发送WM_PAINT,我在用GetDC的时候在return前放了个ValidateRect函数以后就不反复刷新了
    我初学,不知道说的对不,你自己查查看是不是