给你一个函数:
void MyDrawFocusRect(HWND hwnd)
{
//在窗口hwnd的边框上画一个虚线框
RECT rt;
GetWindowRect(hwnd,&rt);
OffsetRect(&rt,-rt.left,-rt.top);
HDC dc=GetWindowDC(hwnd);
DrawFocusRect(dc,&rt);
InflateRect(&rt,-1,-1);
DrawFocusRect(dc,&rt);
InflateRect(&rt,-1,-1);
DrawFocusRect(dc,&rt);
InflateRect(&rt,-1,-1);
DrawFocusRect(dc,&rt);
ReleaseDC(hwnd,dc);
}该函数使用了api函数DrawFocusRect(),画出的捕获框非常标准,因为DrawFocusRect()函数内部使用了xor方式,因此在同一位置第二次绘制就会把第一次画的捕获框擦除。

解决方案 »

  1.   

    void DrawRect(HWND hWnds)
    {
      TRect rect;
      HDC dc;
      GetWindowRect(hWnds, &rect);
      dc= GetDC(0);
      Form1->Label5->Caption="X:"+IntToStr(rect.Width());
      Form1->Label6->Caption="Y:"+IntToStr(rect.Height());
      SetROP2(dc, R2_NOT);
      MoveToEx(dc, rect.left + 1, rect.top + 1, NULL);
      LineTo(dc, rect.right + 1, rect.top + 1);
      MoveToEx(dc, rect.right - 1, rect.top + 1, NULL);
      LineTo(dc, rect.right - 1, rect.bottom - 1);
      MoveToEx(dc, rect.right - 1, rect.bottom -1 , NULL);
      LineTo(dc, rect.left + 1, rect.bottom - 1);
      MoveToEx(dc, rect.left + 1, rect.bottom - 1, NULL);
      LineTo(dc, rect.left + 1, rect.top + 1);  MoveToEx(dc, rect.left + 2, rect.top + 2, NULL);
      LineTo(dc, rect.right + 2, rect.top + 2);
      MoveToEx(dc, rect.right - 2, rect.top + 2, NULL);
      LineTo(dc, rect.right - 2, rect.bottom - 2);
      MoveToEx(dc, rect.right - 2, rect.bottom -2 , NULL);
      LineTo(dc, rect.left + 2, rect.bottom - 2);
      MoveToEx(dc, rect.left + 2, rect.bottom - 2, NULL);
      LineTo(dc, rect.left + 2, rect.top + 2);
    }
      

  2.   

    我需要VC++代码,dycdyc123给出的是bcb吧,我给20分好了请你不要介意。十分感谢你们的热心帮助。