BCB中实现拖拽Panel 改变位置和大小的代码
2016-11-24 15:17
751 查看
//--------------------------------------------------------------------------- #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); } //---------------------------------------------------------------------------
相关文章推荐
- Delphi中运行时改变panel的位置及大小(通过wm_SysCommand来实现)
- JQuery拖拽元素改变大小尺寸实现代码
- JQuery拖拽元素改变大小尺寸实现代码
- C#代码设置窗体和Panel的位置大小
- C# 实现拖拉控件改变位置与大小
- JS实现漂亮的窗口拖拽效果(可改变大小、最大化、最小化、关闭)
- 利用JavaScript实现拖拽改变元素大小
- 实现多个div拖拽移动,交换位置功能,代码复制可运行,有交换特效
- 使用Autolayout和约束后,用代码改变view的位置,并实现动画效果
- JS实现漂亮的窗口拖拽效果(可改变大小、最大化、最小化、关闭)
- C# 实现拖拉控件改变位置与大小的方法
- SDK实现自动改变控件位置和大小的函数
- jquery插件jquery.dragscale.js实现拖拽改变元素大小的方法(附demo源码下载)
- Delphi中运行时改变panel的位置及大小
- 实现移动和改变控件大小的代码
- JS实现漂亮的窗口拖拽效果(可改变大小、最大化、最小化、关闭)
- Ext的Resizable实现图片的展现(弹出式,可以拖拉,改变图片大小和位置)
- js拖拽之二:实现拖动元素上下左右改变元素大小
- jquery插件jquery.dragscale.js实现拖拽改变元素大小的方法(附demo源码下载)