grafik
-
#include <windows.h> #include <iostream> #include <stdio.h> LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { MSG msg; HWND hWnd; WNDCLASS wc; char szAppName[] = "Geometrie"; 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 = szAppName; wc.lpszMenuName = NULL; wc.style = CS_VREDRAW | CS_HREDRAW; RegisterClass(&wc); hWnd = CreateWindow( szAppName, szAppName, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 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[50]; static POINT ende[50]; static POINT position; int anzahl=0; switch (message) { case WM_CREATE: { for(int i=0; i<50; i++) { start[i].x = -1; start[i].y = -1; ende[i].x = -1; ende[i].y = -1; } return 0; } case WM_LBUTTONDOWN: { anzahl++; start[anzahl].x = LOWORD(lParam); start[anzahl].y = HIWORD(lParam); return 0; } case WM_MOUSEMOVE: { position.x = LOWORD(lParam); position.y = HIWORD(lParam); if (wParam & MK_LBUTTON) { ende[anzahl].x = LOWORD(lParam); ende[anzahl].y = HIWORD(lParam); InvalidateRect(hWnd, NULL, TRUE); } return 0; } case WM_PAINT: { PAINTSTRUCT ps; HDC hDC; const char szText[] = "raleigh"; hDC = BeginPaint(hWnd, &ps); { Rectangle(hDC, start[anzahl].x, start[anzahl].y, ende[anzahl].x, ende[anzahl].y); TextOut(hDC, 50, 50, szText, sizeof(szText) - 1); } EndPaint(hWnd, &ps); return 0; } case WM_DESTROY: { PostQuitMessage(0); return 0; } } return DefWindowProc(hWnd, message, wParam, lParam); }hi leute!! wie kann ich machen das die kordinaten bei zeichen angezeigt werden da beim rechteck?? ich will das alte rechteck nicht verschwindet wenn ich ein neues mache!!!!! wie geht das?? cu
-
Super deutsch! Wo hast du das gelernt?
-
#include <windows.h> #include <iostream> #include <stdio.h> #include <string> #include <sstream> using namespace std; stringstream koord_x; LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { MSG msg; HWND hWnd; WNDCLASS wc; char szAppName[] = "Geometrie"; 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 = szAppName; wc.lpszMenuName = NULL; wc.style = CS_VREDRAW | CS_HREDRAW; RegisterClass(&wc); hWnd = CreateWindow( szAppName, szAppName, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 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[50]; static POINT ende[50]; static POINT position; int anzahl=0; switch (message) { case WM_CREATE: { for(int i=0; i<50; i++) { start[i].x = -1; start[i].y = -1; ende[i].x = -1; ende[i].y = -1; } return 0; } case WM_LBUTTONDOWN: { anzahl++; start[anzahl].x = LOWORD(lParam); start[anzahl].y = HIWORD(lParam); return 0; } case WM_MOUSEMOVE: { position.x = LOWORD(lParam); position.y = HIWORD(lParam); // Koordinate x für Ausgabe koord_x << position.x; koord_x.str(); if (wParam & MK_LBUTTON) { ende[anzahl].x = LOWORD(lParam); ende[anzahl].y = HIWORD(lParam); InvalidateRect(hWnd, NULL, TRUE); } return 0; } case WM_PAINT: { PAINTSTRUCT ps; HDC hDC; const char *szText = koord_x.str().c_str(); //"raleigh"; hDC = BeginPaint(hWnd, &ps); { Rectangle(hDC, start[anzahl].x, start[anzahl].y, ende[anzahl].x, ende[anzahl].y); // Koordinate x ausgeben TextOut(hDC, 50, 50, szText, sizeof(szText)-1); } EndPaint(hWnd, &ps); return 0; } case WM_DESTROY: { PostQuitMessage(0); return 0; } } return DefWindowProc(hWnd, message, wParam, lParam); }da klappt mit static POINT position was nicht!! ausgabe von x koordinate ins testfeld there..
sorry to webfritzi ich wohnen noch nicht lange in deutschlad!
cu
-
1.) Nimm für das TextOut mal lstrlen anstelle von sizeof(szText)-1
2.) in WM_LBUTTONDOWN solltest du für anzahl noch eine Bereichsüberprüfung machen
3.) Wegen dem Zeichen könntest du zuerst mal in WM_MOUSEMOVE bei InvalidateRect für den letzten Parameter FALSE einsetzen. Aber da der Fensterinhalt z.B. nach Überlagerung durch ein anderes Fenster eh komplett neugezeichnet werden muss, müsstest du in WM_PAINT eigentlich immer alle Rechtecke neu zeichnen. Da es dann aber zu Flackern kommt (und dies geschwindigkeitstechnisch nicht besonders effizient ist) solltest du mal über DoubleBuffering (-> Forensuche) nachdenken
-
[quote="flenders"]1.) Nimm für das TextOut mal lstrlen anstelle von sizeof(szText)-1 quote]
hi!!
ich kann nun rechteck neu zeichnen aber die x koordinatet wird auch mit strlen nicht richtige anezeicht! kommt nur: YYYYYYYYYYYYYY mit einen haken oben!!???
versteh nicht!source:
#include <windows.h> #include <iostream> #include <stdio.h> #include <string> #include <sstream> using namespace std; stringstream koord_x; LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { MSG msg; HWND hWnd; WNDCLASS wc; char szAppName[] = "Geometrie"; 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 = szAppName; wc.lpszMenuName = NULL; wc.style = CS_VREDRAW | CS_HREDRAW; RegisterClass(&wc); hWnd = CreateWindow( szAppName, szAppName, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 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[50]; static POINT ende[50]; static POINT position; int anzahl=0; switch (message) { case WM_CREATE: { for(int i=0; i<50; i++) { start[i].x = -1; start[i].y = -1; ende[i].x = -1; ende[i].y = -1; } return 0; } case WM_LBUTTONDOWN: { start[anzahl].x = LOWORD(lParam); start[anzahl].y = HIWORD(lParam); return 0; } case WM_MOUSEMOVE: { position.x = LOWORD(lParam); position.y = HIWORD(lParam); // Koordinate x für Ausgabe koord_x << position.x; koord_x.str(); if (wParam & MK_LBUTTON) { ende[anzahl].x = LOWORD(lParam); ende[anzahl].y = HIWORD(lParam); InvalidateRect(hWnd, NULL, TRUE); } return 0; } case WM_PAINT: { PAINTSTRUCT ps; HDC hDC; const char *szText = koord_x.str().c_str(); //"raleigh"; hDC = BeginPaint(hWnd, &ps); { Rectangle(hDC, start[anzahl].x, start[anzahl].y, ende[anzahl].x, ende[anzahl].y); anzahl++; // Koordinate x ausgeben TextOut(hDC, 50, 50, szText, (strlen(szText)-1)); } EndPaint(hWnd, &ps); return 0; } case WM_DESTROY: { PostQuitMessage(0); return 0; } } return DefWindowProc(hWnd, message, wParam, lParam); }
-
Ich nehme an, der Fehler liegt dann bei koord_x.str().c_str(); - aber da kenne ich mich nicht mehr so besonders aus

Lass dir den Wert mal zum Test in einer Message-Box ausgeben
-
der fehler lieg da:
const char *szText = koord_x.str().c_str();koord_x.str().c_str() hat noch einen zahlen wert....aber dann ist szText nur mehr YYYY.....komisch!!
cu
-
Heißt das, dass es funktioniert, wenn du direkt koord_x.str().c_str(); einsetzt

-
schau mal:
stringstream koord_x; stringstream koord_y; // [...] case WM_PAINT: { PAINTSTRUCT ps; HDC hDC; hDC = BeginPaint(hWnd, &ps); { Rectangle(hDC, start[anzahl].x, start[anzahl].y, ende[anzahl].x, ende[anzahl].y); anzahl++; // Koordinate x ausgeben TextOut(hDC, 50, 50, koord_x.str().c_str(), (sizeof(koord_x.str().c_str())-1)); // Koordinate y ausgeben TextOut(hDC, 80, 50, koord_y.str().c_str(), (sizeof(koord_y.str().c_str())-1)); } EndPaint(hWnd, &ps); return 0; }son funktioniert es....aber wenn ich das mit const char* mache dann nicht......versteh das nicht!!!??? *gg*
cu
edit by flenders: habe den Code mal gekürzt - es ist wirklich überflüssig immer wieder den ganzen Code zu posten

-
Warum speicherst du das eigentlich in einem stringstream und nicht direkt in einem String oder int, den du dann mit wsprintf óder itoa in einen String umwandelst?