Zeichnen
-
Ich will bei mit der linken mouse taste zeichnen an iner form. Den code habe ich mir von msdn geholt. Aber nicht geschieht!
Warum?
Danke
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int wmId, wmEvent; HDC hdc; BOOL fDraw = FALSE; POINT ptPrevious; PAINTSTRUCT ps; switch (message) { case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // Parse the menu selections: switch (wmId) { case IDM_ABOUT: DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About); break; case IDM_EXIT: DestroyWindow(hWnd); break; case WM_LBUTTONDOWN: fDraw = TRUE; ptPrevious.x = LOWORD(lParam); ptPrevious.y = HIWORD(lParam); return 0L; case WM_LBUTTONUP: if (fDraw) { hdc = GetDC(hWnd); MoveToEx(hdc, ptPrevious.x, ptPrevious.y, NULL); LineTo(hdc, LOWORD(lParam), HIWORD(lParam)); ReleaseDC(hWnd, hdc); } fDraw = FALSE; return 0L; case WM_MOUSEMOVE: if (fDraw) { hdc = GetDC(hWnd); MoveToEx(hdc, ptPrevious.x, ptPrevious.y, NULL); LineTo(hdc, ptPrevious.x = LOWORD(lParam), ptPrevious.y = HIWORD(lParam)); ReleaseDC(hWnd, hdc); } return 0L; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); // TODO: Add any drawing code here... EndPaint(hWnd, &ps); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
-
Nichts geschieht heisst das program startet aber keine linien erscheninen!
Danke
-
Hast versehentlich einen ganzen Block an die falsche Stelle gepastet.
"case WM_LBUTTONDOWN", "case WM_LBUTTONUP" und "case WM_MOUSEMOVE" stecken in der "switch (wmId)" von "case WM_COMMAND".
Sie sollten aber sein in der "switch (message)".

-
Das habe ich auch gemerkt, aber erst nach dem posten!
Hab es jetzt veraendert, aber es nutzt nichts. Ich kenn mich da sehr schlect aus aber ist es moeglich das ich die farbe irgendwie aendern muss?
Danke
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; BOOL fDraw = FALSE; POINT ptPrevious; switch (message) { case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // Parse the menu selections: switch (wmId) { case IDM_\1: DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About); break; case IDM_EXIT: DestroyWindow(hWnd); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); // TODO: Add any drawing code here... EndPaint(hWnd, &ps); break; case WM_DESTROY: PostQuitMessage(0); break; case WM_LBUTTONDOWN: fDraw = TRUE; ptPrevious.x = LOWORD(lParam); ptPrevious.y = HIWORD(lParam); return 0L; case WM_LBUTTONUP: if (fDraw) { hdc = GetDC(hWnd); MoveToEx(hdc, ptPrevious.x, ptPrevious.y, NULL); LineTo(hdc, LOWORD(lParam), HIWORD(lParam)); ReleaseDC(hWnd, hdc); } fDraw = FALSE; return 0L; case WM_MOUSEMOVE: if (fDraw) { hdc = GetDC(hWnd); MoveToEx(hdc, ptPrevious.x, ptPrevious.y, NULL); LineTo(hdc, ptPrevious.x = LOWORD(lParam), ptPrevious.y = HIWORD(lParam)); ReleaseDC(hWnd, hdc); } return 0L; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
-
"fDraw" und "ptPrevious" sollten entweder statisch oder global deklariert sein damit sie ihre Werte halten können wenn die "WinProc" verlassen wird.
Probier mal so :
// BOOL fDraw = FALSE; static BOOL fDraw = FALSE; // POINT ptPrevious; static POINT ptPrevious;