No se trata de un código optimizado, solo un simple concepto para el q no la conoce, saludos
Form
Código
Option Explicit Private Sub Form_Load() Call SetWindowPos(Me.hwnd, &HFFFF, &H0, &H0, &H0, &H0, &H2 Or &H1) 'on top (opcional) Call StartHook End Sub Private Sub Form_Unload(Cancel As Integer) StopHook End Sub
Module
Código
Option Explicit 'Modulo: NCHITTEST 'Autor : Sergio Desanti (Hasseds) 'Test : XP (32 BIT) Public Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long Private Declare Function SetWindowsHookEx Lib "user32.dll" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long Private Declare Function UnhookWindowsHookEx Lib "user32.dll" (ByVal hHook As Long) As Long Private Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal ncode As Long, ByVal wParam As Long, lParam As Any) As Long Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long Private Type POINTAPI: x As Long: y As Long: End Type Private Const WM_NCHITTEST = &H84 Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Long, ByVal Msg As Long, wParam As Any, lParam As Any) As Long Private Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long Dim hHook As Long Function Make_lParam(ByVal x As Integer, ByVal y As Integer) As Long Make_lParam = x Or (y * &H10000) End Function Public Sub StartHook() hHook = SetWindowsHookEx(&HE, AddressOf MouseProc, App.hInstance, &H0) End Sub Public Sub StopHook() Call UnhookWindowsHookEx(hHook) hHook = 0 End Sub Private Function MouseProc(ByVal ncode As Long, ByVal wParam As Long, lParam As POINTAPI) As Long Dim hwndl As Long hwndl = WindowFromPoint(lParam.x, lParam.y) Dim retNCHITTEST As Long retNCHITTEST = SendMessage(hwndl, WM_NCHITTEST, &H0&, ByVal Make_lParam(lParam.x, lParam.y)) 'If wParam = &H201 Then If hwndl = Form1.hwnd Then Select Case retNCHITTEST Case 1: Form1.Caption = "AREA CLIENTE" Case 2: Form1.Caption = "BARRA DE TITULO" Case 3: Form1.Caption = "ICONO LA BARRA DE TITULO" Case 6: Form1.Caption = "SCROLL HORIZONTAL" Case 7: Form1.Caption = "SCROLL VERTICAL" Case 8: Form1.Caption = "BOTON MINIMIZAR" Case 9: Form1.Caption = "BOTON MAXIMIZAR" Case 10: Form1.Caption = "BORDE IZQUIERDO" Case 11: Form1.Caption = "BORDE DERECHO" Case 12: Form1.Caption = "BORDE SUPERIOR" Case 13: Form1.Caption = "BORDE SUPERIOR IZQUIERDO" Case 14: Form1.Caption = "BORDE SUPERIOR DERECHO" Case 15: Form1.Caption = "BORDE INFERIOR" Case 16: Form1.Caption = "BORDE INFERIOR IZQUIERDO" Case 17: Form1.Caption = "BORDE INFERIOR DERECHO" Case 18: Form1.Caption = "BORDE FIXED" Case 20: Form1.Caption = "BOTON CERRAR" Case 21: Form1.Caption = "BOTON AYUDA" Case Else: Form1.Caption = retNCHITTEST End Select Else Form1.Caption = "FUERA DE VENTANA" End If 'End If '....................................................................... Dim PT As POINTAPI Call ClientToScreen(hwndl, PT) Form1.Cls Form1.Print "Coordenada Screen X " & lParam.x Form1.Print "Coordenada Screen Y " & lParam.y If hwndl = Form1.hwnd Then Form1.Print Form1.Print "Coordenada Control X " & lParam.x - PT.x Form1.Print "Coordenada Control Y " & lParam.y - PT.y End If '....................................................................... MouseProc = CallNextHookEx(hHook, ncode, wParam, lParam) End Function