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

  1. // ObjectWindows - (C) Copyright 1992 by Borland International
  2.  
  3. /* This OWL example demonstrates how to make an application PenWindows
  4.  * sensitive.
  5.  *
  6.  * If this application is not running under PenWindows then the application
  7.  * works like a traditional Windows application with a TextEdit box.
  8.  *
  9.  * Following the instructions in WINPEN.DOC, in the DOC directory, on how to
  10.  * modify your SYSTEM.INI file to support PenWindows with or without a pen.
  11.  * The mouse should only be used as the stylus for testing; it is almost
  12.  * always inferior to a pen/tablet hardware configuration. It will also
  13.  * produce poor recognition results.
  14.  *
  15.  * This is the simplest way to make an application pen aware.  The steps are:
  16.  *
  17.  *     1. Check for PenWindows
  18.  *     2. Register the application as a pen application, if PenWindow exists
  19.  *     3. Create two different dialog boxes depending on whether the application
  20.  *        is running under Windows or PenWindows.  Under Pen Windows a BEDIT
  21.  *        control is used for text recognition and entry.
  22.  */
  23.  
  24. #include <owl.h>
  25. #include <button.h>
  26. #include <dialog.h>
  27.  
  28. #include <penwin.h>
  29.  
  30. #include "owlpen.h"
  31.  
  32. typedef VOID (FAR PASCAL *LPREGPENAPP)(WORD, BOOL);
  33.  
  34. class TTestApp : public TApplication
  35. {
  36. public:
  37.     LPREGPENAPP RegisterPenApp;
  38.     HANDLE hPenWin;
  39.  
  40.     TTestApp(LPSTR AName, HINSTANCE hInstance, HINSTANCE hPrevInstance,
  41.              LPSTR lpCmdLine, int nCmdShow)
  42.         : TApplication(AName, hInstance, hPrevInstance, lpCmdLine, nCmdShow) {};
  43.     virtual void InitMainWindow();
  44. };
  45.  
  46. class TTestWindow : public TWindow
  47. {
  48. public:
  49.     char EditText[80];
  50.     HANDLE hPenWindow;
  51.  
  52.     TTestWindow(PTWindowsObject AParent, LPSTR ATitle, HANDLE hPenWin);
  53.     virtual void HandleButtonMsg(RTMessage Msg) = [ID_FIRST + ID_BUTTON];
  54.     virtual void Paint (HDC PaintDC, PAINTSTRUCT _FAR &PaintInfo);
  55.     void SetEditText (LPSTR lpText);
  56. };
  57.  
  58. _CLASSDEF(TDialogTextentry)
  59. class TDialogTextentry : public TDialog
  60. {
  61. public:
  62.     TDialogTextentry (PTWindowsObject Parent, int iResId);
  63.     virtual void HandleShowButton (RTMessage Msg) = [ID_FIRST + ID_SHOW];
  64. };
  65.  
  66.  
  67. TTestWindow::TTestWindow(PTWindowsObject AParent, LPSTR ATitle, HANDLE hPenWin)
  68.           : TWindow(AParent, ATitle)
  69. {
  70.     hPenWindow = hPenWin;
  71.  
  72.     //display a line of text, showing (Pen)Windows is installed
  73.     if (hPenWindow)
  74.         lstrcpy (EditText, "PenWindows Installed");
  75.     else
  76.         lstrcpy (EditText, "PenWindows is not Installed");
  77.  
  78.     Attr.X = 100;
  79.     Attr.Y = 100;
  80.     Attr.W = 400;
  81.     Attr.H = 300;
  82.     new TButton(this, ID_BUTTON, "Text Entry",0, 0, 100, 24, FALSE);
  83. }
  84.  
  85. void TTestWindow::Paint(HDC PaintDC, PAINTSTRUCT _FAR &)
  86. {
  87.     TextOut (PaintDC, 150, 2, EditText, lstrlen (EditText));
  88. }
  89.  
  90. void TTestWindow::SetEditText (LPSTR lpText)
  91. {
  92.     lstrcpy (EditText, lpText);
  93. }
  94.  
  95. TDialogTextentry::TDialogTextentry (PTWindowsObject Parent, int iResId)
  96.                     :TDialog (Parent, iResId)
  97. {
  98. }
  99.  
  100. // response function to SHOW button, get text and show it in the lower control
  101. void TDialogTextentry::HandleShowButton (RTMessage)
  102. {
  103.     char Buffer[80];
  104.  
  105.     GetDlgItemText (HWindow, ID_EDIT, Buffer, 80);
  106.     SetDlgItemText (HWindow, ID_TEXT, Buffer);
  107. }
  108.  
  109. // open a dialogbox, depending on (Pen)Windows running or not
  110. // You may look at OWLPEN.RC file and see that BEDIT is used in
  111. // PENTEXTENTRY_DIALOG
  112. void TTestWindow::HandleButtonMsg(RTMessage)
  113. {
  114.     GetModule()->ExecDialog(new TDialogTextentry (this, hPenWindow ?
  115.                                    PENTEXTENTRY_DIALOG : TEXTENTRY_DIALOG));
  116. }
  117.  
  118.  
  119. void TTestApp::InitMainWindow()
  120. {
  121.     //Is PenWindows running?
  122.     if ((hPenWin = (HINSTANCE) GetSystemMetrics (SM_PENWINDOWS)) != 0) {
  123.  
  124.         // PenWindows is now running, Get adress of RegisterPenApp() using
  125.         // runtime dynamic linking
  126.         if ((RegisterPenApp = (LPREGPENAPP)GetProcAddress ((HINSTANCE)hPenWin,
  127.                               "RegisterPenApp")) != 0) {
  128.  
  129.             // Call RegisterPenApp() to indicate that we are a PenWindows
  130.             // application
  131.             (*RegisterPenApp)(RPA_DEFAULT, TRUE);
  132.         }
  133.     }
  134.  
  135.     MainWindow = new TTestWindow(NULL, Name, hPenWin);
  136. }
  137.  
  138. int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  139.                    LPSTR lpCmdLine, int nCmdShow)
  140. {
  141.     TTestApp TestApp("This Owl is pen aware", hInstance, hPrevInstance, lpCmdLine, nCmdShow);
  142.     TestApp.Run();
  143.     return TestApp.Status;
  144. }
  145.