T
Thomas Barth
Hi,
I'm new to windows programming and still reading a book about
windows-programming with C++. I copied the following code from
the book into my ide (Eclipse/CDT) to comprehend the code, but
two errors occur.
In function `LRESULT WndProc(HWND__*, unsigned int, unsigned int, long int)':
line 48: error: invalid conversion from `void*' to `HBRUSH__*'
line 49: error: invalid conversion from `void*' to `HPEN__*'
<code>
#include <windows.h>
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow ) {
WNDCLASS WndClass;
WndClass.style = 0;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.lpfnWndProc = WndProc;
WndClass.hInstance = hInstance;
WndClass.hbrBackground = (HBRUSH) (COLOR_WINDOW+1);
WndClass.hCursor = LoadCursor (NULL, IDC_ARROW);
WndClass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
WndClass.lpszMenuName = 0;
WndClass.lpszClassName = "WinProg";
RegisterClass(&WndClass);
HWND hWindow;
hWindow = CreateWindow("WinProg","Fenster", WS_OVERLAPPEDWINDOW,
0,0,600,460,NULL,NULL, hInstance, NULL);
ShowWindow (hWindow, nCmdShow);
UpdateWindow (hWindow);
MSG Message;
while (GetMessage(&Message, NULL, 0, 0)) {
DispatchMessage(&Message);
}
return (Message.wParam);
}
LRESULT CALLBACK WndProc (HWND hWnd, UINT uiMessage,
WPARAM wParam,LPARAM lParam) {
switch(uiMessage) {
case WM_PAINT: HPEN hPen;
HPEN hPenalt;
HBRUSH hBrush;
HBRUSH hBrushalt;
hBrush = CreateSolidBrush (RGB(255,100,0));
hPen = CreatePen (PS_SOLID,2,RGB(0,255,255));
HDC hdc;
PAINTSTRUCT ps;
hdc = BeginPaint (hWnd, &ps);
hBrushalt = SelectObject (hdc, hBrush);
hPenalt = SelectObject (hdc, hPen);
MoveToEx (hdc, 20, 20, NULL);
LineTo (hdc, 100, 100);
Rectangle (hdc, 120, 20, 240, 140);
RoundRect (hdc, 260, 20, 420, 140, 20, 20);
RECT rect;
SetRect (&rect, 20, 260, 240, 420);
FrameRect (hdc, &rect, hBrush);
SetRect (&rect, 260, 260, 420, 420);
FillRect (hdc, &rect, hBrush);
Ellipse (hdc, 440, 260, 480, 420);
SelectObject (hdc, hBrushalt);
SelectObject (hdc, hPenalt);
DeleteObject (hPen);
DeleteObject (hBrush);
EndPaint (hWnd, &ps);
return 0;
case WM_DESTROY: PostQuitMessage(0);
return 0;
default: return DefWindowProc (hWnd, uiMessage, wParam, lParam);
}
}
</code>
Anyone who can help me out?
Thanks in advance,
Thomas B.
I'm new to windows programming and still reading a book about
windows-programming with C++. I copied the following code from
the book into my ide (Eclipse/CDT) to comprehend the code, but
two errors occur.
In function `LRESULT WndProc(HWND__*, unsigned int, unsigned int, long int)':
line 48: error: invalid conversion from `void*' to `HBRUSH__*'
line 49: error: invalid conversion from `void*' to `HPEN__*'
<code>
#include <windows.h>
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow ) {
WNDCLASS WndClass;
WndClass.style = 0;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.lpfnWndProc = WndProc;
WndClass.hInstance = hInstance;
WndClass.hbrBackground = (HBRUSH) (COLOR_WINDOW+1);
WndClass.hCursor = LoadCursor (NULL, IDC_ARROW);
WndClass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
WndClass.lpszMenuName = 0;
WndClass.lpszClassName = "WinProg";
RegisterClass(&WndClass);
HWND hWindow;
hWindow = CreateWindow("WinProg","Fenster", WS_OVERLAPPEDWINDOW,
0,0,600,460,NULL,NULL, hInstance, NULL);
ShowWindow (hWindow, nCmdShow);
UpdateWindow (hWindow);
MSG Message;
while (GetMessage(&Message, NULL, 0, 0)) {
DispatchMessage(&Message);
}
return (Message.wParam);
}
LRESULT CALLBACK WndProc (HWND hWnd, UINT uiMessage,
WPARAM wParam,LPARAM lParam) {
switch(uiMessage) {
case WM_PAINT: HPEN hPen;
HPEN hPenalt;
HBRUSH hBrush;
HBRUSH hBrushalt;
hBrush = CreateSolidBrush (RGB(255,100,0));
hPen = CreatePen (PS_SOLID,2,RGB(0,255,255));
HDC hdc;
PAINTSTRUCT ps;
hdc = BeginPaint (hWnd, &ps);
hBrushalt = SelectObject (hdc, hBrush);
hPenalt = SelectObject (hdc, hPen);
MoveToEx (hdc, 20, 20, NULL);
LineTo (hdc, 100, 100);
Rectangle (hdc, 120, 20, 240, 140);
RoundRect (hdc, 260, 20, 420, 140, 20, 20);
RECT rect;
SetRect (&rect, 20, 260, 240, 420);
FrameRect (hdc, &rect, hBrush);
SetRect (&rect, 260, 260, 420, 420);
FillRect (hdc, &rect, hBrush);
Ellipse (hdc, 440, 260, 480, 420);
SelectObject (hdc, hBrushalt);
SelectObject (hdc, hPenalt);
DeleteObject (hPen);
DeleteObject (hBrush);
EndPaint (hWnd, &ps);
return 0;
case WM_DESTROY: PostQuitMessage(0);
return 0;
default: return DefWindowProc (hWnd, uiMessage, wParam, lParam);
}
}
</code>
Anyone who can help me out?
Thanks in advance,
Thomas B.