?? about1.c
字號:
/*------------------------------------------
ABOUT1.C -- About Box Demo Program No. 1
(c) Charles Petzold, 1998
------------------------------------------*/
#include <windows.h>
#include "Shlwapi.h"
#include "resource.h"
#define ID_TIMER 1
char title[20];
int h=0;
int m=0;
int s=0;
int all=0, temp_all=0;
HMENU hMenu;
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
BOOL CALLBACK AboutDlgProc (HWND, UINT, WPARAM, LPARAM) ;
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT ("About1") ;
MSG msg ;
HWND hwnd ;
WNDCLASS wndclass ;
wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (hInstance, szAppName) ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
wndclass.lpszMenuName = szAppName ;
wndclass.lpszClassName = szAppName ;
if (!RegisterClass (&wndclass))
{
MessageBox (NULL, TEXT ("This program requires Windows NT!"),
szAppName, MB_ICONERROR) ;
return 0 ;
}
hwnd = CreateWindow (szAppName, TEXT ("計時系統"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL) ;
ShowWindow (hwnd, iCmdShow) ;
UpdateWindow (hwnd) ;
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
}
void DisplayDigit (HDC hdc, int iNumber)
{
static BOOL fSevenSegment [10][7] = {
1, 1, 1, 0, 1, 1, 1, // 0
0, 0, 1, 0, 0, 1, 0, // 1
1, 0, 1, 1, 1, 0, 1, // 2
1, 0, 1, 1, 0, 1, 1, // 3
0, 1, 1, 1, 0, 1, 0, // 4
1, 1, 0, 1, 0, 1, 1, // 5
1, 1, 0, 1, 1, 1, 1, // 6
1, 0, 1, 0, 0, 1, 0, // 7
1, 1, 1, 1, 1, 1, 1, // 8
1, 1, 1, 1, 0, 1, 1 } ; // 9
static POINT ptSegment [7][6] = {
7, 6, 11, 2, 31, 2, 35, 6, 31, 10, 11, 10,
6, 7, 10, 11, 10, 31, 6, 35, 2, 31, 2, 11,
36, 7, 40, 11, 40, 31, 36, 35, 32, 31, 32, 11,
7, 36, 11, 32, 31, 32, 35, 36, 31, 40, 11, 40,
6, 37, 10, 41, 10, 61, 6, 65, 2, 61, 2, 41,
36, 37, 40, 41, 40, 61, 36, 65, 32, 61, 32, 41,
7, 66, 11, 62, 31, 62, 35, 66, 31, 70, 11, 70 } ;
int iSeg ;
for (iSeg = 0 ; iSeg < 7 ; iSeg++)
if (fSevenSegment [iNumber][iSeg])
Polygon (hdc, ptSegment [iSeg], 6) ;
}
void DisplayTwoDigits (HDC hdc, int iNumber, BOOL fSuppress)
{
if (!fSuppress || (iNumber / 10 != 0))
DisplayDigit (hdc, iNumber / 10) ;
OffsetWindowOrgEx (hdc, -42, 0, NULL) ;
DisplayDigit (hdc, iNumber % 10) ;
OffsetWindowOrgEx (hdc, -42, 0, NULL) ;
}
void DisplayColon (HDC hdc)
{
POINT ptColon [2][4] = { 2, 21, 6, 17, 10, 21, 6, 25,
2, 51, 6, 47, 10, 51, 6, 55 } ;
Polygon (hdc, ptColon [0], 4) ;
Polygon (hdc, ptColon [1], 4) ;
OffsetWindowOrgEx (hdc, -12, 0, NULL) ;
}
void DisplayTime (HDC hdc, BOOL fSuppress)
{
SYSTEMTIME st ;
st.wHour=temp_all/3600;
st.wMinute=(temp_all-h*3600)/60;
st.wSecond=temp_all%60;
DisplayTwoDigits (hdc, st.wHour, fSuppress) ;
DisplayColon (hdc) ;
DisplayTwoDigits (hdc, st.wMinute,FALSE) ;
DisplayColon (hdc) ;
DisplayTwoDigits (hdc, st.wSecond,FALSE) ;
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static HINSTANCE hInstance ;
static HBRUSH hBrushRed ;
static BOOL fSuppress ;
static int cxClient, cyClient ;
HDC hdc ;
PAINTSTRUCT ps ;
int isStart=0;
switch (message)
{
case WM_CREATE :
hBrushRed = CreateSolidBrush (RGB (255, 0, 0)) ;
hInstance = ((LPCREATESTRUCT) lParam)->hInstance ;
return 0 ;
case WM_SIZE:
cxClient = LOWORD (lParam) ;
cyClient = HIWORD (lParam) ;
return 0 ;
case WM_COMMAND :
hMenu = GetMenu (hwnd) ;
switch (LOWORD (wParam))
{
case IDM_TIMER_START:
SetTimer (hwnd, ID_TIMER, 1000, NULL);
EnableMenuItem (hMenu, IDM_TIMER_START, MF_GRAYED) ;
EnableMenuItem (hMenu, IDM_TIMER_STOP, MF_ENABLED) ;
return 0 ;
case IDM_TIMER_STOP:
KillTimer (hwnd, ID_TIMER) ;
EnableMenuItem (hMenu, IDM_TIMER_START, MF_ENABLED) ;
EnableMenuItem (hMenu, IDM_TIMER_STOP, MF_GRAYED) ;
temp_all=all;
InvalidateRect (hwnd, NULL, TRUE) ;
return 0 ;
case IDM_APP_ABOUT :
DialogBox (hInstance, TEXT ("AboutBox"), hwnd, AboutDlgProc) ;
InvalidateRect (hwnd, NULL, TRUE) ;
break ;
}
return 0 ;
case WM_TIMER:
temp_all=temp_all-1;
InvalidateRect (hwnd, NULL, TRUE) ;
if(temp_all==0)
KillTimer (hwnd, ID_TIMER) ;
return 0 ;
case WM_PAINT:
hdc = BeginPaint (hwnd, &ps) ;
SelectObject (hdc, GetStockObject (NULL_PEN)) ;
SelectObject (hdc, hBrushRed) ;
SetMapMode (hdc, MM_ISOTROPIC) ;
SetWindowExtEx (hdc, 276, 72, NULL) ;
SetViewportExtEx (hdc, cxClient, cyClient, NULL) ;
SetWindowOrgEx (hdc, 138, 36, NULL) ;
SetViewportOrgEx (hdc, cxClient / 2, cyClient/ 2, NULL) ;
DisplayTime (hdc, fSuppress) ;
EndPaint (hwnd, &ps) ;
return 0 ;
case WM_DESTROY :
KillTimer (hwnd, ID_TIMER) ;
DeleteObject (hBrushRed) ;
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
BOOL CALLBACK AboutDlgProc (HWND hDlg, UINT message,
WPARAM wParam, LPARAM lParam)
{
char temp[4];
switch (message)
{
case WM_INITDIALOG :
return TRUE ;
case WM_COMMAND :
switch (LOWORD (wParam))
{
case IDOK :
GetDlgItemText(
hDlg, // handle to dialog box
IDC_EDIT1, // control identifier
title, // pointer to buffer for text
20 // maximum size of string
);
GetDlgItemText(
hDlg, // handle to dialog box
IDC_EDIT2, // control identifier
temp, // pointer to buffer for text
3 // maximum size of string
);
h= StrToInt(temp);
GetDlgItemText(
hDlg, // handle to dialog box
IDC_EDIT3, // control identifier
temp, // pointer to buffer for text
3 // maximum size of string
);
m= StrToInt(temp);
GetDlgItemText(
hDlg, // handle to dialog box
IDC_EDIT4, // control identifier
temp, // pointer to buffer for text
3 // maximum size of string
);
s= StrToInt(temp);
all=h*3600+m*60+s;
temp_all=all;
EnableMenuItem (hMenu, IDM_TIMER_START, MF_ENABLED) ;
case IDCANCEL :
EndDialog (hDlg, 0) ;
return TRUE ;
}
break ;
}
return FALSE ;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -