API

yhaim

New member
API

כתבתי תוכנית שבלחיצה על הכפתור השמאלי בעכבר מציירת ריבוע על המסך. לחיצה כפולה על העכבר במקום שיש כבר ריבוע צובעת את אותו ריבוע בצבע רנדומלי. אם לחצתי פעמיים במקום שאין ריבוע לא קורה כלום. משום מה התוכנית לא מזהה דאבל קליק ורק החלק הראשון של התוכנית עובד.
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc ; PAINTSTRUCT ps ; HBRUSH hbr; int x,y; #define NUM_OF_RECT 30; static RECT arr[30]; static int curr_ind=-1; static int selected_rect=0; int i; switch (message) { case WM_LBUTTONUP: selected_rect=-1; x=LOWORD(lParam); y=HIWORD(lParam); SetRect(&arr[curr_ind],x,y,x+50,y+50); curr_ind++; InvalidateRect (hwnd, NULL, FALSE) ; return 0; case WM_LBUTTONDBLCLK: x=LOWORD(lParam); y=HIWORD(lParam); for(i=0;i<30;i++) if(x>=arr.left && x<=arr.right && y>=arr.top && y<=arr.bottom) { selected_rect=i; InvalidateRect (hwnd, NULL, FALSE) ; break; } return 0; case WM_PAINT: hdc = BeginPaint (hwnd, &ps) ; if(selected_rect<0) { hbr=CreateSolidBrush(RGB(0,0,255)); FillRect(hdc,&arr[curr_ind-1],hbr); } else { hbr=CreateSolidBrush(RGB(rand()%255,rand()%255,rand()%255)); FillRect(hdc,&arr[selected_rect],hbr); } EndPaint (hwnd, &ps) ; return 0 ; case WM_DESTROY: PostQuitMessage (0) ; return 0 ; } return DefWindowProc (hwnd, message, wParam, lParam) ; }

האם למישהו יש רעיון?
 
למעלה