Ici, le menu est créé, mais le programme ne fonctionne pas toujours: soit le menu ne disparaît pas si vous cliquez sur un endroit de l'écran, ou un programme se bloque pendant un certain temps de pièce.
Code : Tout sélectionner
EnableExplicit
Global hhkLLMouse, handle, thread1, thread2
Enumeration
#WIN_MAIN
#MENU_POPUP
EndEnumeration
Structure MSLLHOOKSTRUCT
pt.POINT
mouseData.l
flags.l
time.l
dwExtraInfo.l
EndStructure
Procedure.l MouseHookProcLL(nCode.l, wParam.l, lParam.l)
;{The menu is created, but it works unstably.
;On the desktop, the menu does Not disappear,
;when the window is expanded, it disappears 10-15 times And hangs.
Protected *position.POINT, *MOUSESTRUCT.MOUSEHOOKSTRUCT
If nCode = #HC_ACTION
If lParam <> 0
*MOUSESTRUCT.MOUSEHOOKSTRUCT = lParam
*position.POINT=*MOUSESTRUCT\pt
If wParam = #WM_RBUTTONDOWN
If *position\x>=DesktopWidth(0)-1
ResizeWindow(#WIN_MAIN, *position\x, *position\y, #PB_Ignore, #PB_Ignore)
HideWindow(#WIN_MAIN, 0)
handle=FindWindow_(0,#WIN_MAIN)
Debug handle
thread1=GetWindowThreadProcessId_(GetForegroundWindow_(),0)
Debug thread1
thread2=GetWindowThreadProcessId_(handle,0)
Debug thread2
If thread1<>thread2
AttachThreadInput_(thread1,thread2,#True)
EndIf
SetForegroundWindow_(handle)
Delay(125)
DisplayPopupMenu(#MENU_POPUP, WindowID(#WIN_MAIN))
; HideWindow(#WIN_MAIN, 1)
EndIf
EndIf
EndIf
EndIf
;}
ProcedureReturn CallNextHookEx_(hhkLLMouse, nCode, wParam, lParam)
EndProcedure
ExamineDesktops()
If OpenWindow(#WIN_MAIN, 0, 0, 10, 10, "", #PB_Window_BorderLess | #PB_Window_NoGadgets | #PB_Window_Invisible)
SetWindowLong_(WindowID(#WIN_MAIN), #GWL_EXSTYLE, GetWindowLong_(WindowID(#WIN_MAIN), #GWL_EXSTYLE) | #WS_EX_TOOLWINDOW)
If CreatePopupImageMenu(#MENU_POPUP, #PB_Menu_ModernLook)
MenuItem(1, "Open")
MenuItem(2, "Save")
MenuItem(3, "Save as")
MenuItem(4, "Quit")
MenuBar()
OpenSubMenu("Recent files")
MenuItem(5, "PureBasic")
MenuItem(6, "Test")
CloseSubMenu()
EndIf
hhkLLMouse = SetWindowsHookEx_(#WH_MOUSE_LL,@MouseHookProcLL(),GetModuleHandle_(0),0)
Repeat
Select WaitWindowEvent()
Case #WM_RBUTTONDOWN
Case #WM_RBUTTONUP
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Menu
Select EventMenu()
Case 1 : Debug "Menu: Open"
Case 2 : Debug "Menu: Save"
Case 3 : Debug "Menu: Save as"
Case 4 : Break
Case 5 : Debug "Menu: PureBasic"
Case 6 : Debug "Menu: Text"
EndSelect
EndSelect
ForEver
UnhookWindowsHookEx_(hhkLLMouse)
CloseWindow(#WIN_MAIN)
EndIf
End