מה הבעיה בקוד?

yhaim

New member
מה הבעיה בקוד?

כתבתי תוכנית שבלחיצה על הכפתור השמאלי בעכבר מציירת ריבוע על המסך. לחיצה כפולה על העכבר במקום שיש כבר ריבוע צובעת את אותו ריבוע בצבע רנדומלי. אם לחצתי פעמיים במקום שאין ריבוע לא קורה כלום. משום מה התוכנית לא מזהה דאבל קליק ורק החלק הראשון של התוכנית עובד.
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) ; } האם למישהו יש רעיון?
 

selalerer

New member
נתחיל בזה שהוא ארוך מידיי.

באופן כללי, כדאי שתמקד את השאלה שלך יותר. ולנושא עצמו, שים MessageBoxים בתוך האירוע, תראה דבר ראשון אם הוא מתרחש כלל, לאחר מיכן תבדוק מה יש לך בX ובY שקיבלת, ואם זה מה שאתה מצפה לקבל, אח"כ תבדוק אם הוא נכנס לif ואם כן מה הנתונים של הריבוע בזמן שהוא נכנס לif וכו'... בקיצור, תדבאג! בהצלחה.
 
למעלה