CreatePen!



  • Hi!
    Ich habe ein Programm geschrieben,das einene Zeichenstift definiert.
    Aber ich bekomme immer diese Fehlermeldung:
    C:\Programme\Microsoft Visual Studio\MyProjects\ff\df.cpp(75) : error C2440: '=' : 'void *' kann nicht in 'struct HPEN__ ' konvertiert werden
    Konvertierung von 'void
    ' in Zeiger auf nicht-'void' erfordert eine explizite Typumwandlung
    Hier der Code:

    #include <windows.h>
    #include <math.h>
    
    LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
    {
    	TCHAR szAppName[] = TEXT("HELLOWINXP");
    	HWND hwnd;
    	MSG msg;
    	WNDCLASS wndclass;
    
    	wndclass.style = CS_HREDRAW | CS_VREDRAW;
    	wndclass.lpfnWndProc = WndProc;
    	wndclass.cbClsExtra = 0;
    	wndclass.cbWndExtra = 0;
    	wndclass.hInstance = hInstance;
    	wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
    	wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    	wndclass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
    	wndclass.lpszClassName = szAppName;
    	wndclass.lpszMenuName = 0;
    
    	RegisterClass(&wndclass);
    
    	hwnd = CreateWindow(szAppName,
    		TEXT("Zeichenoperationen"),
    		WS_OVERLAPPEDWINDOW,
    		CW_USEDEFAULT,
    		CW_USEDEFAULT,
            CW_USEDEFAULT,
    		CW_USEDEFAULT,
    		NULL,
    		NULL,
    		hInstance,
    		NULL);
    
    	ShowWindow(hwnd, nShowCmd);
    	UpdateWindow(hwnd);
    
    	while(GetMessage(&msg, 0, NULL, NULL)) {
    		TranslateMessage(&msg);
            DispatchMessage(&msg);
    	}
    	return msg.wParam;
    }
    
    LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    	static int cxClient, cyClient;
    	PAINTSTRUCT ps;
    	HDC hdc;
    	static HPEN hPen;
    
    	switch(message)
    	{
    	case WM_SIZE:
    		cxClient = LOWORD(lParam);
    		cyClient = HIWORD(lParam);
    		return 0;
    
    	case WM_PAINT:
    		hdc = BeginPaint(hwnd, &ps);
    
    		hPen = SelectObject(hdc, CreatePen(PS_SOLID, 3, RGB(255, 0, 0)));
    
            Rectangle(hdc, cxClient/8, cyClient/8, cxClient/8 *7, cyClient/8 *7);
    		MoveToEx(hdc, 0 , 0, NULL);
    		LineTo(hdc, cxClient, cyClient);
    
    		MoveToEx(hdc, cxClient, 0, NULL);
    		LineTo(hdc, 0, cyClient);
    
    		Ellipse(hdc, cxClient/8, cyClient/8, cxClient/8*7, cyClient/8*7);
    		RoundRect(hdc, cxClient/4, cyClient/4, cxClient/4*3, cyClient/4*3, cxClient/4, cyClient/4);
    		TextOut(hdc, cxClient/2, cyClient/2, TEXT("Ich finde mich toll"), lstrlen("Ich finde mich toll"));
    
    		DeleteObject(SelectObject(hdc, hPen));
    
    		EndPaint(hwnd, &ps);
    		return 0;
    
    	case WM_DESTROY:
    		PostQuitMessage(0);
    		return 0;
    	}
    	return DefWindowProc(hwnd, message, wParam, lParam);
    }
    


  • ich würde mal sagen statt

    hPen = SelectObject(hdc, CreatePen(PS_SOLID, 3, RGB(255, 0, 0)));

    muß es heißen

    hPen = CreatePen(PS_SOLID, 3, RGB(255, 0, 0));
    SelectObject(hdc, hPen);



  • im Petzold steh aber,das es eigentlich auch so gehen müsste!
    Habe noch ein Problem!

    HBRUSH hBrush;
    
    hBrush = GetStockObject(GRAY_BRUSH);
    SelectObject(hdc, hBrush);
    

    Und da kommt jetzt wieder die gleiche Fehermeldung!



  • GetStockObject auf HBRUSH casten.



  • Thanks!Funzt jetzt!


Anmelden zum Antworten