|
|
|
date: Mon, 16 Jun 2008 15:08:52 -0700 (PDT),
group: microsoft.public.win32.programmer.ui
back
List View - Finding mouse position after getting focus
Hey all,
So I have created a listview window that I've set to report view, with
grids, like so:
VialGrid = CreateWindowEx(NULL, WC_LISTVIEW, "", WS_CHILD | WS_BORDER
| LVS_REPORT | LVS_EDITLABELS | LBS_NOTIFY, 5, 270, 530, 250,
MasterWindowHandle, (HMENU)ID_PDS_VIALGRID, Instance, NULL);
ListView_SetExtendedListViewStyle(VialGrid, LVS_EX_GRIDLINES);
Then, in my message handler, I have this:
case WM_NOTIFY:
{
lpnmh = (LPNMITEMACTIVATE)lParam;
if (wParam == (unsigned int)ID_PDS_VIALGRID)
{
pNM = (NM_LISTVIEW*)lParam;
if (pNM->hdr.code == NM_CLICK)
{
ss << lpnmh->ptAction.x << "," << lpnmh->ptAction.y;
ss << " " << lpnmh->iItem << "," << lpnmh->iSubItem;
OutputDebugString(ss.str().c_str());
}
if (pNM->hdr.code == NM_SETFOCUS)
{
ss << lpnmh->ptAction.x << "," << lpnmh->ptAction.y;
ss << " " << lpnmh->iItem << "," << lpnmh->iSubItem;
OutputDebugString(ss.str().c_str());
}
return 0;
}
return DefWindowProc(Wnd, Message, wParam, lParam);
}
The idea is I need to know, when the user clicks on the grid, where
they clicked, so that I can put up an edit box over the right grid
entry (the users will be typing in values into the grid, and as
ListViews don't seem to like that behavior, I'm going to simulate it
with an edit box superimposed over the grid). At the moment I have in
there some test strings that output to the debugger.
I get the data I need from NM_CLICK, it has a subitem that corresponds
to the column the user clicked in, and the x and y values are fine, so
I should be able to calculate where to put my edit box from that.
Fine.
The problem comes when the listview does not have focus. The
NM_SETFOCUS gives back garbage for x, y, item, and subitem in the
NMITEMACTIVATE structure. This does me no good, heh. The user is not
going to want to click twice on the grid before they can start typing
in data. They will want to click on the grid where they want to input
some numbers and expect to be able to do so. I therefore need to set
the focus on the grid (if it's not there) and then get the data I need
to set up the edit box, all in one click.
I thought about using a SendMessage in the NM_SETFOCUS routine to try
to simulate a LMB click after focus has been set, but I haven't had
any luck with it.
Any advice?
date: Mon, 16 Jun 2008 15:08:52 -0700 (PDT)
author: Ron Hiler
Re: List View - Finding mouse position after getting focus
If the only way to edit a cell in the grid is by clicking with the mouse you don't need to handle NM_SETFOCUS. The control should be getting NM_CLICK no matter if it has the focus prior to the click.
The reason that NM_SETFOCUS doesn't fill the x/y/item/subitem members is that it is not a mouse notification. You need to handle it if you want to support other ways (besides a click) to focus the control. One such way is to press Tab from the previous control. In that case I think the best solution is to remember the last edited cell and activate it on focus.
Ivo
"Ron Hiler" wrote in message news:65174318-bcee-468e-8d99-f307494101f3@i76g2000hsf.googlegroups.com...> Hey all,
>
> So I have created a listview window that I've set to report view, with
> grids, like so:
>
> VialGrid = CreateWindowEx(NULL, WC_LISTVIEW, "", WS_CHILD | WS_BORDER
> | LVS_REPORT | LVS_EDITLABELS | LBS_NOTIFY, 5, 270, 530, 250,
> MasterWindowHandle, (HMENU)ID_PDS_VIALGRID, Instance, NULL);
>
> ListView_SetExtendedListViewStyle(VialGrid, LVS_EX_GRIDLINES);
>
>
> Then, in my message handler, I have this:
>
> case WM_NOTIFY:
> {
> lpnmh = (LPNMITEMACTIVATE)lParam;
> if (wParam == (unsigned int)ID_PDS_VIALGRID)
> {
> pNM = (NM_LISTVIEW*)lParam;
> if (pNM->hdr.code == NM_CLICK)
> {
> ss << lpnmh->ptAction.x << "," << lpnmh->ptAction.y;
> ss << " " << lpnmh->iItem << "," << lpnmh->iSubItem;
> OutputDebugString(ss.str().c_str());
> }
> if (pNM->hdr.code == NM_SETFOCUS)
> {
> ss << lpnmh->ptAction.x << "," << lpnmh->ptAction.y;
> ss << " " << lpnmh->iItem << "," << lpnmh->iSubItem;
> OutputDebugString(ss.str().c_str());
> }
> return 0;
> }
> return DefWindowProc(Wnd, Message, wParam, lParam);
> }
>
> The idea is I need to know, when the user clicks on the grid, where
> they clicked, so that I can put up an edit box over the right grid
> entry (the users will be typing in values into the grid, and as
> ListViews don't seem to like that behavior, I'm going to simulate it
> with an edit box superimposed over the grid). At the moment I have in
> there some test strings that output to the debugger.
>
> I get the data I need from NM_CLICK, it has a subitem that corresponds
> to the column the user clicked in, and the x and y values are fine, so
> I should be able to calculate where to put my edit box from that.
> Fine.
>
> The problem comes when the listview does not have focus. The
> NM_SETFOCUS gives back garbage for x, y, item, and subitem in the
> NMITEMACTIVATE structure. This does me no good, heh. The user is not
> going to want to click twice on the grid before they can start typing
> in data. They will want to click on the grid where they want to input
> some numbers and expect to be able to do so. I therefore need to set
> the focus on the grid (if it's not there) and then get the data I need
> to set up the edit box, all in one click.
>
> I thought about using a SendMessage in the NM_SETFOCUS routine to try
> to simulate a LMB click after focus has been set, but I haven't had
> any luck with it.
>
> Any advice?
>
date: Mon, 16 Jun 2008 22:06:29 -0700
author: Ivo Beltchev ivo _@_ roadrunner _ com
Re: List View - Finding mouse position after getting focus
On Jun 16, 10:06 pm, "Ivo Beltchev" <ivo _@_ roadrunner _ com> wrote:
> If the only way to edit a cell in the grid is by clicking with the mouse you don't need to handle NM_SETFOCUS. The control should be getting NM_CLICK no matter if it has the focus prior to the click.
Unfortunately, no, it doesn't. It will not get a NM_CLICK unless it
already has focus. I've confirmed this with DebugOutputs.
My latest attempt, but it's not working either, for some reason.
Haven't yet put much debugging time into it though, so I may just be
missing something silly:
if (pNM->hdr.code == NM_SETFOCUS)
{
GetCursorPos(&pt);
ScreenToClient(ControlWindow.GetHandle(), &pt);
HitTestInfo.pt.x = pt.x;
HitTestInfo.pt.y = pt.y;
ListView_HitTest(VialGrid, &HitTestInfo);
ss << HitTestInfo.iItem << "," << HitTestInfo.iSubItem;
OutputDebugString(ss.str().c_str());
}
date: Tue, 17 Jun 2008 07:38:20 -0700 (PDT)
author: Ron Hiler
Re: List View - Finding mouse position after getting focus
I suggest you check again - it definitely should be getting NM_CLICK whether
it has focus or not.
"Ron Hiler" wrote in message
news:a5c7014d-ad22-45c3-9f0e-a5c29b46c46b@w7g2000hsa.googlegroups.com...
On Jun 16, 10:06 pm, "Ivo Beltchev" <ivo _@_ roadrunner _ com> wrote:
> If the only way to edit a cell in the grid is by clicking with the mouse
> you don't need to handle NM_SETFOCUS. The control should be getting
> NM_CLICK no matter if it has the focus prior to the click.
Unfortunately, no, it doesn't. It will not get a NM_CLICK unless it
already has focus. I've confirmed this with DebugOutputs.
My latest attempt, but it's not working either, for some reason.
Haven't yet put much debugging time into it though, so I may just be
missing something silly:
if (pNM->hdr.code == NM_SETFOCUS)
{
GetCursorPos(&pt);
ScreenToClient(ControlWindow.GetHandle(), &pt);
HitTestInfo.pt.x = pt.x;
HitTestInfo.pt.y = pt.y;
ListView_HitTest(VialGrid, &HitTestInfo);
ss << HitTestInfo.iItem << "," << HitTestInfo.iSubItem;
OutputDebugString(ss.str().c_str());
}
date: Thu, 19 Jun 2008 07:39:10 +1000
author: Jon Potter am
Re: List View - Finding mouse position after getting focus
On Jun 18, 2:39 pm, "Jon Potter" <gps...@nospam.nospam> wrote:
> I suggest you check again - it definitely should be getting NM_CLICK whether
> it has focus or not.
>
<shrug> I have given you my code. Very clearly the lines:
if (pNM->hdr.code == NM_CLICK)
{
ss << lpnmh->ptAction.x << "," << lpnmh-
>ptAction.y;
ss << " " << lpnmh->iItem << "," << lpnmh-
>iSubItem;
OutputDebugString(ss.str().c_str());
}
will give output if the control sends a NM_CLICK notification (through
the WM_NOTIFY message). This output is recieved in my debugger when
the control has focus and is clicked on. It is NOT recieved when it
does not have focus (e.g. an edit box is active) and is clicked on (it
DOES send a NM_SETFOCUS notification, I get that DebugOutput, but NOT
the NM_CLICK DebugOutput, unless I click on it again after it has
focus). I don't know how to make it any more clear. Run the code
yourself if you don't believe me.
In any event, I got it working. In the last code fragment, I
substituted ListView_SubItemHitTest for ListView_HitTest and now I
have all the same information I get from the NM_CLICK, so all is good.
date: Thu, 19 Jun 2008 15:39:40 -0700 (PDT)
author: Ron Hiler
|
|