RECT rectnew5;
SetRect(&rectnew5,330,200,480,320);
HBRUSH hbrush5;
hbrush5=CreateSolidBrush(RGB(143,188,143));
FillRect(hdc,&rectnew5,hbrush5);if (int a=DrawText(hdc,"请选择你要走的位置",18,&rectnew5,DT_VCENTER))
{
  int a=GetLastError();
                                            a=87(参数不对)

}执行失败!
   a= GetLastError()得到a= 87,说是参数不对,但是我没发现参数哪里不对啊!!编译能通过!  恳求帮忙!

解决方案 »

  1.   

    int a=DrawText(hdc,"请选择你要走的位置",18,&rectnew5,DT_VCENTER);
    if (a==0)
    {
    int a=GetLastError(); 
                                                a=87(参数不对) 
    }
    画对了,是你判断不对!
      

  2.   

    RECT rectnew5; 
    SetRect(&rectnew5,330,200,480,320); 
    HBRUSH hbrush5; 
    hbrush5=CreateSolidBrush(RGB(143,188,143)); 
    FillRect(hdc,&rectnew5,hbrush5); if (int a=DrawText(hdc,"请选择你要走的位置",18,&rectnew5,DT_VCENTER)) 

    int a=GetLastError(); 
                                                a=87(参数不对) } 
    ====================
    18不正确,应该是19,应该有结束符\0
      

  3.   

    RECT rectnew5; 
    SetRect(&rectnew5,330,200,480,320); 
    HBRUSH hbrush5; 
    hbrush5=CreateSolidBrush(RGB(143,188,143)); 
    FillRect(hdc,&rectnew5,hbrush5); 
    char *pText = "请选择你要走的位置",if (int a=DrawText(hdc,pText,strlen(pText),&rectnew5,DT_VCENTER)) 

    int a=GetLastError(); 
                                                a=87(参数不对) } 
      

  4.   

    上面的代码是在 case WM_KEYDOWN:下写的执行失败,但是如果在 WM_PAINT:下写的话就能执行正确?这是怎么回事????
      

  5.   

    DrawText
    Return ValuesThe height of the text indicates success. Zero indicates failure. To get extended error information, call GetLastError.
      

  6.   

    能看一下完整一点的代码么。看一下hdc正常么?
      

  7.   

    然而 我用textout()函数。在case WM_KEYDOWN下却能执行正确????
      

  8.   

    case WM_KEYDOWN:
    static int times=1;
    static int times2=1;
    rect.left=0;
    rect.top=0;
    rect.right=XBW;
    rect.bottom=YBW;
    hdc=GetDC(hWnd);
    ShowRect(hdc,&rect);
    SetFocus(hWnd);
    //TextOut()
    char *pText = "请选择你要走的位置";
        if (DrawText(hdc,"请选择你要走的位置",strlen(pText),&rectnew5,DT_VCENTER))
    {
      int a=GetLastError();

    }
    执行失败!换成textout(hdc...) 同一个hdc,执行正确! case WM_PAINT:
    hdc = BeginPaint(hWnd, &ps);
    // hdc=GetDC(hWnd);
    // TODO: Add any drawing code here...
    RECT rect;

    GetClientRect(hWnd, &rect);
    ShowRect(hdc,&rect);
    DrawIcon(hdc,138,275,g_hIconBox);
    RECT rectnew5;
    SetRect(&rectnew5,330,200,480,320);
    HBRUSH hbrush5;
    hbrush5=CreateSolidBrush(RGB(143,188,143));
    FillRect(hdc,&rectnew5,hbrush5); // DrawText(hdc,"请选择棋子",19,&rectnew5,DT_VCENTER);

    EndPaint(hWnd, &ps);
    break;在这里面执行正确!
      

  9.   

     if (DrawText(hdc,"请选择你要走的位置",strlen(pText),&rectnew5,DT_VCENTER)) 
    换成 if (DrawText(hdc,pText,strlen(pText),&rectnew5,DT_VCENTER)) 
      

  10.   

    非常感谢你的热心帮助,但是还是不行和原来一样!
    int a=GetLastError();
    a=87(参数不对);
      

  11.   


    HDC hDC;
    PAINTSTRUCT ps;
    HBITMAP hBM;
    RECT rect;
    HBRUSH hBrush;
    char *pText = "请选择你要走的位置";case WM_LBUTTONDOWN:
    hDC = GetDC(hWnd); 
    SetRect(&rect, 330, 200, 480, 320); 
    hBrush = CreateSolidBrush(RGB(143, 188, 143)); 
    FillRect(hDC,&rect,hBrush);  if (!DrawText(hDC, pText, strlen(pText), &rect, DT_VCENTER)) 

    int a = GetLastError(); 
    }  break;试了下,没问题,你再试试
      

  12.   

    case WM_KEYDOWN: 
    static int times=1; 
    static int times2=1; 
    rect.left=0; 
    rect.top=0; 
    rect.right=XBW; 
    rect.bottom=YBW; 
    hdc=GetDC(hWnd); 
    ShowRect(hdc,&rect); 
    SetFocus(hWnd); ==这里的ShowRect干啥了?有没有成功获取到rect呢?最好仔细调试一下,看看是否某个参数是异常的
      

  13.   

    ShowRect((hdc,&rect))是我自己写的一个函数,更新一个矩形!不是我下面要输出文字的矩形(rectnew5);if (DrawText(hdc,"请选择你要走的位置",strlen(pText),&rectnew5,DT_VCENTER))  rectnew5是我在 case WM_PAINT: 下定义的,然后在case WM_KEYDOWN:下用,这样在编译的时候不报错!但是执行错误! 
     
      

  14.   

    DT_VCENTER 必须要与DT_SINGLELINE 搭配着用。
    忘了吗?