怎样制作一个计算机关机的程序
发布网友
发布时间:2022-04-23 18:09
我来回答
共3个回答
热心网友
时间:2023-10-12 08:22
自己制作一个一键关机程序,相信大家电脑里都有winrar这个软件吧,现在就利用这个软件的关机功能,1分钟做一个只有4k的关机程序。
第一步:右击桌面空白处,选择“新建→快捷方式”,弹出“创建快捷方式”窗口,点击“浏览”,在浏览文件夹窗口找到WinRAR安装目录c:\Program files\winrar\Rar.exe,按“确定“。
第二步:在“请键入快捷方式名称”那里,键入快捷方式的名称“Rar关机(或者自己喜欢的名字)”,点击“完成”返回桌面。
第三步:右击“Rar关机”快捷方式,选择“属性”,在“快捷方式”标签下“应用程序”的目标文本框c:\Program files\WinRAR\Rar.exe后加入命令“-ioff”,注意Rar.exe和-ioff用空格隔开,在“运行方式”窗口选择“最小化”,按“确定”。 第四步:要关机时,只要双击“关机”快捷方式,WinRAR就会自动关闭系统。
需要注意的是,要实现关机功能,需要使用WinRAR 3.11以上版本。以上方法同样适用Windows 98/XP。
在这里你可以点击更改图标选项,选折一个自己喜欢的图标,还可以在快捷键里面键入一个关机键,我的是f12,这样按f12就可以关机了。
热心网友
时间:2023-10-12 08:22
VB dephi C C++ JAVA ASP VC VC++
你随便学一门语言就可以了
热心网友
时间:2023-10-12 08:23
// MyClosePCDlg.cpp : implementation file
//
#include "stdafx.h"
#include "MyClosePC.h"
#include "MyClosePCDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyClosePCDlg dialog
CMyClosePCDlg::CMyClosePCDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMyClosePCDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMyClosePCDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CMyClosePCDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMyClosePCDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMyClosePCDlg, CDialog)
//{{AFX_MSG_MAP(CMyClosePCDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_LOGOFF_BUTTON, OnLogoffButton)
ON_BN_CLICKED(IDC_REBOOT_BUTTON, OnRebootButton)
ON_BN_CLICKED(IDC_SHUTDOW_BUTTON, OnShutdowButton)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyClosePCDlg message handlers
BOOL CMyClosePCDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CMyClosePCDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CMyClosePCDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CMyClosePCDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CMyClosePCDlg::OnLogoffButton()
{
// TODO: Add your control notification handler code here
ExitWindowsEx(EWX_LOGOFF,0);
}
void CMyClosePCDlg::OnRebootButton()
{
// TODO: Add your control notification handler code here
//获取操作系统版本信息
OSVERSIONINFO OsInfo;
OsInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx(&OsInfo);
//Windows98关闭计算机
if( OsInfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS )
{
::ExitWindowsEx(EWX_REBOOT,0);
}
//Windows2000关闭计算机
if(OsInfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
{
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
// Get a token for this process.
if (!OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
{
MessageBox("无法打开存取令牌");
return;
}
// Get the LUID(the locally unique identifier) for the shutdown privilege.
LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME,
&tkp.Privileges[0].Luid);
tkp.PrivilegeCount = 1; // one privilege to set
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
// Get the shutdown privilege for this process.
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
(PTOKEN_PRIVILEGES)NULL, 0);
// Cannot test the return value of AdjustTokenPrivileges.
if (GetLastError() != ERROR_SUCCESS)
{
MessageBox("无法重启");
return;
}
// Shut down the system and turns off the power and force all applications to close.
if (!ExitWindowsEx(EWX_REBOOT, 0))
MessageBox("无法重启");
}
}
void CMyClosePCDlg::OnShutdowButton()
{
// TODO: Add your control notification handler code here
//获取操作系统版本信息
OSVERSIONINFO OsInfo;
OsInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx(&OsInfo);
//Windows98关闭计算机
if( OsInfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS )
{
::ExitWindowsEx(EWX_SHUTDOWN,0);
}
//Windows2000关闭计算机
if(OsInfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
{
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
// Get a token for this process.
if (!OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
{
MessageBox("无法打开存取令牌");
return;
}
// Get the LUID(the locally unique identifier) for the shutdown privilege.
LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME,
&tkp.Privileges[0].Luid);
tkp.PrivilegeCount = 1; // one privilege to set
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
// Get the shutdown privilege for this process.
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
(PTOKEN_PRIVILEGES)NULL, 0);
// Cannot test the return value of AdjustTokenPrivileges.
if (GetLastError() != ERROR_SUCCESS)
{
MessageBox("无法关机");
return;
}
// Shut down the system and turns off the power and force all applications to close.
if (!ExitWindowsEx(EWX_POWEROFF | EWX_FORCE, 0))
MessageBox("无法关机");
}
}