Jump to content

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


zvvyt
 Share

Go to solution Solved by Melba23,

Recommended Posts

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

Link to comment
Share on other sites

  • Moderators
  • Solution

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

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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • Moderators

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

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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • Moderators

zvvyt,

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

M23

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

 

Link to comment
Share on other sites

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

  • Moderators

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

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

 

Link to comment
Share on other sites

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
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

×
×
  • Create New...