OVH Cloud OVH Cloud

SetBkColor

2 réponses
Avatar
Jean Pierre Daviau
Bonjour à tous,

J'ai établi SetBkColor à TRANSPARENT mais ne puis plus la ramener à une
couleur quelconque.
J'ai regarder un peu partout lcc, VC++, DEVC++. Heu.....

Comment puis-je ramener SetBkColor a la couleur de mon choix (disons blanc)
dans la section qui se trouve entre ;es deus lignes

=============

===============

Merci.

----------------------------------------------

/* Managing Text Output */

#include <windows.h>
#include <string.h>
#include <stdio.h>

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;

/* Make the window background white. SetBkColor(hdc, RGB(255, 0,
255));*/
wcl.hbrBackground = CreateSolidBrush(RGB(189, 168, 136 )); /* (HBRUSH)
(COLOR_GRAYTEXT+1); */
cColor = (int)((HBRUSH) (COLOR_WINDOW + 1));
/* Register the window class. */
if(!RegisterClassEx(&wcl)) return 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

2 réponses

Avatar
AMcD®
Jean Pierre Daviau wrote:
Bonjour à tous,

J'ai établi SetBkColor à TRANSPARENT mais ne puis plus la ramener à
une couleur quelconque.
J'ai regarder un peu partout lcc, VC++, DEVC++. Heu.....

Comment puis-je ramener SetBkColor a la couleur de mon choix (disons
blanc) dans la section qui se trouve entre ;es deus lignes



Je crains que tu ne confondes SetBkColor() et SetBkMode()...
OPAQUE/TRANSPARENT c'est pour SetBkMode().

De plus ces fonctions retournent des valeurs, qu'il te faut sauvegarder si
tu veux les réutiliser ensuite.

--
AMcD®

http://arnold.mcdonald.free.fr/
Avatar
Christian ASTOR
Jean Pierre Daviau wrote:

J'ai établi SetBkColor à TRANSPARENT mais ne puis plus la ramener à une
couleur quelconque.



SetBkColor(hdc, OPAQUE);



SetBkMode()