Private Declare Function SetWindowsHookEx& _ Lib "user32" Alias "SetWindowsHookExA" _ (ByVal idHook&, ByVal lpfn&, ByVal hMod&, ByVal dwThreadId&) Private Declare Function GetCurrentThreadId& _ Lib "kernel32" _ () Private Declare Function UnhookWindowsHookEx& _ Lib "user32" _ (ByVal hHook&) Private Declare Function DeleteMenu& _ Lib "user32" _ (ByVal hMenu&, ByVal nPosition&, ByVal wFlags&) Private Declare Function GetSystemMenu& _ Lib "user32" _ (ByVal hwnd&, ByVal bRevert&) Private lgHook& Private Function Inhibe&(ByVal lMsg&, ByVal wParam&, ByRef lParam&) Const SC_CLOSE& &HF060&, MF_BYCOMMAND& &H0& Const HCBT_ACTIVATE& = 5& If lMsg = HCBT_ACTIVATE Then DeleteMenu GetSystemMenu(wParam, False), SC_CLOSE, MF_BYCOMMAND UnhookWindowsHookEx lgHook End If Inhibe = False End Function Sub InhibeCloseBouton() Const WH_CBT& = &H5 lgHook = SetWindowsHookEx(WH_CBT, AddressOf Inhibe, 0&, GetCurrentThreadId) MsgBox "Boite de message avec Close bouton inhibé.", vbYesNoCancel, "Bouton Obligatoire" End Sub
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionOn Error GoTo erreur 'juste pour la cas où ... Dim Filactu As Long Filactu = GetCurrentThreadId() 'Détermination du fil actuel ' fonction GetCurrentThreadId à déclarer, bien évidemment affX = ....... 'abscisse d'affichage affY = ........ ' ordonnée d'affichage hHook = SetWindowsHookEx(WH_CBT, AddressOf Position, 0&, Filactu) MsgBox "patatipatata" erreur: end sub
Option Explicit Public Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long Public Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long 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 Public Declare Function GetCurrentThreadId Lib "kernel32" () As Long Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long 'Constantes pour SetWindowPos : Public Const SWP_NOSIZE = &H1 Public Const SWP_NOZORDER = &H4 Public Const SWP_NOACTIVATE = &H10 Public Const HCBT_ACTIVATE = 5 Public hHook As Long Public affX As Long Public affY As Long Public Function Position(ByVal Messg As Long, ByVal Hhandle As Long, ByVal afterhwnd As Long) As Long If Messg = HCBT_ACTIVATE Then 'positionnement du msgbox : SetWindowPos Hhandle, 0, affX, affY, 0, 0, SWP_NOSIZE Or SWP_NOZORDER Or SWP_NOACTIVATE DoEvents UnhookWindowsHookEx hHook 'Déchargement End If Position = False End Function
Private Sub CommandButton1_Click() Dim Filactu As Long Filactu = GetCurrentThreadId() 'Détermination du fil actuel affX = 300 ' mon abscisse affY = 100 ' mon ordonnée 'procédure de positionnement pour la prochaine fenêtre à afficher hHook = SetWindowsHookEx(WH_CBT, AddressOf Position, 0, Filactu) MsgBox "coucou" End Sub
Option Explicit Public Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long Public Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long 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 Public Declare Function GetCurrentThreadId Lib "kernel32" () As Long Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long 'Constantes pour SetWindowPos : Public Const SWP_NOSIZE = &H1 Public Const SWP_NOZORDER = &H4 Public Const SWP_NOACTIVATE = &H10 Public Const HCBT_ACTIVATE = 5 Public Const WH_CBT = 5 Public hHook As Long Public affX As Long Public affY As Long Public Function Position(ByVal Messg As Long, ByVal Hhandle As Long, ByVal afterhwnd As Long) As Long If Messg = HCBT_ACTIVATE Then 'positionnement du msgbox : SetWindowPos Hhandle, 0, affX, affY, 0, 0, SWP_NOSIZE Or SWP_NOZORDER Or SWP_NOACTIVATE DoEvents UnhookWindowsHookEx hHook 'Déchargement End If Position = False End Function
xx = App.hInstance
xx = GetCurrentThreadId()