minhlap Admin - Quản trị viên
Tổng số bài gửi : 129 Points : 374 Reputation : 5 Join date : 22/07/2009 Age : 34 Đến từ : TP Hồ Chí Minh
| Tiêu đề: Draw Marker Wed Mar 17, 2010 8:33 am | |
| - Code:
-
#define MAX_MARKERS 100 int tsize=5; int tang=2; int color=0; void DrawMarker(HDC hdc, POINT pt, int size); LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
PAINTSTRUCT ps; HDC hdc; TCHAR szHello[MAX_LOADSTRING]; LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING); int i; static POINT apt[MAX_MARKERS]; static int nMarkers=0;
switch (message) { case WM_LBUTTONDOWN: if(nMarkers <= MAX_MARKERS) { apt[nMarkers].x = LOWORD(lParam); apt[nMarkers].y = HIWORD(lParam); nMarkers++; } InvalidateRect(hWnd, NULL, TRUE); break;
case WM_RBUTTONDOWN: nMarkers=0; InvalidateRect(hWnd, NULL, TRUE); break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); // TODO: Add any drawing code here... for(i=0 ; i < nMarkers ; i++) DrawMarker(hdc, apt[i], tsize); RECT rt; GetClientRect(hWnd, &rt); wsprintf(szHello,"So marker: %d",nMarkers);
DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER); EndPaint(hWnd, &ps); break;
case WM_DESTROY: PostQuitMessage(0); break; case WM_CHAR: switch(wParam) { case '+': if(tsize >100 || tsize <0) tang =- tang; tsize +=tang; InvalidateRect(hWnd, NULL, TRUE); break; case '-':
if(tsize >100 || tsize <0) tang =- tang; tsize -=tang; InvalidateRect(hWnd, NULL, TRUE); break; case 'a': if(color<255) color+=100; else color=0; InvalidateRect(hWnd, NULL, TRUE); break; } default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; } void InvertPixel(HDC hdc, int x, int y) { COLORREF crColor = GetPixel(hdc, x, y); SetPixel(hdc, x, y, RGB(255, color ,255)); } void DrawMarkervuong(HDC hdc, POINT pt, int size) { int i, x=pt.x, y=pt.y; InvertPixel(hdc, x, y); for (i=1 ; i<= size; i++) { InvertPixel(hdc, x + i, y + size); InvertPixel(hdc, x + i, y); InvertPixel(hdc, x + size , y + i); InvertPixel(hdc, x , y + i); } }
void DrawMarkernhan(HDC hdc, POINT pt, int size) { int i, x=pt.x, y=pt.y; InvertPixel(hdc, x, y); for (i=1 ; i<= size; i++) { InvertPixel(hdc, x + i, y + i); InvertPixel(hdc, x - i, y - i); InvertPixel(hdc, x - i , y + i); InvertPixel(hdc, x +i , y - i); } } void DrawMarker(HDC hdc, POINT pt, int size) { int i, x=pt.x, y=pt.y; double xc,yc; InvertPixel(hdc, x, y); for (i=0 ; i<= 360; i++) { xc = (double)size*cos(i); yc = (double)size*sin(i); InvertPixel(hdc, (int)x+xc , (int)y + yc); } } | |
|