How to embed Notepad in a GUI?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
newbieforever
Posts: 493
Joined: 24 Aug 2016, 03:34

How to embed Notepad in a GUI?

28 Mar 2020, 03:59

How to embed Notepad in a GUI?

Is there a simple method like this one to embed IE, https://www.autohotkey.com/boards/viewtopic.php?t=46702#p210448?

EDITED: I would like to embed in a GUI both of them, IE and Notepad.
ahk7
Posts: 575
Joined: 06 Nov 2013, 16:35

Re: How to embed Notepad in a GUI?

28 Mar 2020, 05:06

A standard (AHK) edit control almost has the same functionality as notepad so why would you want to do so?
If you need a "bit more" functionality try the Edit library by jballi, check the "editor" example https://www.autohotkey.com/boards/viewtopic.php?t=5063 which is just like notepad. Simply expand that example and embed a browser.
newbieforever
Posts: 493
Joined: 24 Aug 2016, 03:34

Re: How to embed Notepad in a GUI?

28 Mar 2020, 05:13

Thank you, ahk7!

Edit, of course, this was my first attempt, but: There seems to be a data limit for Edit, e.g. a 300 kB file can not be displayed and edited in Edit.
ahk7
Posts: 575
Joined: 06 Nov 2013, 16:35

Re: How to embed Notepad in a GUI?

28 Mar 2020, 05:18

You could try the scintilla control 32 bit version here https://github.com/RaptorX/scintilla-wrapper

[ If you need 64bit I have a patched version here https://github.com/RaptorX/scintilla-wrapper/issues/5 ]
ahk7
Posts: 575
Joined: 06 Nov 2013, 16:35

Re: How to embed Notepad in a GUI?

28 Mar 2020, 05:19

possible alternative: use any editor as normal and dock your ahk gui to it https://www.autohotkey.com/boards/viewtopic.php?f=6&t=30912 ?
vsub
Posts: 541
Joined: 29 Sep 2015, 03:39

Re: How to embed Notepad in a GUI?

28 Mar 2020, 05:31

I think it's the variable size or AHK cannot create a control with too much text in it
AHK shows an error with this

Code: Select all

Gui,Add,Edit,x0 y0 W640 h480,% Clipboard
Gui,Show,Center, w640 h480
Return
This works fine but it takes some time until I see the gui(the clipboard contains 3.79mb text

Code: Select all

Gui,Add,Edit,x0 y0 W640 h480,
GuiControl,,Edit1,% Clipboard
Gui,Show,Center, w640 h480
Return
teadrinker
Posts: 4326
Joined: 29 Mar 2015, 09:41
Contact:

Re: How to embed Notepad in a GUI?

28 Mar 2020, 05:43

vsub wrote: This works fine but it takes some time until I see the gui(the clipboard contains 3.79mb text
Just as a notepad takes some time to open a large file. You could use -wrap option to speed up.
vsub
Posts: 541
Joined: 29 Sep 2015, 03:39

Re: How to embed Notepad in a GUI?

28 Mar 2020, 05:53

Hmm,I didn't know that,thanks
But why is it so much faster,is it because AHK is trying to wrap the text so the text will not be wider than the edit control?
Seems that's the case(notepad also instantly displays the text if I disable word wrap)
garry
Posts: 3763
Joined: 22 Dec 2013, 12:50

Re: How to embed Notepad in a GUI?

28 Mar 2020, 06:11

just an example , tried movetogether script from wolf_II

Code: Select all

;- movetogether from user wolf_II
;- https://www.autohotkey.com/boards/viewtopic.php?p=199402#p199402

#warn
#NoEnv
setworkingdir,%a_scriptdir%
wa:=a_screenwidth
ha:=a_screenheight
xx:=100
Handles := []
;------------ ahk script  --------------------
   ;- create ahk GUI
   Gui,2: New, hwndhwin1, Window 1
   Gui,2: -DPIScale
   SS_REALSIZECONTROL := 0x40
   Gui,2:default
   Gui,2:Color,Black,Black
   Gui,2:Font,s12 cYellow ,Lucida Console
   ;------------------------------------------------------

;url:="https://autohotkey.com/boards/"
f1:="https://autohotkey.com/boards/"

x1:=(wa*1)/xx,y1:=(ha*1)/xx,w1:=(wa*48)/xx,h1:=(ha*2.7)/xx
Gui,2: Add, Edit,x%x1% y%y1% w%w1% h%h1% vURL,%f1%

x1:=(wa*50)/xx,y1:=(ha*1)/xx,w1:=(wa*2.5)/xx,h1:=(ha*2.7)/xx
Gui,2: Add, Button, x%x1% y%y1% w%w1% h%h1%  Default gA1, Go

x1:=(wa*53)/xx,y1:=(ha*1)/xx,w1:=(wa*2.5)/xx,h1:=(ha*2.7)/xx
Gui,2: Add, Button, x%x1% y%y1% w%w1% h%h1%  gBrB, <

x1:=(wa*56)/xx,y1:=(ha*1)/xx,w1:=(wa*2.5)/xx,h1:=(ha*2.7)/xx
Gui,2: Add, Button, x%x1% y%y1% w%w1% h%h1%  gBrF, >
xxa:="Shell.Explorer"
;xxa:="Mozilla.Browser"

x1:=(wa*1)/xx,y1:=(ha*5)/xx,w1:=(wa*59)/xx,h1:=(ha*88)/xx
Gui,2: Add, ActiveX,x%x1% y%y1% w%w1% h%h1%  vWB,%xxa%
wb.silent := true

x1:=(wa*.1)/xx,y1:=(ha*.1)/xx,w1:=(wa*59.9)/xx,h1:=(ha*94)/xx
Gui,2:Show,       x%x1% y%y1% w%w1% h%h1%,TEST
gosub,a1
Handles.Push(hwin1)
;=================================================

;----------- next-attached window ----------
run,notepad,,,pid2
;-------------------------------------------------
WinWaitActive, ahk_pid %pid2%
x1:=(wa*59.9)/xx,y1:=(ha*.1)/xx,w1:=(wa*40)/xx,h1:=(ha*96)/xx
WinMove, ahk_pid %pid2%, , x1,y1,w1,h1                        ;- move 2nd-script to the right position
IfWinNotActive ,ahk_pid %pid2%,,WinActivate,ahk_pid %pid2%    ;- Activate 2nd-script
  WinWaitActive,ahk_pid %pid2%
Handles.Push(WinExist("A"))                                   ;- 2nd-script is lastactive
MoveTogether(Handles)
settimer,closethisscript,500                                  ;- close this script also if 2nd-script was closed
Return
;-------------------------------------------------------------------------------------------------------------
closethisscript:
process, exist, %PID2%
 status1 = %ErrorLevel%
if (status1 = 0)          ;- close this ahk-script if PID2 not exist
  {
  exitapp
  }
return
;-----------------------------------
2Guiescape:
2Guiclose: 
WinClose, ahk_pid %pid2%             
WinWaitClose,ahk_pid %pid2%
exitapp
;------------------------------------
a1:
Gui,2: Submit, NoHide
WB.Navigate(URL)
return
;--------------
Brb:
try{WB.GoBack()
}catch e{
;xxx:=e.Message
;msgbox, 262208,ERROR,Error=`n%xxx%`n------------------------------------------`n
return
}
return
BrF:
try{WB.GoForward()
}catch e{
;xxx:=e.Message
;msgbox, 262208,ERROR,Error=`n%xxx%`n------------------------------------------`n
return
}
return
;----------------
class WB_events
{
NavigateComplete2(wb, NewURL)
  {
  GuiControl,2:Text, URL, %NewURL%  ;- Update the URL edit control.
  }
}

;====================================


;----------- ATTACH from user 'wolf_II' ----------------------------------------
MoveTogether(wParam, lParam = "", _ = "", hWnd = "") { ; using DeferWindowPos
;-------------------------------------------------------------------------------
    ; call MoveTogether(Handles) with an array of handles
    ; to set up a bundle of AHK Gui's that move together
    ;---------------------------------------------------------------------------
    ; https://autohotkey.com/boards/viewtopic.php?p=199402#p199402
    ; version 2018.02.08
    static init := OnMessage(0xA1, "MoveTogether") ; WM_NCLBUTTONDOWN
    static Handles
	If IsObject(wParam)             ; detect a set up call
		Return, Handles := wParam   ; store the array of handles
    If (wParam != 2) ; HTCAPTION
        Return
    ; changing AHK settings here will have no side effects
    CoordMode, Mouse, Screen    ; for MouseGetPos
    SetBatchLines, -1           ; for onMessage
    SetWinDelay, -1             ; for WinActivate, WinMove
    M_old_X := lParam & 0xFFFF, M_old_Y := lParam >> 16 & 0xFFFF
    WinActivate, ahk_id %hWnd%
    Win := {}
    For each, Handle in Handles {
        WinGetPos, X, Y, W, H, ahk_id %Handle%
        Win[Handle] := {X: X, Y: Y, W: W, H: H}
    }
    While GetKeyState("LButton", "P") {
        MouseGetPos, M_new_X, M_new_Y
        dX := M_new_X - M_old_X, M_old_X := M_new_X
      , dY := M_new_Y - M_old_Y, M_old_Y := M_new_Y
        If GetKeyState("Shift", "P")
            WinMove, ahk_id %hWnd%,, Win[hWnd].X += dX, Win[hWnd].Y += dY
        Else { ; DeferWindowPos cycle
            hDWP := DllCall("BeginDeferWindowPos", "Int", Handles.Length(), "Ptr")
            For each, Handle in Handles
                hDWP := DllCall("DeferWindowPos", "Ptr", hDWP
                    , "Ptr", Handle, "Ptr", 0
                    , "Int", Win[Handle].X += dX
                    , "Int", Win[Handle].Y += dY
                    , "Int", Win[Handle].W
                    , "Int", Win[Handle].H
                    , "UInt", 0x214, "Ptr")
            DllCall("EndDeferWindowPos", "Ptr", hDWP)
        }
    }
}
;=================================== END script ====================================
teadrinker
Posts: 4326
Joined: 29 Mar 2015, 09:41
Contact:

Re: How to embed Notepad in a GUI?

28 Mar 2020, 06:18

@garry
How about Gui,2: New, hwndhwin1 +Resize, Window 1 ?
newbieforever
Posts: 493
Joined: 24 Aug 2016, 03:34

Re: How to embed Notepad in a GUI?

28 Mar 2020, 07:03

newbieforever wrote:
28 Mar 2020, 05:13
There seems to be a data limit for Edit, e.g. a 300 kB file can not be displayed and edited in Edit.
Interesting:

This doesn't work with larger files (f1):

Code: Select all

FileRead, Code, % f1
;;;
Gui Add, Edit, w1080 h200 vvEdit, %Code%      ;;; Error: Can't create control.
But this does:

Code: Select all

FileRead, Code, % f1
;;;
Gui Add, Edit, w1080 h200 vvEdit 
GuiControl, , vEdit, %Code%
garry
Posts: 3763
Joined: 22 Dec 2013, 12:50

Re: How to embed Notepad in a GUI?

28 Mar 2020, 08:27

@teadrinker, resize is only for the GUI , notepad is only attached ( not embedded in GUI )
teadrinker
Posts: 4326
Joined: 29 Mar 2015, 09:41
Contact:

Re: How to embed Notepad in a GUI?

28 Mar 2020, 09:21

But what if I want to make resizable GUI? :)
garry
Posts: 3763
Joined: 22 Dec 2013, 12:50

Re: How to embed Notepad in a GUI?

28 Mar 2020, 09:25

yes you can resize the GUI ... but the notepad doesn't follow ( it's only attached to the GUI )
teadrinker
Posts: 4326
Joined: 29 Mar 2015, 09:41
Contact:

Re: How to embed Notepad in a GUI?

28 Mar 2020, 09:38

It's the inconvenience of this approach.
newbieforever
Posts: 493
Joined: 24 Aug 2016, 03:34

Re: How to embed Notepad in a GUI?

30 Mar 2020, 05:27

Thanks to ahk7, teadrinker, garry.

In the meantime I experimented with the "workaround" Edit, but the functionality limitations compared to Notepad are too big for my purpose.

So may I put my original question once again into the foreground:

Of course I see and know that there are workaround solutions to link a notepad window with a GUI (as shown above by garry, for example).

But I ask again, is it really the case that embedding Notepad in a similar simple way as it can be done for IE is not possible?
teadrinker
Posts: 4326
Joined: 29 Mar 2015, 09:41
Contact:

Re: How to embed Notepad in a GUI?

30 Mar 2020, 07:57

newbieforever wrote: is it really the case that embedding Notepad in a similar simple way as it can be done for IE is not possible?
Nope.
newbieforever wrote: the functionality limitations compared to Notepad are too big
What functionality are you missing?
newbieforever
Posts: 493
Joined: 24 Aug 2016, 03:34

Re: How to embed Notepad in a GUI?

30 Mar 2020, 11:16

teadrinker wrote:
30 Mar 2020, 07:57
What functionality are you missing?
... The whole standard functionality of Notepad ... searching/replacing, simple encoding management when saving ... ...

Another (off topic) question: Is there a simple command to refresh the embedded IE?

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: CuriousDad, rc76 and 225 guests