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

  1. // ObjectWindows - (C) Copyright 1992 by Borland International
  2.  
  3. #include <stdio.h>
  4. #include <owl.h>
  5. #include <window.h>
  6. #include <edit.h>
  7. #include <static.h>
  8. #include <button.h>
  9.  
  10. const WORD ID_EDIT1 = 101;
  11. const WORD ID_EDIT2 = 102;
  12. const WORD ID_BUTTON = 103;
  13. const WORD MAX_TEXTLEN = 20;
  14.  
  15. class TTestApp : public TApplication
  16. {
  17. public:
  18.   TTestApp(LPSTR AName, HINSTANCE hInstance, HINSTANCE hPrevInstance,
  19.     LPSTR lpCmdLine, int nCmdShow)
  20.     : TApplication(AName, hInstance, hPrevInstance, lpCmdLine, nCmdShow) {};
  21.   virtual void InitMainWindow();
  22. };
  23.  
  24. class TTestWindow : public TWindow
  25. {
  26. public:
  27.   TEdit *Edit1, *Edit2;
  28.   TTestWindow::TTestWindow(PTWindowsObject AParent, LPSTR ATitle);
  29.   virtual void HandleButtonMsg(RTMessage Msg)
  30.     = [ID_FIRST + ID_BUTTON];
  31. };
  32.  
  33. TTestWindow::TTestWindow(PTWindowsObject AParent, LPSTR ATitle)
  34.   : TWindow(AParent, ATitle)
  35. {
  36.   new TStatic(this, -1, "&Original:", 20, 30, 150, 20, 0);
  37.   Edit1 = new TEdit(this, ID_EDIT1, "Default Text", 20, 50, 150, 30,
  38.     MAX_TEXTLEN, FALSE);
  39.   new TButton(this, ID_BUTTON, "-->", 190, 50, 50, 30, FALSE);
  40.   new TStatic(this, -1, "&Copy:", 260, 30, 150, 20, 0);
  41.   Edit2 = new TEdit(this, ID_EDIT2, "", 260, 50, 150, 30, MAX_TEXTLEN, FALSE);
  42.   Edit2->Attr.Style |= ES_UPPERCASE;
  43.   AssignMenu("COMMANDS");
  44.   EnableKBHandler();
  45. }
  46.  
  47. void TTestWindow::HandleButtonMsg(RTMessage)
  48. {
  49.   int StartPos, EndPos;
  50.   char TheText[MAX_TEXTLEN];
  51.  
  52.   // Handle notification messages from button
  53.   Edit1->GetSelection(StartPos, EndPos);
  54.   if ( StartPos == EndPos )
  55.     Edit1->GetText(TheText, sizeof(TheText));
  56.   else Edit1->GetSubText(TheText, StartPos, EndPos);
  57.   Edit2->SetText(TheText);
  58.   Edit1->SetSelection(0, 0);
  59. }
  60.  
  61. void TTestApp::InitMainWindow()
  62. {
  63.   MainWindow = new TTestWindow(NULL, Name);
  64. }
  65.  
  66. int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  67.   LPSTR lpCmdLine, int nCmdShow)
  68. {
  69.   TTestApp TestApp("Edit Control Tester", hInstance, hPrevInstance,
  70.     lpCmdLine, nCmdShow);
  71.   TestApp.Run();
  72.   return TestApp.Status;
  73. }
  74.