Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > C/C++: Системное программирование и WinAPI > Проблема с Контекстным меню для ListBox'a


Автор: Doc_d0s 15.1.2008, 00:20
Кусок кода где обрабатывается сообщение:
Код

case WM_CONTEXTMENU:
            wmId    = LOWORD(wParam); 
            wmEvent = HIWORD(wParam); 
            GetCursorPos(&pt);
            TrackPopupMenu(    GetSubMenu(ContextMenu, 0), 
                    TPM_RIGHTALIGN|TPM_RIGHTBUTTON, 
                    pt.x, 
                    pt.y, 
                    NULL, 
                    hWnd, 
                    NULL);
            nItem = SendMessage(hwndList, LB_ITEMFROMPOINT, 0, lParam);

            i = SendMessage(hwndList, LB_GETITEMDATA,nItem,0);
            
            SendMessage(hwndList,LB_SETCURSEL,i,0);
                        
            break;


так вот nItem возвращает 0x0001003 а это значит что на лист бокс координаты не попадают, варианта два, либо у меня галллюцинации с нарушением координации либо я чего то не допонимаю

Автор: dizzy1984 15.1.2008, 12:11
Цитата

WM_CONTEXTMENU Notification
...
The low-order word specifies the horizontal position of the cursor, in screen coordinates, at the time of the mouse click. 
The high-order word specifies the vertical position of the cursor, in screen coordinates, at the time of the mouse click. 


Цитата

LB_ITEMFROMPOINT Message
lParam
The low-order word specifies the x-coordinate of a point, relative to the upper-left corner of the client area of the list box. 
The high-order word specifies the y-coordinate of a point, relative to the upper-left corner of the client area of the list box.

Автор: Doc_d0s 15.1.2008, 17:04
Цитата(dizzy1984 @ 15.1.2008,  12:11)
Цитата

WM_CONTEXTMENU Notification
...
The low-order word specifies the horizontal position of the cursor, in screen coordinates, at the time of the mouse click. 
The high-order word specifies the vertical position of the cursor, in screen coordinates, at the time of the mouse click. 


Цитата

LB_ITEMFROMPOINT Message
lParam
The low-order word specifies the x-coordinate of a point, relative to the upper-left corner of the client area of the list box. 
The high-order word specifies the y-coordinate of a point, relative to the upper-left corner of the client area of the list box.

Я знаю английский, и целый вечер провел изучая МСДН, но все же если бы мне отписались кодом я бы понял гораздо лучше

Автор: dizzy1984 16.1.2008, 06:37
Сначала идея, потом код.
Я хотел сказать, что lparam от WM_CONTEXTMENU в координатах дисплея, а lparam для LB_ITEMFROMPOINT ждет его в координатах относительно левого врхнего угла листбокса. Соответственно где-то должен быть переход :
х_координита_в_границах_листбокса = х_координата_клика_на_экране - х_координата_левого_верхнего_угла_листбокса_на_экране
у_координита_в_границах_листбокса = у_координата_клика_на_экране - у_координата_левого_верхнего_угла_листбокса_на_экране

Автор: Doc_d0s 17.1.2008, 18:37
это я понял, только вот проблема в том что GetClientRect(GetDlgItem(hWnd,IDC_LRESULT), &rect)
возвращает rect у которого верхний левый угол стоит в (0,0)

Автор: dizzy1984 18.1.2008, 11:25
Попробуй GetWindowRect вместо этого.

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)