include<bits/stdc++.h>
这是蒟蒻们(就比如我)常用的头文件,他包含了许多C++头文件,如
iostream
cmath
string
......
好的那么有人说了,能不能自编头文件呢??
看标题就知道了
怎么自编呢??
看下面的syst.h就知道了。。。
更新日志板块取消
#include <bits/stdc++.h>
#include <windows.h>
#include <conio.h>
#include <tlhelp32.h>
#include <tchar.h>
#include <ShellAPI.h>
#include <iostream>
#define cls system("cls");
#define putendl printf("\n")
#define put printf
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
using namespace std;
void HideWindow() {
HWND hwnd;
hwnd=FindWindow("ConsoleWindowClass",NULL);
if(hwnd) ShowWindow(hwnd,SW_HIDE);
return;
}
void cdraw() {
char a[1000001];
cin>>a;
//HideWindow();
while(1) {
HDC hdc = GetWindowDC(GetDesktopWindow());
for(int i=1; i<=1920; i+=8*strlen(a))
for(int j=1; j<=1200; j+=20)
TextOutA(hdc, i, j, a, 6);
}
}
void cl(void) {
cout<<"\r \r";
}
bool password(string _password) {
bool ok=true,backspace=false;
char a[10001];
int len=0;
while(1) {
a[len]=getch();
if(a[len]==8) {
len=0;
memset(a,0,sizeof(a));
cl();
ok=true;
continue;
}
if(a[len]==13) {
len--;
break;
}
if(_password[len]!=a[len])
ok=false;
cout<<"*";
len++;
}
return ok;
}
bool input_password(int test,string _password) {
bool ok=true;
int i=test;
string pw=_password;
while(i) {
cout<<"请输入密码来继续:\n";
if(password(pw)==false) {
cout<<"\n密码错误!!\n";
ok=false;
} else {
ok=true;
break;
}
i--;
}
if(ok==true)
cout<<"\n正确!";
return 0;
}
void pos() { //隐藏光标
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO cci;
GetConsoleCursorInfo(hOut, &cci);
cci.bVisible = FALSE;
SetConsoleCursorInfo(hOut, &cci);
}
void _pos(void) {
CONSOLE_CURSOR_INFO cursor_info = {1, 0};
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
}
int trand() { //int随机数
srand((unsigned)time(NULL));
return rand();
}
char crand() { //char随机数
srand((unsigned)time(NULL));
return char(rand());
}
void mouxy(int &x,int &y) {
POINT p;
GetCursorPos(&p);//获取鼠标坐标
x=p.x;
y=p.y;
}
void move_mouse(int x,int y) {
SetCursorPos(x,y);
}
void open_start() {
keybd_event(VK_LWIN, 0, 0 ,0);
keybd_event(VK_LWIN, 0, KEYEVENTF_KEYUP,0);
}
bool pri(int n) {//素数
if(n<2) return false;
for(int i=2; i*i<=n; i++) {
if(n%i==0) return false;
}
return true;
}
int sum(int n) {//阶乘
return n==1?1:sum(n-1)*n;
}
int rev(int a,int od) {//颠倒数
int n=a,m=0;
while(n!=0) {
m=m*10+n%10+od;
n/=10;
}
return m;
}
int addb(int a,int k,int p) {//进制转换
int n=a,m=0,t=1,bt=0;
if(k!=10) {
while(n!=0) {
m+=n%10*t;
n/=10;
t*=k;
}
n=m;
m=0;
}
t=0;
if(p!=10) {
while(n!=0) {
m=m*10+n%p;
n/=p;
t++;
}
m=rev(m,0);
t--;
bt=m;
while(t>0) {
if(bt<10) m*=10;
else bt=bt/10;
t--;
}
} else {
m=n;
}
return m;
}
int gys(int a, int b) {//最大公因数
int t;
if(a<b) swap(a,b);
while (b!=0) {
t=a%b;
a=b;
b=t;
}
return a;
}
int gbs (int a, int b) {//最小公倍数
return a*b/gys(a,b);
}
//------------
void modeset(int w,int h); //设置窗口大小
void pause(void); //无回显暂停
void color(int a); //修改当前控制台颜色
//------------
void modeset(int w,int h) {
// 设置窗口大小为 w*h
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
COORD size = {w, h};
SetConsoleScreenBufferSize(hOut,size);
SMALL_RECT rc = {1,1, w, h};
SetConsoleWindowInfo(hOut ,true ,&rc);
Sleep(10);
return;
}
void pause(void) {
std::cout<<"请按任意键继续. . .";
getch();
std::cout<<"\r \r";
return;
}
void getpos(POINT &pt) {
HWND hwnd=GetForegroundWindow();
GetCursorPos(&pt);
ScreenToClient(hwnd,&pt);
pt.y=pt.y/16,pt.x=pt.x/8;
}
void color(int a) {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),a);
}
void pos_gto(int x,int y) {
COORD pos;
pos.X=y;
pos.Y=x;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);
}
void button_slow(char str[],int color1,int color2,int x,int x1,int y,int y1) {
POINT a;
while(1) {
pos();
getpos(a);
if(a.x>=x&&a.x<=x1&&a.y>=y&&a.y<=y1) {
color(color2);
getpos(a);
if(KEY_DOWN(VK_LBUTTON)&&a.x>=x&&a.x<=x1&&a.y>=y&&a.y<=y1)break;
} else color(color1);
cout<<str;
cls
}
}
void button_fast(char str[],int color1,int color2,int x,int x1,int y,int y1) {
POINT a;
color(color1);
puts(str);
bool ok=false;
while(1) {
pos();
getpos(a);
if(a.x>=x&&a.x<=x1&&a.y>=y&&a.y<=y1&&ok==true)if(KEY_DOWN(VK_LBUTTON)&&a.x>=x&&a.x<=x1&&a.y>=y&&a.y<=y1)break;
if(a.x>=x&&a.x<=x1&&a.y>=y&&a.y<=y1&&ok==false) {
color(color2);
cls
puts(str);
ok=true;
getpos(a);
if(KEY_DOWN(VK_LBUTTON)&&a.x>=x&&a.x<=x1&&a.y>=y&&a.y<=y1)break;
}
if(ok==true&&(a.x<x||a.x>x1||a.y<y||a.y>y1)) {
cls
ok=false;
color(color1);
puts(str);
}
}
}
void stc(string str,char p[]) {//string to char[]
int i;
for(i=0; i<str.length(); ++i)
p[i]=str[i];
p[i] = '\0'; //这一步比较重要
}
int strcmp(const char* s1,const char* s2) {//判断2个string是否相等
while(*s1++ == *s2++) {
if(*s1=='\0' && *s2=='\0')
return 0;
}
return 1;
}
void gy_cmd(void) {
bool ok=true;
int i=3;
string pw="gy123666";
while(i) {
cout<<"使用此产品需要激活码:\n";
if(password(pw)==false) {
cout<<"\n激活码错误!!\n";
ok=false;
} else {
ok=true;
break;
}
i--;
}
if(ok==true)
cout<<"\n激活成功!";
cls
char cmd[1000001];
put("GY版本cmd open:gy有惊喜\n\n");
while(true) {
put("cmd命令:");
string a;
getline(cin,a);
int i;
for(i=0; i<a.length(); ++i)
cmd[i]=a[i];
cmd[i] = '\0'; //这一步比较重要
if(strcmp(cmd,"open:gy"))
system(cmd);
else {
char h[100001];
string b;
put("GY cmd专用命令:\n\n open start 打开开始菜单\n\n slow shutdown 移动鼠标来关机(不是cmd命令)\n\n");
while(1) {
getline(cin,b);
int i;
for(i=0; i<a.length(); ++i)
h[i]=b[i];
h[i] = '\0'; //这一步比较重要
if(strcmp(h,"open start")) {
open_start();
}
if(strcmp(h,"slow shutdown")) {
HideWindow();
//377 677
//26 1058
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
int a,b;
mouxy(a,b);
if(a>305)
for(int i=a; i>305; i--) {
move_mouse(i,b);
Sleep(2);
}
if(a<305)
for(int i=a; i<305; i++) {
move_mouse(i,b);
Sleep(2);
}
mouxy(a,b);
if(b>1011)
for(int i=b; i>1011; i--) {
move_mouse(a,i);
Sleep(2);
}
if(b<1011)
for(int i=b; i<1011; i++) {
move_mouse(a,i);
Sleep(2);
}
open_start();
mouxy(a,b);
Sleep(100);
move_mouse(a,b);
mouse_event(MOUSEEVENTF_LEFTDOWN,a,b,0,0);
mouse_event(MOUSEEVENTF_LEFTUP,a,b,0,0);
}
}
}
}
}
void display(int time,string word) {
for(int i=0; i<word.size(); i++) {
cout<<word[i];
Sleep(time);
}
}
void process_e() {
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken);
LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid);
tkp.PrivilegeCount = 1;
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, NULL, NULL);
CloseHandle(hToken);
}
bool process_k(DWORD dwPid) {
printf("Kill进程Pid = %d\n", dwPid);
//关闭进程
HANDLE killHandle = OpenProcess(PROCESS_TERMINATE | PROCESS_QUERY_INFORMATION | // Required by Alpha
PROCESS_CREATE_THREAD | // For CreateRemoteThread
PROCESS_VM_OPERATION | // For VirtualAllocEx/VirtualFreeEx
PROCESS_VM_WRITE, // For WriteProcessMemory);
FALSE, dwPid);
if (killHandle == NULL)
return false;
TerminateProcess(killHandle, 0);
return true;
}
bool process_f(std::string strProcessName, DWORD& nPid) {
TCHAR tszProcess[64] = { 0 };
lstrcpy(tszProcess, _T(strProcessName.c_str()));
//查找进程
STARTUPINFO st;
PROCESS_INFORMATION pi;
PROCESSENTRY32 ps;
HANDLE hSnapshot;
memset(&st, 0, sizeof(STARTUPINFO));
st.cb = sizeof(STARTUPINFO);
memset(&ps, 0, sizeof(PROCESSENTRY32));
ps.dwSize = sizeof(PROCESSENTRY32);
memset(&pi, 0, sizeof(PROCESS_INFORMATION));
// 遍历进程
hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hSnapshot == INVALID_HANDLE_VALUE)
return false;
if (!Process32First(hSnapshot, &ps))
return false;
do {
if (lstrcmp(ps.szExeFile, tszProcess) == 0) {
//找到制定的程序
nPid = ps.th32ProcessID;
CloseHandle(hSnapshot);
printf("找到进程: %s\n", tszProcess);
return true;
//getchar();
//return dwPid;
}
} while (Process32Next(hSnapshot, &ps));
CloseHandle(hSnapshot);
return false;
}
/*
// 程序开机自动启动
void autostart() {
HKEY hKey;
QString strRegPath = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";
//RegOpenKeyEx(,LPCWSTR)
//1、找到系统的启动项
if (RegOpenKeyEx(HKEY_CURRENT_USER, strRegPath.toStdString().c_str(), 0, KEY_ALL_ACCESS, &hKey) == ERROR_SUCCESS) { ///打开启动项
//2、得到本程序自身的全路径
TCHAR strExeFullDir[MAX_PATH];
GetModuleFileName(NULL, strExeFullDir, MAX_PATH);
//3、判断注册表项是否已经存在
TCHAR strDir[MAX_PATH] = {};
DWORD nLength = MAX_PATH;
long result = RegGetValue(hKey, nullptr, "GISRestart", RRF_RT_REG_SZ, 0, strDir, &nLength);
//4、已经存在
if (result != ERROR_SUCCESS || _tcscmp(strExeFullDir, strDir) != 0) {
//5、添加一个子Key,并设置值,"GISRestart"是应用程序名字(不加后缀.exe)
RegSetValueEx(hKey, "GISRestart", 0, REG_SZ, (LPBYTE)strExeFullDir, (lstrlen(strExeFullDir) + 1)*sizeof(TCHAR));
//6、关闭注册表
RegCloseKey(hKey);
}
} else {
QMessageBox::warning(0, QString::fromLocal8Bit("警告"), QString::fromLocal8Bit("\n系统参数错误,不能随系统启动n"));
}
}
// 取消开机自动启动
void SGISRestartDlg::cancelAutoStart() {
HKEY hKey;
QString strRegPath = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";
//1、找到系统的启动项
if (RegOpenKeyEx(HKEY_CURRENT_USER, strRegPath.toStdString().c_str(), 0, KEY_ALL_ACCESS, &hKey) == ERROR_SUCCESS) {
//2、删除值
RegDeleteValue(hKey, "GISRestart");
//3、关闭注册表
RegCloseKey(hKey);
}
}
int delete_self(int argc, _TCHAR* argv[])
{
printf("任意按键,程序自删除!!!\n");
system("pause");
char szFileName[MAX_PATH] = {0};
char szCmdFileName[MAX_PATH] = {0};
char szCmd[MAX_PATH] = {0};
char szBat[MAX_PATH] = {0};
int iTime = 5;
// 构造批处理文件路径
::GetModuleFileName(NULL, szFileName, MAX_PATH);
::lstrcpy(szCmdFileName, szFileName);
char *p = ::strrchr(szCmdFileName, '\\');
p[0] = '\0';
::lstrcat(szCmdFileName, "\\selfdel.bat");
// 构造批处理内容
::wsprintf(szBat, "@echo off\nchoice /t %d /d y /n >nul\ndel %s\ndel %%0\n", iTime, szFileName);
// 生成批处理文件
FILE *fp = NULL;
fopen_s(&fp, szCmdFileName, "w+");
if (NULL == fp)
{
return 1;
}
fwrite(szBat, (1 + ::lstrlen(szBat)), 1, fp);
fclose(fp);
// 构造命令行
::wsprintf(szCmd, "cmd.exe /c call %s", szCmdFileName);
// 创建新的进程,以隐藏控制台的方式执行cmd命令行
STARTUPINFO si = { 0 };
PROCESS_INFORMATION pi;
si.cb = sizeof(si);
si.dwFlags = STARTF_USESHOWWINDOW;//指定wShowWindow成员有效
si.wShowWindow = FALSE;//此成员设为TRUE的话则显示新建进程的主窗口
BOOL bRet = CreateProcess(
NULL,//不在此指定可执行文件的文件名
szCmd,//命令行参数
NULL,//默认进程安全性
NULL,//默认进程安全性
FALSE,//指定当前进程内句柄不可以被子进程继承
CREATE_NEW_CONSOLE,//为新进程创建一个新的控制台窗口
NULL,//使用本进程的环境变量
NULL,//使用本进程的驱动器和目录
&si,
&pi);
if (bRet)
{
//不使用的句柄最好关掉
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
}
return 0;
}
*/
/*
keybd_event(VK_LWIN, 0, 0 ,0);
keybd_event(VK_LWIN, 0, KEYEVENTF_KEYUP,0);
*/
/*
if (NumKey == VK_ESCAPE) // 退出
revalue = "[Esc]";
else if (NumKey == VK_F1) // F1至F12
revalue = "[F1]";
else if (NumKey == VK_F2)
revalue = "[F2]";
else if (NumKey == VK_F3)
revalue = "[F3]";
else if (NumKey == VK_F4)
revalue = "[F4]";
else if (NumKey == VK_F5)
revalue = "[F5]";
else if (NumKey == VK_F6)
revalue = "[F6]";
else if (NumKey == VK_F7)
revalue = "[F7]";
else if (NumKey == VK_F8)
revalue = "[F8]";
else if (NumKey == VK_F9)
revalue = "[F9]";
else if (NumKey == VK_F10)
revalue = "[F10]";
else if (NumKey == VK_F11)
revalue = "[F11]";
else if (NumKey == VK_F12)
revalue = "[F12]";
else if (NumKey == VK_SNAPSHOT) // 打印屏幕
revalue = "[PrScrn]";
else if (NumKey == VK_SCROLL) // 滚动锁定
revalue = "[Scroll Lock]";
else if (NumKey == VK_PAUSE) // 暂停、中断
revalue = "[Pause]";
else if (NumKey == VK_CAPITAL) // 大写锁定
revalue = "[Caps Lock]";
else if (NumKey == 8) //<- 回格键
revalue = "[Backspace]";
else if (NumKey == VK_RETURN) // 回车键、换行
revalue = "[Enter]\n";
else if (NumKey == VK_SPACE) // 空格
revalue = " ";
else if (NumKey == VK_TAB) // 制表键
revalue = "[Tab]";
else if (NumKey == VK_LCONTROL) // 左控制键
revalue = "[Ctrl]";
else if (NumKey == VK_RCONTROL) // 右控制键
revalue = "[CTRL]";
else if (NumKey == VK_LMENU) // 左换档键
revalue = "[Alt]";
else if (NumKey == VK_LMENU) // 右换档键
revalue = "[ALT]";
else if (NumKey == VK_LWIN) // 右 WINDOWS 键
revalue = "[Win]";
else if (NumKey == VK_RWIN) // 右 WINDOWS 键
revalue = "[WIN]";
else if (NumKey == VK_APPS) // 键盘上 右键
revalue = "右键";
else if (NumKey == VK_INSERT) // 插入
revalue = "[Insert]";
else if (NumKey == VK_DELETE) // 删除
revalue = "[Delete]";
else if (NumKey == VK_HOME) // 起始
revalue = "[Home]";
else if (NumKey == VK_END) // 结束
revalue = "[End]";
else if (NumKey == VK_PRIOR) // 上一页
revalue = "[PgUp]";
else if (NumKey == VK_NEXT) // 下一页
revalue = "[PgDown]";
// 不常用的几个键:一般键盘没有
else if (NumKey == VK_CANCEL) // Cancel
revalue = "[Cancel]";
else if (NumKey == VK_CLEAR) // Clear
revalue = "[Clear]";
else if (NumKey == VK_SELECT) //Select
revalue = "[Select]";
else if (NumKey == VK_PRINT) //Print
revalue = "[Print]";
else if (NumKey == VK_EXECUTE) //Execute
revalue = "[Execute]";
//----------------------------------------//
else if (NumKey == VK_LEFT) //上、下、左、右键
revalue = "[←]";
else if (NumKey == VK_RIGHT)
revalue = "[→]";
else if (NumKey == VK_UP)
revalue = "[↑]";
else if (NumKey == VK_DOWN)
revalue = "[↓]";
else if (NumKey == VK_NUMLOCK)//小键盘数码锁定
revalue = "[NumLock]";
else if (NumKey == VK_ADD) // 加、减、乘、除
revalue = "+";
else if (NumKey == VK_SUBTRACT)
revalue = "-";
else if (NumKey == VK_MULTIPLY)
revalue = "*";
else if (NumKey == VK_DIVIDE)
revalue = "/";
else if (NumKey == 190 || NumKey == 110) // 小键盘 . 及键盘 .
revalue = ".";
//小键盘数字键:0-9
else if (NumKey == VK_NUMPAD0)
revalue = "0";
else if (NumKey == VK_NUMPAD1)
revalue = "1";
else if (NumKey == VK_NUMPAD2)
revalue = "2";
else if (NumKey == VK_NUMPAD3)
revalue = "3";
else if (NumKey == VK_NUMPAD4)
revalue = "4";
else if (NumKey == VK_NUMPAD5)
revalue = "5";
else if (NumKey == VK_NUMPAD6)
revalue = "6";
else if (NumKey == VK_NUMPAD7)
revalue = "7";
else if (NumKey == VK_NUMPAD8)
revalue = "8";
else if (NumKey == VK_NUMPAD9)
revalue = "9";
*/
这是我自编的一个头文件
怎么用呢??
(你问题真多啊)
复制后,打开C++,新建源代码,粘贴。。
F11,选择保存在c++的根目录(…\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++)
就比如我的是C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++
保存的时候在底下的那个框选择
名字不能是中文
名字自己随便取,这个不重复,shit.h也是可以的
某些函数可能初次使用会报错(这是我自己头文件涉及别的领域的问题)
怎么办??
-static-libgcc -lgdi32
开心的应用!!
include<你保存的名字(我是syst.h,避免和system.h重复)>
using namespace std不要了,头文件定义过
偶对了,button_fast和button_slow函数是在屏幕上显示一个给定字符串,第二参数是鼠标放在X轴是第4,5个参数之间,Y轴在6,7参数之间时button显示的颜色;
第三个是平时的颜色
颜色是color函数定义的