zoukankan      html  css  js  c++  java
  • BCB中实现拖拽Panel 改变位置和大小的代码

    //---------------------------------------------------------------------------
    
    #ifndef Unit1H
    #define Unit1H
    //---------------------------------------------------------------------------
    #include <Classes.hpp>
    #include <Controls.hpp>
    #include <StdCtrls.hpp>
    #include <Forms.hpp>
    #include <ExtCtrls.hpp>
    #include <AppEvnts.hpp>
    //---------------------------------------------------------------------------
    class TForm1 : public TForm
    {
    __published:    // IDE-managed Components
        TPanel *Panel1;
        TApplicationEvents *ApplicationEvents1;
        void __fastcall FormCreate(TObject *Sender);
        void __fastcall Panel1MouseMove(TObject *Sender, TShiftState Shift,
              int X, int Y);
    private:    // User declarations
        void __fastcall MyWndProc(Messages::TMessage &Message);
        TWndMethod oldProc;
    public:        // User declarations
        __fastcall TForm1(TComponent* Owner);
    };
    //---------------------------------------------------------------------------
    extern PACKAGE TForm1 *Form1;
    //---------------------------------------------------------------------------
    #endif
    //---------------------------------------------------------------------------
    
    #include <vcl.h>
    #pragma hdrstop
    
    #include "Unit1.h"
    //---------------------------------------------------------------------------
    #pragma package(smart_init)
    #pragma resource "*.dfm"
    TForm1 *Form1;
    
    
    void __fastcall TForm1::MyWndProc(Messages::TMessage &Message)
    {
        HWND hWnd = Panel1->Handle;
        switch(Message.Msg)
        {
            case WM_NCHITTEST:
            {
                TPoint pt;
                GetCursorPos(&pt);
                pt = Panel1->ScreenToClient(pt);
                TRect rcClient = Panel1->ClientRect;
    
                if (pt.x <= 20  && pt.y <= 20)//左上角,判断是不是在左上角,就是看当前坐标是不是即在左边拖动的范围内,又在上边拖动的范围内,其它角判断方法类似
                {
                    Message.Result = HTTOPLEFT;
                }else if (pt.x>rcClient.right-20 && pt.y<rcClient.top+20)//右上角  
                {  
                    Message.Result = HTTOPRIGHT;
                    
                }else if (pt.x<rcClient.left+20 && pt.y>rcClient.bottom-20)//左下角  
                {  
                    Message.Result = HTBOTTOMLEFT;
                }else if (pt.x>rcClient.right-20 && pt.y>rcClient.bottom-20)//右下角  
                {
                    Message.Result = HTBOTTOMRIGHT;
    
                }else if (pt.x<rcClient.left+20)
                {  
                    Message.Result = HTLEFT;
                }else if (pt.x>rcClient.right-20)  
                {
                    Message.Result = HTRIGHT;
                }else if (pt.y<rcClient.top+20)
                {  
                    Message.Result = HTTOP;
                }
                else if (pt.y > rcClient.Bottom - 20)
                {
                    Message.Result = HTBOTTOM;
                }
                else
                {
                    oldProc(Message);
                }
            }
            break;
            case WM_SIZE:   //要让窗体能够随着缩放改变,要响应WM-SIZE消息
            {
                RECT rcClient = { 0 };
                ::GetClientRect(hWnd, &rcClient);
                InvalidateRect(hWnd,&rcClient,FALSE);
            }
            break;
            default:
                oldProc(Message);
        }
    }
    //---------------------------------------------------------------------------
    __fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
    {
    
    }
    //---------------------------------------------------------------------------
    
    void __fastcall TForm1::FormCreate(TObject *Sender)
    {
        oldProc = Panel1->WindowProc;
        Panel1->WindowProc = MyWndProc;    
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::Panel1MouseMove(TObject *Sender, TShiftState Shift,
          int X, int Y)
    {
        WORD SC_DragMove =   0xF012   ;
        ReleaseCapture();
        ((TWinControl*)Sender)->Perform(WM_SYSCOMMAND,SC_DragMove,0);
    }
    //---------------------------------------------------------------------------

  • 相关阅读:
    点击listview 的列头对其item进行自动排序
    将选择的图片显示在listview中,并显示filename,path和type
    【翻译】8 个可以节省时间的 C# 开发相关工具
    【原创】关于乘法运算的新思路
    【翻译】为什么我们要用抽象类?
    【翻译】如何使用 C# 的 BackgroundWorker
    【汉化】DevExpress插件中RichEdit控件的自定义汉化方法
    关于C#日期格式化问题
    C#获取(大陆)身份证基本信息的算法
    C#关于精确年龄的算法(精确到天)
  • 原文地址:https://www.cnblogs.com/songr/p/6097935.html
Copyright © 2011-2022 走看看