Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

683 lines
20 KiB

  1. // FaxApi.cpp : Defines the class behaviors for the application.
  2. //
  3. #include "stdafx.h"
  4. #include "FaxApi.h"
  5. #include "MainFrm.h"
  6. #include "FxApiDoc.h"
  7. #include "function.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CFaxApiApp
  15. BEGIN_MESSAGE_MAP(CFaxApiApp, CWinApp)
  16. //{{AFX_MSG_MAP(CFaxApiApp)
  17. ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  18. // NOTE - the ClassWizard will add and remove mapping macros here.
  19. // DO NOT EDIT what you see in these blocks of generated code!
  20. //}}AFX_MSG_MAP
  21. // Standard file based document commands
  22. ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
  23. ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
  24. END_MESSAGE_MAP()
  25. /////////////////////////////////////////////////////////////////////////////
  26. // CFaxApiApp construction
  27. CFaxApiApp::CFaxApiApp()
  28. {
  29. // TODO: add construction code here,
  30. // Place all significant initialization in InitInstance
  31. }
  32. /////////////////////////////////////////////////////////////////////////////
  33. // The one and only CFaxApiApp object
  34. CFaxApiApp FaxApiBrowserApp;
  35. CFaxApiApp * pFaxApiBrowserApp; // This pointer is declared external in
  36. // other modules where access to certain
  37. // member functions of the CFaxApiApp
  38. // object are needed.
  39. /////////////////////////////////////////////////////////////////////////////
  40. // CFaxApiApp initialization
  41. BOOL CFaxApiApp::InitInstance()
  42. {
  43. BOOL fReturnValue;
  44. pFaxApiBrowserApp = &FaxApiBrowserApp; // Initialize the pointer to the
  45. // CFaxApiApp object.
  46. /* Initialize the array of pointers to CFaxApiFunctionInfo objects. */
  47. fReturnValue = InitFaxApiFunctionInfoPointerArray();
  48. // Standard initialization
  49. // If you are not using these features and wish to reduce the size
  50. // of your final executable, you should remove from the following
  51. // the specific initialization routines you do not need.
  52. #ifdef _AFXDLL
  53. Enable3dControls(); // Call this when using MFC in a shared DLL
  54. #else
  55. Enable3dControlsStatic(); // Call this when linking to MFC statically
  56. #endif
  57. #ifdef NOT_NEEDED
  58. // Change the registry key under which our settings are stored.
  59. // You should modify this string to be something appropriate
  60. // such as the name of your company or organization.
  61. SetRegistryKey(_T("Local AppWizard-Generated Applications"));
  62. LoadStdProfileSettings(); // Load standard INI file options (including MRU)
  63. #endif // NOT_NEEDED
  64. // Register the application's document templates. Document templates
  65. // serve as the connection between documents, frame windows and views.
  66. CSingleDocTemplate* pDocTemplate;
  67. pDocTemplate = new CSingleDocTemplate(
  68. IDR_MAINFRAME,
  69. RUNTIME_CLASS(CFaxApiDoc),
  70. RUNTIME_CLASS(CMainFrame), // main SDI frame window
  71. RUNTIME_CLASS(CFormView));
  72. AddDocTemplate(pDocTemplate);
  73. // Parse command line for standard shell commands, DDE, file open
  74. CCommandLineInfo cmdInfo;
  75. ParseCommandLine(cmdInfo);
  76. // Dispatch commands specified on the command line
  77. if (!ProcessShellCommand(cmdInfo))
  78. return FALSE;
  79. // The one and only window has been initialized, so show and update it.
  80. m_pMainWnd->ShowWindow(SW_SHOW);
  81. m_pMainWnd->UpdateWindow();
  82. return ( fReturnValue );
  83. }
  84. /////////////////////////////////////////////////////////////////////////////
  85. // CAboutDlg dialog used for App About
  86. class CAboutDlg : public CDialog
  87. {
  88. public:
  89. CAboutDlg();
  90. // Dialog Data
  91. //{{AFX_DATA(CAboutDlg)
  92. enum { IDD = IDD_ABOUTBOX };
  93. //}}AFX_DATA
  94. // ClassWizard generated virtual function overrides
  95. //{{AFX_VIRTUAL(CAboutDlg)
  96. protected:
  97. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
  98. //}}AFX_VIRTUAL
  99. // Implementation
  100. protected:
  101. //{{AFX_MSG(CAboutDlg)
  102. // No message handlers
  103. //}}AFX_MSG
  104. DECLARE_MESSAGE_MAP()
  105. };
  106. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  107. {
  108. //{{AFX_DATA_INIT(CAboutDlg)
  109. //}}AFX_DATA_INIT
  110. }
  111. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  112. {
  113. CDialog::DoDataExchange(pDX);
  114. //{{AFX_DATA_MAP(CAboutDlg)
  115. //}}AFX_DATA_MAP
  116. }
  117. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  118. //{{AFX_MSG_MAP(CAboutDlg)
  119. // No message handlers
  120. //}}AFX_MSG_MAP
  121. END_MESSAGE_MAP()
  122. // App command to run the dialog
  123. void CFaxApiApp::OnAppAbout()
  124. {
  125. CAboutDlg aboutDlg;
  126. aboutDlg.DoModal();
  127. }
  128. /////////////////////////////////////////////////////////////////////////////
  129. // CFaxApiApp commands
  130. // There are five views derived from CFormView that populate the panes of the
  131. // splitter windows that overlay the CMainFrame. Since each view object is
  132. // constructed at the time that the associated CSplitterWnd::CreateView() call
  133. // is made, it is necessary to record the HWND for each view so that a pointer
  134. // the the view object may be obtained when it is necessary for the views to
  135. // communicate.
  136. // The HWND values for each view are recorded in private data members of the
  137. // CFaxApiApp object.
  138. // Each of the following set of functions stored the HWND for a view object in
  139. // a private data member of the CFaxApiApp object.
  140. void CFaxApiApp::StoreFunctionInfoFormViewHWND( HWND hView )
  141. {
  142. m_hwndFunctionInfoFormView = hView;
  143. }
  144. void CFaxApiApp::StoreParameterInfoFormViewHWND( HWND hView )
  145. {
  146. m_hwndParameterInfoFormView = hView;
  147. }
  148. void CFaxApiApp::StoreReturnValueOutputFormViewHWND( HWND hView )
  149. {
  150. m_hwndReturnValueOutputFormView = hView;
  151. }
  152. void CFaxApiApp::StoreExecutionLogFormViewHWND( HWND hView )
  153. {
  154. m_hwndExecutionLogFormView = hView;
  155. }
  156. void CFaxApiApp::StoreFaxApiFunctionSelectionFormViewHWND( HWND hView )
  157. {
  158. m_hwndFaxApiFunctionSelectionFormView = hView;
  159. }
  160. // Each of the following set of functions returns a pointer to the view object.
  161. // That pointer is obtained by CWnd::FromHandle() to which the HWND for the
  162. // view object is passed.
  163. CWnd * CFaxApiApp::GetFunctionInfoFormViewPointer()
  164. {
  165. CWnd * pFunctionInfoFormView;
  166. pFunctionInfoFormView = CWnd::FromHandle( m_hwndFunctionInfoFormView );
  167. return ( pFunctionInfoFormView );
  168. }
  169. CWnd * CFaxApiApp::GetParameterInfoFormViewPointer()
  170. {
  171. CWnd * pParameterInfoFormView;
  172. pParameterInfoFormView = CWnd::FromHandle( m_hwndParameterInfoFormView );
  173. return ( pParameterInfoFormView );
  174. }
  175. CWnd * CFaxApiApp::GetReturnValueOutputFormViewPointer()
  176. {
  177. CWnd * pReturnValueOutputFormView;
  178. pReturnValueOutputFormView = CWnd::FromHandle( m_hwndReturnValueOutputFormView );
  179. return ( pReturnValueOutputFormView );
  180. }
  181. CWnd * CFaxApiApp::GetExecutionLogFormViewPointer()
  182. {
  183. CWnd * pExecutionLogFormView;
  184. pExecutionLogFormView = CWnd::FromHandle( m_hwndExecutionLogFormView );
  185. return ( pExecutionLogFormView );
  186. }
  187. CWnd * CFaxApiApp::GetFaxApiFunctionSelectionFormViewPointer()
  188. {
  189. CWnd * pFaxApiFunctionSelectionFormView;
  190. pFaxApiFunctionSelectionFormView = CWnd::FromHandle( m_hwndFaxApiFunctionSelectionFormView );
  191. return ( pFaxApiFunctionSelectionFormView );
  192. }
  193. /*
  194. * InitFaxApiFunctionInfoPointerArray
  195. *
  196. * Purpose:
  197. * This function initializes the CObArray object whose elements are
  198. * pointers to CFaxApiFunctionInfo objects. The individual
  199. * CFaxApiFunctionInfo objects are allocated (via the new operator)
  200. * and initialized using data that is read from the Fax API Browser
  201. * initialization file.
  202. *
  203. * Arguments:
  204. * None
  205. *
  206. * Returns:
  207. * TRUE - indicates success
  208. * FALSE - indicates failure
  209. *
  210. * Note:
  211. * The Fax API Browser initialization file consists of one section
  212. * for each Fax API function.
  213. *
  214. */
  215. BOOL CFaxApiApp::InitFaxApiFunctionInfoPointerArray()
  216. {
  217. BOOL fReturnValue = (BOOL) TRUE;
  218. /* Verify that the Fax API Browser initialization file is present. */
  219. CFile cfTempFile;
  220. CFileException cfeTemp;
  221. if ( cfTempFile.Open( TEXT(".\\faxapi.ini"), CFile::modeRead, &cfeTemp ) ==
  222. (BOOL) TRUE )
  223. {
  224. /* INI file is readable. */
  225. cfTempFile.Close();
  226. /* Get a list of the section names in the Fax API Browser initialization */
  227. /* file. The section names map into Fax API function names. */
  228. TCHAR tszSectionNames[5000]; // This is arbirtarily large.
  229. // As of 9/24/97 there are 47
  230. // Fax Api functions. The longest
  231. // function name at this time is
  232. // 26 characters.
  233. DWORD dwGPPSNrv = (DWORD) 0; // returned by GetPrivateProfileSectionNames
  234. /* Read the section names (Fax API function names) from the initialization */
  235. /* file into a NULL terminated list of section names delimited by NULLs. */
  236. dwGPPSNrv = GetPrivateProfileSectionNames( (LPTSTR) &tszSectionNames,
  237. (DWORD) sizeof( tszSectionNames ),
  238. (LPCTSTR) TEXT(".\\faxapi.ini") );
  239. /* Were the section names read successfully ? */
  240. if ( dwGPPSNrv > 0 )
  241. {
  242. /* How many section names were read ? */
  243. TCHAR * ptszSectionName;
  244. CStringArray csaSectionNames;
  245. DWORD dwErrorCode;
  246. ptszSectionName = tszSectionNames;
  247. while ( (*ptszSectionName != (TCHAR) L'\0') && (fReturnValue == (BOOL) TRUE) )
  248. {
  249. try
  250. {
  251. csaSectionNames.Add( (LPCTSTR) ptszSectionName );
  252. }
  253. catch ( ... )
  254. {
  255. dwErrorCode = GetLastError();
  256. if ( dwErrorCode == (DWORD) NO_ERROR )
  257. {
  258. dwErrorCode = (DWORD) ERROR_NOT_ENOUGH_MEMORY;
  259. fReturnValue = (BOOL) FALSE;
  260. }
  261. }
  262. if ( fReturnValue == (BOOL) TRUE )
  263. {
  264. /* Search for the next (TCHAR) null. */
  265. while ( *(ptszSectionName++) != (TCHAR) L'\0' );
  266. }
  267. } // end of outer while loop
  268. /* Find out how many section names were extracted from the buffer. */
  269. int xNumberOfSectionNames;
  270. xNumberOfSectionNames = csaSectionNames.GetSize();
  271. /* Initialize the size of the CObArray object. */
  272. m_coaFaxApiFunctionInfo.SetSize( xNumberOfSectionNames );
  273. /* Start adding elements to m_caoFaxApiFinctionInfo. The elements */
  274. /* are pointers to CFaxApiFunctionInfo objects. */
  275. CFaxApiFunctionInfo * pcfafiElement;
  276. int xElementIndex;
  277. CString csFunctionName;
  278. CString csFunctionPrototype;
  279. CString csReturnType;
  280. CString csReturnValueDescription;
  281. CString csRemarks;
  282. DWORD dwGPPSrv; // returned by GetPrivateProfileString
  283. TCHAR tszProfileString[500]; // arbitrarily chosen size
  284. for ( xElementIndex = 0; xElementIndex < xNumberOfSectionNames; xElementIndex++ )
  285. {
  286. if ( fReturnValue == (BOOL) TRUE )
  287. {
  288. /* Gather the information necessary to create and initialize a */
  289. /* CFaxApiFunctionInfo object. */
  290. csFunctionName = csaSectionNames.GetAt( xElementIndex );
  291. /* Read the rest of the info from the ini file. */
  292. // Read the "Function Prototype" from the ini file.
  293. dwGPPSrv = GetPrivateProfileString( (LPCTSTR) csFunctionName,
  294. (LPCTSTR) TEXT("Prototype"),
  295. (LPCTSTR) TEXT("NULL"),
  296. (LPTSTR) tszProfileString,
  297. (DWORD) sizeof( tszProfileString ),
  298. (LPCTSTR) TEXT(".\\faxapi.ini") );
  299. /* Did GetPrivateProfileString return the string "NULL" ? */
  300. if ( _wcsicmp( tszProfileString, TEXT("NULL") ) != 0 )
  301. {
  302. /* Did GetPrivateProfileString read an entry ? */
  303. if ( dwGPPSrv > (DWORD) 0L )
  304. {
  305. csFunctionPrototype = (CString) tszProfileString;
  306. }
  307. else
  308. {
  309. csFunctionPrototype = (CString) TEXT("Error reading faxapi.ini");
  310. }
  311. }
  312. else
  313. {
  314. csFunctionPrototype = (CString) TEXT("Error reading faxapi.ini");
  315. }
  316. // Read the "Return Type" from the ini file.
  317. dwGPPSrv = GetPrivateProfileString( (LPCTSTR) csFunctionName,
  318. (LPCTSTR) TEXT("ReturnType"),
  319. (LPCTSTR) TEXT("NULL"),
  320. (LPTSTR) tszProfileString,
  321. (DWORD) sizeof( tszProfileString ),
  322. (LPCTSTR) TEXT(".\\faxapi.ini") );
  323. /* Did GetPrivateProfileString return the string "NULL" ? */
  324. if ( _wcsicmp( tszProfileString, TEXT("NULL") ) != 0 )
  325. {
  326. /* Did GetPrivateProfileString read an entry ? */
  327. if ( dwGPPSrv > (DWORD) 0L )
  328. {
  329. csReturnType = (CString) tszProfileString;
  330. }
  331. else
  332. {
  333. csReturnType = (CString) TEXT("Error reading faxapi.ini");
  334. }
  335. }
  336. else
  337. {
  338. csReturnType = (CString) TEXT("Error reading faxapi.ini");
  339. }
  340. // Read the "Return Value Description" from the ini file.
  341. dwGPPSrv = GetPrivateProfileString( (LPCTSTR) csFunctionName,
  342. (LPCTSTR) TEXT("ReturnValueDescription"),
  343. (LPCTSTR) TEXT("NULL"),
  344. (LPTSTR) tszProfileString,
  345. (DWORD) sizeof( tszProfileString ),
  346. (LPCTSTR) TEXT(".\\faxapi.ini") );
  347. /* Did GetPrivateProfileString return the string "NULL" ? */
  348. if ( _wcsicmp( tszProfileString, TEXT("NULL") ) != 0 )
  349. {
  350. /* Did GetPrivateProfileString read an entry ? */
  351. if ( dwGPPSrv > (DWORD) 0L )
  352. {
  353. csReturnValueDescription = (CString) tszProfileString;
  354. }
  355. else
  356. {
  357. csReturnValueDescription = (CString) TEXT("Error reading faxapi.ini");
  358. }
  359. }
  360. else
  361. {
  362. csReturnValueDescription = (CString) TEXT("Error reading faxapi.ini");
  363. }
  364. // Read the "Remarks" from the ini file.
  365. dwGPPSrv = GetPrivateProfileString( (LPCTSTR) csFunctionName,
  366. (LPCTSTR) TEXT("Remarks"),
  367. (LPCTSTR) TEXT("NULL"),
  368. (LPTSTR) tszProfileString,
  369. (DWORD) sizeof( tszProfileString ),
  370. (LPCTSTR) TEXT(".\\faxapi.ini") );
  371. /* Did GetPrivateProfileString return the string "NULL" ? */
  372. if ( _wcsicmp( tszProfileString, TEXT("NULL") ) != 0 )
  373. {
  374. /* Did GetPrivateProfileString read an entry ? */
  375. if ( dwGPPSrv > (DWORD) 0L )
  376. {
  377. csRemarks = (CString) tszProfileString;
  378. }
  379. else
  380. {
  381. csRemarks = (CString) TEXT("Error reading faxapi.ini");
  382. }
  383. }
  384. else
  385. {
  386. csRemarks = (CString) TEXT("Error reading faxapi.ini");
  387. }
  388. /* Create a CFaxApiFunctionInfo object. */
  389. pcfafiElement = new CFaxApiFunctionInfo(
  390. (const CString &) csFunctionName,
  391. (const CString &) csFunctionPrototype,
  392. (const CString &) csReturnType,
  393. (const CString &) csReturnValueDescription,
  394. (const CString &) csRemarks );
  395. if ( pcfafiElement != (CFaxApiFunctionInfo *) NULL )
  396. {
  397. /* Add the pointer to the CFaxApiFunctionInfo object to the array. */
  398. try
  399. {
  400. m_coaFaxApiFunctionInfo.SetAtGrow( xElementIndex, pcfafiElement );
  401. }
  402. catch ( ... )
  403. {
  404. dwErrorCode = GetLastError();
  405. if ( dwErrorCode == (DWORD) NO_ERROR )
  406. {
  407. dwErrorCode = (DWORD) ERROR_NOT_ENOUGH_MEMORY;
  408. fReturnValue = (BOOL) FALSE;
  409. }
  410. }
  411. }
  412. }
  413. else
  414. {
  415. /* An error occured while attempting to add an element to */
  416. /* m_coaFaxApiFunctionInfo. Terminate ! */
  417. break;
  418. }
  419. } // end of for loop adding elements to m_coaFaxApiFunctionInfo
  420. m_coaFaxApiFunctionInfo.FreeExtra();
  421. fReturnValue = (BOOL) TRUE;
  422. }
  423. else
  424. {
  425. /* No section names were read from the Fax API Browser initialization file. */
  426. fReturnValue = (BOOL) FALSE;
  427. }
  428. }
  429. else
  430. {
  431. /* tha Fax API Browser initialization file could not be opened. */
  432. fReturnValue = (BOOL) FALSE;
  433. }
  434. return ( fReturnValue );
  435. }
  436. /*
  437. * GetNumberOfFaxApiFunctions
  438. *
  439. * Purpose:
  440. * This function returns the number of Fax API functions.
  441. *
  442. * Arguments:
  443. * None
  444. *
  445. * Returns:
  446. * The number of Fax API functions
  447. *
  448. */
  449. int CFaxApiApp::GetNumberOfFaxApiFunctions()
  450. {
  451. int xNumberOfFaxApiFunctions;
  452. xNumberOfFaxApiFunctions = m_coaFaxApiFunctionInfo.GetSize();
  453. return ( xNumberOfFaxApiFunctions );
  454. }
  455. /*
  456. * GetFaxApiFunctionInfoPointer
  457. *
  458. * Purpose:
  459. * This function returns a pointer to a CFaxApiFunctionInfo object.
  460. *
  461. * Arguments:
  462. * xElementIndex is the index into the array of pointers to CFaxApiFunctionInfo
  463. * objects to the desired pointer.
  464. *
  465. * Returns:
  466. * A pointer to a CFaxApiFunctionInfoObject
  467. *
  468. */
  469. CFaxApiFunctionInfo * CFaxApiApp::GetFaxApiFunctionInfoPointer( int xElementIndex )
  470. {
  471. CFaxApiFunctionInfo * pcfafiFunctionInfo;
  472. pcfafiFunctionInfo = (CFaxApiFunctionInfo *) m_coaFaxApiFunctionInfo[xElementIndex];
  473. return ( pcfafiFunctionInfo );
  474. }
  475. /*
  476. * DeleteCFaxApiFunctionInfoObjects
  477. *
  478. * Purpose:
  479. * This function deletes any CFaxApiFunctionInfo objects that
  480. * may have been created.
  481. *
  482. * Arguments:
  483. * None
  484. *
  485. * Returns:
  486. * None
  487. *
  488. */
  489. void CFaxApiApp::DeleteCFaxApiFunctionInfoObjects()
  490. {
  491. int xNumberOfElements;
  492. xNumberOfElements = m_coaFaxApiFunctionInfo.GetSize();
  493. if ( xNumberOfElements > 0 )
  494. {
  495. int xElementIndex;
  496. CFaxApiFunctionInfo * pcfafiElement;
  497. for ( xElementIndex = 0; xElementIndex < xNumberOfElements; xElementIndex++ )
  498. {
  499. pcfafiElement = (CFaxApiFunctionInfo *) m_coaFaxApiFunctionInfo.GetAt( xElementIndex );
  500. if ( pcfafiElement != (CFaxApiFunctionInfo *) NULL )
  501. {
  502. delete pcfafiElement;
  503. }
  504. }
  505. }
  506. }