Hi, I have got a problem with changing color of the pen...
Can someone analyse what is wrong in the source
Compiler sais that problem is on line which is highlighted...
Crosses initialization of 'struct HPEN__ * hBluePen'
Dev-c++
Code:
#include <windows.h>
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
TCHAR szAppName[] = TEXT("Default window"); // Header
HWND hWnd;
MSG msg;
WNDCLASSEX wc;
wc.cbSize = sizeof(wc);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); // Ico
wc.hIconSm = NULL; // Ico_sm
wc.hCursor = (HCURSOR)LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+0); // Background
wc.lpszMenuName = "WMENU";
wc.lpszClassName = szAppName;
RegisterClassEx(&wc);
hWnd = CreateWindowEx(0,szAppName,
szAppName,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, // Margin from left
CW_USEDEFAULT, // Margin from top
CW_USEDEFAULT, // Widht
CW_USEDEFAULT, // Height
NULL,
NULL,
hInstance,NULL);
ShowWindow(hWnd, iCmdShow);
UpdateWindow(hWnd);
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hDC;
PAINTSTRUCT ps;
HPEN hPen = CreatePen(PS_SOLID, 1, RGB(0,0,255));
switch(message)
{
case WM_PAINT:
HPEN hBluePen = SelectObject(hDC, hBluePen);
hDC = BeginPaint(hWnd, &ps);
TextOut(hDC, 50, 50, TEXT("ahoj"), 5);
EndPaint(hWnd, &ps);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
Thx for help