Jump to content
Sign in to follow this  
zvvyt

Last created GUI handle and RichEdit handle from unspecified number of GUIs

Recommended Posts

zvvyt

Hey ya'll.

I'm making a something like the Windows 7-app Sticky-note consisting of unspecified numbers of "note"-GUIs with RichEdits in them.

The problem I'm facing is that for the RichEdit to work it requires the hWnd of its GUI (which can be solved by just having a variable that's getting replaced as new "notes" are being made), but the next problem is to read the handle/ID of the RichEdit for further functions.

This is what it looks like atm:

#cs
Unlimited, controlable windows
#ce
Opt("GUIOnEventMode", 1)
Opt("TrayMenuMode", 1 + 2)
Opt("TrayOnEventMode",1)
#include <array.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
#include <TrayConstants.au3>
#include <GuiRichEdit.au3>

TrayCreateItem("LAN-notes")
TrayItemSetState(-1, $TRAY_DISABLE)
TrayCreateItem("")
TrayCreateItem("New")
TrayItemSetOnEvent(-1, "New")
TrayCreateItem("")
TrayCreateItem("Exit")
TrayItemSetOnEvent(-1,"TrayExit")
TraySetState(1)

$hWnd = GUICreate("",0,0)
GUISetState(@SW_HIDE,-1)

Call("New")
while 1
    Sleep(10)
    #cs
    $GUI_CurrentSize = WinGetPos($hGui)
    If $GUI_CurrentSize[2] <> $GUI_PrevSize[0] Or $GUI_CurrentSize[3] <> $GUI_PrevSize[1] Then
        _WinAPI_MoveWindow($Edit1,0,20,$GUI_CurrentSize[2]-20,$GUI_CurrentSize[3]-60)
        $GUI_PrevSize[0] = $GUI_CurrentSize[2]
        $GUI_PrevSize[1] = $GUI_CurrentSize[3]
    EndIf
    #ce
WEnd

Func New()
$p = GUICreate("LAN-notes - ",200,200,Default,Default,BitOR($ws_sizebox,$WS_MINIMIZEBOX),Default,$hWnd)
$winlist = WinList("LAN-notes")


GUISetOnEvent($GUI_EVENT_CLOSE, "MainEvents")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "MainEvents")
GUICtrlCreateButton("+",0,0,20,20)
    GUICtrlSetFont(-1,12)
    GUICtrlSetOnEvent(-1,"New")
GUICtrlCreateButton("Save",22,0,35,20)
    GUICtrlSetOnEvent(-1,"Save")
;GUICtrlCreateButton("Test", 50,80)
;    GUICtrlSetOnEvent(-1,"Test")
GUICtrlCreateInput("",60,0,105,20)
    GUICtrlSetState(-1,$GUI_DISABLE)
GUICtrlCreateButton("Edit",165,0,35,20)
    GUICtrlSetOnEvent(-1,"EditProjName")
_GUICtrlRichEdit_Create($p, "",0,25,180,160, BitOR($ES_AUTOVSCROLL, $WS_VSCROLL, $ES_WANTRETURN,$ES_MULTILINE))
GUISetState()

EndFunc

Func Test()
    $winlist = WinList("LAN-notes")
    _ArrayDisplay($winlist)
EndFunc

Func MainEvents()
    Select
        Case @GUI_CtrlId = $GUI_EVENT_CLOSE
            If WinExists("LAN-notes") Then
                If MsgBox(4,"Exit?","You sure you want to close this note?") = 6 Then GUIDelete(@GUI_WinHandle)
            EndIf
    EndSelect
EndFunc

Func EditProjName()
    ConsoleWrite("Edit projName" & @CRLF)
    If GUICtrlGetState(@GUI_CtrlId-1) = 144 Then
        GUICtrlSetState(@GUI_CtrlId-1,$GUI_ENABLE)
        GUICtrlSetData(@GUI_CtrlId,"Done")
    Else
        WinSetTitle(@GUI_WinHandle,"","LAN-notes - " & GUICtrlRead(@GUI_CtrlId-1))
        GUICtrlSetState(@GUI_CtrlId-1,$GUI_DISABLE)
        GUICtrlSetData(@GUI_CtrlId,"Edit")
    EndIf
EndFunc

Func Save()
    ConsoleWrite("--> Save" & @CRLF)
    ConsoleWrite(_GUICtrlRichEdit_GetText(@GUI_CtrlId+4) & @CRLF)
EndFunc

Func TrayExit()
    ConsoleWrite("TrayExit")
    Exit
EndFunc

 

Thanks,

zvvyt

Share this post


Link to post
Share on other sites
Melba23

zvvyt,

The handle of the RichEdit is returned by the _GUICtrlRichEdit_Create function - just save it in a variable as you do with the GUI that contains it. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
zvvyt

The handle of the RichEdit is returned by the _GUICtrlRichEdit_Create function - just save it in a variable as you do with the GUI that contains it. :)

I could do that, but then I wouldn't be able to retrace the RichEdit in a scenario of .. say 15 GUIs with their own RichEdit as the variable would only get written over in my script.

The rest of the script is based on GUICtrl-events as they both return @GUI_CtrlID and @GUI_Winhandle, but as _GUICtrlRichEdit_Create ain't really a control, but another window, I can't figure out a way to return its handle without variables or arrays.

I'm sorry if I'm not making any sense. Still a bit too early for me x)

zvvyt

Share this post


Link to post
Share on other sites
Melba23

zvvyt,

 

I can't figure out a way to return its handle without variables or arrays

Why the aversion to arrays? :huh:

I suggest storing the GUI and RichEdit handles in a 2D array - then when you get the GUI handle you can retrieve the RichEdit handle as well. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
zvvyt

Why the aversion to arrays? :huh:

This is because GUIs will be able to be created and deleted all on random. And it would be great not having the need for replacing array-values and increasing/decreasing arraysizes..

I suggest storing the GUI and RichEdit handles in a 2D array - then when you get the GUI handle you can retrieve the RichEdit handle as well. :)

But if there ain't another way to keep track of the hWnd for the RichEdits togeather with their GUIs I guess I don't have a choice.. :c

Share this post


Link to post
Share on other sites
Melba23

zvvyt,

Look at my Notify UDF to see how I managed a similar problem and please ask if you have any questions. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
zvvyt

Look at my Notify UDF to see how I managed a similar problem and please ask if you have any questions. ;)

I'll have a deeper look at it after this weekend, but at the first glance I had I couldn't find where you've hid it >__<

(And I ment the function, not the UDF)

Edited by zvvyt

Share this post


Link to post
Share on other sites
Melba23

zvvyt,

Look for the $aNotify_Data lines, particularly at the end of _Notify_Show and in _Notify_Delete. Please ask if you get stuck. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
zvvyt

just save it in a variable as you do with the GUI that contains it. :)

 

I did as you suggested with the winhandles in an array. 

The result (I took away all the other mumbojumbo as it's not complete yet. If anyone wants the whole thing I'll post it on request):

Global $WinArray[1][2]
 
Func New()

ReDim $WinArray[UBound($WinArray,1)+1][2]
$WinArray[UBound($WinArray,1)-1][0] = GUICreate("LAN-notes - ",200,200,Default,Default,BitOR($ws_sizebox,$WS_MINIMIZEBOX),Default,$hWnd)
$WinArray[UBound($WinArray,1)-1][1] = _GUICtrlRichEdit_Create($WinArray[UBound($WinArray,1)-1][0], "",0,25,180,160, BitOR($ES_AUTOVSCROLL, $WS_VSCROLL, $ES_WANTRETURN,$ES_MULTILINE))
 
EndFunc
 
Func Close()
     For $1 = (_ArraySearch($WinArray,@GUI_WinHandle)) To (UBound($WinArray,1)-2) Step +1
         $WinArray[$1][0] = $WinArray[$1+1][0]
         $WinArray[$1][1] = $WinArray[$1+1][1]
    Next
    ReDim $WinArray[UBound($WinArray,1)-1][2]
    GUIDelete(@GUI_WinHandle)
EndFunc
Edited by zvvyt

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  

  • Similar Content

    • Reziskonh
      By Reziskonh
      Hi, everybody
      I look for GUI whose behavior similar to the message of an email client or antivirus
      In other words:
          Any PC screen able to calculate the size
          To consider the Task bar size
          To find the lower corner on the right/below and to nestle on it

      Notes:
      In GUI the GUICtrlCreateEdit field (as option) - that can be received and displayed through variable information
      Thanks a lot
      PS
      I use the translator, excuse if something is not clear
       

    • VollachR
      By VollachR
      Hi,
      I'd like to show a progress bar for an operation performed by an external program my script is running silently, I want to show it in a GUI I created using the GUICtrlCreateProgress but I have no idea how to do it.
      The important thing to point out is that there's no way of knowing how long the external program will run, as it is a file splitter and it depends on the size of file it splits and the split parts size.
      Can someone point me in the right direction or give me an example how to do so?
      This is my RunWait command:
      RunWait($MYFILES1 & '\fsplit.exe -split ' & $Size & ' mb ' & $File & " -f " & $File & "." & $extension) It uses multiple variables declared and set earlier in the script, how will I got about having the progress of that command shown using GUICtrlCreateProgress ? Is it possible?
      Thank you.
    • nacerbaaziz
      By nacerbaaziz
      Hello my friends
      I have an inquiry and I hope to find the answer here
      I want to create a graphical user interface
      but I want to hide the system menu
      I mean the window menu
      Is this possible?
      If is possible please give me how to do that
      Thanks in advance
    • helmar
      By helmar
      I was playing around with simple GUI creation.  I tend to like parameter driven coding (in prior life (years ago) as Clipper/FoxPro/dBase coder).  Just wanted to see what I could do with a GUI.
      #Region options, includes Opt('MustDeclareVars', 1) Opt("GUIOnEventMode", 1) ; Change to OnEvent mode #include <GUIConstantsEx.au3> #EndRegion options, includes Global Const $nCols = 2, $nRows = 6, $nSpacer = 10, $nBtnWidth = 150, $nBtnHeight = 30 Global $xName = 0, $xID = 0 Global $nGUIWidth = ($nCols * $nBtnWidth) + (($nCols + 1) * $nSpacer) Global $nGUIHeight = ($nRows * $nBtnHeight) + (($nRows + 1) * $nSpacer) Global $hMainGUI = GUICreate("Calculated GUI", $nGUIWidth, $nGUIHeight, -1, -1) For $xRows = 1 to $nRows ;in this arrangement, tabbing is left to right, then next row For $xCols = 1 to $nCols ;reverse the order of this line with the prior line for top to bottom tabbing, then next col $xName += 1 $xID += 1 Global $Dummy = GUICtrlCreateButton("Button" & $xName, _ ($nBtnWidth * ($xCols - 1)) + (($xCols - 1) * $nSpacer) + $nSpacer, _ ($nBtnHeight* ($xRows - 1)) + (($xRows - 1) * $nSpacer) + $nSpacer, _ $nBtnWidth, _ $nBtnHeight) GUICtrlSetOnEvent($xID+2, "Handler") Next Next GUISetOnEvent($GUI_EVENT_CLOSE, "CloseApp") GUISetState(@SW_SHOW) While 1 Sleep(10) WEnd Func CloseApp() Exit EndFunc Func Handler() MsgBox(0,0,"Button " & @GUI_CtrlId - 2) EndFunc  
    • XinYoung
      By XinYoung
      For fun, I'm building an app that opens a webpage and refreshes it every 30 seconds.
      But once the script performs _IEAction($oIE, "refresh"), the GUI closes.
      Any help is appreciated.
       

      #include <ButtonConstants.au3>
      #include <EditConstants.au3>
      #include <GUIConstantsEx.au3>
      #include <StaticConstants.au3>
      #include <WindowsConstants.au3>
      #include <WinAPIFiles.au3>
      #include <Array.au3>
      #include <File.au3>
      #include <Excel.au3>
      #include <DateTimeConstants.au3>
      #include <MsgBoxConstants.au3>
      #include <WinAPIShellEx.au3>
      #include <MsgBoxConstants.au3>
      #include <Date.au3>
      #include <ComboConstants.au3>
      #include <guimenu.au3>
      #include <IE.au3>
      HotKeySet("{F4}", "_Exit")
      ;Open the file(s) in the selected folder
      $extension = ".txt"
      $app2openWith = @SystemDir & "\notepad.exe"
      Func Begin()
          Global $loopTrick = 0
          #Region ### START Koda GUI section ### Form=c:\users\mchu\downloads\autoit\my code\form1.kxf
          Global $UI = GUICreate("Hit Em Up!", 256, 113, -1, -1)
          GUISetBkColor(0x000000)
          $menu = _GUICtrlMenu_GetSystemMenu($UI)
          _GUICtrlMenu_EnableMenuItem($menu, $SC_CLOSE, 1, False)
          Global $url = GUICtrlCreateInput("https://www.youtube.com/watch?v=dQw4w9WgXcQ", 81, 8, 160, 21)
          $Label1 = GUICtrlCreateLabel("Target:", 16, 8, 55, 17)
          GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
          GUICtrlSetColor(-1, 0x00FF00)
          Global $StartBut = GUICtrlCreateButton("Start", 16, 40, 67, 25)
          GUICtrlSetFont(-1, 13, 800, 0, "MS Sans Serif")
          GUICtrlSetBkColor(-1, 0x008000)
          $Label2 = GUICtrlCreateLabel("(Press F4 to Exit)", 96, 40, 8000, 17)
          GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
          GUICtrlSetColor(-1, 0x00FF00)
          GUISetState(@SW_SHOW)
          #EndRegion ### END Koda GUI section ###
          While 1
              $UIfunc = GUIGetMsg()
              Select
                  Case $UIfunc = $GUI_EVENT_CLOSE
                      _Exit()
                  Case $UIfunc = $StartBut
                      If GUICtrlRead($url) = "" Then
                          MsgBox(48, "Um...", "Give me a target you idiot.")
                      Else
                          GUICtrlSetState($url, $GUI_DISABLE)
                          GUICtrlSetState($StartBut, $GUI_DISABLE)
                          Start()
                      EndIf
              EndSelect
          WEnd
      EndFunc   ;==>Begin
      Func Start()
          If $loopTrick = 0 Then
              Global $oIE = _IECreate(GUICtrlRead($url))
              _IELoadWait($oIE)
              Again()
          ElseIf $loopTrick = 1 Then
              Sleep(3000)
              _IEAction($oIE, "refresh")
              Sleep(3000)
              Start()
          EndIf
      EndFunc   ;==>Start
      Func Again()
          $loopTrick = 1
          Start()
      EndFunc   ;==>Again
      Func _Exit()
          Exit
      EndFunc   ;==>_Exit
×