home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / dovetail.zip / LISTBOX.CC < prev    next >
C/C++ Source or Header  |  1994-04-07  |  3KB  |  91 lines

  1. #include "listbox.h"
  2.  
  3.  
  4. // Constructor for window created in resource file
  5. Listbox::Listbox(HWND hParent, ULONG ulId) : Control(hParent, ulId)
  6. {
  7. }
  8.  
  9. // Constructor for window created on the fly
  10. Listbox::Listbox(HWND hParent, ULONG ulId, SHORT xp, SHORT yp, SHORT dx,
  11.                  SHORT dy, ULONG ulStyle) : Control()
  12.    {
  13.  
  14.    hWnd = WinCreateWindow(
  15.               hParent,       /* Parent Window Handle */
  16.               WC_LISTBOX,     /* ListBox Window class name */
  17.               NULL,     /* No Window Text */
  18.               ulStyle, /* Listbox style */
  19.               xp,   /* Xcoord */
  20.               yp,   /* Ycoord */
  21.               dx,   /* Width */
  22.               dy,    /* Height */
  23.               hParent,       /* Owner Window Handle */
  24.               HWND_TOP,      /* Sibling Window Handle */
  25.               ulId,     /* Window ID */
  26.               (PVOID)NULL,     /* Control Data Structure */
  27.               (PVOID)NULL);  /* no presentation parameters */
  28.    fCreated = TRUE;
  29. }
  30.  
  31. // return text of selection in listbox
  32.  
  33.  Listbox::operator char *()
  34. {
  35.   SHORT length;
  36.   char *text;
  37.   SHORT curitem;
  38.  
  39.   curitem = (SHORT) WinSendMsg( hWnd,
  40.              LM_QUERYSELECTION,
  41.              (PVOID) NULL,(PVOID) NULL);
  42.   if(curitem == LIT_NONE)
  43.       return (char *) NULL;
  44.   length = (SHORT) WinSendMsg( hWnd,
  45.              LM_QUERYITEMTEXTLENGTH,
  46.              MPFROMSHORT(curitem),(PVOID) NULL);
  47.   text = new char[length+1];
  48.   WinSendMsg( hWnd,
  49.              LM_QUERYITEMTEXT,
  50.              MPFROM2SHORT(curitem,length+1),MPFROMP(text));
  51.   return text;
  52. }
  53.  
  54. // return index of current selection
  55.  Listbox::operator SHORT ()
  56. {
  57.  
  58.   return (SHORT) WinSendMsg( hWnd,
  59.                    LM_QUERYSELECTION,
  60.                    (PVOID) NULL,(PVOID) NULL);
  61. }
  62.  
  63. // insert item
  64. VOID Listbox::Insert(char * text,SHORT sWhere)
  65. {
  66.   WinSendMsg(hWnd,
  67.              LM_INSERTITEM,
  68.              MPFROMSHORT(sWhere),
  69.              MPFROMP(text));
  70. }
  71.  
  72. // delete item.  if sWhich = -1 (the default), delete currently selected item
  73. VOID Listbox::Delete(SHORT sWhich)
  74. {
  75.   if(sWhich == -1)   // delete currently selected item
  76.     sWhich = (SHORT) WinSendMsg( hWnd,
  77.                        LM_QUERYSELECTION,
  78.                        (PVOID) NULL,(PVOID) NULL);
  79.   WinSendMsg(hWnd,
  80.              LM_DELETEITEM,
  81.              MPFROMSHORT(sWhich),
  82.              NULL);
  83. }
  84.  
  85. VOID Listbox::DeleteAll()
  86. {
  87.   WinSendMsg(hWnd,
  88.              LM_DELETEALL,
  89.              NULL,NULL);
  90. }
  91.