Jump to content

Recommended Posts

Posted (edited)
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <StaticConstants.au3>
#include <WinAPI.au3>

Example()

Func Example()

    local $hGui = GUICreate("My GUI menu", 300, 200)

    Local $idFilemenu = GUICtrlCreateMenu("&File")
    Local $idFileitem = GUICtrlCreateMenuItem("Open", $idFilemenu)
    Local $idHelpmenu = GUICtrlCreateMenu("?")
    GUICtrlCreateMenuItem("Save", $idFilemenu)
    GUICtrlSetState(-1, $GUI_DISABLE)
    Local $idInfoitem = GUICtrlCreateMenuItem("Info", $idHelpmenu)
    Local $idExititem = GUICtrlCreateMenuItem("Exit", $idFilemenu)
    Local $idRecentfilesmenu = GUICtrlCreateMenu("Recent Files", $idFilemenu, 1)

    Local $idViewmenu = GUICtrlCreateMenu("View", -1, 1) ; is created before "?" menu
    Local $idViewstatusitem = GUICtrlCreateMenuItem("Statusbar", $idViewmenu)
    GUICtrlSetState(-1, $GUI_CHECKED)
    Local $idButton_1 = GUICtrlCreateButton("Button 1", 50, 130, 70, 20)
    Local $idButton_2 = GUICtrlCreateButton("Button 2", 180, 130, 70, 20)

    GUISetState(@SW_SHOW)

    Local $sFile

    Local $tPoint = GUIGetCursorInfo()
    Local $hWnd1 = ControlGetHandle(WinGetHandle($hGui), "", $idButton_1)
    Local $hWnd2 = ControlGetHandle(WinGetHandle($hGui), "", $idFilemenu)

    While 1
        $tPoint = _WinAPI_GetMousePos()
        If _WinAPI_WindowFromPoint($tPoint) = $hWnd1 Then
            GUICtrlSetState($idButton_2, $GUI_HIDE)
        ElseIf _WinAPI_WindowFromPoint($tPoint) = $hWnd2 Then   ; Got PROBLEM at here
            GUICtrlSetState($idButton_2, $GUI_HIDE)
        Else
            GUICtrlSetState($idButton_2, $GUI_SHOW)
        EndIf

        Switch GUIGetMsg()
            Case $idFileitem
                $sFile = FileOpenDialog("Choose file...", @TempDir, "All (*.*)")
                If @error <> 1 Then GUICtrlCreateMenuItem($sFile, $idRecentfilesmenu)
            Case $idViewstatusitem
                If BitAND(GUICtrlRead($idViewstatusitem), $GUI_CHECKED) = $GUI_CHECKED Then
                    GUICtrlSetState($idViewstatusitem, $GUI_UNCHECKED)
                Else
                    GUICtrlSetState($idViewstatusitem, $GUI_CHECKED)
                EndIf
            Case $GUI_EVENT_CLOSE, $idExititem
                ExitLoop
            Case $idInfoitem
                MsgBox($MB_SYSTEMMODAL, "Info", "Only a test...")
        EndSwitch
    WEnd
    GUIDelete()
EndFunc

Hi, I got stuck at mouse hover problem. This is my code. From the code, you can see when mouse hover on Button 1, Button 2 will be hided. But when mouse hover on the File Menu, Button 2 doesn't work. I think the main reason is due to the File Menu's control ID cannot be detected. I used the AutoIT Info Tool also can't detected the Menu bar. Appreciate if anybody can help. Thank you.New AutoIt v3 Script.au3

Edited by kftang
To attached with the code
  • Moderators
Posted

Moved to the appropriate forum.

Moderation Team

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted (edited)

Maybe this way (it doesn't solve the flickers, but I will let you handle it) :

#include <GUIConstants.au3>
#include <MsgBoxConstants.au3>
#include <StaticConstants.au3>
#include <WinAPI.au3>
#include <GuiMenu.au3>
#include <Array.au3>

Example()

Func Example()

  Local $hGui = GUICreate("My GUI menu", 300, 200)

  Local $idFilemenu = GUICtrlCreateMenu("&File")
  Local $idFileitem = GUICtrlCreateMenuItem("Open", $idFilemenu)
  Local $idHelpmenu = GUICtrlCreateMenu("?")
  GUICtrlCreateMenuItem("Save", $idFilemenu)
  GUICtrlSetState(-1, $GUI_DISABLE)
  Local $idInfoitem = GUICtrlCreateMenuItem("Info", $idHelpmenu)
  Local $idExititem = GUICtrlCreateMenuItem("Exit", $idFilemenu)
  Local $idRecentfilesmenu = GUICtrlCreateMenu("Recent Files", $idFilemenu, 1)

  Local $idViewmenu = GUICtrlCreateMenu("View", -1, 1)   ; is created before "?" menu
  Local $idViewstatusitem = GUICtrlCreateMenuItem("Statusbar", $idViewmenu)
  GUICtrlSetState(-1, $GUI_CHECKED)
  Local $idButton_1 = GUICtrlCreateButton("Button 1", 50, 130, 70, 20)
  Local $idButton_2 = GUICtrlCreateButton("Button 2", 180, 130, 70, 20)

  GUISetState(@SW_SHOW)

  Local $tPoint = DllStructCreate($tagPOINT)

  Local $hMain = _GUICtrlMenu_GetMenu($hGui)
  ConsoleWrite($hMain & @CRLF)
  Local $aFile = _GUICtrlMenu_GetItemRect($hGui, $hMain, 0)
  $tPoint.X = $aFile[0]
  $tPoint.Y = $aFile[1]
  _WinAPI_ScreenToClient($hGui, $tPoint)
  ConsoleWrite($tPoint.X & "/" & $tPoint.Y & @CRLF)
  $aFile[0] = $tPoint.X
  $aFile[1] = $tPoint.Y

  $tPoint.X = $aFile[2]
  $tPoint.Y = $aFile[3]
  _WinAPI_ScreenToClient($hGui, $tPoint)
  ConsoleWrite($tPoint.X & "/" & $tPoint.Y & @CRLF)
  $aFile[2] = $tPoint.X
  $aFile[3] = $tPoint.Y

  While 1
    $aPos = GUIGetCursorInfo()
    If $aPos[0] >= $aFile[0] And $aPos[1] >= $aFile[1] And $aPos[0] <= $aFile[2] And $aPos[1] <= $aFile[3] Then
      GUICtrlSetState($idButton_2, $GUI_HIDE)
    ElseIf $aPos[4] = $idButton_1 Then
      GUICtrlSetState($idButton_2, $GUI_HIDE)
    Else
      GUICtrlSetState($idButton_2, $GUI_SHOW)
    EndIf

    Switch GUIGetMsg()
      Case $idFileitem
        $sFile = FileOpenDialog("Choose file...", @TempDir, "All (*.*)")
        If @error <> 1 Then GUICtrlCreateMenuItem($sFile, $idRecentfilesmenu)
      Case $idViewstatusitem
        If BitAND(GUICtrlRead($idViewstatusitem), $GUI_CHECKED) = $GUI_CHECKED Then
          GUICtrlSetState($idViewstatusitem, $GUI_UNCHECKED)
        Else
          GUICtrlSetState($idViewstatusitem, $GUI_CHECKED)
        EndIf
      Case $GUI_EVENT_CLOSE, $idExititem
        ExitLoop
      Case $idInfoitem
        MsgBox($MB_SYSTEMMODAL, "Info", "Only a test...")
    EndSwitch
  WEnd
EndFunc   ;==>Example

 

Edited by Nine
Posted

Nine, thanks your reply. It works. However, this method create another problem. Whenever I minimize the GUI window, or mouse click outside the range from Window, it will prompt an error: Subscript used on non-accessible variable. Any further advise? Thank you.

#include <GUIConstants.au3>
#include <MsgBoxConstants.au3>
#include <StaticConstants.au3>
#include <WinAPI.au3>
#include <GuiMenu.au3>
#include <Array.au3>

Example()

Func Example()

  Local $hGui = GUICreate("My GUI menu", 300, 200)

  Local $idFilemenu = GUICtrlCreateMenu("&File")
  Local $idFileitem = GUICtrlCreateMenuItem("Open", $idFilemenu)
  Local $idHelpmenu = GUICtrlCreateMenu("?")
  GUICtrlCreateMenuItem("Save", $idFilemenu)
  GUICtrlSetState(-1, $GUI_DISABLE)
  Local $idInfoitem = GUICtrlCreateMenuItem("Info", $idHelpmenu)
  Local $idExititem = GUICtrlCreateMenuItem("Exit", $idFilemenu)
  Local $idRecentfilesmenu = GUICtrlCreateMenu("Recent Files", $idFilemenu, 1)

  Local $idViewmenu = GUICtrlCreateMenu("View", -1, 1)   ; is created before "?" menu
  Local $idViewstatusitem = GUICtrlCreateMenuItem("Statusbar", $idViewmenu)
  GUICtrlSetState(-1, $GUI_CHECKED)
  Local $idButton_1 = GUICtrlCreateButton("Button 1", 50, 130, 70, 20)
  Local $idButton_2 = GUICtrlCreateButton("Button 2", 180, 130, 70, 20)

  GUISetState(@SW_SHOW)

  Local $tPoint = DllStructCreate($tagPOINT)

  Local $hMain = _GUICtrlMenu_GetMenu($hGui)
  ConsoleWrite($hMain & @CRLF)
  Local $aFile = _GUICtrlMenu_GetItemRect($hGui, $hMain, 0)
  $tPoint.X = $aFile[0]
  $tPoint.Y = $aFile[1]
  _WinAPI_ScreenToClient($hGui, $tPoint)
  ConsoleWrite($tPoint.X & "/" & $tPoint.Y & @CRLF)
  $aFile[0] = $tPoint.X
  $aFile[1] = $tPoint.Y

  $tPoint.X = $aFile[2]
  $tPoint.Y = $aFile[3]
  _WinAPI_ScreenToClient($hGui, $tPoint)
  ConsoleWrite($tPoint.X & "/" & $tPoint.Y & @CRLF)
  $aFile[2] = $tPoint.X
  $aFile[3] = $tPoint.Y

  While 1
    $aPos = GUIGetCursorInfo()
    If $aPos[0] >= $aFile[0] And $aPos[1] >= $aFile[1] And $aPos[0] <= $aFile[2] And $aPos[1] <= $aFile[3] Then
      GUICtrlSetState($idButton_2, $GUI_HIDE)
    ElseIf $aPos[4] = $idButton_1 Then
      GUICtrlSetState($idButton_2, $GUI_HIDE)
    Else
      GUICtrlSetState($idButton_2, $GUI_SHOW)
    EndIf

    Switch GUIGetMsg()
      Case $idFileitem
        $sFile = FileOpenDialog("Choose file...", @TempDir, "All (*.*)")
        If @error <> 1 Then GUICtrlCreateMenuItem($sFile, $idRecentfilesmenu)
      Case $idViewstatusitem
        If BitAND(GUICtrlRead($idViewstatusitem), $GUI_CHECKED) = $GUI_CHECKED Then
          GUICtrlSetState($idViewstatusitem, $GUI_UNCHECKED)
        Else
          GUICtrlSetState($idViewstatusitem, $GUI_CHECKED)
        EndIf
      Case $GUI_EVENT_CLOSE, $idExititem
        ExitLoop
      Case $idInfoitem
        MsgBox($MB_SYSTEMMODAL, "Info", "Only a test...")
    EndSwitch
    Sleep(30)
  WEnd
EndFunc   ;==>Example

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...