home *** CD-ROM | disk | FTP | other *** search
/ Internet Publisher's Toolbox 2.0 / Internet Publisher's Toolbox.iso / html / rtf2html / wrtf2htm / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-21  |  7.6 KB  |  275 lines

  1. //*************************************************************
  2. //  File name: main.c
  3. //
  4. //    Demonstrates how to use the 3.1 Drag and Drop APIs.  The 
  5. //    main window is registered for drag/drop messages by calling
  6. //    DragAcceptFiles.  Whenever a file is dragged and dropped on
  7. //    the app, the name is the file is added to a listbox which 
  8. //    fills the main window's client area.
  9. //
  10. //  Description:
  11. //
  12. //      WinMain and window procedure routines.
  13. //
  14. //  Development Team:
  15. //
  16. //      Mike Brehm
  17. //      Irfan Gowani
  18. //
  19. //  Written by Microsoft Product Support Services, Windows Developer Support
  20. //  Copyright (c) 1992 Microsoft Corporation. All rights reserved.
  21. //*************************************************************
  22.  
  23. #include "global.h"
  24. #include "shellapi.h"
  25.  
  26. HANDLE ghInst = NULL;
  27. HWND ghWndMain = NULL;
  28. HWND ghListBox = NULL;
  29.  
  30. char szMainMenu[] = "MainMenu";
  31. char szMainClass[] = "MainClass";
  32.  
  33. //*************************************************************
  34. //
  35. //  WinMain()
  36. //
  37. //  Purpose:
  38. //
  39. //        Entry point for all Windows applications.
  40. //
  41. //
  42. //  Parameters:
  43. //
  44. //      HANDLE hInstance     - Handle to current instance
  45. //      HANDLE hPrevInstance - Handle to previous instance
  46. //      LPSTR  lpCmdLine     - Command-line arguments
  47. //      int    nCmdShow      - How window is initially displayed
  48. //      
  49. //
  50. //  Return: (int PASCAL)
  51. //
  52. //
  53. //  Comments:
  54. //
  55. //
  56. //  History:    Date       Author       Comment
  57. //              12/12/91   Mike Brehm   Created
  58. //
  59. //*************************************************************
  60.  
  61. int PASCAL WinMain (HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpCmdLine, int nCmdShow
  62.                     )
  63. {
  64.    MSG msg;        // Message passed to our application
  65.  
  66.    if (!hPrevInstance && !InitApplication(hInstance))
  67.       return (FALSE);
  68.  
  69.    if (!InitInstance(hInstance, nCmdShow))
  70.       return (FALSE);
  71.  
  72.    while (GetMessage(&msg, NULL, 0, 0))
  73.    {
  74.       TranslateMessage(&msg);
  75.       DispatchMessage(&msg);
  76.    }
  77.    return (msg.wParam);
  78. }                  /* WinMain() */
  79.  
  80. //*************************************************************
  81. //
  82. //  MainWndProc()
  83. //
  84. //  Purpose:
  85. //
  86. //        Main Window procedure.  Since window has been registered to accept
  87. //    dropped files (DragAcceptFile()), it will receive a WM_DROPFILES 
  88. //    message whenever files are dropped over it.  The window processes
  89. //    the message by adding the filenames to the list box filling
  90. //    its client area.
  91. //
  92. //
  93. //  Parameters:
  94. //
  95. //      HWND     hWnd   - Handle to main window
  96. //      unsigned msg    - Message passed to application
  97. //      WORD     wParam - Additional message information
  98. //      LONG     lParam - Additional message information
  99. //      
  100. //
  101. //  Return: (long FAR PASCAL)
  102. //
  103. //
  104. //  Comments:
  105. //
  106. //
  107. //  History:    Date       Author       Comment
  108. //              12/12/91   Mike Brehm   Created
  109. //
  110. //*************************************************************
  111. // Character array used for input to mainconv
  112. char *Args[3];
  113. char *Progname = "convrtf";
  114. char szFileName[254];
  115. LRESULT CALLBACK  MainWndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
  116. {
  117.    FARPROC lpProc; // Proc-instance address for Abour dialog box
  118.    HDROP hFilesInfo;                  // Handle to file info structure when files
  119.    // are dropped on our application
  120.    WORD wTotalFiles;                   // Number of files dropped on our application
  121.    WORD wIndex;    // Counter of files
  122.    char szFileName[FILE_NAME_LENGTH];  // Buffer for filename    
  123.    int iRtn;
  124.    HCURSOR hCursor,hStdCursor;
  125.    char TempStr[100];
  126.  
  127.    switch (msg)
  128.    {
  129.       case WM_DROPFILES:               //file was dropped over window
  130.          hFilesInfo = (HANDLE)wParam;
  131.  
  132.          // get number of files dropped
  133.          wTotalFiles = DragQueryFile(hFilesInfo, 0xffffffff, NULL, 0);
  134.  
  135.          // add the file names to the listbox
  136.          if(wTotalFiles != 0xffff) {
  137.          for (wIndex = 0; wIndex < wTotalFiles; wIndex++)
  138.          {
  139.             // get the next file name
  140.             DragQueryFile(hFilesInfo, wIndex, (LPSTR)szFileName, FILE_NAME_LENGTH);
  141.  
  142.             // add the file name to the list box
  143.             SendMessage(ghListBox, LB_ADDSTRING, 0, (LONG)(LPSTR)szFileName);
  144.             
  145.          }
  146.          SetTimer(hWnd,5,1000,NULL);
  147.          // release memory Windows allocated for transferring 
  148.          // filenames to app
  149.          } 
  150.          DragFinish(hFilesInfo);
  151.  
  152.          return 0;
  153.  
  154.          break;
  155.       case WM_TIMER:
  156.           KillTimer(hWnd,wParam);
  157.         PostMessage(hWnd,WM_COMMAND,IDM_CONVERT,0L);
  158.         break;
  159.  
  160.       case WM_SIZE:
  161.          // list box should fill client area
  162.          MoveWindow(ghListBox, 0, 0, LOWORD( lParam ), HIWORD( lParam ), TRUE);
  163.  
  164.          break;
  165.  
  166.       case WM_COMMAND:
  167.          switch (wParam)
  168.          {
  169.             case IDM_ABOUT:            // About box
  170.                lpProc = MakeProcInstance(About, ghInst);
  171.                DialogBox(ghInst, "AboutBox", hWnd, lpProc);
  172.                FreeProcInstance(lpProc);
  173.  
  174.                return 0;
  175.  
  176.                break;
  177.  
  178.             //
  179.             // Clear out the listbox
  180.             //
  181.  
  182.             case IDM_CLEAR:
  183.                SendMessage(ghListBox, LB_RESETCONTENT, 0, 0L);
  184.  
  185.                return 0;
  186.  
  187.                break;
  188.  
  189.             case IDM_CONVERT:
  190.                 // There is at least one entry in the listbox. Fetch an entry and process.
  191.                 iRtn=SendMessage(ghListBox, LB_GETTEXT,0, (LONG)(char far *)szFileName);     // Get zeroth entry
  192.                 if(iRtn != LB_ERR) {
  193.                     SendMessage(ghListBox, LB_DELETESTRING, 0, (LONG)0);  // Delete the entry
  194.                     sprintf(TempStr,"Converting %s",szFileName);
  195.                     SetWindowText(hWnd,TempStr);
  196.                     MessageBeep(MB_ICONASTERISK);
  197.                     Args[0]=Progname;
  198.                     Args[1]=szFileName;     
  199.                     hCursor = LoadCursor(NULL,IDC_WAIT);
  200.                     hStdCursor = SetCursor(hCursor);
  201.                     mainconv(2,Args);
  202.                     SetCursor(hStdCursor);
  203.                     SetWindowText(hWnd,"Pausing RTF to HTML Converter");
  204.                     SetTimer(hWnd,5,3000,NULL);
  205.                     //Sleep(3000);   // Pause 3 seconds between conversions
  206.                     //PostMessage(hWnd,WM_COMMAND,IDM_CONVERT,0L);  // See if there are any more
  207.                 } 
  208.                 SetWindowText(hWnd,"RTF to HTML Converter");
  209.                 break;
  210.          }
  211.          break;
  212.  
  213.       case WM_DESTROY:
  214.          PostQuitMessage(0);
  215.  
  216.          break;
  217.    }
  218.  
  219.    return (DefWindowProc(hWnd, msg, wParam, lParam));
  220. }                  /* MainWndProc() */
  221.  
  222. //*************************************************************
  223. //
  224. //  About()
  225. //
  226. //  Purpose:
  227. //
  228. //        The About dialog box procedure.
  229. //
  230. //
  231. //  Parameters:
  232. //
  233. //      HWND     hDlg   - Handle to dialog window
  234. //      unsigned msg    - Message passed to dialog window
  235. //      WORD     wParam - Additional message information
  236. //      LONG     lParam - Additional message information
  237. //      
  238. //
  239. //  Return: (BOOL FAR PASCAL)
  240. //
  241. //      TRUE  - About dialog procedure handled the message.
  242. //      FALSE - About dialog procedure did not handle the message.
  243. //
  244. //  Comments:
  245. //
  246. //
  247. //  History:    Date       Author       Comment
  248. //              12/12/91   Mike Brehm   Created
  249. //
  250. //*************************************************************
  251.  
  252. BOOL FAR PASCAL About (HWND hDlg, unsigned msg, WORD wParam, LONG lParam)
  253. {
  254.    switch (msg)
  255.    {
  256.       case WM_INITDIALOG:
  257.          return (TRUE);
  258.  
  259.          break;
  260.  
  261.       case WM_COMMAND:
  262.          if (wParam == IDOK || wParam == IDCANCEL)
  263.          {
  264.             EndDialog(hDlg, TRUE);
  265.             return (TRUE);
  266.          }
  267.          break;
  268.    }
  269.  
  270.    return (FALSE); // Didn't process a message
  271. }                  /* About() */
  272.  
  273.  
  274. /*** EOF: main.c ***/
  275.