Right click on listbox?

Started by
6 comments, last by nivlekio 16 years, 1 month ago
Hey all im trying to right click on a listbox and have a menu pop. But for some strange reason windows does not detect a right click on a listbox or edit control, I tried putting the popup menu code in the WM_RBUTTONUP message switch case it only detected if i did not right click on a listbox or editcontrol. I then tried making an array then doing the old WM_KEYDOWN and WM_KEYUP and again it does not get detected if i click on a list box. how do u detect a right click on a list box? btw im not using mfc
Advertisement
AFAIK a ListBox doesn't provide you with notifications for a right-click. You may have to subclass the window, and handle the WM_RBUTTONDOWN message yourself.
I got it to work i used GetAsyncKeyState(VK_RBUTTON) it detects the mouse right click any where even on a list box :).

Erm is it possible to get the dimentions and position of a list box during runtime? also change its position?
You can use GetWindowRect to retrieve the listbox's (or any HWNDs) position and size in screen coordinates.
If you only need the inner size you use GetClientRect (these coordinates are relative to the inner rect, so you basically only get the size).
You can use SetWindowPos to move/resize a HWND.

Using GetAsyncKeyState sounds like a weird way, since you'll have to keep polling all the time.

Like MJP said, you'd be better off subclassing the control and watch for WM_RBUTTONDOWN.
If you're using MFC you can use PreTranslateMessage (inbuilt subclassing for you).

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

Yeah subclassing is a much better idea in this case, polling is a waste of of CPU time. No need to do something Windows already does for you (hit detection with mouse clicks). To subclass a window in Win32, you need to use SetWindowLongPtr to set the ListBox's WindowProc to your new window procedure. When you set this, also store the return value because it is a pseudo-pointer to the ListBox's actual window procedure (it's not actually a function pointer for complicated reasons). So then what you do is in your new window procedure you check for WM_RBUTTONDOWN, and in every other case you pass on the message to the real window procedure using CallWindowProc.
kool thanks guys for the info, ill look in to subclassing at some point what is polling btw?
Polling is repeatedly asking the computer for information. The computer doesn't get to rest and relax when you poll, it gets tired, and then takes it out on the user in the form of performance problems.

ah k cool, i think i commit that crime quite a bit in my program's hehe

This topic is closed to new replies.

Advertisement