首页 > 学院 > 开发设计 > 正文

VB中拖动没有标题栏的窗体

2019-11-18 17:53:50
字体:
来源:转载
供稿:网友
程序代码:

Module1
OptionExplicit
PublicConstGWL_WNDPROC=(-4)

PublicConstWM_NCHITTEST=&H84
PublicConstHTCLIENT=1
PublicConstHTCAPTION=2

DeclareFunctionCallWindowProcLib"user32"Alias"CallWindowProcA"(ByVallpPrevWndFuncAsLong,ByValhWndAsLong,ByValMsgAsLong,ByValwParamAsLong,ByVallParamAsLong)AsLong
DeclareFunctionGetWindowLongLib"user32"Alias"GetWindowLongA"(ByValhWndAsLong,ByValnIndexAsLong)AsLong
DeclareFunctionSetWindowLongLib"user32"Alias"SetWindowLongA"(ByValhWndAsLong,ByValnIndexAsLong,ByValdwNewLongAsLong)AsLong

PublicprevWndProcAsLong

FunctionWndProc(ByValhWndAsLong,ByValMsgAsLong,ByValwParamAsLong,ByVallParamAsLong)AsLong
WndProc=CallWindowProc(prevWndProc,hWnd,Msg,wParam,lParam)
IfMsg=WM_NCHITTESTAndWndProc=HTCLIENTThen
WndProc=HTCAPTION
EndIf
EndFunction

  程序首先调用CallWindowProc,这样就可以从还回值的知当前的鼠标位置位于那一个区域,接着判断返回值是否等于HTCLENT(工作区)内,如果是,则将返回值设置成TICAPTION(标题区),这样就可以瞒过Windows,让Windows以为鼠标位于标题区内

Form1

OptionExplicit

PrivateSubCommand1_Click()
UnloadMe
EndSub

PrivateSubForm_Load()
prevWndProc=GetWindowLong(Me.hWnd,GWL_WNDPROC)
SetWindowLongMe.hWnd,GWL_WNDPROC,AddressOfWndProc
EndSub

PrivateSubForm_Unload(CancelAsInteger)
SetWindowLongMe.hWnd,GWL_WNDPROC,prevWndProc
EndSub

->


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表