📄 unit1.cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include "Unit2.h"
#include "SysUtils.hpp"
#include <tlhelp32.h>
#include "stdio.h"
#include "dos.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
MyThread *Thread;//声明一个自己的线程
Thread = new MyThread();
Thread->FreeOnTerminate=true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
Form1->Memo1->Lines->Text = Now();
// Timer->Enabled = true;
//按时触发演示程序
struct time t;
AnsiString thour,tmin,tsec;
AnsiString tShour,tSmin,tSsec;
AnsiString tEhour,tEmin,tEsec;
//取当时时间
gettime(&t);
thour=AnsiString(t.ti_hour);
tmin=AnsiString(t.ti_min);
//tsec=AnsiString(t.ti_sec);
// StrToTime(const AnsiString S);
/// TDateTime dtTime = StrToTime(sStartTime);
/// dtTime.
tShour = sStartTime.SubString(12,2);
tSmin = sStartTime.SubString(15,2);
//tSsec = sStartTime.SubString(15,2);
tEhour = sEndTime.SubString(12,2);
tEmin = sEndTime.SubString(15,2);
Form1->Label3->Caption = tShour + tSmin;
Form1->Label4->Caption = tEhour + tEmin;
Form1->Label5->Caption = thour + tmin;
//闹钟服务功能
if (((StrToInt(thour)>StrToInt(tShour))||((StrToInt(thour)==StrToInt(tShour))&&
(StrToInt(tmin)>=StrToInt(tSmin))))&&((StrToInt(thour)<StrToInt(tEhour))||((StrToInt(thour)==StrToInt(tEhour))&&
(StrToInt(tmin)<=StrToInt(tEmin)))))
{
// EnterCreiticalSection (&gTimeKey );
if(!bTimeState)bTimeState=true;
Form1->Label2->Caption ="true";
//时间条件满足,置标志位。
// LeaveCreiticalSection (&gTimeKey);
// ShowMessage("bTimeState=true");
return;
}
else{
// EnterCreiticalSection (&gTimeKey );
if(bTimeState)bTimeState=false;
Form1->Label2->Caption ="false";
//时间条件满足,置标志位。
// LeaveCreiticalSection (&gTimeKey);
// ShowMessage("bTimeState=false");
return;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
// Find each process and display it.
HANDLE snapshot ;
PROCESSENTRY32 processinfo ;
processinfo.dwSize = sizeof (processinfo) ;
snapshot = CreateToolhelp32Snapshot (TH32CS_SNAPPROCESS, 0) ;
if (snapshot == NULL)
return ;
bool status = Process32First (snapshot, &processinfo) ;
while (status)
{
TListItem *li = ListView1->Items->Add () ;
String buffer ;
int length ;
buffer.SetLength (512) ;
length = sprintf (buffer.c_str (), "%08X", processinfo.th32ProcessID) ;
buffer.SetLength (length) ;
li->Caption = buffer;
buffer.SetLength (512) ;
length = sprintf (buffer.c_str (), "%08X", processinfo.th32ParentProcessID) ;
buffer.SetLength (length) ;
li->SubItems->Add (buffer) ;
li->SubItems->Add (processinfo.szExeFile) ;
AnsiString str=processinfo.szExeFile;
FILE *EasyUpdate ;
char Buffer[256];
strcpy(Buffer,(GetCurrentDir()+"\\updatefile.txt").c_str());
if((EasyUpdate=fopen(Buffer,"a"))==NULL)
{
Application->MessageBox("系统启动所需文件EasyUpdate.ini丢失,系统不能启动!","错误",MB_OK|MB_ICONERROR);
Application->Terminate();
//终止程序运行
return ;
}
else
{
fwrite(&str, sizeof(str), 1, EasyUpdate);
fclose(EasyUpdate);
}
status = Process32Next (snapshot, &processinfo) ;
}
if (ListView1->SelCount==0)
{
MessageBox(Handle,"请首先选择一个进程!","中止进程",MB_OK|MB_ICONWARNING);
return;
}
int pPid=StrToInt(ListView1->Selected->SubItems->Strings[0]);
HANDLE ps = OpenProcess(1,false,pPid);
if(ps&&TerminateProcess(ps,-9))
{
MessageBox(Handle,"成功中止进程!","中止进程",MB_OK|MB_ICONINFORMATION);
}
else
MessageBox(Handle,"中止进程失败!","中止进程",MB_OK|MB_ICONWARNING);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
ListView2->Items->Clear();
TListItem *mItem;
AnsiString ExeFile;
Pointer pt,pt2;
unsigned int s;
DWORD size,size2;
HANDLE snapshot;
PROCESSENTRY32 processinfo;
processinfo.dwSize = sizeof(processinfo);
snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
if (snapshot==NULL) return;
bool flag = Process32First (snapshot,&processinfo);
while (flag)
{
mItem=ListView2->Items->Add();
ExeFile=AnsiString(processinfo.szExeFile);
mItem->Caption=ExeFile;
mItem->SubItems->Add(IntToStr(int(processinfo.th32ParentProcessID)));
mItem->SubItems->Add(IntToHex(int(processinfo.th32ProcessID),8).UpperCase());
size=GetFileVersionInfoSize(ExeFile.c_str(),&size2);
pt=malloc(size);
GetFileVersionInfo(ExeFile.c_str(),NULL,size,pt);
if(VerQueryValue(pt,"\\StringFileInfo\\040904E4\\FileVersion",&pt2,&s))
mItem->SubItems->Add(PChar(pt2));
if(VerQueryValue(pt,"\\StringFileInfo\\040904E4\\CompanyName",&pt2,&s))
mItem->SubItems->Add(PChar(pt2));
if(VerQueryValue(pt,"\\StringFileInfo\\040904E4\\FileDescription",&pt2,&s))
mItem->SubItems->Add(PChar(pt2));
free(pt);
flag = Process32Next(snapshot,&processinfo);
}
if (ListView2->SelCount==0)
{
MessageBox(Handle,"请首先选择一个进程!","中止进程",MB_OK|MB_ICONWARNING);
return;
}
int pPid=StrToInt(ListView2->Selected->SubItems->Strings[0]);
HANDLE ps = OpenProcess(1,false,pPid);
if(ps&&TerminateProcess(ps,-9))
{
MessageBox(Handle,"成功中止进程!","中止进程",MB_OK|MB_ICONINFORMATION);
}
else
MessageBox(Handle,"中止进程失败!","中止进程",MB_OK|MB_ICONWARNING);
// ViewProcess();
}
//---------------------------------------------------------------------------
// 检测活动桌面是否激活
bool __fastcall TWallFrm::ActiveDesktop(void)
{
/*检测是否启动了Active Desktop
是则返回true,否则返回false*/
HWND hwnd;
hwnd=FindWindow("Progman",NULL);
hwnd= FindWindowEx(hwnd,NULL,"SHELLDLL_DefView",NULL);
hwnd=FindWindowEx(hwnd,NULL,"Internet Explorer_Server",NULL);
if (hwnd>0)
return true;
else
return false;
}/*以上代码在c++ Builder5/Win98 SE下编译通过*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -