如何在win32中绘制自定义边框? [英] How to draw custom border in win32?

查看:34
本文介绍了如何在win32中绘制自定义边框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何绘制自定义边框,实际上我正在尝试绘制 1 个像素的边框但失败了,我们该如何实现?我试过这个.但失败了.我试过这样,当窗口没有子窗口时它工作正常..在我的情况下,在我的窗口顶部有 3 个子窗口在这种情况下我正在闪烁.

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; 

推荐答案

有点复杂.它至少需要正确处理 WM_NCCALCSIZEWM_NCPAINTWM_NCHITTEST.

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

另请注意,自从 Aero 出现以来我还没有尝试过,我知道 Aero 改变了很多东西:在 Aero 下,不是仅仅调整实际边框的大小,而是使用无边框窗口,然后调用 Dwm* 函数来添加类似边框的外观和行为(有 MSDN 上的一篇文章.

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).

这篇关于如何在win32中绘制自定义边框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆