Created
October 20, 2023 19:02
-
-
Save kcvinker/8fc8616f7fb4ebdd9c6395766cc8781b to your computer and use it in GitHub Desktop.
Code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Control :: struct | |
{ | |
kind : ControlKind, | |
name : string, | |
handle : HWND, | |
controlID : UINT, | |
parent : ^Form, | |
text : string, | |
width, height : int, | |
xpos, ypos : int, | |
font : ^Font, | |
backColor : uint, | |
foreColor : uint, | |
enabled : bool, | |
visible : bool, | |
.... | |
} | |
Font :: struct | |
{ | |
name : string, | |
size : int, | |
weight : FontWeight, | |
underline : bool, | |
italics : bool, | |
handle : HFONT, | |
_defFontChanged : bool, | |
} | |
new_font_1 :: proc() -> ^Font | |
{ | |
f := new(Font) | |
f.name = _def_font_name | |
f.size = _def_font_size | |
f.weight = FontWeight.Normal | |
f.underline = false | |
f.italics = false | |
f._defFontChanged = false | |
return f | |
} | |
Form :: struct | |
{ | |
using control : Control, | |
start_pos : StartPosition, | |
.... | |
} | |
@private | |
new_form_internal :: proc(t : string = "", w : int = 500, h : int = 400) -> Form | |
{ | |
app.formCount += 1 | |
f : Form | |
f.kind = .Form | |
f.text = t == "" ? concat_number("Form_", app.formCount) : t | |
f.width = w | |
f.height = h | |
f.start_pos = .Center | |
f.style = .Default | |
f.maximizeBox = true | |
f.minimizeBox = true | |
f.font = new_font() // Creating new font | |
f._drawMode = .Default | |
f.backColor = def_window_color | |
f.foreColor = app.clrBlack | |
f.windowState = .Normal | |
f._uDrawChilds = make(map[UINT]HWND) | |
return f | |
} | |
create_form_hwnd :: proc(frm : ^Form ) | |
{ | |
frm.handle = CreateWindowEx(.....) | |
if frm.handle == nil { fmt.println("Error in CreateWindoeEx,", GetLastError()) } | |
else | |
{ | |
set_form_font_internal(frm) // Setting up the font handle and send it form's wndproc | |
SetWindowLongPtr(frm.handle, GWLP_USERDATA, cast(LONG_PTR) cast(UINT_PTR) frm) | |
} | |
} | |
@private | |
form_dtor :: proc(frm : ^Form) | |
{ | |
delete_gdi_object(frm.font.handle) | |
delete(frm._uDrawChilds) | |
delete(frm._cDrawChilds) | |
free(frm.font) | |
print("frm dtor called") | |
} | |
@private | |
window_proc :: proc "std" (hw : HWND, msg : u32, wp : WPARAM, lp : LPARAM ) -> LRESULT | |
{ | |
context = runtime.default_context() | |
frm := direct_cast(GetWindowLongPtr(hw, GWLP_USERDATA), ^Form) | |
switch msg { | |
case WM_DESTROY: | |
form_dtor(frm) // Caling form's destructor | |
...... | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment