LRESULT CALLBACK WindowFunc(HWND, UINT, WPARAM, LPARAM);
COLORREF cColor;
char szWinName[] = "MyWin"; /* name of window class */
char str[255]; /* holds output strings */
int X=0, Y=0; /* current output location */
int WINAPI WinMain(HINSTANCE hThisInst, HINSTANCE hPrevInst,
LPSTR lpszArgs, int nWinMode)
{
HWND hwnd;
MSG msg;
WNDCLASSEX wcl;
/* Define a window class. */
wcl.cbSize = sizeof(WNDCLASSEX);
wcl.hInstance = hThisInst; /* handle to this instance */
wcl.lpszClassName = szWinName; /* window class name */
wcl.lpfnWndProc = WindowFunc; /* window function */
wcl.style = CS_HREDRAW|CS_VREDRAW |CS_DBLCLKS ; /*
default style */
wcl.hIcon = LoadIcon(NULL, IDI_APPLICATION); /* large icon */
wcl.hIconSm = NULL; /* use small version of large icon */
wcl.hCursor = LoadCursor(NULL, IDC_ARROW); /* cursor style */
wcl.lpszMenuName = NULL; /* no class menu */
wcl.cbClsExtra = 0; /* no extra memory needed */
wcl.cbWndExtra = 0;
/* Now that a window class has been registered, a window
can be created. */
hwnd = CreateWindow(
szWinName, /* name of window class */
"Au sujet de JeanPierreDaviau.com", /* title */
WS_OVERLAPPEDWINDOW, /* window style - normal */
250, /* X coordinate - let Windows decide */
100, /* Y coordinate - let Windows decide */
450, /* width - let Windows decide */
300, /* height - let Windows decide */
NULL, /* no parent window */
NULL, /* no menu */
hThisInst, /* instance handle */
NULL /* no additional arguments */
);
/* Display the window. */
ShowWindow(hwnd, nWinMode);
UpdateWindow(hwnd);
/* Create the message loop. */
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg); /* translate keyboard messages */
DispatchMessage(&msg); /* return control to Windows 2000 */
}
return msg.wParam;
}
/* This function is called by Windows 2000 and is passed
messages from the message queue.
*/
LRESULT CALLBACK WindowFunc(HWND hwnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
HDC hdc;
TEXTMETRIC tm;
SIZE size;
PAINTSTRUCT paintstruct;
switch(message) {
case WM_PAINT:
hdc = BeginPaint(hwnd, &paintstruct);
/* get text metrics */
GetTextMetrics(hdc, &tm);
X = Y = 0;
/* switch to transparent mode */
SetBkMode(hdc, TRANSPARENT);
SetTextColor(hdc, RGB(0, 0, 200));
sprintf(str, "This is on the first line.");
TextOut(hdc, X, Y, str, strlen(str));
Y = Y + tm.tmHeight + tm.tmExternalLeading; /* next line */
strcpy(str, "This is on the second line. ");
TextOut(hdc, X, Y, str, strlen(str));
Y = Y + tm.tmHeight + tm.tmExternalLeading; /* next line */
strcpy(str, "This is on the third line. ");
TextOut(hdc, X, Y, str, strlen(str));
/* compute length of a string */
GetTextExtentPoint32(hdc, str, strlen(str), &size);
sprintf(str, "The preceding sentence is %ld units long",
size.cx);
X = size.cx; /* advance to end of previous string */
TextOut(hdc, X, Y, str, strlen(str));
Y = Y + tm.tmHeight + tm.tmExternalLeading; /* next line */
X = 0; /* return to start of line */
SetTextColor(hdc, RGB(255, 0, 0));
sprintf(str, "The space between lines is %ld pixels.",
tm.tmExternalLeading+tm.tmHeight);
TextOut(hdc, X, Y, str, strlen(str));
Y = Y + tm.tmHeight + tm.tmExternalLeading; /* next line */
sprintf(str, "Average character width is %ld pixels",
tm.tmAveCharWidth);
TextOut(hdc, X, Y, str, strlen(str));
Y = Y + tm.tmHeight + tm.tmExternalLeading; /* next line */
=======================================================================================
/* set background color to mauve */
SetBkColor(hdc, OPAQUE);
SetBkColor(hdc, RGB(240, 240, 0));
/* set text color to green */
SetTextColor(hdc, RGB(0, 180, 0));
sprintf(str, "This line is green on mauve background.");
TextOut(hdc, X, Y, str, strlen(str));
Y = Y + tm.tmHeight + tm.tmExternalLeading; /* next line */
===========================================================================
sprintf(str,
"This line is red. The background is unchanged.");
TextOut(hdc, X, Y, str, strlen(str));
EndPaint(hwnd, &paintstruct);
break;
case WM_DESTROY: /* terminate the program */
PostQuitMessage(0);
break;
default:
/* Let Windows 2000 process any messages not specified in
the preceding switch statement. */
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}
--
Jean Pierre Daviau
--
http://jeanpierredaviau.com