home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1998 November / VPR9811A.BIN / VPR_DATA / Program / Ce / Main.c < prev    next >
C/C++ Source or Header  |  1998-09-04  |  5KB  |  191 lines

  1. #include    <windows.h>
  2. #include    <windowsx.h>
  3. #include    <commctrl.h>
  4. #include    <commdlg.h>
  5. #include    "resource.h"
  6.  
  7. TCHAR szAppName[] = TEXT("システム情報");
  8. #define        szTitle        szAppName
  9.  
  10. HINSTANCE    ghInstance;
  11. HWND        hwMain;
  12. HWND        hwCmdBar;
  13.  
  14. BOOL DisplaySystemInfo(HWND, PAINTSTRUCT *);
  15. BOOL DisplayBatteryStatus(HWND, PAINTSTRUCT *);
  16. LRESULT CALLBACK AboutProc(HWND, UINT, WPARAM, LPARAM);
  17.  
  18.  
  19. //----------------------------------------------------------------------------
  20. LRESULT WINAPI Main_OnCommand(
  21.     HWND    hwnd,
  22.     int        id,
  23.     HWND    hwndCtl,
  24.     UINT    codeNotify)
  25. //----------------------------------------------------------------------------
  26. {
  27.     switch (id)
  28.     {
  29.     case IDM_FILE_EXIT:    // 「終了」を選択
  30.         SendMessage(hwnd, WM_CLOSE, 0, 0L);
  31.         break;
  32.  
  33.     case IDM_ABOUT:        // 「About」を選択
  34.         DialogBox(ghInstance, MAKEINTRESOURCE(IDD_ABOUT), hwnd, (DLGPROC)AboutProc);
  35.         break;
  36.  
  37.     default:
  38.         return FALSE;
  39.  
  40.     }
  41.     return TRUE;
  42. }
  43.  
  44. //----------------------------------------------------------------------------
  45. BOOL WINAPI Main_OnCreate(
  46.     HWND            hwnd,
  47.     LPCREATESTRUCT    lpCreateStruct)
  48. //----------------------------------------------------------------------------
  49. {
  50.     // Small Icon on taskbar
  51.     SendMessage(hwnd, WM_SETICON, FALSE,
  52.                 (LPARAM) LoadImage(ghInstance, MAKEINTRESOURCE(IDI_ICON1),
  53.                                    IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR));
  54.     // 3Sec.Timer start
  55.     SetTimer(hwnd, 99, 3000, NULL);
  56.  
  57.     return TRUE;
  58. }
  59.  
  60. //----------------------------------------------------------------------------
  61. void WINAPI Main_OnDestroy(
  62.     HWND    hwnd)
  63. //----------------------------------------------------------------------------
  64. {
  65.     // Timer stop
  66.     KillTimer(hwnd, 99);
  67.  
  68.     PostQuitMessage(0);
  69. }
  70.  
  71. //----------------------------------------------------------------------------
  72. //    the WM_PAINT message will re-display
  73. void WINAPI Main_OnPaint(
  74.     HWND    hwnd)
  75. //----------------------------------------------------------------------------
  76. {
  77.     HDC          hdc;
  78.     PAINTSTRUCT  ps;
  79.  
  80.     hdc = BeginPaint(hwnd, &ps);
  81.     // the current system information
  82.     DisplaySystemInfo(hwnd, &ps);
  83.     // the current battery status
  84.     DisplayBatteryStatus(hwnd, &ps);
  85.     EndPaint(hwnd, &ps);
  86. }
  87.  
  88. //----------------------------------------------------------------------------
  89. //    Timer Proc - the WM_TIMER message will re-display
  90. BOOL WINAPI Main_OnTimer(
  91.     HWND    hwnd,
  92.     UINT    id)
  93. //----------------------------------------------------------------------------
  94. {
  95.     InvalidateRect(hwnd, NULL, TRUE);
  96.     UpdateWindow(hwnd);
  97.  
  98.     return TRUE;
  99. }
  100.  
  101. //----------------------------------------------------------------------------
  102. LRESULT CALLBACK WndProc(
  103.     HWND    hwnd,
  104.     UINT    uMsg,
  105.     WPARAM    wParam,
  106.     LPARAM    lParam)
  107. //----------------------------------------------------------------------------
  108. {
  109.     switch(uMsg)
  110.     {
  111.     HANDLE_MSG(hwnd, WM_COMMAND,    Main_OnCommand);
  112.     HANDLE_MSG(hwnd, WM_DESTROY,    Main_OnDestroy);
  113.     HANDLE_MSG(hwnd, WM_CREATE,        Main_OnCreate );
  114.     HANDLE_MSG(hwnd, WM_PAINT,        Main_OnPaint);
  115.     HANDLE_MSG(hwnd, WM_TIMER,        Main_OnTimer);
  116.     default:
  117.         return DefWindowProc(hwnd, uMsg, wParam, lParam);
  118.     }
  119.  
  120.     return FALSE;
  121. }
  122.  
  123. //----------------------------------------------------------------------------
  124. BOOL InitApplication(
  125.     HINSTANCE    hInstance)
  126. //----------------------------------------------------------------------------
  127. {
  128.     WNDCLASS    wc;
  129.  
  130.     memset(&wc, 0, sizeof(WNDCLASS));
  131.     wc.style         = CS_HREDRAW | CS_VREDRAW ;
  132.     wc.lpszClassName = szAppName;
  133.     wc.lpfnWndProc   = (WNDPROC) WndProc;
  134.     wc.hInstance     = hInstance;
  135.     wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
  136.  
  137.     return RegisterClass(&wc);
  138. }
  139.  
  140. //----------------------------------------------------------------------------
  141. BOOL InitInstance(
  142.     HINSTANCE    hInstance,
  143.     int            CmdShow)
  144. //----------------------------------------------------------------------------
  145. {
  146.     ghInstance = hInstance;
  147.     InitCommonControls();
  148.  
  149.     // create MainWindow
  150.     if((hwMain = CreateWindow(szAppName, szTitle, WS_VISIBLE,
  151.                               CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
  152.                               NULL, NULL, ghInstance, NULL)) == NULL)
  153.         return FALSE;
  154.  
  155.     // create Commandbar(menu)
  156.     hwCmdBar = CommandBar_Create (ghInstance, hwMain, 1);
  157.     CommandBar_InsertMenubar(hwCmdBar, ghInstance, IDR_MENU1, 0);
  158.     CommandBar_AddAdornments(hwCmdBar, 0, 0);
  159.  
  160.     ShowWindow(hwMain, CmdShow);
  161.     UpdateWindow(hwMain);
  162.  
  163.     return TRUE;
  164. }
  165.  
  166. //----------------------------------------------------------------------------
  167. int WINAPI WinMain(
  168.     HINSTANCE    hInstance,            // 
  169.     HINSTANCE    hPrevInstance,        // 
  170.     LPTSTR        lpCmdLine,            // 
  171.     int            nCmdShow)            // 
  172. //----------------------------------------------------------------------------
  173. {
  174.     MSG        msg;
  175.  
  176.     if(! hPrevInstance)
  177.         if(! InitApplication(hInstance))
  178.             return FALSE;
  179.  
  180.     if(! InitInstance(hInstance, nCmdShow))
  181.         return FALSE;
  182.  
  183.     while(GetMessage(&msg, NULL, 0, 0))
  184.     {    // Message Loop
  185.         TranslateMessage(&msg);        // Translates virtual key codes
  186.         DispatchMessage(&msg);        // Dispatches message to window
  187.     }
  188.  
  189.     return msg.wParam;
  190. }
  191.