- 积分
- 7
- 最后登录
- 2018-1-31
- 阅读权限
- 10
- 积分
- 7
- 帖子
- 27
- 精华
- 1
TA的每日心情 | 郁闷 2026-2-11 11:36 |
|---|
签到天数: 8 天 连续签到: 1 天 [LV.3]偶尔看看II 老百姓

- UID
- 14
- 小七币
- 33
- 贡献
- 2
- 在线时间
- 6 小时
- 注册时间
- 2011-12-26
|
Logon.cpp
//---------------------------------------------------------------------------
#include <vcl.h>
#include "Registry.hpp"
#pragma hdrstop
//---------------------------------------------------------------------------
//USEFORM("Mainform.cpp", Form1);
//---------------------------------------------------------------------------
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
try
{
int Number=0;
TRegistry *Registry = new TRegistry;
Registry->RootKey = HKEY_USERS;
if(!Registry->OpenKey(".DEFAULT\\MonitorLogon\\History", false))
{ //如果打开主键失败
Registry->CreateKey(".DEFAULT\\MonitorLogon\\History"); //创建主键
if(!(Registry->OpenKey(".DEFAULT\\MonitorLogon\\History", false)))
{
return 0;
}
else
{ //将程序设置为开机时自动运行程序
TRegistry *Reg = new TRegistry;
Reg->RootKey = HKEY_LOCAL_MACHINE;
Reg->OpenKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run",false);
Reg->WriteString("MonitorLogon",Application->ExeName);
Reg->CloseKey();
delete Reg;
Application->MessageBox("程序注册成功!","信息提示",MB_OK); // ②
Registry->WriteInteger("开机次数",Number);
Registry->WriteString("程序注册时间",Date()+Time());
return 0;
}
}
else
{
Number=Registry->ReadInteger("开机次数");
Registry->WriteInteger("开机次数",Number+1); //记录开机次数
Registry->WriteString("第"+AnsiString(Number+1)+"次开机",Date()+Time()); //记录开机时间
}
Registry->CloseKey();
delete Registry;
Application->Initialize();
Application->Run();
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
return 0;
}
//---------------------------------------------------------------------------
Mainform.h
//---------------------------------------------------------------------------
#ifndef MainformH
#define MainformH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
Mainform.cpp
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Mainform.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
|
|