Case paint en dev c++

Signaler
Messages postés
1
Date d'inscription
samedi 27 décembre 2008
Statut
Membre
Dernière intervention
28 mars 2010
-
Messages postés
21042
Date d'inscription
jeudi 23 janvier 2003
Statut
Modérateur
Dernière intervention
21 août 2019
-
j'ai ce code dev c++ qui ne veut pas fonctionner:
#include <windows.h>
LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK MainWndProc (HWND h, UINT ms, WPARAM wp, LPARAM lp)
{
static BOOL rt;
static PAINTSTRUCT ps;
static HDC hdc = BeginPaint(h, &ps);
static HBRUSH hbRed, hbGreen;// hbrOld;
static HPEN hp2; //, hpOld;
//static HGDIOBJ hp2px;
static HGDIOBJ hpOld;
static HGDIOBJ hbrOld,NewFont,OldFont;
// static HFONT OldFont; ////NewFont,
static LOGFONT lf;

switch (ms) {
case WM_PAINT:
{

char st[] = "Bienvenue sur Developpez.com" ;


SetBkMode(hdc, TRANSPARENT);

TextOut(hdc, 10, 20, st, lstrlen(st));

Rectangle(hdc, 20, 60, 120, 100);

hp2 = CreatePen(PS_SOLID, 2, 0x00FF0000);
hpOld =SelectObject(hdc,hp2);

hbRed = CreateSolidBrush(0x000000FF);
hbrOld =SelectObject(hdc,hbRed);

Rectangle(hdc, 160, 60, 260, 100);

hbGreen = CreateHatchBrush(HS_DIAGCROSS, 0x0000BB00);
SelectObject(hdc,hbGreen);
DeleteObject(hbRed);

Ellipse(hdc, 300, 20, 400, 120);

MoveToEx(hdc, 20, 140, NULL);
LineTo(hdc, 400, 140);

SelectObject(hdc,hbrOld);
DeleteObject(hbGreen);

SelectObject(hdc,hpOld);
DeleteObject(hp2);

ZeroMemory(&lf, sizeof(LOGFONT));
lstrcpy(lf.lfFaceName,"Times New Roman");
lf.lfHeight = 36;
lf.lfItalic = TRUE;
lf.lfWeight = FW_BOLD;

NewFont = CreateFontIndirect(&lf);
OldFont = SelectObject(hdc,NewFont);

SetTextColor(hdc, 0x000000FF);
TextOut(hdc, 10, 180, st, lstrlen(st));

SelectObject(hdc,OldFont);
DeleteObject(NewFont);

EndPaint(h, &ps);
return 0;
}

case WM_DESTROY: PostQuitMessage (0); break;
default: return DefWindowProc (h, ms, wp, lp); }
return 0; }
int WINAPI WinMain (HINSTANCE h1,HINSTANCE h2,LPSTR l,int n)
{ HWND h; MSG m; WNDCLASSEX w;
w.hInstance = h1;
w.lpszClassName = "WindowsApp";
w.lpfnWndProc = MainWndProc;
w.style = CS_DBLCLKS;
w.cbSize = sizeof (WNDCLASSEX);
w.hIcon = LoadIcon (NULL, IDI_APPLICATION);
w.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
w.hCursor = LoadCursor (NULL, IDC_ARROW);
w.cbClsExtra = 0;
w.cbWndExtra = 0;
w.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
if (!RegisterClassEx (&w)) return 0;
h = CreateWindowEx (0,"WindowsApp","Windows App",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT, 544,375,HWND_DESKTOP,NULL,h1,NULL);
ShowWindow (h, n);
while (GetMessage (&m, NULL, 0, 0)){ TranslateMessage(&m); DispatchMessage(&m); }
return m.wParam; }


merci

1 réponse

Messages postés
21042
Date d'inscription
jeudi 23 janvier 2003
Statut
Modérateur
Dernière intervention
21 août 2019
24
static HDC hdc = BeginPaint(h, &ps);

NON, BeginPaint() nest valide que dans le message WM_PAINT.

ciao...
BruNews, MVP VC++