A simple Windows Programm in C
The following programm is a minimal Windows program. It opens a window and writes a text into the window.
If you compile it with MinGW, being sure to add the-mwindows flag in order to prevent the ... undefined reference to ' [email Protected] ' and ... undefined reference to ' [email protected] linker error.
#include <windows.h>
LRESULT CALLBACK WndProc (
HWND hwnd,
UINT msg,
WPARAM WPARAM,
LPARAM LPARAM) {
Switch (msg) {
Case WM_PAINT: {
Paintstruct PS;
HDC hdc = BeginPaint (hWnd, &ps);
TextOut (HDC, ten, Ten, "ADP GmbH", 8);
EndPaint (HWnd, &ps);
}
Break
Case Wm_destroy:
PostQuitMessage (0);
Break
Default
Return DefWindowProc (HWnd, MSG, WParam, LParam);
}
return 0;
}
int WINAPI WinMain (hinstance hinstance, HInstance hprevinstance,
LPSTR lpcmdline, int ncmdshow) {
Wndclassex WCE;
wce.cbsize = sizeof (WCE);
Wce.style = Cs_vredraw | Cs_hredraw;
Wce.lpfnwndproc = (WNDPROC) WNDPROC;
Wce.cbclsextra = 0;
Wce.cbwndextra = 0;
Wce.hinstance = hinstance;
Wce.hicon = LoadIcon ((hinstance) NULL, idi_application);
Wce.hcursor = LoadCursor ((hinstance) NULL, Idc_arrow);
Wce.hbrbackground = (hbrush) getstockobject (White_brush);
Wce.lpszmenuname = 0;
Wce.lpszclassname = "Adpwinclass",
WCE.HICONSM = 0;
if (! RegisterClassEx (&WCE)) return 0;
HWND hwnd = CREATEWINDOWEX (
0,//Ex Styles
"Adpwinclass",
"ADP GmbH",
Ws_overlappedwindow,
Cw_usedefault,//X
Cw_usedefault,//Y
Cw_usedefault,//Height
Cw_usedefault,//Width
NULL,//Parent Window
NULL,//Menu, or Windows ID if child
HINSTANCE,//
NULL//Pointer to window specific data
);
ShowWindow (HWnd, ncmdshow);
MSG msg;
int R;
while ((R = GetMessage (&msg, NULL, 0, 0))! = 0) {
if (r = =-1) {
; error!
}
else {
TranslateMessage (&MSG);
DispatchMessage (&MSG);
}
}
The application ' s return value
return msg.wparam;
};
A simple Windows Programm in C