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

  1. // ObjectWindows - (C) Copyright 1992 by Borland International
  2.  
  3. #include <owl.h>
  4. #include <listbox.h>
  5.  
  6. const WORD ID_LISTBOX = 101;
  7.  
  8. class TTestApp : public TApplication
  9. {
  10. public:
  11.   TTestApp(LPSTR AName, HINSTANCE hInstance, HINSTANCE hPrevInstance,
  12.     LPSTR lpCmdLine, int nCmdShow)
  13.     : TApplication(AName, hInstance, hPrevInstance, lpCmdLine, nCmdShow) {};
  14.   virtual void InitMainWindow();
  15. };
  16.  
  17. class TLBoxWindow : public TWindow
  18. {
  19. public:
  20.   TListBox *ListBox;
  21.   PTListBoxData ListBoxData;
  22.  
  23.   TLBoxWindow();
  24.   ~TLBoxWindow();
  25.   virtual void HandleListBoxMsg(RTMessage Msg) =
  26.     [ID_FIRST + ID_LISTBOX];
  27. };
  28.  
  29. TLBoxWindow::TLBoxWindow() : TWindow(NULL, "List Box Transfer Tester")
  30. {
  31.   ListBox = new TListBox(this, ID_LISTBOX, 20, 20, 340, 100);
  32.   ListBoxData = new TListBoxData();
  33.   ListBox->EnableTransfer();
  34.   ListBoxData->AddString("Item 1");
  35.   ListBoxData->AddString("Item 1.5");
  36.   ListBoxData->AddString("Item 2");
  37.   ListBoxData->AddString("Item 3", TRUE);
  38.   ListBoxData->AddString("Item 4");
  39.   ListBoxData->AddString("Item 5");
  40.   ListBoxData->AddString("Item 6");
  41.   TransferBuffer = &ListBoxData;
  42.   EnableKBHandler(); // so focus goes to ListBox, see also lboxtest.cpp
  43. }
  44.  
  45. TLBoxWindow::~TLBoxWindow()
  46. {
  47.   delete ListBoxData;
  48. }
  49.  
  50. void TLBoxWindow::HandleListBoxMsg(RTMessage Msg)
  51. {
  52.   char TheStr[10];
  53.  
  54.   if ( Msg.LP.Hi == LBN_SELCHANGE )
  55.   {
  56.     ListBox->Transfer(&ListBoxData, TF_GETDATA);
  57.     if ( ListBoxData->GetSelStringLength() < 10 )
  58.     {
  59.       ListBoxData->GetSelString(TheStr, 10);
  60.       MessageBox(HWindow, TheStr, "You selected:", MB_OK);
  61.     }
  62.     else  // This should never happen, strings are all small enough
  63.       MessageBox(HWindow, "Selection too large for output buffer",
  64.           "Error", MB_OK);
  65.   }
  66. }
  67.  
  68. void TTestApp::InitMainWindow()
  69. {
  70.   MainWindow = new TLBoxWindow();
  71. }
  72.  
  73. int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  74.   LPSTR lpCmdLine, int nCmdShow)
  75. {
  76.   TTestApp TestApp("List Box Transfer Tester", hInstance, hPrevInstance,
  77.     lpCmdLine, nCmdShow);
  78.   TestApp.Run();
  79.   return TestApp.Status;
  80. }
  81.