Jump to content

WinQueryLboxItemText

From EDM2
Revision as of 17:35, 9 April 2025 by Martini (talk | contribs) (Created page with "This macro fills the buffer with the text of the indexed item. It returns the length of the text. ==Syntax==  WinQueryLboxItemText(hwndLbox, index, psz, cchMax) ==Parameters== ;hwndLbox (HWND) - Input : List box handle. ;index (SHORT) - Input : Index of the listbox item. ;psz (PSZ) - Input : Pointer to a null terminated string. ;cchMax (SHORT) - Input : Maximum number of characters allocated to the string. ;lRetTxtL (LONG) - returns :Actual text le...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This macro fills the buffer with the text of the indexed item. It returns the length of the text.

Syntax

 WinQueryLboxItemText(hwndLbox, index, psz, cchMax)

Parameters

hwndLbox (HWND) - Input
List box handle.
index (SHORT) - Input
Index of the listbox item.
psz (PSZ) - Input
Pointer to a null terminated string.
cchMax (SHORT) - Input
Maximum number of characters allocated to the string.
lRetTxtL (LONG) - returns
Actual text length copied.

Remarks

This macro is defined as&colon.

#define WinQueryLboxItemText(hwndLbox, index, psz, cchMax)  \
        ((LONG)WinSendMsg(hwndLbox,                         \
                          LM_QUERYITEMTEXT,                 \
                          MPFROM2SHORT((index), (cchMax)),  \
                          MPFROMP(psz)))

This macro requires the existence of a message queue.

Example Code

#define INCL_WINWINDOWMGR /* Or use INCL_WIN, INCL_PM, */
#include <os2.h>

HWND     hwndLbox;  /*  List box handle. */
SHORT    index;     /*  Index of the listbox item. */
PSZ      psz;       /*  Pointer to a null terminated string. */
SHORT    cchMax;    /*  Maximum number of characters allocated to the string. */
LONG     lRetTxtL;  /*  Actual text length copied. */

lRetTxtL = WinQueryLboxItemText(hwndLbox,
             index, psz, cchMax);

This example uses WinQueryLboxItemText to copy all of the list box items into a buffer.

#define INCL_WINLISTBOXES
#define INCL_WINWINDOWMGR
#include <OS2.H>

LONG  cWindows;
char *szTemp;
HWND hwndLB;
SHORT maxchar, index = 0;

cWindows = WinQueryLboxCount(hwndLB);

/* allocate a buffer for cWindows items. */

DosAllocMem((PPVOID)&szTemp,
            (ULONG)cWindows*256*sizeof(char),
             PAG_READ |
             PAG_WRITE |
             PAG_COMMIT);

/* loop through all of the items;  copying each */
/* one the buffer.                              */

while (index <= cWindows)
{
   maxchar = WinQueryLboxItemTextLength(hwndLB,index);
   WinQueryLboxItemText(hwndLB,
                       index++,
                       szTemp,
                       maxchar);
   szTemp+=maxchar; /* increment pointer by number */
                                    /* of bytes copied. */
}

Related Messages

Related Functions