0

how to draw custom border, Actually i'am trying to draw 1 pixels border but failed, how can we achieve this? i had tried this.but failed.i tried like this it works fine when window does't have child window .. in my case on top of my window there are 3 child window on this case i'am getting flickering.

           case WM_NCACTIVATE :
            {
                if(TRUE == wParam)
          {
         stateofWindow = true;
        InvalidateRect(hwnd,NULL,true);
          }
         else if(FALSE == wParam )
         {
        stateofWindow = false;
        InvalidateRect(hwnd,NULL,true);
         }
    }
break;

case WM_NCCALCSIZE :
    {   
        if (true == wParam )
        {       
           return 0;
        }
    }
    break;
case WM_PAINT:
    {
        HDC hcd = NULL;
        PAINTSTRUCT ps;
        hcd = BeginPaint(hwnd,&ps);

        HPEN hPen = CreatePen(PS_SOLID, 1, RGB(165,165,165));; 

        SelectObject(hcd, hPen);

        RECT rcClientRect = {0};

        GetClientRect(hwnd,&rcClientRect);
        //GetWindowRect(hwnd,&rcClientRect);

        if(FALSE == stateofWindow)
        {
            MoveToEx(hcd,rcClientRect.left,rcClientRect.top,NULL);

            LineTo(hcd,rcClientRect.right-1,rcClientRect.top );

            LineTo(hcd,rcClientRect.right-1,rcClientRect.bottom-1 );

            LineTo(hcd,rcClientRect.left,rcClientRect.bottom-1 );

            LineTo(hcd,rcClientRect.left,rcClientRect.top);
        }
        else
        {
            HPEN hPen1 = CreatePen(PS_SOLID, 1, RGB(255,0,0));; 

            SelectObject(hcd, hPen1);

            MoveToEx(hcd,rcClientRect.left,rcClientRect.top,NULL);

            LineTo(hcd,rcClientRect.right-1,rcClientRect.top );

            LineTo(hcd,rcClientRect.right-1,rcClientRect.bottom-1 );

            LineTo(hcd,rcClientRect.left,rcClientRect.bottom-1 );

            LineTo(hcd,rcClientRect.left,rcClientRect.top);
        }
        EndPaint(hwnd,&ps);
    }
           break; 
sindhu
  • 41
  • 2
  • 6

1 Answers1

2

It's a bit complicated. It requires correctly handling WM_NCCALCSIZE, WM_NCPAINT and WM_NCHITTEST at least.

Also note that I haven't tried ever since Aero came by, and I know Aero changed a lot of things: Under Aero, instead of just resizing the actual border, you use a border-less window and then call Dwm* functions to add border-like appearance and behavior (there was an article on MSDN about that).

Medinoc
  • 6,577
  • 20
  • 42
  • Thanks , can u give some idea to handle this. i tried but not get exact result. – sindhu Feb 28 '14 at 11:00
  • IIRC, WM_NCCALCSIZE had some kind of gotcha, I couldn't use it right from the first try. Unfortunately I don't have the details handy. For your first test maybe you can ignore WM_NCPAINT if you just fill a rectangle in WM_PAINT, the objective just being to make sure the client area has the right size at all times. – Medinoc Feb 28 '14 at 11:05