summary refs log tree commit diff stats
path: root/tinyc/win32/examples
diff options
context:
space:
mode:
Diffstat (limited to 'tinyc/win32/examples')
-rw-r--r--tinyc/win32/examples/dll.c8
-rw-r--r--tinyc/win32/examples/fib.c4
-rw-r--r--tinyc/win32/examples/hello_dll.c17
-rw-r--r--tinyc/win32/examples/hello_win.c224
4 files changed, 128 insertions, 125 deletions
diff --git a/tinyc/win32/examples/dll.c b/tinyc/win32/examples/dll.c
index 4202e99ca..052a05644 100644
--- a/tinyc/win32/examples/dll.c
+++ b/tinyc/win32/examples/dll.c
@@ -5,11 +5,9 @@
 
 #include <windows.h>
 
-#define DLL_EXPORT __declspec(dllexport)
+__declspec(dllexport) const char *hello_data = "(not set)";
 
-
-DLL_EXPORT void HelloWorld (void)
+__declspec(dllexport) void hello_func (void)
 {
-	MessageBox (0, "Hello World!", "From DLL", MB_ICONINFORMATION);
+    MessageBox (0, hello_data, "From DLL", MB_ICONINFORMATION);
 }
-
diff --git a/tinyc/win32/examples/fib.c b/tinyc/win32/examples/fib.c
index 6a4bdf5c4..8da26bce6 100644
--- a/tinyc/win32/examples/fib.c
+++ b/tinyc/win32/examples/fib.c
@@ -1,7 +1,7 @@
 #include <stdio.h>
-#include <math.h>
+#include <stdlib.h>	// atoi()
 
-int fib(int n)
+int fib(n)
 {
 	if (n <= 2)
 		return 1;
diff --git a/tinyc/win32/examples/hello_dll.c b/tinyc/win32/examples/hello_dll.c
index 7adba77ec..4813c5b94 100644
--- a/tinyc/win32/examples/hello_dll.c
+++ b/tinyc/win32/examples/hello_dll.c
@@ -5,15 +5,16 @@
 
 #include <windows.h>
 
-void HelloWorld (void);
+void hello_func (void);
+__declspec(dllimport) extern const char *hello_data;
 
 int WINAPI WinMain(
-	HINSTANCE hInstance,
-	HINSTANCE hPrevInstance,
-	LPSTR     lpCmdLine,
-	int       nCmdShow)
+    HINSTANCE hInstance,
+    HINSTANCE hPrevInstance,
+    LPSTR     lpCmdLine,
+    int       nCmdShow)
 {
-	HelloWorld();
-	return 0;
+    hello_data = "Hello World!";
+    hello_func();
+    return 0;
 }
-
diff --git a/tinyc/win32/examples/hello_win.c b/tinyc/win32/examples/hello_win.c
index 294b7279a..96546e415 100644
--- a/tinyc/win32/examples/hello_win.c
+++ b/tinyc/win32/examples/hello_win.c
@@ -10,9 +10,7 @@
 
 char szAppName[] = APPNAME; // The name of this application
 char szTitle[]   = APPNAME; // The title bar text
-char *pWindowText;
-
-HINSTANCE g_hInst;          // current instance
+const char *pWindowText;
 
 void CenterWindow(HWND hWnd);
 
@@ -28,51 +26,49 @@ void CenterWindow(HWND hWnd);
 
 LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
 {
-	switch (message)
-	{
-		// ----------------------- first and last
-		case WM_CREATE:
-			CenterWindow(hwnd);
-			break;
-
-		case WM_DESTROY:
-			PostQuitMessage(0);
-			break;
-
-
-		// ----------------------- get out of it...
-		case WM_RBUTTONUP:
-			DestroyWindow(hwnd);
-			break;
-
-		case WM_KEYDOWN:
-			if (VK_ESCAPE == wParam)
-				DestroyWindow(hwnd);
-			break;
-
-
-		// ----------------------- display our minimal info
-		case WM_PAINT:
-		{
-			PAINTSTRUCT ps;
-			HDC         hdc;
-			RECT        rc;
-			hdc = BeginPaint(hwnd, &ps);
-
-			GetClientRect(hwnd, &rc);
-			SetTextColor(hdc, RGB(240,240,96));
-			SetBkMode(hdc, TRANSPARENT);
-			DrawText(hdc, pWindowText, -1, &rc, DT_CENTER|DT_SINGLELINE|DT_VCENTER);
-
-			EndPaint(hwnd, &ps);
-			break;
-		}
-
-		// ----------------------- let windows do all other stuff
-		default:
-			return DefWindowProc(hwnd, message, wParam, lParam);
-	}
-	return 0;
+    switch (message) {
+
+        // ----------------------- first and last
+        case WM_CREATE:
+            CenterWindow(hwnd);
+            break;
+
+        case WM_DESTROY:
+            PostQuitMessage(0);
+            break;
+
+        // ----------------------- get out of it...
+        case WM_RBUTTONUP:
+            DestroyWindow(hwnd);
+            break;
+
+        case WM_KEYDOWN:
+            if (VK_ESCAPE == wParam)
+                DestroyWindow(hwnd);
+            break;
+
+        // ----------------------- display our minimal info
+        case WM_PAINT:
+        {
+            PAINTSTRUCT ps;
+            HDC         hdc;
+            RECT        rc;
+            hdc = BeginPaint(hwnd, &ps);
+
+            GetClientRect(hwnd, &rc);
+            SetTextColor(hdc, RGB(240,240,96));
+            SetBkMode(hdc, TRANSPARENT);
+            DrawText(hdc, pWindowText, -1, &rc, DT_CENTER|DT_SINGLELINE|DT_VCENTER);
+
+            EndPaint(hwnd, &ps);
+            break;
+        }
+
+        // ----------------------- let windows do all other stuff
+        default:
+            return DefWindowProc(hwnd, message, wParam, lParam);
+    }
+    return 0;
 }
 
 //+---------------------------------------------------------------------------
@@ -83,57 +79,57 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
 //
 //----------------------------------------------------------------------------
 int APIENTRY WinMain(
-				HINSTANCE hInstance,
-				HINSTANCE hPrevInstance,
-				LPSTR     lpCmdLine,
-				int       nCmdShow)
+        HINSTANCE hInstance,
+        HINSTANCE hPrevInstance,
+        LPSTR lpCmdLine,
+        int nCmdShow
+        )
 {
-	MSG msg;
-
-	WNDCLASS wc;
-
-	HWND hwnd;
-
-	// Fill in window class structure with parameters that describe
-	// the main window.
-
-	ZeroMemory(&wc, sizeof wc);
-	wc.hInstance     = hInstance;
-	wc.lpszClassName = szAppName;
-	wc.lpfnWndProc   = (WNDPROC)WndProc;
-	wc.style         = CS_DBLCLKS|CS_VREDRAW|CS_HREDRAW;
-	wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
-	wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
-	wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
-
-	if (FALSE == RegisterClass(&wc)) return 0;
-
-	// create the browser
-	hwnd = CreateWindow(
-		szAppName,
-		szTitle,
-		WS_OVERLAPPEDWINDOW|WS_VISIBLE,
-		CW_USEDEFAULT,
-		CW_USEDEFAULT,
-		360,//CW_USEDEFAULT,
-		240,//CW_USEDEFAULT,
-		0,
-		0,
-		g_hInst,
-		0);
-
-	if (NULL == hwnd) return 0;
-
-	pWindowText = lpCmdLine[0] ? lpCmdLine : "Hello Windows!";
-
-	// Main message loop:
-	while (GetMessage(&msg, NULL, 0, 0) > 0)
-	{
-		TranslateMessage(&msg);
-		DispatchMessage(&msg);
-	}
-
-	return msg.wParam;
+    MSG msg;
+    WNDCLASS wc;
+    HWND hwnd;
+
+    pWindowText = lpCmdLine[0] ? lpCmdLine : "Hello Windows!";
+
+    // Fill in window class structure with parameters that describe
+    // the main window.
+
+    ZeroMemory(&wc, sizeof wc);
+    wc.hInstance     = hInstance;
+    wc.lpszClassName = szAppName;
+    wc.lpfnWndProc   = (WNDPROC)WndProc;
+    wc.style         = CS_DBLCLKS|CS_VREDRAW|CS_HREDRAW;
+    wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
+    wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
+    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
+
+    if (FALSE == RegisterClass(&wc))
+        return 0;
+
+    // create the browser
+    hwnd = CreateWindow(
+        szAppName,
+        szTitle,
+        WS_OVERLAPPEDWINDOW|WS_VISIBLE,
+        CW_USEDEFAULT,
+        CW_USEDEFAULT,
+        360,//CW_USEDEFAULT,
+        240,//CW_USEDEFAULT,
+        0,
+        0,
+        hInstance,
+        0);
+
+    if (NULL == hwnd)
+        return 0;
+
+    // Main message loop:
+    while (GetMessage(&msg, NULL, 0, 0) > 0) {
+        TranslateMessage(&msg);
+        DispatchMessage(&msg);
+    }
+
+    return msg.wParam;
 }
 
 //+---------------------------------------------------------------------------
@@ -142,18 +138,26 @@ int APIENTRY WinMain(
 
 void CenterWindow(HWND hwnd_self)
 {
-	RECT rw_self, rc_parent, rw_parent; HWND hwnd_parent;
-	hwnd_parent = GetParent(hwnd_self);
-	if (NULL==hwnd_parent) hwnd_parent = GetDesktopWindow();
-	GetWindowRect(hwnd_parent, &rw_parent);
-	GetClientRect(hwnd_parent, &rc_parent);
-	GetWindowRect(hwnd_self, &rw_self);
-	SetWindowPos(hwnd_self, NULL,
-		rw_parent.left + (rc_parent.right + rw_self.left - rw_self.right) / 2,
-		rw_parent.top  + (rc_parent.bottom + rw_self.top - rw_self.bottom) / 2,
-		0, 0,
-		SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE
-		);
+    HWND hwnd_parent;
+    RECT rw_self, rc_parent, rw_parent;
+    int xpos, ypos;
+
+    hwnd_parent = GetParent(hwnd_self);
+    if (NULL == hwnd_parent)
+        hwnd_parent = GetDesktopWindow();
+
+    GetWindowRect(hwnd_parent, &rw_parent);
+    GetClientRect(hwnd_parent, &rc_parent);
+    GetWindowRect(hwnd_self, &rw_self);
+
+    xpos = rw_parent.left + (rc_parent.right + rw_self.left - rw_self.right) / 2;
+    ypos = rw_parent.top + (rc_parent.bottom + rw_self.top - rw_self.bottom) / 2;
+
+    SetWindowPos(
+        hwnd_self, NULL,
+        xpos, ypos, 0, 0,
+        SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE
+        );
 }
 
 //+---------------------------------------------------------------------------