• [WTL]Resize处理|


    1. 实现自绘窗口的Resize

    自绘的主窗口,往往没有WS_BORDER【特别是Win7下的Border,厚厚的~】,但是没有Border,就等于没有了WS_SIZEBOX。那么我们怎么样才能实现同等的功能呢?

    接管以下三个消息:

    MESSAGE_HANDLER(WM_NCHITTEST,     OnNcHitTest)
    MESSAGE_HANDLER(WM_SETCURSOR,     OnSetCursor)
    MESSAGE_HANDLER(WM_NCLBUTTONDOWN, OnNcLButtonDown)

    第一个好说,到处都是MFC的例子,判断以下Border的位置,返回HTBOTTOMRIGHT 这些值即可。

    Cursor这里,我直接给出WTL的代码好了,以后直接抄:

    LRESULT OnSetCursor(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/)
    {
            
    int nHitTest = LOWORD(lParam);
            
    if(nHitTest == HTCAPTION || nHitTest == HTSYSMENU ||
                nHitTest 
    == HTMENU || nHitTest == HTCLIENT)
            {
                SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW)));
            }
            
    else if(nHitTest == HTTOP || nHitTest == HTBOTTOM)
            {
                SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_SIZENS)));
            }
            
    else if(nHitTest == HTLEFT || nHitTest == HTRIGHT)
            {
                SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_SIZEWE)));
            }
            
    else if(nHitTest == HTTOPLEFT || nHitTest == HTBOTTOMRIGHT)
            {
                SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_SIZENWSE)));
            }
            
    else if(nHitTest == HTTOPRIGHT || nHitTest == HTBOTTOMLEFT)
            {
                SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_SIZENESW)));
            }
            
    else
            {
                SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW)));
            }
            
    return S_OK;

    NCLBUTTONDOWN可以这么写:

        LRESULT OnNcLButtonDown(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/)
        {
            T
    * pT = static_cast<T*>(this);
            POINT point;
            point.x 
    = HIWORD(lParam);
            point.y 
    = LOWORD(lParam);
            
    int nHitTest = LOWORD(wParam);
            
    if(nHitTest == HTTOP)
                pT
    ->SendMessage( WM_SYSCOMMAND, SC_SIZE | WMSZ_TOP, MAKELPARAM(point.x, point.y));
            
    else if(nHitTest == HTBOTTOM)
                pT
    ->SendMessage( WM_SYSCOMMAND, SC_SIZE | WMSZ_BOTTOM, MAKELPARAM(point.x, point.y));
            
    else if(nHitTest == HTLEFT)
                pT
    ->SendMessage( WM_SYSCOMMAND, SC_SIZE | WMSZ_LEFT, MAKELPARAM(point.x, point.y));
            
    else if(nHitTest == HTRIGHT)
                pT
    ->SendMessage( WM_SYSCOMMAND, SC_SIZE | WMSZ_RIGHT, MAKELPARAM(point.x, point.y));
            
    else if(nHitTest == HTTOPLEFT)
                pT
    ->SendMessage( WM_SYSCOMMAND, SC_SIZE | WMSZ_TOPLEFT, MAKELPARAM(point.x, point.y));
            
    else if(nHitTest == HTTOPRIGHT)
                pT
    ->SendMessage( WM_SYSCOMMAND, SC_SIZE | WMSZ_TOPRIGHT, MAKELPARAM(point.x, point.y));
            
    else if(nHitTest == HTBOTTOMLEFT)
                pT
    ->SendMessage( WM_SYSCOMMAND, SC_SIZE | WMSZ_BOTTOMLEFT, MAKELPARAM(point.x, point.y));
            
    else if(nHitTest == HTBOTTOMRIGHT)
                pT
    ->SendMessage(WM_SYSCOMMAND, SC_SIZE | WMSZ_BOTTOMRIGHT, MAKELPARAM(point.x, point.y));

            
    return 0;

        } 

     参考:

    http://hi.baidu.com/bdxiong/blog/item/b7273b3031103294a9018e06.html 

  • 相关阅读:
    释放下一代网络应用的能量[转载]
    帮助创建未来的 .NET 客户端开发
    ASP.NET Ajax替代品AjaxWidgets
    Microsoft Surface
    有意思的《致招商银行的公开信》行动!
    Applying DomainDriven Design and Patterns(ADDDP) With examples in C# and .NET
    Silverlight ASP.NET control
    StructureMap 轻量IOC框架
    DDay.iCal an iCalendar class library
    Mono ASP.NET 上几个性能调优技巧
  • 原文地址:https://www.cnblogs.com/healerkx/p/2153210.html
Copyright © 2020-2023  润新知