// Sd.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include "resource.h"
#include <stdio.h>
#define MAX_LOADSTRING 100
#define BUTTON_HEIGHT 26
#define BUTTON_WIDTH 95
#define OK_X 180
#define OK_Y 45
#define Cancel_X OK_X
#define Cancel_Y OK_Y + BUTTON_HEIGHT + 10
// Global Variables:
HINSTANCE hInst; // current instance
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text
HBITMAP ScreenBitmap,MainFrameBitmap;
HBITMAP vScreenBitmap;
HDC vScreenDC;
int maxX, maxY;
HDC WindowDC;
int oldX, oldY;
int CaptionHeight, BorderSizeX, BorderSizeY;
UINT shutdown = 0;
BOOL OKplus = FALSE, Cancelplus = FALSE;
BOOL LButtonUp = TRUE;
short mouseX, mouseY, mouseDownX, mouseDownY;
INT timeout = 0;
DWORD count = 0;
HWND hwnd, countdlg;
// Foward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
void StartShutdown();
BOOL isNT();
inline BOOL InBox(int x1, int y1, int x2, int y2, int x, int y)
{
return (x >= x1) && (x <= x2) && (y >= y1) && (y <= y2);
}
/********************************************************************/
void ShowBitmap(HWND hWnd, int sourceX, int sourceY, int destX, int destY, int width, int height)
{
HDC memdc;
memdc = CreateCompatibleDC(WindowDC);
SelectObject(memdc, MainFrameBitmap);
BitBlt(WindowDC, destX, destY, width, height, memdc, sourceX, sourceY, SRCCOPY);
DeleteDC(memdc);
}
void ShowMainFrame(HWND hWnd)
{
ShowBitmap(hWnd, 0, 0 ,0, 0, 300, 180);
}
/********************************************************************/
void CheckShutdown(HWND hWnd, UINT sd)
{
if (sd == 0)
{
ShowBitmap(hWnd, 205, 185, 38, 43, 18, 18);
ShowBitmap(hWnd, 205, 210, 38, 64, 18, 18);//Clear
ShowBitmap(hWnd, 205, 210, 38, 85, 18, 18);//Clear
}
else
if (sd == 1)
{
ShowBitmap(hWnd, 205, 185, 38, 64, 18, 18);
ShowBitmap(hWnd, 205, 210, 38, 43, 18, 18);//Clear
ShowBitmap(hWnd, 205, 210, 38, 85, 18, 18);//Clear
}
else
{
ShowBitmap(hWnd, 205, 185, 38, 85, 18, 18);
ShowBitmap(hWnd, 205, 210, 38, 43, 18, 18);//Clear
ShowBitmap(hWnd, 205, 210, 38, 64, 18, 18);//Clear
}
}
void CancelButton(HWND hWnd, BOOL plus)
{
const int Y = 208;
if (plus)
{
ShowBitmap(hWnd, 0, Y, Cancel_X, Cancel_Y, BUTTON_WIDTH, BUTTON_HEIGHT+1);
}
else
{
ShowBitmap(hWnd, BUTTON_WIDTH+1, Y, Cancel_X, Cancel_Y, BUTTON_WIDTH, BUTTON_HEIGHT+1);
}
}
void OKButton(HWND hWnd, BOOL plus)
{
const int Y = 180;
if (plus)
{
ShowBitmap(hWnd, 0, Y, OK_X, OK_Y, BUTTON_WIDTH, BUTTON_HEIGHT);
}
else
{
ShowBitmap(hWnd, BUTTON_WIDTH+1, Y, OK_X, OK_Y, BUTTON_WIDTH, BUTTON_HEIGHT);
}
}
void TrackBar(HWND hWnd, UINT timeout, BOOL on)
{
static char strtime[10];
int hour,min;
if (on)
{
ShowBitmap(hWnd, 260, 188, timeout + 12, 122, 6, 18);
hour = timeout / 60;
min = timeout % 60;
SetBkMode(WindowDC, TRANSPARENT);
sprintf(strtime, "%02d:%02d", hour, min);
ShowBitmap(hWnd, 250, 2, 250, 2, 50, 20);
SetTextColor(WindowDC, 0x0);
TextOut(WindowDC, 251, 7, strtime, strlen(strtime));
SetTextColor(WindowDC, 0xFFFFFFFF);
TextOut(WindowDC, 250, 6, strtime, strlen(strtime));
}
else
{
if (timeout > 20)
ShowBitmap(hWnd, 20, 122, timeout + 12, 122, 6, 18);
else
ShowBitmap(hWnd, 50, 122, timeout + 12, 122, 6, 18);
}
}
inline void TitleBar(HWND hWnd)
{
ShowBitmap(hWnd, 0, 0, 0, 0, 300, CaptionHeight+5);
TrackBar(hWnd, timeout, TRUE);
}
void RefreshAll(HWND hWnd)
{
ShowMainFrame(hWnd);
OKButton(hWnd, OKplus);
CancelButton(hWnd, Cancelplus);
CheckShutdown(hWnd, shutdown);
TrackBar(hWnd, timeout, TRUE);
}
/********************************************************************/
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
MSG msg;
HACCEL hAccelTable;
// Initialize global strings
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_SD, szWindowClass, MAX_LOADSTRING);
MainFrameBitmap = LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_MAINFRAME));
if (MainFrameBitmap == NULL) return FALSE;
MyRegisterClass(hInstance);
// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}
hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_SD);
// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
}
//
// FUNCTION: MyRegisterClass()
//
// PURPOSE: Registers the window class.
//
// COMMENTS:
//
// This function and its usage is only necessary if you want this code
// to be compatible with Win32 systems prior to the 'RegisterClassEx'
// function that was added to Windows 95. It is important to call this function
// so that the application will get 'well formed' small icons associated
// with it.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_SD);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = NULL;//(LPCSTR)IDC_SD;
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
return RegisterClassEx(&wcex);
}
//
// FUNCTION: InitInstance(HANDLE, int)
//
// PURPOSE: Saves instance handle and creates main window
//
// COMMENTS:
//
// In this function, we save the instance handle in a global variable and
// create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
hInst = hInstance; // Store instance handle in our global variable
maxX = GetSystemMetrics(SM_CXSCREEN);
maxY = GetSystemMetrics(SM_CYSCREEN);
oldX = (maxX - 300) >> 1;
oldY = ((maxY - 180) >> 1) - 30;
// hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPED,
// oldX, oldY, 300, 180, NULL, NULL, hInstance, NULL);
hWnd = CreateWindowEx(WS_EX_APPWINDOW ,szWindowClass, szTitle, WS_VISIBLE | WS_POPUP,
oldX, oldY, 300, 180, NULL, NULL, hInstance, NULL);
if (!hWnd)
{
return FALSE;
}
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
return TRUE;
}
inline BOOL MouseInOK(int mouseX, int mouseY)
{
return ((mouseX >= OK_X-2) && (mouseX <= OK_X+BUTTON_WIDTH-2)
&& (mouseY > OK_Y - CaptionHeight) && (mouseY < OK_Y+BUTTON_HEIGHT - CaptionHeight));
}
inline BOOL MouseInCancel(int mouseX, int mouseY)
{
return ((mouseX >= Cancel_X-2) && (mouseX <= Cancel_X+BUTTON_WIDTH-2)
&& (mouseY > Cancel_Y - CaptionHeight) && (mouseY < Cancel_Y+BUTTON_HEIGHT - CaptionHeight));
}
inline BOOL MouseInTrack(int mouseX, int mouseY)
{
return (InBox(12, 122 - CaptionHeight, 300 - 18, 122 + 18 - CaptionHeight, mouseX, mouseY));
}
inline BOOL TrackInRange(int index)
{
return (index >= 0) && (index <= 60*4+30);
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
static BOOL InMove = 0;
switch (message)
{
case WM_CREATE:
WindowDC = GetWindowDC(hWnd);
vScreenDC = CreateCompatibleDC(Window
商业编程-源码-定时关机重启DOS运行模式.zip
版权申诉
178 浏览量
2022-06-22
21:03:48
上传
评论
收藏 97KB ZIP 举报
programxh
- 粉丝: 17
- 资源: 1万+