Hi all,
I am practising nim by writing a gui library based on win32 api. So far so good. I have a working model now. But i am seeking more better method to make this lib stronger and better.
This is my current scenario. Pseudocode;
xPos : int32, yPos : int32, width : int32, height : int32, style : DWORD, exStyle : DWORD, parent : HWND]
So, this is the strategy of my lib right now. Now, my question is, how can i improve this ? I would like to eliminate the need of single function and divide the functionality into multiple functions like "formCreate", "button1Click".
This is my WndProc function in Module1
proc WndProc( hwnd: HWND, message: UINT, wParam: WPARAM, lParam: LPARAM): LRESULT {.stdcall.} =
eArgs.uMsg = message # this eArgs is global.
eArgs.wHandle = hwnd
eArgs.lParam = lParam
eArgs.wParam = wParam
result = byPassProc()
case message
of WM_DESTROY:
PostQuitMessage(0)
return 0
else:
return DefWindowProc(hwnd, message, wParam, lParam)
And this is the code from Module2
import winim/lean
import "Module1.nim"
proc myCallBack() : LRESULT # forward declaration
var mApp = newWinApp(myCallBack) # this constructor call will register this function in WndProc
mApp.config.caption = "My New Window" #some tweaks.
let wHwn = mApp.createGui() # this proc will create a gui and return it's hwnd
var btn = newButton(wHwn) # button type constructor. This will take the parent handle as parameter.
btn.config.caption = "Click Me" # some tweaks
btn.config.xPos = 200
btn.config.yPos = 100
discard btn.createButton() #creating the button.
mApp.ShowGui( ) # Displaying the gui
mApp.appMainLoop() # Entering into the main loop.
proc myCallBack() : LRESULT = #Here comes all the actions of this gui. I have simplified this as much i can.
case eArgs.uMsg
of WM_CREATE :
echo "Window just Created"
of WM_LBUTTONDOWN :
msgBox("You clicked on Window")
of WM_COMMAND :
if eArgs.lParam == btn.bHandle :
msgBox("You clicked on Button")
else :
return 0