home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / CPROG / TOOLOW.ZIP / TUTOR.CPP < prev    next >
C/C++ Source or Header  |  1992-04-22  |  8KB  |  306 lines

  1. //***************************************************************************
  2. // tutor.cpp - My First PowerCode App
  3. // 4/22/92 - 6:24:12pm
  4. // John Doe
  5. //***************************************************************************
  6. #include <owl.h>
  7. #include <string.h>
  8. #include <stdlib.h>
  9. #include <ctype.h>
  10. #include <dialog.h>
  11. #include <listbox.h>
  12. #include <edit.h>
  13. #include <radiobut.h>
  14. #include <checkbox.h>
  15. #include <combobox.h>
  16. #include <listbox.h>
  17. #include "Tutor.h"                // Resource Constants
  18. #include "Tutor.hpp"                // Main App Class Definitions
  19. #include "jtools.hpp"                // Module Class Definitions
  20.  
  21. //
  22. // Member Functions - Main 
  23. //
  24. // Window Constructor
  25. Main::Main(PTWindowsObject AParent) 
  26. : TWindow(AParent, "My First PowerCode App")
  27. {
  28.  
  29.     // Create ToolBar - This is a child window so OWL will delete
  30.     PTToolBar pTB = new TToolBar(this, 44);    
  31.     pTB->ToolItems->add(* new TToolItem(this, "Button", CM_MAINAPP, -1, -1, 45, 45, 
  32.          "NMainApp", "SMainApp", "Y", "Y"));
  33.     pTB->ToolItems->add(* new TToolItem(this, "Button", CM_MAINDIALOG, 43, -1, 45, 45, 
  34.          "NMainDialog", "SMainDialog", "Y", "Y"));
  35.     pTB->ToolItems->add(* new TToolItem(this, "Button", CM_MAINWINDOW, 87, -1, 45, 45, 
  36.          "NMainWindow", "SMainWindow", "Y", "Y"));
  37.     pTB->ToolItems->add(* new TToolItem(this, "Checkbox", CM_MAINCHECKBOX, 134, 2, 40, 40, 
  38.          "NMainCheckBox", "SMainCheckBox", "N", "N"));
  39. }
  40. //
  41. // GetWindowClass - Allows a new window class to be defined 
  42. //
  43. void Main::GetWindowClass(WNDCLASS& AWndClass)
  44. {
  45.     TWindow::GetWindowClass(AWndClass);
  46.     AWndClass.hbrBackground = CreateSolidBrush(RGB(255,255,128));
  47.     AWndClass.hIcon = LoadIcon(GetApplication()->hInstance, "Main");
  48. }
  49. //
  50. //    SetupWindow - Initialization stuff requiring a window handle
  51. //
  52. void Main::SetupWindow()
  53. {
  54.     AssignMenu("Main");
  55.  
  56.     TWindowsObject::SetupWindow();    // will setup child windows
  57. }
  58. //
  59. // Window Response functions
  60. //
  61. void Main::MsgMainApp(RTMessage )
  62. {
  63.     WinExec("notepad.exe tutor.txt", SW_SHOW);
  64. }
  65. void Main::MsgMainDialog(RTMessage )
  66. {
  67.     PAddress pDlg = new Address(this, "ADDRESS");
  68.     GetApplication()->MakeWindow(pDlg);
  69.     pDlg->Show(SW_SHOW);
  70. }
  71. void Main::MsgMainWindow(RTMessage )
  72. {
  73.     PTWindow pWin = new NewWin(this);
  74.     GetApplication()->MakeWindow(pWin);
  75.     pWin->Show(SW_SHOW);
  76. }
  77. void Main::MsgNew(RTMessage )
  78. {
  79.     PTWindow pWin = new NewWin(this);
  80.     GetApplication()->MakeWindow(pWin);
  81.     pWin->Show(SW_SHOW);
  82. }
  83. void Main::MsgOpen(RTMessage )
  84. {
  85.     MessageBox(HWindow, "User Clicked on Item: &Open", "Info", 
  86.        MB_OK | MB_ICONINFORMATION);
  87. }
  88. void Main::MsgSave(RTMessage )
  89. {
  90.     MessageBox(HWindow, "User Clicked on Item: &Save", "Info", 
  91.        MB_OK | MB_ICONINFORMATION);
  92. }
  93. void Main::MsgExit(RTMessage )
  94. {
  95.     MessageBox(HWindow, "User Clicked on Item: &Exit", "Info", 
  96.        MB_OK | MB_ICONINFORMATION);
  97. }
  98. void Main::MsgAbout(RTMessage )
  99. {
  100.     GetApplication()->ExecDialog(new About(this, "ABOUT") );
  101. }
  102. //
  103. // CloseWindow - Close Window and Update Data
  104. //
  105. void Main::CloseWindow()
  106. {
  107.     if ( CanClose() )    // Update Window if OK
  108.     {
  109.         TWindow::CloseWindow();    // Finish the CloseWindow
  110.     }
  111. }
  112.  
  113.  
  114. //
  115. // Member Functions - NewWin 
  116. //
  117. // Window Constructor
  118. NewWin::NewWin(PTWindowsObject AParent) 
  119. : TWindow(AParent, "")
  120. {
  121.     Attr.Style = WS_OVERLAPPEDWINDOW|WS_VISIBLE;
  122.  
  123. }
  124. //
  125. // GetWindowClass - Allows a new window class to be defined 
  126. //
  127. void NewWin::GetWindowClass(WNDCLASS& AWndClass)
  128. {
  129.     TWindow::GetWindowClass(AWndClass);
  130. }
  131. //
  132. //    SetupWindow - Initialization stuff requiring a window handle
  133. //
  134. void NewWin::SetupWindow()
  135. {
  136.  
  137.     TWindowsObject::SetupWindow();    // will setup child windows
  138. }
  139. //
  140. // Window Response functions
  141. //
  142. //
  143. // CloseWindow - Close Window and Update Data
  144. //
  145. void NewWin::CloseWindow()
  146. {
  147.     if ( CanClose() )    // Update Window if OK
  148.     {
  149.         TWindow::CloseWindow();    // Finish the CloseWindow
  150.     }
  151. }
  152.  
  153.  
  154. //
  155. // Dialog Member Functions - About 
  156. //
  157. About::About(PTWindowsObject AParent, Pchar DlgName) : TDialog(AParent, DlgName)
  158. {
  159. }
  160. //
  161. //    SetupWindow - Initialize controls, anything requiring win handle
  162. //
  163. void About::SetupWindow()
  164. {
  165.     TWindowsObject::SetupWindow();    // will setup child windows
  166. }
  167. //
  168. // Dialog Response functions - About
  169. //
  170. //
  171. // CanClose - Determine if dialog should be allowed to update
  172. //
  173. BOOL About::CanClose()
  174. {
  175.     return TRUE;
  176. }
  177. //
  178. // CloseWindow - Close Window and Update Data
  179. //
  180. void About::CloseWindow(int ARetValue)
  181. {
  182.     if ( ARetValue == IDOK && CanClose() ) // Update Dialog
  183.     {
  184.         
  185.         TDialog::CloseWindow(ARetValue);    // Finish the CloseWindow
  186.     }
  187. }
  188. //
  189. // Dialog Member Functions - Address 
  190. //
  191. Address::Address(PTWindowsObject AParent, Pchar DlgName) : TDialog(AParent, DlgName)
  192. {
  193.     Lname = new TEdit(this, ID_LNAME, 30);
  194.     Name = new TEdit(this, ID_NAME, 0);
  195.     Title = new TEdit(this, ID_TITLE, 0);
  196.     Coname = new TEdit(this, ID_CONAME, 0);
  197.     Street1 = new TEdit(this, ID_STREET1, 0);
  198.     Street2 = new TEdit(this, ID_STREET2, 0);
  199.     City = new TEdit(this, ID_CITY, 0);
  200.     State = new TEdit(this, ID_STATE, 0);
  201.     Zip = new TEdit(this, ID_ZIP, 0);
  202.     Bphone = new TEdit(this, ID_BPHONE, 0);
  203.     Hphone = new TEdit(this, ID_HPHONE, 0);
  204.     Fax = new TEdit(this, ID_FAX, 0);
  205.     Comments = new TEdit(this, ID_COMMENTS, 0);
  206.     Addtype = new TComboBox(this, ID_ADDTYPE, 0);
  207.     Male = new TRadioButton(this, ID_MALE, NULL);
  208.     Female = new TRadioButton(this, ID_FEMALE, NULL);
  209. }
  210. //
  211. //    SetupWindow - Initialize controls, anything requiring win handle
  212. //
  213. void Address::SetupWindow()
  214. {
  215.     TWindowsObject::SetupWindow();    // will setup child windows
  216.     Female->SetCheck(TRUE);     // Set Initial Check
  217.     // Fill Combo with initial values
  218.     Addtype->AddString("Employee");
  219.     Addtype->AddString("Vendor");
  220.     Addtype->AddString("Friend");
  221.     Addtype->AddString("Other");
  222. }
  223. //
  224. // Dialog Response functions - Address
  225. //
  226. void Address::MsgSearch(RTMessage )
  227. {
  228.     GetApplication()->ExecDialog(new Search(this, "SEARCH") );
  229. }
  230. //
  231. // CanClose - Determine if dialog should be allowed to update
  232. //
  233. BOOL Address::CanClose()
  234. {
  235.     if ( Lname->GetTextLen() == 0 )
  236.     {
  237.         MessageBox(HWindow, "Mandatory field requires input.", "Error", 
  238.            MB_OK | MB_ICONEXCLAMATION);
  239.         SetFocus(Lname->HWindow);     // Position cursor to error
  240.         return FALSE;
  241.     }
  242.     return TRUE;
  243. }
  244. //
  245. // CloseWindow - Close Window and Update Data
  246. //
  247. void Address::CloseWindow(int ARetValue)
  248. {
  249.     if ( ARetValue == IDOK && CanClose() ) // Update Dialog
  250.     {
  251.         
  252.         TDialog::CloseWindow(ARetValue);    // Finish the CloseWindow
  253.     }
  254. }
  255. //
  256. // Dialog Member Functions - Search 
  257. //
  258. Search::Search(PTWindowsObject AParent, Pchar DlgName) : TDialog(AParent, DlgName)
  259. {
  260.     List = new TListBox(this, ID_LIST, NULL);
  261. }
  262. //
  263. //    SetupWindow - Initialize controls, anything requiring win handle
  264. //
  265. void Search::SetupWindow()
  266. {
  267.     TWindowsObject::SetupWindow();    // will setup child windows
  268. }
  269. //
  270. // Dialog Response functions - Search
  271. //
  272. //
  273. // CanClose - Determine if dialog should be allowed to update
  274. //
  275. BOOL Search::CanClose()
  276. {
  277.     return TRUE;
  278. }
  279. //
  280. // CloseWindow - Close Window and Update Data
  281. //
  282. void Search::CloseWindow(int ARetValue)
  283. {
  284.     if ( ARetValue == IDOK && CanClose() ) // Update Dialog
  285.     {
  286.         
  287.         TDialog::CloseWindow(ARetValue);    // Finish the CloseWindow
  288.     }
  289. }
  290. //
  291. //    Application Member Functions
  292. //
  293. void TutorApp::InitMainWindow()
  294. {
  295.         MainWindow = new Main(NULL);
  296. }
  297.  
  298. int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance,
  299.            LPSTR lpCmd, int nCmdShow)
  300. {
  301.     TutorApp TutorApp("My First PowerCode App", hInstance, hPrevInstance,
  302.         lpCmd, nCmdShow);
  303.     TutorApp.Run();
  304.     return TutorApp.Status;
  305. }
  306.