VB中拖动没有标题栏的窗体
2006-02-27 11:38:48 来源:WEB开发网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
赞助商链接