Sign in to follow this  
Followers 0
Miniz

Input box on top of menu?

7 posts in this topic

#1 ·  Posted (edited)

Hi!

I was just wondering how to get a input box on top of a menu?

Does anyone know how i can do that or if it's possible at all?

Like this:

Posted Image

GUICreate("My GUI menu", 300, 200)

$filemenu = GUICtrlCreateMenu("&File")
$fileitem = GUICtrlCreateMenuItem("Open", $filemenu)
$helpmenu = GUICtrlCreateMenu("&Help")
$saveitem = GUICtrlCreateMenuItem("Save", $filemenu)
$infoitem = GUICtrlCreateMenuItem("Info", $helpmenu)
$exititem = GUICtrlCreateMenuItem("Exit", $filemenu)

$inputbox = GUICtrlCreateInput("", 100, 0, 200, 18)

GUISetState()
While 1
    Switch GUIGetMsg()
        case -3
            ExitLoop
    EndSwitch
WEnd
GUIDelete()

Best regards, Miniz

Edited by Miniz

Share this post


Link to post
Share on other sites



Miniz,

You could use GUICtrlCreateContextMenu(). You can attach a context menu to just about any control including buttons and labels.

Realm


My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry.  

Share this post


Link to post
Share on other sites

Miniz,

You could use GUICtrlCreateContextMenu(). You can attach a context menu to just about any control including buttons and labels.

Realm

No that's not what i'm after :/ but thanks anyway :x

I've attached an image to show what i meant.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Here something similar:

#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <WindowsConstants.au3>

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

;~ $filemenu = GUICtrlCreateMenu("&File")
;~ $fileitem = GUICtrlCreateMenuItem("Open", $filemenu)
;~ $helpmenu = GUICtrlCreateMenu("&Help")
;~ $saveitem = GUICtrlCreateMenuItem("Save", $filemenu)
;~ $infoitem = GUICtrlCreateMenuItem("Info", $helpmenu)
;~ $exititem = GUICtrlCreateMenuItem("Exit", $filemenu)

$OptionsBtn = GUICtrlCreateButton("&File", 0, 0, 40, 20,$BS_FLAT)

; At first create a dummy control for the options and a contextmenu for it
$OptionsDummy = GUICtrlCreateDummy()
$OptionsContext = GUICtrlCreateContextMenu($OptionsDummy)
$OptionsCommon = GUICtrlCreateMenuItem("Open", $OptionsContext)
$OptionsFile = GUICtrlCreateMenuItem("Save", $OptionsContext)
GUICtrlCreateMenuItem("", $OptionsContext)
$OptionsExit = GUICtrlCreateMenuItem("Exit", $OptionsContext)


$HelpBtn = GUICtrlCreateButton("&Help", 40, 0, 40, 20, $BS_FLAT)

; Create a dummy control and a contextmenu for the help too
$HelpDummy = GUICtrlCreateDummy()
$HelpContext = GUICtrlCreateContextMenu($HelpDummy)
$HelpWWW = GUICtrlCreateMenuItem("&Info", $HelpContext)

$inputbox = GUICtrlCreateInput("", 80, 0, 220, 20)

GUISetState()
While 1
    $msg = GUIGetMsg()
    Switch $msg
        case -3
            ExitLoop

        Case $OptionsBtn
            ShowMenu($hGui, $msg, $OptionsContext)

        Case $HelpBtn
            ShowMenu($hGui, $msg, $HelpContext)
    EndSwitch
WEnd
GUIDelete()

; Show a menu in a given GUI window which belongs to a given GUI ctrl
Func ShowMenu($hWnd, $CtrlID, $nContextID)
    Local $arPos, $x, $y
    Local $hMenu = GUICtrlGetHandle($nContextID)

    $arPos = ControlGetPos($hWnd, "", $CtrlID)

    $x = $arPos[0]
    $y = $arPos[1] + $arPos[3]

    ClientToScreen($hWnd, $x, $y)
    TrackPopupMenu($hWnd, $hMenu, $x, $y)
EndFunc   ;==>ShowMenu


; Convert the client (GUI) coordinates to screen (desktop) coordinates
Func ClientToScreen($hWnd, ByRef $x, ByRef $y)
    Local $stPoint = DllStructCreate("int;int")

    DllStructSetData($stPoint, 1, $x)
    DllStructSetData($stPoint, 2, $y)

    DllCall("user32.dll", "int", "ClientToScreen", "hwnd", $hWnd, "ptr", DllStructGetPtr($stPoint))

    $x = DllStructGetData($stPoint, 1)
    $y = DllStructGetData($stPoint, 2)
    ; release Struct not really needed as it is a local
    $stPoint = 0
EndFunc   ;==>ClientToScreen


; Show at the given coordinates (x, y) the popup menu (hMenu) which belongs to a given GUI window (hWnd)
Func TrackPopupMenu($hWnd, $hMenu, $x, $y)
    DllCall("user32.dll", "int", "TrackPopupMenuEx", "hwnd", $hMenu, "int", 0, "int", $x, "int", $y, "hwnd", $hWnd, "ptr", 0)
EndFunc   ;==>TrackPopupMenu

I don't know whether it is possible to put an input box over a Ctrl menu!

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

To achieve this you will have to use a toolbar as a menu. Have a look at the example for _GUICtrlRebar_SetBarInfo in the help file.


"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Share this post


Link to post
Share on other sites

Seems like more trouble than fun :P

Thank you all for the help :x

Share this post


Link to post
Share on other sites

You could try this, but then the main window will be not active. :x

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

$inputbox = GUICtrlCreateInput("", 100, 0, 200, 18)

GUICreate("Child", 100, 18, 0, 1, BitOR(0x80000000, 0x00000000), 0x40, $hGui)

$filemenu = GUICtrlCreateMenu("&File")
$fileitem = GUICtrlCreateMenuItem("Open", $filemenu)
$helpmenu = GUICtrlCreateMenu("&Help")
$saveitem = GUICtrlCreateMenuItem("Save", $filemenu)
$infoitem = GUICtrlCreateMenuItem("Info", $helpmenu)
$exititem = GUICtrlCreateMenuItem("Exit", $filemenu)

GUISetState()

GUISetState(@SW_SHOW, $hGui)

While 1
 Switch GUIGetMsg()
  Case -3
   ExitLoop
 EndSwitch
WEnd

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0