Jump to content

Cloning Notepad 1:1, for funsies/for tutorial


Recommended Posts

Basically just using Au3Info to inspect the various elements of the Notepad app to try to clone the position/scaling/styling.

I think it's a good exercise to go through as a beginner too, to get comfortable with styling elements as well as making Au3Info your best friend.

So far I've only cloned the main window's UI and the dropdowns, with dummy placeholder texts in the status bar.

None of the buttons are functional yet, though I did make the status bar resize correctly, but I'm not sure if my way of doing it is frowned upon -- please give me copious critiques/pointers on what the best-practices are for keeping track of UI state.

  

#NoTrayIcon
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <GuiStatusBar.au3>
#include <WinApi.au3>

Opt("GUICloseOnESC",0)

Global Const $APP_DEFAULT_WINDOW_WIDTH  = 640
Global Const $APP_DEFAULT_WINDOW_HEIGHT = 480
Global Const $APP_DEFAULT_TITLE = "Untitled"
Global Const $APP_TITLE_SUFFIX = " - Notepad"

Local $w = $APP_DEFAULT_WINDOW_WIDTH
Local $h = $APP_DEFAULT_WINDOW_HEIGHT
Local $n = $APP_DEFAULT_TITLE & $APP_TITLE_SUFFIX

local $hWnd = GUICreate($n,$w,$h,-1,-1,$WS_SIZEBOX+$WS_MAXIMIZEBOX+$WS_MINIMIZEBOX,$WS_EX_WINDOWEDGE)
GUISetIcon(@SystemDir&"\notepad.exe")
GUICtrlCreateLabel("",0,0)
local $hEdit = GUICtrlCreateEdit("",0,0,$w-2,$h-40-23-5,0x50200104+$WS_HSCROLL,0x00000000)
;GUICtrlSetBkColor($hEdit,0x000000)
;GUICtrlSetColor($hEdit,0x00FF00)
GUICtrlSetFont($hEdit, 11.5, 0, 0, "Consolas")
GUICtrlSetResizing($hEdit, $GUI_DOCKBORDERS)
local $hMenu = [ _
    GUICtrlCreateMenu (  "&File"  ), _
    GUICtrlCreateMenu (  "&Edit"  ), _ 
    GUICtrlCreateMenu ( "F&ormat" ), _
    GUICtrlCreateMenu (  "&View"  ), _
    GUICtrlCreateMenu (  "&Help"  )  _
]
local $hStatus = StatusBarSingleton ( $hWnd , -1 , $w)
GUIRegisterMsg($WM_SIZE, "StatusBarSingleton")


local $hMenuFiles = [ _
    GUICtrlCreateMenuItem ( "New"            & @TAB & "Ctrl+N",       $hMenu[0] ), _
    GUICtrlCreateMenuItem ( "New &Window"    & @TAB & "Ctrl+Shift+N", $hMenu[0] ), _
    GUICtrlCreateMenuItem ( "&Open..."       & @TAB & "Ctrl+O",       $hMenu[0] ), _
    GUICtrlCreateMenuItem ( "&Save"          & @TAB & "Ctrl+S",       $hMenu[0] ), _
    GUICtrlCreateMenuItem ( "Save &As..."    & @TAB & "Ctrl+Shift+S", $hMenu[0] ), _
    GUICtrlCreateMenuItem ( "",                                       $hMenu[0] ), _
    GUICtrlCreateMenuItem ( "Page Set&up...",                         $hMenu[0] ), _
    GUICtrlCreateMenuItem ( "&Print..."      & @TAB & "Ctrl+P",       $hMenu[0] ), _
    GUICtrlCreateMenuItem ( "",                                       $hMenu[0] ), _
    GUICtrlCreateMenuItem ( "E&xit",                                  $hMenu[0] )  _
]

;MsgBox(0,UBound($hMenu),"")

local $hMenuEdit = [ _
    GUICtrlCreateMenuItem ( "&Undo"               & @TAB & "Ctrl+Z",   $hMenu[1] ), _
    GUICtrlCreateMenuItem ( "",                                        $hMenu[1] ), _
    GUICtrlCreateMenuItem ( "Cu&t"                & @TAB & "Ctrl+X",   $hMenu[1] ), _
    GUICtrlCreateMenuItem ( "&Copy"               & @TAB & "Ctrl+C",   $hMenu[1] ), _
    GUICtrlCreateMenuItem ( "&Paste"              & @TAB & "Ctrl+V",   $hMenu[1] ), _
    GUICtrlCreateMenuItem ( "De&lete"             & @TAB & "Del",      $hMenu[1] ), _
    GUICtrlCreateMenuItem ( "",                                        $hMenu[1] ), _
    GUICtrlCreateMenuItem ( "&Seach with Bing..." & @TAB & "Ctrl+E",   $hMenu[1] ), _
    GUICtrlCreateMenuItem ( "&Find..."            & @TAB & "Ctrl+F",   $hMenu[1] ), _
    GUICtrlCreateMenuItem ( "Find &Next"          & @TAB & "F3",       $hMenu[1] ), _
    GUICtrlCreateMenuItem ( "Find Pre&vious"      & @TAB & "Shift+F3", $hMenu[1] ), _
    GUICtrlCreateMenuItem ( "&Replace..."         & @TAB & "Ctrl+H",   $hMenu[1] ), _
    GUICtrlCreateMenuItem ( "&Go To..."           & @TAB & "Ctrl+G",   $hMenu[1] ), _
    GUICtrlCreateMenuItem ( "",                                        $hMenu[1] ), _
    GUICtrlCreateMenuItem ( "Select &All"         & @TAB & "Ctrl+A",   $hMenu[1] ), _
    GUICtrlCreateMenuItem ( "Time/&Date"          & @TAB & "F5",       $hMenu[1] )  _
]

local $hMenuFormat = [ _
    GUICtrlCreateMenuItem ( "&Word Wrap", $hMenu[2] ), _
    GUICtrlCreateMenuItem ( "&Font...",   $hMenu[2] )  _
]

local $hMenuView = [ _
    GUICtrlCreateMenuItem ( "&Zoom",       $hMenu[3] ), _
    GUICtrlCreateMenuItem ( "&Status Bar", $hMenu[3] )  _
]

local $hMenuHelp = [ _
    GUICtrlCreateMenuItem ( "View &Help",     $hMenu[4] ), _
    GUICtrlCreateMenuItem ( "Send &Feedback", $hMenu[4] ), _
    GUICtrlCreateMenuItem ( "",               $hMenu[4] ), _
    GUICtrlCreateMenuItem ( "&About Notepad", $hMenu[4] )  _
]

;GUICtrlSetState($hMenuFormat[0], $GUI_CHECKED)
GUICtrlSetState($hMenuView[1], $GUI_CHECKED)
GUISetState()

do
until GUIGetMsg() == $GUI_EVENT_CLOSE





Func StatusBarSingleton($hWnd, $iMsg=0, $iwParam=0, $ilParam=0)
    If $iMsg == $WM_SIZE Then
        _GUICtrlStatusBar_Resize($hStatus)
        Local $aClientSize = WinGetClientSize($hWnd)
        Local $arr = [$aClientSize[0]-430, $aClientSize[0]-290, $aClientSize[0]-240, $aClientSize[0]-120, -1]
        _GUICtrlStatusBar_SetParts ($hStatus,$arr)
        Return $GUI_RUNDEFMSG
    Else
        Local Static $hStatus = _GUICtrlStatusBar_Create ($hWnd, -1, -1,0x54000000,0x00000000)
        Local $arr = [$iwParam-430, $iwParam-290, $iwParam-240, $iwParam-120, -1]
        _GUICtrlStatusBar_SetParts ($hStatus,$arr)
        _GUICtrlStatusBar_SetText ( $hStatus , " Found next from the top" , 0 )
        _GUICtrlStatusBar_SetText ( $hStatus , "  Ln 1, Col 1" , 1 )
        _GUICtrlStatusBar_SetText ( $hStatus , " 100%" , 2 )
        _GUICtrlStatusBar_SetText ( $hStatus , " Windows (CRLF)" , 3 )
        _GUICtrlStatusBar_SetText ( $hStatus , " UTF-8" , 4 )
        Return $hStatus
    EndIf
EndFunc

 

Would folks here be interested in make it a collaborative effort for creating a singular "Textbook Answer" to this exercise, that could be incorporated into the introductory tutorial?

 

Having a 1:1 clone also makes it a nice sandbox to play around with altering the UI, such as adding color themes to the editbox/text. I'm partial to black background with lime text myself:

image.png.ed10378bff52681d99e763aaec6c95ec.png

 

Edited by AutoXenon
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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...