A simple Windows Programm in C

Source: Internet
Author: User


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 (&AMP;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 (&AMP;MSG);
DispatchMessage (&AMP;MSG);
}
}

The application ' s return value
return msg.wparam;
};

A simple Windows Programm in C

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.