Jump to content

Inserting text from menu item into control


GEOSoft
 Share

Recommended Posts

Maybe it's just me, but I thought I had either seen or posted a reply to a similar question quite a while back. Today the solution eludes me.

Situation:

I have an input control into which I have typed

"I have this control."

Now I want to click on a menu (&Insert) which has the following items

Good

Bad

Ugly

Now I want to move my cursor to a position right after the word "this", click on the menu item "Ugly" and insert that at the caret position in the input control.

Any ideas?

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Of the 3 options this is bad and ugly, if you right click on the from a contex menu will allow you to select one of the 3 and insert at the caret position

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <GuiEdit.au3>
Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 300, 300)
$Input1 = GUICtrlCreateInput("I have this control.", 10, 10, 200, 21)
$Input2 = GUICtrlCreateInput("I have this other control.", 10, 40, 200, 21)
$Form1context = GUICtrlCreateContextMenu(-1)
$MenuItem2 = GUICtrlCreateMenu("Insert", $Form1context)
$MenuItem1 = GUICtrlCreateMenuItem("Good", $MenuItem2)
GUICtrlSetOnEvent(-1, "_Good")
$MenuItem3 = GUICtrlCreateMenuItem("Bad", $MenuItem2)
GUICtrlSetOnEvent(-1, "_Bad")
$MenuItem4 = GUICtrlCreateMenuItem("Ugly", $MenuItem2)
GUICtrlSetOnEvent(-1, "_Ugly")
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    Sleep(100)
WEnd

Func Form1Close()
    Exit
EndFunc

Func _Good()
    Insert("Good")
EndFunc
Func _Bad()
    Insert("Bad")
EndFunc
Func _Ugly()
    Insert("Ugly")
EndFunc
Func Insert($sInsert)
    Send($sInsert)
EndFunc
GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF.
Link to comment
Share on other sites

Of the 3 options this is bad and ugly, if you right click on the from a contex menu will allow you to select one of the 3 and insert at the caret position

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <GuiEdit.au3>
Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 300, 300)
$Input1 = GUICtrlCreateInput("I have this control.", 10, 10, 200, 21)
$Input2 = GUICtrlCreateInput("I have this other control.", 10, 40, 200, 21)
$Form1context = GUICtrlCreateContextMenu(-1)
$MenuItem2 = GUICtrlCreateMenu("Insert", $Form1context)
$MenuItem1 = GUICtrlCreateMenuItem("Good", $MenuItem2)
GUICtrlSetOnEvent(-1, "_Good")
$MenuItem3 = GUICtrlCreateMenuItem("Bad", $MenuItem2)
GUICtrlSetOnEvent(-1, "_Bad")
$MenuItem4 = GUICtrlCreateMenuItem("Ugly", $MenuItem2)
GUICtrlSetOnEvent(-1, "_Ugly")
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    Sleep(100)
WEnd

Func Form1Close()
    Exit
EndFunc

Func _Good()
    Insert("Good")
EndFunc
Func _Bad()
    Insert("Bad")
EndFunc
Func _Ugly()
    Insert("Ugly")
EndFunc
Func Insert($sInsert)
    Send($sInsert)
EndFunc

Thanks Yoriz.

I may have to take the context menu route especially since there are actually more than just 1 (sub)menu to be concerned with and each has several items.

It's really just something that I want to add into the app. I already have auto-complete working for the controls but if someone forgets to insert something, I want them to be able to click on the insertion point and add it there. I think you're probably correct in that a context menu solution will do it and I suspect we agree that it can't be done from a standard menu because control focus will have changed, and WinGetCaretPos() coupled with ControlGetFocus() is just too unreliable in this situation and in fact may not even be doable.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Does this do what you're looking for?

#include <GUIConstants.au3>
#include <GUIEdit.au3>

$gui = GUICreate('', 200, 200)
$meInsert = GUICtrlCreateMenu('&Insert')
$miGood = GUICtrlCreateMenuItem('Good', $meInsert)
$miBad = GUICtrlCreateMenuItem('Bad', $meInsert)
$miUgly = GUICtrlCreateMenuItem('Ugly', $meInsert)

$inPut = GUICtrlCreateInput('I have this control.', 5, 5, 150, 20)
GUISetState()

While 1
    $gm = GUIGetMsg()
    Switch $gm
        Case $miGood
            $aSel = _GUICtrlEdit_GetSel($inPut)
            _GUICtrlEdit_InsertText($inPut, 'Good', $aSel[1])
        Case $miBad
            $aSel = _GUICtrlEdit_GetSel($inPut)
            _GUICtrlEdit_InsertText($inPut, 'Bad', $aSel[1])
        Case $miUgly
            $aSel = _GUICtrlEdit_GetSel($inPut)
            _GUICtrlEdit_InsertText($inPut, 'Ugly', $aSel[1])
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd
Link to comment
Share on other sites

Thanks. I know us BC boys have to stick together but that doesn't do it. The context menu idea works but now I'm even debating if the end result is going to be worth all the trouble. I was hoping to generate the menu items dynamicly from an ini file but even that won't work becuase of certain characters in some of the ini keys are not being seen as keys by IniReadSection(). I could solve that problem by rewiting the ini using binary, but again is it all worth it in the end, just for the little bit of convienience it will provide. If the user forgets to type something into the string they can just put the cursor at the right point and start typing, the auto-complete will pick it up anyway.

Obviously the strings that I showed were just dummy strings and in no way reflect what will actually be inserted.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Actually the Context menu doesn't work. It worked in a test gui with different controls. I just used the examples to test it in there.

What I want to do won't work with context menus and it's simply stated in the help file.

Note: You can't create context menus for controls that already have system context menus, i.e. edit or input controls.

For now I have kind of a clutzy work-around but I'm still not sure if I'll even leave it in.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

You can create context menus for controls that have system menus like edits if you subclass the control. There are a few examples around though with edits there is a problem so you need to deal with the cursor changing. My memory is a bit vague but there was a post by Saio where he helped me with this once.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

You can create context menus for controls that have system menus like edits if you subclass the control. There are a few examples around though with edits there is a problem so you need to deal with the cursor changing. My memory is a bit vague but there was a post by Saio where he helped me with this once.

Thanks martin. actually the info from a menuitem can be sent very easily without context menus (infact Send() will handle it) but the fact that the input is actually a combo box and the text had to be inserted at a point in the middle of the existing text (in the edit portion of the control), complicated it a bit. The workaround is in a question I posted in the private group regarding controlsend along with a brief desription of the complications.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

It's because the controls that I had refered to (for simplicity) were actualy comboboxes and working with them will usually generate a different result. It also had the same problem as I was having where it ignoredd the current Conbo box and inserted the text into whatever control the caret was in at the time. The work-around is fine for now and one of the Devs is taking a look to see if there is something wrong with ControlSend() when sending text to a combo box. I solved it by using WindowGetCaretPos() first.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
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
 Share

  • Recently Browsing   0 members

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