home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c045 / 5.ddi / EDITMENU / EDITMENU.C$ / EDITMENU.bin
Encoding:
Text File  |  1992-01-01  |  6.0 KB  |  238 lines

  1. /****************************************************************************
  2.  
  3.     PROGRAM: EditMenu.c
  4.  
  5.     PURPOSE: EditMenu template for Windows applications
  6.  
  7.     FUNCTIONS:
  8.  
  9.     WinMain() - calls initialization function, processes message loop
  10.     InitApplication() - initializes window data and registers window
  11.     InitInstance() - saves instance handle and creates main window
  12.     MainWndProc() - processes messages
  13.     About() - processes messages for "About" dialog box
  14.  
  15. ****************************************************************************/
  16.  
  17. #include "windows.h"
  18. #include "editmenu.h"
  19.  
  20. HANDLE hInst;
  21.  
  22. HANDLE hAccTable;                                /* handle to accelerator table */
  23.  
  24. HWND   hwnd;                                    /* handle to main window */
  25.  
  26. /****************************************************************************
  27.  
  28.     FUNCTION: WinMain(HANDLE, HANDLE, LPSTR, int)
  29.  
  30.     PURPOSE: calls initialization function, processes message loop
  31.  
  32. ****************************************************************************/
  33.  
  34. int PASCAL WinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow)
  35. HANDLE hInstance;
  36. HANDLE hPrevInstance;
  37. LPSTR lpCmdLine;
  38. int nCmdShow;
  39. {
  40.     MSG msg;
  41.  
  42.     if (!hPrevInstance)
  43.     if (!InitApplication(hInstance))
  44.         return (FALSE);
  45.  
  46.     if (!InitInstance(hInstance, nCmdShow))
  47.         return (FALSE);
  48.  
  49.     while (GetMessage(&msg, NULL, NULL, NULL)) {
  50.  
  51.     /* Only translate message if it is not an accelerator message */
  52.  
  53.         if (!TranslateAccelerator(hwnd, hAccTable, &msg)) {
  54.             TranslateMessage(&msg);
  55.             DispatchMessage(&msg); 
  56.         }
  57.     }
  58.     return (msg.wParam);
  59. }
  60.  
  61.  
  62. /****************************************************************************
  63.  
  64.     FUNCTION: InitApplication(HANDLE)
  65.  
  66.     PURPOSE: Initializes window data and registers window class
  67.  
  68. ****************************************************************************/
  69.  
  70. BOOL InitApplication(hInstance)
  71. HANDLE hInstance;
  72. {
  73.     WNDCLASS  wc;
  74.  
  75.     wc.style = NULL;
  76.     wc.lpfnWndProc = MainWndProc;
  77.     wc.cbClsExtra = 0;
  78.     wc.cbWndExtra = 0;
  79.     wc.hInstance = hInstance;
  80.     wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  81.     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  82.     wc.hbrBackground = GetStockObject(WHITE_BRUSH); 
  83.     wc.lpszMenuName =  "EditMenuMenu";
  84.     wc.lpszClassName = "EditMenuWClass";
  85.  
  86.     return (RegisterClass(&wc));
  87. }
  88.  
  89.  
  90. /****************************************************************************
  91.  
  92.     FUNCTION:  InitInstance(HANDLE, int)
  93.  
  94.     PURPOSE:  Saves instance handle and creates main window
  95.  
  96. ****************************************************************************/
  97.  
  98. BOOL InitInstance(hInstance, nCmdShow)
  99.     HANDLE          hInstance;
  100.     int             nCmdShow;
  101. {
  102.  
  103.     hInst = hInstance;
  104.  
  105.     hAccTable = LoadAccelerators(hInst, "EditMenuAcc");
  106.  
  107.     hwnd = CreateWindow(
  108.         "EditMenuWClass",
  109.         "EditMenu Sample Application",
  110.         WS_OVERLAPPEDWINDOW,
  111.         CW_USEDEFAULT,
  112.         CW_USEDEFAULT,
  113.         CW_USEDEFAULT,
  114.         CW_USEDEFAULT,
  115.         NULL,
  116.         NULL,
  117.         hInstance,
  118.         NULL
  119.     );
  120.  
  121.     if (!hwnd)
  122.         return (FALSE);
  123.  
  124.     ShowWindow(hwnd, nCmdShow);
  125.     UpdateWindow(hwnd);
  126.     return (TRUE);
  127.  
  128. }
  129.  
  130. /****************************************************************************
  131.  
  132.     FUNCTION: MainWndProc(HWND, unsigned, WORD, LONG)
  133.  
  134.     PURPOSE:  Processes messages
  135.  
  136.     MESSAGES:
  137.  
  138.     WM_COMMAND    - application menu (About dialog box)
  139.     WM_DESTROY    - destroy window
  140.  
  141. ****************************************************************************/
  142.  
  143. long FAR PASCAL MainWndProc(hWnd, message, wParam, lParam)
  144. HWND hWnd;
  145. unsigned message;
  146. WORD wParam;
  147. LONG lParam;
  148. {
  149.     FARPROC lpProcAbout;
  150.  
  151.     switch (message) {
  152.     case WM_COMMAND:
  153.             switch (wParam) {
  154.                 case IDM_ABOUT:
  155.                     lpProcAbout = MakeProcInstance(About, hInst);
  156.                     DialogBox(hInst, "AboutBox", hWnd, lpProcAbout);
  157.                     FreeProcInstance(lpProcAbout);
  158.                     break;
  159.  
  160.                 /* file menu commands */
  161.  
  162.                 case IDM_NEW:
  163.                 case IDM_OPEN:
  164.                 case IDM_SAVE:
  165.                 case IDM_SAVEAS:
  166.                 case IDM_PRINT:
  167.                     MessageBox (
  168.                           GetFocus(),
  169.                           "Command not implemented",
  170.                           "EditMenu Sample Application",
  171.                           MB_ICONASTERISK | MB_OK);
  172.                     break;  
  173.  
  174.                 case IDM_EXIT:
  175.                     DestroyWindow(hWnd);
  176.                     break;
  177.     
  178.                 /* edit menu commands */
  179.  
  180.                 case IDM_UNDO:
  181.                 case IDM_CUT:
  182.                 case IDM_COPY:
  183.                 case IDM_PASTE:
  184.                 case IDM_CLEAR:
  185.                     MessageBox (
  186.                           GetFocus(),
  187.                           "Command not implemented",
  188.                           "EditMenu Sample Application",
  189.                           MB_ICONASTERISK | MB_OK);
  190.                     break;  
  191.             } 
  192.             break;
  193.  
  194.     case WM_DESTROY:
  195.         PostQuitMessage(0);
  196.         break;
  197.  
  198.     default:
  199.         return (DefWindowProc(hWnd, message, wParam, lParam));
  200.     }
  201.     return (NULL);
  202. }
  203.  
  204.  
  205. /****************************************************************************
  206.  
  207.     FUNCTION: About(HWND, unsigned, WORD, LONG)
  208.  
  209.     PURPOSE:  Processes messages for "About" dialog box
  210.  
  211.     MESSAGES:
  212.  
  213.     WM_INITDIALOG - initialize dialog box
  214.     WM_COMMAND    - Input received
  215.  
  216. ****************************************************************************/
  217.  
  218. BOOL FAR PASCAL About(hDlg, message, wParam, lParam)
  219. HWND hDlg;
  220. unsigned message;
  221. WORD wParam;
  222. LONG lParam;
  223. {
  224.     switch (message) {
  225.     case WM_INITDIALOG:
  226.         return (TRUE);
  227.  
  228.     case WM_COMMAND:
  229.         if (wParam == IDOK
  230.                 || wParam == IDCANCEL) {
  231.         EndDialog(hDlg, TRUE);
  232.         return (TRUE);
  233.         }
  234.         break;
  235.     }
  236.     return (FALSE);
  237. }
  238.