Re: Compile for foreign systems.
Posted: Mon Jul 18, 2011 12:21 am
I will definitely be avoiding bloat. This code compiled with GCC produces an 8k exe; PureBasic's equivalent, just the window and button, comes in at 18k:
Code: Select all
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <commctrl.h>
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
INITCOMMONCONTROLSEX icc;
char szClassName[ ] = "Windows App";
int WINAPI WinMain ( HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nCmdShow)
{
InitCommonControlsEx(&icc);
HWND button;
HWND hwnd;
MSG messages;
WNDCLASSEX mywinclass;
INT font;
int windowx = GetSystemMetrics(SM_CXSCREEN)/2 - (640/2);
int windowy = GetSystemMetrics(SM_CYSCREEN)/2 - (480/2);
mywinclass.hInstance = hThisInstance;
mywinclass.lpszClassName = szClassName;
mywinclass.lpfnWndProc = WindowProcedure;
mywinclass.style = CS_DBLCLKS;
mywinclass.cbSize = sizeof (WNDCLASSEX);
mywinclass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
mywinclass.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
mywinclass.hCursor = LoadCursor (NULL, IDC_ARROW);
mywinclass.lpszMenuName = NULL;
mywinclass.cbClsExtra = 0;
mywinclass.cbWndExtra = 0;
mywinclass.hbrBackground = (HBRUSH) COLOR_WINDOW;
if (!RegisterClassEx (&mywinclass))
return 0;
hwnd = CreateWindowEx (
0,
szClassName,
"Windows App",
WS_OVERLAPPEDWINDOW,
windowx,
windowy,
640,
480,
HWND_DESKTOP,
NULL,
hThisInstance,
NULL
);
button = CreateWindowEx (
0,
"BUTTON",
"I can be pushed around",
WS_CHILD | WS_VISIBLE,
20,
20,
200,
20,
hwnd,
NULL,
hThisInstance,
NULL
);
font = (INT)GetStockObject(DEFAULT_GUI_FONT);
SendMessage(button,WM_SETFONT, font, 0);
ShowWindow (hwnd, nCmdShow);
while (GetMessage (&messages, NULL, 0, 0))
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}
return messages.wParam;
}
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_DESTROY:
PostQuitMessage (0);
break;
default:
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}