mysqlshutdown.c
上传用户:romrleung
上传日期:2022-05-23
资源大小:18897k
文件大小:6k
源码类别:

MySQL数据库

开发平台:

Visual C++

  1. /****************************************************************************
  2.    MySqlShutdown - shutdown MySQL on system shutdown (Win95/98)
  3.  ----------------------------------------------------------------------------
  4.  Revision History :
  5.  Version  Author   Date         Description
  6.  001.00   Irena    21-12-99
  7. *****************************************************************************/
  8. #include <windows.h>
  9. //-----------------------------------------------------------------------
  10. // Local  data
  11. //-----------------------------------------------------------------------
  12. static char szAppName[] = "MySqlShutdown";
  13. static HINSTANCE hInstance;
  14. #define MYWM_NOTIFYICON (WM_APP+100)
  15. //-----------------------------------------------------------------------
  16. // Exported functions
  17. //-----------------------------------------------------------------------
  18. LRESULT CALLBACK MainWindowProc (HWND, UINT, WPARAM, LPARAM);
  19. //-----------------------------------------------------------------------
  20. // Local functions
  21. //-----------------------------------------------------------------------
  22. static BOOL InitAppClass (HINSTANCE hInstance);
  23. BOOL TrayMessageAdd(HWND hWnd, DWORD dwMessage)
  24. {
  25.     BOOL res;
  26.     HICON hIcon =LoadIcon (hInstance, "MySql");
  27.     char *szTip="MySql Shutdown";
  28. NOTIFYICONDATA tnd;
  29. tnd.cbSize = sizeof(NOTIFYICONDATA);
  30. tnd.hWnd = hWnd;
  31. tnd.uID = 101;
  32. tnd.uFlags = NIF_MESSAGE|NIF_ICON|NIF_TIP;
  33. tnd.uCallbackMessage = MYWM_NOTIFYICON;
  34. tnd.hIcon = hIcon;
  35.     strcpy(tnd.szTip, szTip);
  36. res = Shell_NotifyIcon(dwMessage, &tnd);
  37. if (hIcon) DestroyIcon(hIcon);
  38. return res;
  39. }
  40. //-----------------------------------------------------------------------
  41. //   Name:      WinMain
  42. //   Purpose: Main application entry point
  43. //-----------------------------------------------------------------------
  44. int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow)
  45. {   HWND  hWnd;
  46.     MSG   Msg;
  47.     hInstance=hInst;
  48.     // Register application class if needed
  49.     if (InitAppClass (hInstance) == FALSE) return (0);
  50.     hWnd = CreateWindow (szAppName, "MySql",
  51.                         WS_OVERLAPPEDWINDOW|WS_MINIMIZE,
  52.                         0, 0,
  53.                         GetSystemMetrics(SM_CXSCREEN)/4,
  54.                         GetSystemMetrics(SM_CYSCREEN)/4,
  55.                         0, 0, hInstance, NULL);
  56.     if(!hWnd)
  57.     {
  58.         return (0);
  59.     }
  60.     ShowWindow (hWnd, SW_HIDE);
  61.     UpdateWindow (hWnd);
  62.     while (GetMessage (&Msg, 0, 0, 0))
  63.     {  TranslateMessage (&Msg);
  64.         DispatchMessage (&Msg);
  65.     }
  66.     return ((int) (Msg.wParam));
  67. }
  68. //-----------------------------------------------------------------------
  69. //   Name:    InitAppClass
  70. //   Purpose: Register the main application window class
  71. //-----------------------------------------------------------------------
  72. static BOOL InitAppClass (HINSTANCE hInstance)
  73. {
  74.     WNDCLASS cls;
  75.     if (GetClassInfo (hInstance, szAppName, &cls) == 0)
  76.     {
  77.         cls.style          = CS_HREDRAW | CS_VREDRAW ;;
  78.         cls.lpfnWndProc    = (WNDPROC) MainWindowProc;
  79.         cls.cbClsExtra     = 0;
  80.         cls.cbWndExtra     = sizeof(HWND);
  81.         cls.hInstance      = hInstance;
  82.         cls.hIcon          = LoadIcon (hInstance, "MySql");
  83.         cls.hCursor        = LoadCursor (NULL, IDC_ARROW);
  84.         cls.hbrBackground  = GetStockObject (WHITE_BRUSH) ;
  85.         cls.lpszMenuName   = 0; //szAppName;
  86.         cls.lpszClassName  = szAppName;
  87.         return RegisterClass (&cls);
  88.     }
  89.     return (TRUE);
  90. }
  91. //-----------------------------------------------------------------------
  92. //   Name:      MainWindowProc
  93. //   Purpose: Window procedure for main application window.
  94. //-----------------------------------------------------------------------
  95. LRESULT CALLBACK MainWindowProc (HWND hWnd, UINT Msg,WPARAM wParam, LPARAM lParam)
  96. {
  97.  static RECT   rect ;
  98.  HDC           hdc ;
  99.  PAINTSTRUCT   ps ;
  100.  static BOOL   bShutdown=FALSE;
  101.     switch (Msg)
  102.     {
  103.           case WM_CREATE:
  104.                TrayMessageAdd(hWnd, NIM_ADD);
  105.                return TRUE;
  106. /***************
  107.           case WM_SYSCOMMAND:
  108.                if(wParam==SC_CLOSE)
  109.                { HANDLE hEventShutdown;
  110.                 bShutdown=TRUE;
  111.                 InvalidateRect(hWnd,NULL,TRUE);
  112.                 ShowWindow (hWnd, SW_NORMAL);
  113.                 UpdateWindow(hWnd);
  114.                 hEventShutdown=OpenEvent(EVENT_MODIFY_STATE, 0, "MySqlShutdown");
  115.                 if(hEventShutdown)
  116.                 {
  117.                   SetEvent(hEventShutdown);
  118.                   CloseHandle(hEventShutdown);
  119.                   Sleep(1000);
  120.                   MessageBox(hWnd,"Shutdown", "MySql", MB_OK);
  121.                 }
  122.                TrayMessageAdd(hWnd, NIM_DELETE);
  123.                }
  124.                break;
  125. **************/
  126.           case WM_DESTROY:
  127.                TrayMessageAdd(hWnd, NIM_DELETE);
  128.                PostQuitMessage (0);
  129.                return 0;
  130.           case WM_SIZE:
  131.                GetClientRect (hWnd, &rect) ;
  132.                return 0 ;
  133.           case WM_PAINT:
  134.                hdc = BeginPaint (hWnd, &ps) ;
  135.                if(bShutdown)
  136.                  DrawText (hdc, "MySql shutdown in progress...",
  137.                                 -1, &rect, DT_WORDBREAK) ;
  138.                EndPaint (hWnd, &ps) ;
  139.                return 0 ;
  140.           case WM_QUERYENDSESSION: //Shutdown MySql
  141.                { HANDLE hEventShutdown;
  142.                 bShutdown=TRUE;
  143.                 InvalidateRect(hWnd,NULL,TRUE);
  144.                 ShowWindow (hWnd, SW_NORMAL);
  145.                 UpdateWindow(hWnd);
  146.                 hEventShutdown=OpenEvent(EVENT_MODIFY_STATE, 0, "MySqlShutdown");
  147.                 if(hEventShutdown)
  148.                 {
  149.                   SetEvent(hEventShutdown);
  150.                   CloseHandle(hEventShutdown);
  151.                   Sleep(1000);
  152.                   MessageBox(hWnd,"Shutdown", "MySql", MB_OK);
  153.                 }
  154.                }
  155.                return 1;
  156.       case MYWM_NOTIFYICON:
  157.    switch (lParam)
  158.    {
  159.      case WM_LBUTTONDOWN:
  160.      case WM_RBUTTONDOWN:
  161.       ShowWindow(hWnd, SW_SHOWNORMAL);
  162.       SetForegroundWindow(hWnd); // make us come to the front
  163.       break;
  164.      default:
  165.       break;
  166.      }
  167.      break;
  168.     }
  169.     return DefWindowProc (hWnd, Msg, wParam, lParam);
  170. }
  171. // ----------------------- The end ------------------------------------------