Article View: comp.os.os2.programmer
Article #2057Re: Receiving LN_ENTER with a LS_MULTIPLESEL listbox?
From: Carl+Chris Samos
Date: Wed, 14 Oct 1992 18:08
Date: Wed, 14 Oct 1992 18:08
77 lines
2903 bytes
2903 bytes
For those who are interested, here is my solution to the LN_ENTER
notification problem with a multiple selection listbox.
The problem was that I do not know the index of the item that was double
clicked in a multiple selection listbox. LM_QUERYSELECTION cannot be used
because it returns the first selected item, and then the next selected item.
My first idea was to keep track of the selection stated of all the items, and
when a double click occurred, check to see which one changed.
I settled on a different solution, however. I declare the listbox to have
the LBS_OWNERDRAW style, and I intercept the WM_MEASUREITEM and
WM_DRAWITEM messages. WM_MEASUREITEM is only sent once when the listbox is
created. WM_DRAWITEM is sent whenever an item needs to be drawn. I return
FALSE from this message so I don't actually have to draw the items, but
the second MPARAM that's passed in is a pointer to a OWNERITEM struct:
typedef struct _OWNERITEM {
HWND hwnd;
HPS hps;
USHORT fsState;
USHORT fsAttribute;
USHORT fsStateOld;
USHORT fsAttributeOld;
RECTL rclItem;
SHORT idItem;
ULONG hItem;
} OWNERITEM;
The idItem field is the position index of the item that needs to be drawn.
So I just keep a static int called nLastIndex in the dialog box function
that always keeps track of the last item drawn.
MRESULT EXPENTRY DialogBoxProc(HWND hWnd, unsigned message, MPARAM mp1,
MPRAM mp2)
{
static int nLastIndex;
switch (message) {
case WM_INITDLG:
nLastIndex = 0;
return(0);
break;
case WM_DRAWITEM:
if (SHORT1FROMMP(mParam1) == ID_LISTBOX) {
// store the position index of the item that is going to be drawn
nLastIndex = ((POWNERITEM) mp2) -> idItem;
}
return(FALSE);
break;
case WM_CONTROL:
if (SHORT1FROMMP(mp1) == ID_LISTBOX) {
if (SHORT2FROMMP(mp1) == LN_ENTER) {
// got the double click, so get the position index
nIndex = nLastIndex;
// now use nIndex in what ever way you need.
WinSendDlgItemMsg(hWnd, ID_LISTBOX, LM_QUERYITEMTEXT,
MPFROM2SHORT(nIndex, 256), MPFROMP(szBuffer));
return(0);
}
}
break;
}
return WinDefDlgProc(hWnd, message, mp1, mp2);
}
If anybody has any questions, feel free to ask.
-Carl Samos
cjs33278@uxa.cso.uiuc.edu
Technical Details
Message-ID:
<Bw4IEL.JHn@news.cso.uiuc.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!ogicse!uwm.edu!ux1.cso.uiuc.edu!news.cso.uiuc.edu!uxa.cso.uiuc.edu!cjs33278References:
<719058360.F00050@monly.wlink.nl.wlink.nl>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!ogicse!uwm.edu!ux1.cso.uiuc.edu!news.cso.uiuc.edu!uxa.cso.uiuc.edu!cjs33278 From: cjs33278@uxa.cso.uiuc.edu (Carl+Chris Samos) Newsgroups: comp.os.os2.programmer Subject: Re: Receiving LN_ENTER with a LS_MULTIPLESEL listbox? Message-ID: <Bw4IEL.JHn@news.cso.uiuc.edu> Date: 14 Oct 92 18:08:41 GMT Article-I.D.: news.Bw4IEL.JHn References: <719058360.F00050@monly.wlink.nl.wlink.nl> Sender: usenet@news.cso.uiuc.edu (Net Noise owner) Organization: University of Illinois at Urbana Lines: 77