Tidied up the main souce code file a bit.
; This source code written by zedd151 @ masm32.com
include \masm32\include\masm32rt.inc
RegWindow proto :dword, :dword
WinMain proto :dword, :dword, :dword
WndProc proto :dword, :dword, :dword, :dword
CenterMain proto :dword, :dword, :dword
wwidth equ 1024
wheight equ 768
cwidth equ 960
cheight equ 720
ws equ WS_BORDER or WS_CAPTION or WS_MINIMIZEBOX or WS_MAXIMIZEBOX or WS_SYSMENU
menuid equ 1000
iconid equ 500
.data?
bak_colour dd ?
txt_colour dd ?
CustomColors dd 16 dup(?)
strx db 64 dup (?)
edfont db 64 dup (?)
edfntsiz dd ?
hWnd dd ?
hInstance dd ?
hAlready dd ?
hEdit dd ?
btFlag dd ?
.const
wclass db "BasicEdClass", 0
dname db "My Editor", 0
about db "My Editor v. ?", 0
smscr db "Screen size must be at least 1024 x 768", 0
section1 db "Settings", 0
key1 db "BackColor", 0
key2 db "TextColor", 0
key3 db "Font", 0
key4 db "FontSize", 0
inifile db ".\editor.ini", 0
.code
; include files\search.asm ; not yet implemented
include files\fileio.asm
include files\settings.asm
include files\richedit.asm
start:
invoke SetSettings ; load setting from ini file
; code to detect if program is already open
invoke FindWindow, addr wclass, 0
cmp eax, 0
je @F ; jump if not open
mov hAlready, eax
invoke ShowWindow, hAlready, SW_RESTORE ; elseif open bring window to top
invoke SetForegroundWindow, hAlready
mov eax, 0
jmp twoinst
@@:
; code to detect screen size
invoke GetSystemMetrics, SM_CXSCREEN ; 1024 x 768 minimum required
cmp eax, wwidth
jb smallscr ; if not met display message
invoke GetSystemMetrics, SM_CYSCREEN ; then exit
cmp eax, wheight
jb smallscr
invoke GetModuleHandle, 0
mov hInstance, eax
invoke RegWindow, hInstance, addr wclass
invoke WinMain, hInstance, addr wclass, addr dname
jmp overit
smallscr:
invoke MessageBox, 0, addr smscr, addr dname, 0
twoinst:
overit:
invoke ExitProcess, eax
WinMain proc hi:dword, cn:dword, dn:dword
local msg:MSG, Wtx:dword, Wty:dword
invoke CreateWindowEx, 0, cn, dn, ws, 0, 0, 0, 0, 0, 0, hi, 0
mov hWnd, eax
invoke LoadMenu, hi, menuid
invoke SetMenu, hWnd, eax
invoke ShowWindow, hWnd, SW_SHOWNORMAL
invoke UpdateWindow, hWnd
StartLoop:
invoke GetMessage, addr msg, 0, 0, 0
cmp eax, 0
je ExitLoop
invoke TranslateMessage, addr msg
invoke DispatchMessage, addr msg
jmp StartLoop
ExitLoop:
return msg.wParam
WinMain endp
WndProc proc hWin:dword, uMsg:dword, wParam:dword, lParam:dword
local rct:RECT
.if uMsg == WM_CREATE
invoke CenterMain, hWin, wwidth, wheight
fn LoadLibrary, "riched20.dll"
invoke rich_edit, hWin, hInstance
mov hEdit, eax
invoke set_edit_colours
.elseif uMsg == WM_COMMAND
.if wParam == 1001
mov szFileName[0], 0
invoke GetFileName, hWin, ADDR szTitleO, ADDR szFilterO
cmp szFileName[0], 0
je @F
invoke stream_file_in, hEdit, ADDR szFileName
invoke SetWindowText, hWin, ADDR szFileName
@@:
.elseif wParam == 1012
fn SendMessage, hWin, WM_CLOSE, 0, 0
.elseif wParam == 2001
invoke DialogBoxParamA, hInstance, 3000, hWin, addr ColorProc, 0
.elseif wParam == 1900
invoke MessageBox, hWin, addr about, addr dname, MB_OK
.endif
.elseif uMsg == WM_SIZE
invoke GetClientRect, hWin, addr rct
mov eax, rct.bottom
; sub eax, sbh ; uncomment if using status bar.
mov rct.bottom, eax
invoke MoveWindow, hEdit, rct.left, rct.top, rct.right, rct.bottom, TRUE
.elseif uMsg == WM_CLOSE
.elseif uMsg == WM_DESTROY
invoke PostQuitMessage, 0
return 0
.endif
invoke DefWindowProc, hWin, uMsg, wParam, lParam
ret
WndProc endp
RegWindow proc hi:dword, cn:dword
local wc:WNDCLASSEX, icn:dword
mov wc.cbSize, sizeof WNDCLASSEX
mov wc.style, CS_HREDRAW or CS_VREDRAW or CS_BYTEALIGNWINDOW
mov wc.lpfnWndProc, offset WndProc
mov wc.cbClsExtra, 0
mov wc.cbWndExtra, 0
mrm wc.hInstance, hi
mov wc.hbrBackground, COLOR_BTNFACE+6
mov wc.lpszMenuName, 0
mrm wc.lpszClassName, cn
invoke LoadIcon, hi, iconid
mov wc.hIcon, eax
mov icn, eax
invoke LoadCursor, 0, IDC_ARROW
mov wc.hCursor, eax
mrm wc.hIconSm, icn
invoke RegisterClassEx, addr wc
ret
RegWindow endp
CenterMain proc hWin:dword, wd:dword, ht:dword
local rct:RECT, h:dword, w:dword, x:dword, y:dword
@@: ; dynamically adjusting width of the window for proper client rect size
invoke MoveWindow, hWin, x, y, wd, ht, 0
invoke GetClientRect, hWin, addr rct
mov eax, rct.right
sub eax, rct.left
.if eax > 872 ; desired client rect width
dec wd
jmp @b
.elseif eax < 872
inc wd
jmp @b
.endif
@@: ; dynamically adjusting height of the window for proper client rect size
invoke MoveWindow, hWin, x, y, wd, ht, 0
invoke GetClientRect, hWin, addr rct
mov eax, rct.bottom
sub eax, rct.top
.if eax > 604 ; desired client rect height
dec ht
jmp @b
.elseif eax < 604
inc ht
jmp @b
.endif
invoke GetSystemMetrics, SM_CYMENU
add ht, eax
invoke SystemParametersInfoA, SPI_GETWORKAREA, 0, addr rct, 0
mov eax, rct.right
sub eax, wd
sar eax, 1
mov x, eax
mov eax, rct.bottom
sub eax, ht
sar eax, 1
mov y, eax
invoke MoveWindow, hWin, x, y, wd, ht, TRUE
ret
CenterMain endp
end start
Using a 'modular' approach to not clutter the main source. Makes code easier for me to find.