home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1999 April / PCO0499.ISO / filesbbs / os2 / apach134.arj / APACH134.ZIP / src / os / win32 / installer / installdll / test / test.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-02-24  |  3.4 KB  |  155 lines

  1. /*
  2.  * Tester for the Apache Install DLL
  3.  */
  4.  
  5. #include <windows.h>
  6.  
  7. #include "test.h"
  8.  
  9. #define APPNAME "Test"
  10.  
  11. HINSTANCE hInst;      // current instance
  12. char szAppName[100];  // Name of the app
  13. char szTitle[100];    // The title bar text
  14.  
  15. extern CHAR WINAPI BeforeExit(HWND, LPSTR,LPSTR,LPSTR,LPSTR);
  16.  
  17. BOOL InitApplication(HINSTANCE);
  18. BOOL InitInstance(HINSTANCE, int);
  19. LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
  20. LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
  21.  
  22. int APIENTRY WinMain(HINSTANCE hInstance,
  23.                      HINSTANCE hPrevInstance,
  24.                      LPSTR     lpCmdLine,
  25.                      int       nCmdShow)
  26. {
  27.    MSG msg;
  28.    HANDLE hAccelTable;
  29.  
  30.    lstrcpy (szAppName, APPNAME);
  31.    lstrcpy (szTitle, APPNAME);
  32.  
  33.    if (!hPrevInstance) {
  34.       if (!InitApplication(hInstance)) {
  35.          return (FALSE);
  36.       }
  37.    }
  38.  
  39.    if (!InitInstance(hInstance, nCmdShow)) {
  40.       return (FALSE);
  41.    }
  42.  
  43.    hAccelTable = LoadAccelerators (hInstance, szAppName);
  44.  
  45.    while (GetMessage(&msg, NULL, 0, 0)) {
  46.       if (!TranslateAccelerator (msg.hwnd, hAccelTable, &msg)) {
  47.          TranslateMessage(&msg);
  48.          DispatchMessage(&msg);
  49.       }
  50.    }
  51.  
  52.    return (msg.wParam);
  53.  
  54.    lpCmdLine; // This will prevent 'unused formal parameter' warnings
  55. }
  56.  
  57. BOOL InitApplication(HINSTANCE hInstance)
  58. {
  59.     WNDCLASS  wc;
  60.     HWND      hwnd;
  61.  
  62.     hwnd = FindWindow (szAppName, szTitle);
  63.  
  64.     wc.style         = CS_HREDRAW | CS_VREDRAW;
  65.     wc.lpfnWndProc   = (WNDPROC)WndProc;
  66.     wc.cbClsExtra    = 0;
  67.     wc.cbWndExtra    = 0;
  68.     wc.hInstance     = hInstance;
  69.     wc.hIcon         = LoadIcon (hInstance, MAKEINTRESOURCE(IDI_TEST));
  70.     wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
  71.     wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  72.     wc.lpszMenuName  = MAKEINTRESOURCE(IDM_TEST);
  73.     wc.lpszClassName = szAppName;
  74.  
  75.     return RegisterClass(&wc);
  76. }
  77.  
  78. BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
  79. {
  80.    HWND hWnd;
  81.  
  82.    hInst = hInstance;
  83.  
  84.    hWnd = CreateWindow(szAppName, szTitle, WS_OVERLAPPEDWINDOW,
  85.       CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
  86.       NULL, NULL, hInstance, NULL);
  87.  
  88.    if (!hWnd) {
  89.       return (FALSE);
  90.    }
  91.  
  92.    ShowWindow(hWnd, nCmdShow);
  93.    UpdateWindow(hWnd);
  94.  
  95.    return (TRUE);
  96. }
  97.  
  98. LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  99. {
  100.    int wmId, wmEvent;
  101.  
  102.    switch (message) {
  103.  
  104.       case WM_COMMAND:
  105.          wmId    = LOWORD(wParam);
  106.          wmEvent = HIWORD(wParam);
  107.  
  108.          switch (wmId) {
  109.  
  110.             case IDM_ABOUT:
  111.                DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUT), hWnd, (DLGPROC)About);
  112.                break;
  113.  
  114.         case IDM_BEFOREEXIT:
  115.         BeforeExit(hWnd, "C:\\", "C:\\", "C:\\Apache", NULL);
  116.         break;
  117.  
  118.             case IDM_EXIT:
  119.                DestroyWindow (hWnd);
  120.                break;
  121.  
  122.             default:
  123.                return (DefWindowProc(hWnd, message, wParam, lParam));
  124.          }
  125.          break;
  126.  
  127.       case WM_DESTROY:
  128.          PostQuitMessage(0);
  129.          break;
  130.  
  131.       default:
  132.          return (DefWindowProc(hWnd, message, wParam, lParam));
  133.    }
  134.    return (0);
  135. }
  136.  
  137. LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  138. {
  139.  
  140.    switch (message) {
  141.         case WM_INITDIALOG:
  142.          return (TRUE);
  143.  
  144.       case WM_COMMAND:
  145.          if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) {
  146.             EndDialog(hDlg, TRUE);
  147.             return (TRUE);
  148.          }
  149.          break;
  150.    }
  151.  
  152.     return FALSE;
  153. }
  154.  
  155.