home *** CD-ROM | disk | FTP | other *** search
- //*************************************************************
- // File name: main.c
- //
- // Demonstrates how to use the 3.1 Drag and Drop APIs. The
- // main window is registered for drag/drop messages by calling
- // DragAcceptFiles. Whenever a file is dragged and dropped on
- // the app, the name is the file is added to a listbox which
- // fills the main window's client area.
- //
- // Description:
- //
- // WinMain and window procedure routines.
- //
- // Development Team:
- //
- // Mike Brehm
- // Irfan Gowani
- //
- // Written by Microsoft Product Support Services, Windows Developer Support
- // Copyright (c) 1992 Microsoft Corporation. All rights reserved.
- //*************************************************************
-
- #include "global.h"
- #include "shellapi.h"
-
- HANDLE ghInst = NULL;
- HWND ghWndMain = NULL;
- HWND ghListBox = NULL;
-
- char szMainMenu[] = "MainMenu";
- char szMainClass[] = "MainClass";
-
- //*************************************************************
- //
- // WinMain()
- //
- // Purpose:
- //
- // Entry point for all Windows applications.
- //
- //
- // Parameters:
- //
- // HANDLE hInstance - Handle to current instance
- // HANDLE hPrevInstance - Handle to previous instance
- // LPSTR lpCmdLine - Command-line arguments
- // int nCmdShow - How window is initially displayed
- //
- //
- // Return: (int PASCAL)
- //
- //
- // Comments:
- //
- //
- // History: Date Author Comment
- // 12/12/91 Mike Brehm Created
- //
- //*************************************************************
-
- int PASCAL WinMain (HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpCmdLine, int nCmdShow
- )
- {
- MSG msg; // Message passed to our application
-
- if (!hPrevInstance && !InitApplication(hInstance))
- return (FALSE);
-
- if (!InitInstance(hInstance, nCmdShow))
- return (FALSE);
-
- while (GetMessage(&msg, NULL, 0, 0))
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- return (msg.wParam);
- } /* WinMain() */
-
- //*************************************************************
- //
- // MainWndProc()
- //
- // Purpose:
- //
- // Main Window procedure. Since window has been registered to accept
- // dropped files (DragAcceptFile()), it will receive a WM_DROPFILES
- // message whenever files are dropped over it. The window processes
- // the message by adding the filenames to the list box filling
- // its client area.
- //
- //
- // Parameters:
- //
- // HWND hWnd - Handle to main window
- // unsigned msg - Message passed to application
- // WORD wParam - Additional message information
- // LONG lParam - Additional message information
- //
- //
- // Return: (long FAR PASCAL)
- //
- //
- // Comments:
- //
- //
- // History: Date Author Comment
- // 12/12/91 Mike Brehm Created
- //
- //*************************************************************
- // Character array used for input to mainconv
- char *Args[3];
- char *Progname = "convrtf";
- char szFileName[254];
- LRESULT CALLBACK MainWndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
- {
- FARPROC lpProc; // Proc-instance address for Abour dialog box
- HDROP hFilesInfo; // Handle to file info structure when files
- // are dropped on our application
- WORD wTotalFiles; // Number of files dropped on our application
- WORD wIndex; // Counter of files
- char szFileName[FILE_NAME_LENGTH]; // Buffer for filename
- int iRtn;
- HCURSOR hCursor,hStdCursor;
- char TempStr[100];
-
- switch (msg)
- {
- case WM_DROPFILES: //file was dropped over window
- hFilesInfo = (HANDLE)wParam;
-
- // get number of files dropped
- wTotalFiles = DragQueryFile(hFilesInfo, 0xffffffff, NULL, 0);
-
- // add the file names to the listbox
- if(wTotalFiles != 0xffff) {
- for (wIndex = 0; wIndex < wTotalFiles; wIndex++)
- {
- // get the next file name
- DragQueryFile(hFilesInfo, wIndex, (LPSTR)szFileName, FILE_NAME_LENGTH);
-
- // add the file name to the list box
- SendMessage(ghListBox, LB_ADDSTRING, 0, (LONG)(LPSTR)szFileName);
-
- }
- SetTimer(hWnd,5,1000,NULL);
- // release memory Windows allocated for transferring
- // filenames to app
- }
- DragFinish(hFilesInfo);
-
- return 0;
-
- break;
- case WM_TIMER:
- KillTimer(hWnd,wParam);
- PostMessage(hWnd,WM_COMMAND,IDM_CONVERT,0L);
- break;
-
- case WM_SIZE:
- // list box should fill client area
- MoveWindow(ghListBox, 0, 0, LOWORD( lParam ), HIWORD( lParam ), TRUE);
-
- break;
-
- case WM_COMMAND:
- switch (wParam)
- {
- case IDM_ABOUT: // About box
- lpProc = MakeProcInstance(About, ghInst);
- DialogBox(ghInst, "AboutBox", hWnd, lpProc);
- FreeProcInstance(lpProc);
-
- return 0;
-
- break;
-
- //
- // Clear out the listbox
- //
-
- case IDM_CLEAR:
- SendMessage(ghListBox, LB_RESETCONTENT, 0, 0L);
-
- return 0;
-
- break;
-
- case IDM_CONVERT:
- // There is at least one entry in the listbox. Fetch an entry and process.
- iRtn=SendMessage(ghListBox, LB_GETTEXT,0, (LONG)(char far *)szFileName); // Get zeroth entry
- if(iRtn != LB_ERR) {
- SendMessage(ghListBox, LB_DELETESTRING, 0, (LONG)0); // Delete the entry
- sprintf(TempStr,"Converting %s",szFileName);
- SetWindowText(hWnd,TempStr);
- MessageBeep(MB_ICONASTERISK);
- Args[0]=Progname;
- Args[1]=szFileName;
- hCursor = LoadCursor(NULL,IDC_WAIT);
- hStdCursor = SetCursor(hCursor);
- mainconv(2,Args);
- SetCursor(hStdCursor);
- SetWindowText(hWnd,"Pausing RTF to HTML Converter");
- SetTimer(hWnd,5,3000,NULL);
- //Sleep(3000); // Pause 3 seconds between conversions
- //PostMessage(hWnd,WM_COMMAND,IDM_CONVERT,0L); // See if there are any more
- }
- SetWindowText(hWnd,"RTF to HTML Converter");
- break;
- }
- break;
-
- case WM_DESTROY:
- PostQuitMessage(0);
-
- break;
- }
-
- return (DefWindowProc(hWnd, msg, wParam, lParam));
- } /* MainWndProc() */
-
- //*************************************************************
- //
- // About()
- //
- // Purpose:
- //
- // The About dialog box procedure.
- //
- //
- // Parameters:
- //
- // HWND hDlg - Handle to dialog window
- // unsigned msg - Message passed to dialog window
- // WORD wParam - Additional message information
- // LONG lParam - Additional message information
- //
- //
- // Return: (BOOL FAR PASCAL)
- //
- // TRUE - About dialog procedure handled the message.
- // FALSE - About dialog procedure did not handle the message.
- //
- // Comments:
- //
- //
- // History: Date Author Comment
- // 12/12/91 Mike Brehm Created
- //
- //*************************************************************
-
- BOOL FAR PASCAL About (HWND hDlg, unsigned msg, WORD wParam, LONG lParam)
- {
- switch (msg)
- {
- case WM_INITDIALOG:
- return (TRUE);
-
- break;
-
- case WM_COMMAND:
- if (wParam == IDOK || wParam == IDCANCEL)
- {
- EndDialog(hDlg, TRUE);
- return (TRUE);
- }
- break;
- }
-
- return (FALSE); // Didn't process a message
- } /* About() */
-
-
- /*** EOF: main.c ***/
-