home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DOS/V Power Report 1998 November
/
VPR9811A.BIN
/
VPR_DATA
/
Program
/
Ce
/
Main.c
< prev
next >
Wrap
C/C++ Source or Header
|
1998-09-04
|
5KB
|
191 lines
#include <windows.h>
#include <windowsx.h>
#include <commctrl.h>
#include <commdlg.h>
#include "resource.h"
TCHAR szAppName[] = TEXT("システム情報");
#define szTitle szAppName
HINSTANCE ghInstance;
HWND hwMain;
HWND hwCmdBar;
BOOL DisplaySystemInfo(HWND, PAINTSTRUCT *);
BOOL DisplayBatteryStatus(HWND, PAINTSTRUCT *);
LRESULT CALLBACK AboutProc(HWND, UINT, WPARAM, LPARAM);
//----------------------------------------------------------------------------
LRESULT WINAPI Main_OnCommand(
HWND hwnd,
int id,
HWND hwndCtl,
UINT codeNotify)
//----------------------------------------------------------------------------
{
switch (id)
{
case IDM_FILE_EXIT: // 「終了」を選択
SendMessage(hwnd, WM_CLOSE, 0, 0L);
break;
case IDM_ABOUT: // 「About」を選択
DialogBox(ghInstance, MAKEINTRESOURCE(IDD_ABOUT), hwnd, (DLGPROC)AboutProc);
break;
default:
return FALSE;
}
return TRUE;
}
//----------------------------------------------------------------------------
BOOL WINAPI Main_OnCreate(
HWND hwnd,
LPCREATESTRUCT lpCreateStruct)
//----------------------------------------------------------------------------
{
// Small Icon on taskbar
SendMessage(hwnd, WM_SETICON, FALSE,
(LPARAM) LoadImage(ghInstance, MAKEINTRESOURCE(IDI_ICON1),
IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR));
// 3Sec.Timer start
SetTimer(hwnd, 99, 3000, NULL);
return TRUE;
}
//----------------------------------------------------------------------------
void WINAPI Main_OnDestroy(
HWND hwnd)
//----------------------------------------------------------------------------
{
// Timer stop
KillTimer(hwnd, 99);
PostQuitMessage(0);
}
//----------------------------------------------------------------------------
// the WM_PAINT message will re-display
void WINAPI Main_OnPaint(
HWND hwnd)
//----------------------------------------------------------------------------
{
HDC hdc;
PAINTSTRUCT ps;
hdc = BeginPaint(hwnd, &ps);
// the current system information
DisplaySystemInfo(hwnd, &ps);
// the current battery status
DisplayBatteryStatus(hwnd, &ps);
EndPaint(hwnd, &ps);
}
//----------------------------------------------------------------------------
// Timer Proc - the WM_TIMER message will re-display
BOOL WINAPI Main_OnTimer(
HWND hwnd,
UINT id)
//----------------------------------------------------------------------------
{
InvalidateRect(hwnd, NULL, TRUE);
UpdateWindow(hwnd);
return TRUE;
}
//----------------------------------------------------------------------------
LRESULT CALLBACK WndProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
//----------------------------------------------------------------------------
{
switch(uMsg)
{
HANDLE_MSG(hwnd, WM_COMMAND, Main_OnCommand);
HANDLE_MSG(hwnd, WM_DESTROY, Main_OnDestroy);
HANDLE_MSG(hwnd, WM_CREATE, Main_OnCreate );
HANDLE_MSG(hwnd, WM_PAINT, Main_OnPaint);
HANDLE_MSG(hwnd, WM_TIMER, Main_OnTimer);
default:
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
return FALSE;
}
//----------------------------------------------------------------------------
BOOL InitApplication(
HINSTANCE hInstance)
//----------------------------------------------------------------------------
{
WNDCLASS wc;
memset(&wc, 0, sizeof(WNDCLASS));
wc.style = CS_HREDRAW | CS_VREDRAW ;
wc.lpszClassName = szAppName;
wc.lpfnWndProc = (WNDPROC) WndProc;
wc.hInstance = hInstance;
wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
return RegisterClass(&wc);
}
//----------------------------------------------------------------------------
BOOL InitInstance(
HINSTANCE hInstance,
int CmdShow)
//----------------------------------------------------------------------------
{
ghInstance = hInstance;
InitCommonControls();
// create MainWindow
if((hwMain = CreateWindow(szAppName, szTitle, WS_VISIBLE,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, ghInstance, NULL)) == NULL)
return FALSE;
// create Commandbar(menu)
hwCmdBar = CommandBar_Create (ghInstance, hwMain, 1);
CommandBar_InsertMenubar(hwCmdBar, ghInstance, IDR_MENU1, 0);
CommandBar_AddAdornments(hwCmdBar, 0, 0);
ShowWindow(hwMain, CmdShow);
UpdateWindow(hwMain);
return TRUE;
}
//----------------------------------------------------------------------------
int WINAPI WinMain(
HINSTANCE hInstance, //
HINSTANCE hPrevInstance, //
LPTSTR lpCmdLine, //
int nCmdShow) //
//----------------------------------------------------------------------------
{
MSG msg;
if(! hPrevInstance)
if(! InitApplication(hInstance))
return FALSE;
if(! InitInstance(hInstance, nCmdShow))
return FALSE;
while(GetMessage(&msg, NULL, 0, 0))
{ // Message Loop
TranslateMessage(&msg); // Translates virtual key codes
DispatchMessage(&msg); // Dispatches message to window
}
return msg.wParam;
}