Problem mit DC

paddymann

Mitglied
Hallo!
Ich schreib gerade an einem Programm mit dem man zeichnen kann. Hier mal mein Code:

Code:
#include <windows.h>
#include <string.h>


const char *CLASSNAME = "Draw", *WINNAME = "Zeichenprogramm";

LRESULT CALLBACK WndProc (HWND,UINT,WPARAM,LPARAM);

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, 
                   PSTR szCmdLine, int iCmdShow)
{
   MSG         msg;
   HWND        hWnd;
   WNDCLASS    wc;
   
   wc.cbClsExtra         = 0;
   wc.cbWndExtra         = 0;
   wc.hbrBackground      = (HBRUSH)GetStockObject(WHITE_BRUSH);
   wc.hCursor            = LoadCursor(NULL, IDC_ARROW);
   wc.hIcon              = LoadIcon(NULL, IDI_APPLICATION);
   wc.hInstance          = hInstance;
   wc.lpfnWndProc        = WndProc;
   wc.lpszClassName      = CLASSNAME;
   wc.lpszMenuName       = NULL;
   wc.style              = CS_VREDRAW | CS_HREDRAW;
   
   RegisterClass(&wc);
   
   hWnd = CreateWindow (CLASSNAME, WINNAME, WS_OVERLAPPEDWINDOW,
											CW_USEDEFAULT, CW_USEDEFAULT, 1024, 768,
											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)
{
        static POINT start;
        static POINT ende;
     
        switch(message)
        {
             case WM_LBUTTONDOWN:
                 HDC hDC = GetDC(hWnd);
                  {                                                                             
                        SetPixel(hDC, LOWORD(lParam), HIWORD(lParam), RGB(0, 0, 255));
                        ReleaseDC(hWnd,hDC);
                        short xp = LOWORD(lParam);
			            short yp = HIWORD(lParam);
			            MoveToEx(hDC, xp, yp, NULL);
                        return 0;
                  }
                  break;
                  
             case WM_MOUSEMOVE:
                  {
                         if(hDC)
                         {
                          short xp = LOWORD(lParam);
			              short yp = HIWORD(lParam);
			              LineTo(hDC, xp, yp);
                         }
                   }
                            
             case WM_DESTROY :
                  {
                         PostQuitMessage(0);
                         return 0;
                  }
                  break;
        }
        
return DefWindowProc(hWnd, message, wParam, lParam);
}

Eigentlich soll das Programm bis jetzt Punkte und Linien zeichnen, doch der Compiler gibt ne Fehlermeldung aus: jump to case label...crosses initialization of HDC__*hDC.
Wo ist der Fehler?
 
moin


Sorry, aber du hast nciht nur einen schlechten, sondern auch einen falschen Programmierstil.

So gehts:
Code:
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	static POINT start;
	static POINT ende;

	switch(message)
	{
	case WM_LBUTTONDOWN:
		{
			HDC hDC = GetDC(hWnd);
			{                                                                             
				SetPixel(hDC, LOWORD(lParam), HIWORD(lParam), RGB(0, 0, 255));
				short xp = LOWORD(lParam);
				short yp = HIWORD(lParam);
				MoveToEx(hDC, xp, yp, NULL);
			}
			ReleaseDC(hWnd,hDC);
			return 0;
		}

	case WM_MOUSEMOVE:
		{
			HDC hDC = GetDC(hWnd);
			if(hDC)
			{
				short xp = LOWORD(lParam);
				short yp = HIWORD(lParam);
				LineTo(hDC, xp, yp);
			}
			ReleaseDC(hWnd,hDC);

			return 0;
		}

	case WM_DESTROY :
		{
			PostQuitMessage(0);
			return 0;
		}
		break;
	}

	return DefWindowProc(hWnd, message, wParam, lParam);
}


mfg
umbrasaxum
 
Zurück