diff --git a/examples/windows/build.hancho b/examples/windows/build.hancho index 9012439..5ad3010 100644 --- a/examples/windows/build.hancho +++ b/examples/windows/build.hancho @@ -9,13 +9,13 @@ compile = Rule( link = Rule( desc = "Link {files_in} -> {files_out}", - command = "link.exe /nologo {files_in} /out:{files_out} > NUL", + command = "link.exe /nologo {libs} {files_in} /out:{files_out} > NUL", + libs = "user32.lib" ) def c_binary(files_in, files_out, **kwargs): objs = [compile(file, **kwargs) for file in files_in] return link(objs, files_out, **kwargs) - main_o = compile("src/main.cpp") -link([ain_o, , "app") +link(main_o, "app.exe") diff --git a/examples/windows/src/main.cpp b/examples/windows/src/main.cpp index 4f5abd0..0f434f0 100644 --- a/examples/windows/src/main.cpp +++ b/examples/windows/src/main.cpp @@ -1,8 +1,43 @@ -// src/main.cpp -#include "main.hpp" -#include +#include + +LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { + switch (uMsg) { + case WM_DESTROY: { + PostQuitMessage(0); + return 0; + } + case WM_PAINT: { + PAINTSTRUCT ps; + HDC hdc = BeginPaint(hwnd, &ps); + FillRect(hdc, &ps.rcPaint, (HBRUSH)(COLOR_WINDOW + 1)); + DrawText(hdc, "Hello World", 11, &ps.rcPaint, 0); + EndPaint(hwnd, &ps); + return 0; + } + } + return DefWindowProc(hwnd, uMsg, wParam, lParam); +} + +int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR /*pCmdLine*/, int nCmdShow) { + WNDCLASS wc = { }; + + wc.lpfnWndProc = WindowProc; + wc.hInstance = hInstance; + wc.lpszClassName = "Sample Window Class"; + + RegisterClass(&wc); + + HWND hwnd = CreateWindowEx(0, "Sample Window Class", "Win32 Hello World", + WS_OVERLAPPEDWINDOW, 400, 400, 400, 400, + NULL, NULL, hInstance, NULL); + + ShowWindow(hwnd, nCmdShow); + + MSG msg = { }; + while (GetMessage(&msg, NULL, 0, 0)) { + TranslateMessage(&msg); + DispatchMessage(&msg); + } -int main(int argc, char** argv) { - printf("Hello World\n"); return 0; } diff --git a/tutorial/rules.hancho b/tutorial/rules.hancho index f0c970e..81f4d5d 100644 --- a/tutorial/rules.hancho +++ b/tutorial/rules.hancho @@ -2,22 +2,16 @@ import os -compile_lin = "g++ -MMD -c {files_in} -o {files_out}" -compile_win = "cl.exe /nologo /c {files_in} /sourceDependencies {depfile} /Fo:{files_out} > NUL" - -link_lin = "g++ {files_in} -o {files_out}" -link_win = "link.exe /nologo {files_in} /out:{files_out} > NUL" - compile = Rule( desc = "Compile {files_in} -> {files_out}", - command = compile_win if os.name == 'nt' else compile_lin, + command = "g++ -MMD -c {files_in} -o {files_out}", files_out = "{swap_ext(files_in, '.o')}", depfile = "{swap_ext(files_out, '.d')}", ) link = Rule( desc = "Link {files_in} -> {files_out}", - command = link_win if os.name == 'nt' else link_lin, + command = "g++ {files_in} -o {files_out}", ) def c_binary(files_in, files_out, **kwargs): diff --git a/tutorial/tut0.hancho b/tutorial/tut0.hancho index c39008e..269d4b0 100644 --- a/tutorial/tut0.hancho +++ b/tutorial/tut0.hancho @@ -2,13 +2,8 @@ import os -if os.name == 'nt': - rule = Rule( - command = "cl.exe /c {files_in} /Fo:{files_out}", - ) -else: - rule = Rule( - command = "g++ {files_in} -o {files_out}", - ) +rule = Rule( + command = "g++ {files_in} -o {files_out}", +) rule(["src/main.cpp", "src/util.cpp"], "tut0/app")