home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_144 / 6.ddi / OWLDEMOS.ZIP / LBOXTEST.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  2.1 KB  |  85 lines

  1. // ObjectWindows - (C) Copyright 1992 by Borland International
  2.  
  3. #include <owl.h>
  4. #include <window.h>
  5. #include <listbox.h>
  6.  
  7. const WORD ID_LISTBOX = 101;
  8.  
  9. class TTestApp : public TApplication
  10. {
  11. public:
  12.   TTestApp(LPSTR AName, HINSTANCE hInstance, HINSTANCE hPrevInstance,
  13.     LPSTR lpCmdLine, int nCmdShow)
  14.     : TApplication(AName, hInstance, hPrevInstance, lpCmdLine, nCmdShow) {};
  15.   virtual void InitMainWindow();
  16. };
  17.  
  18. class TLBoxWindow : public TWindow
  19. {
  20. public:
  21.   PTListBox ListBox;
  22.   TLBoxWindow(PTWindowsObject AParent, LPSTR ATitle);
  23.   virtual void SetupWindow();
  24.   virtual void HandleListBoxMsg(RTMessage Msg)
  25.     = [ID_FIRST + ID_LISTBOX];
  26.   virtual void WMSetFocus(RTMessage Msg) =
  27.     [WM_FIRST + WM_SETFOCUS];
  28. };
  29.  
  30. TLBoxWindow::TLBoxWindow(PTWindowsObject AParent, LPSTR ATitle) :
  31.   TWindow(AParent, ATitle)
  32. {
  33.   ListBox = new TListBox(this, ID_LISTBOX, 20, 20, 340, 100);
  34. }
  35.  
  36. void TLBoxWindow::SetupWindow()
  37. {
  38.   TWindow::SetupWindow();
  39.   ListBox->AddString("Item 1");
  40.   ListBox->AddString("Item 2");
  41.   ListBox->AddString("Item 3");
  42.   ListBox->InsertString("Item 1.5", 1);
  43.   ListBox->AddString("Item 4");
  44.   ListBox->AddString("Item 5");
  45.   ListBox->AddString("Item 6");
  46. }
  47.  
  48. void TLBoxWindow::HandleListBoxMsg(RTMessage Msg)
  49. {
  50.   int Idx;
  51.   char Str[10];
  52.  
  53.   if ( Msg.LP.Hi == LBN_SELCHANGE )
  54.   {
  55.     Idx = ListBox->GetSelIndex();
  56.     if ( ListBox->GetStringLen(Idx) <= sizeof(Str))
  57.     {
  58.       ListBox->GetSelString(Str, sizeof(Str));
  59.       MessageBox(HWindow, Str, "You selected:", MB_OK);
  60.     }
  61.   }
  62. }
  63.  
  64. /* When the TLBoxWindow gets focus, pass it on to the list box.
  65.    This could also be done by calling EnableKBHandler in the
  66.    TLBoxWindow constructor (see lbxttest.cpp). */
  67. void TLBoxWindow::WMSetFocus(RTMessage)
  68. {
  69.   SetFocus(ListBox->HWindow);
  70. }
  71.  
  72. void TTestApp::InitMainWindow()
  73. {
  74.   MainWindow = new TLBoxWindow(NULL, Name);
  75. }
  76.  
  77. int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  78.   LPSTR lpCmdLine, int nCmdShow)
  79. {
  80.   TTestApp TestApp("List Box Tester", hInstance, hPrevInstance,
  81.     lpCmdLine, nCmdShow);
  82.   TestApp.Run();
  83.   return TestApp.Status;
  84. }
  85.