home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / PICKLIST.PAK / PICKLISX.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  2.6 KB  |  102 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1995, 1995 by Borland International, All Rights Reserved
  4. //----------------------------------------------------------------------------
  5. #include <owl/pch.h>
  6. #include <owl/applicat.h>
  7. #include <owl/picklist.h>
  8. #include <stdio.h>
  9. #include "picklist.rh"
  10.  
  11. //
  12. // classTTestWindow
  13. // ~~~~~~~~~~~~~~~~
  14. class TTestWindow : public TWindow {
  15.   public:
  16.     TTestWindow()
  17.     :
  18.       TWindow(0, 0, 0)
  19.     {
  20.     }
  21.  
  22.     void CmPickItem()
  23.     {
  24.       // Build up a string array of selections to choose from
  25.       //
  26.       TStringArray strings(10, 2, 10);
  27.       strings.Add("Snow");
  28.       strings.Add("Great horned");
  29.       strings.Add("Grey");
  30.       strings.Add("Bald");
  31.       strings.Add("Barn");
  32.  
  33.       // Construct a pick list dialog using the string array built above, and
  34.       // then add another string for the fun of it.
  35.       //
  36.       TPickListDialog picklist(this, &strings, 0, 0, "Owls");
  37.       picklist.AddString("Hoot");
  38.  
  39.       // If the execute return result is non-negative, then a selection was
  40.       // made
  41.       //
  42.       int result = picklist.Execute();
  43.       if (result >= 0) {
  44.         char msg[80];
  45.         sprintf(msg, "Item #%d, string:%s", result,
  46.                 result < strings.UpperBound() ? strings[result].c_str()
  47.                                               : "Beyond list...");
  48.         MessageBox(msg, "You've selected", MB_OK);
  49.       }
  50.     }
  51.  
  52.     void CmPickPopItem()
  53.     {
  54.       TPickListPopup picklist(this, "Owls");
  55.       picklist.AddString("Snow");
  56.       picklist.AddString("Great horned");
  57.       picklist.AddString("Grey");
  58.       picklist.AddString("Bald");
  59.       picklist.AddString("Barn");
  60.       picklist.AddString("Hoot");
  61.  
  62.       int result = picklist.Execute();
  63.       if (result >= 0) {
  64.         char msg[80];
  65.         sprintf(msg, "Item #%d", result);
  66.         MessageBox(msg, "You've selected", MB_OK);
  67.       }
  68.     }
  69.  
  70.   DECLARE_RESPONSE_TABLE(TTestWindow);
  71. };
  72.  
  73. DEFINE_RESPONSE_TABLE1(TTestWindow, TWindow)
  74.   EV_COMMAND(CM_PICKITEM, CmPickItem),
  75.   EV_COMMAND(CM_PICKPOPITEM, CmPickPopItem),
  76. END_RESPONSE_TABLE;
  77.  
  78. //
  79. // class TTestApp
  80. // ~~~~~ ~~~~~~~~
  81. class TTestApp : public TApplication {
  82.   public:
  83.     void InitMainWindow();
  84. };
  85.  
  86. void
  87. TTestApp::InitMainWindow()
  88. {
  89.   TWindow* testWindow = new TTestWindow;
  90.   TDecoratedFrame* frame = new TDecoratedFrame(0, "Test application", testWindow, true);
  91.   frame->AssignMenu(IDM_MAINMENU);
  92.   SetMainWindow(frame);
  93. }
  94.  
  95. int
  96. OwlMain(int /*argc*/, char* /*argv*/ [])
  97. {
  98.   TTestApp app;
  99.   return app.Run();
  100. }
  101.  
  102.