方法一:
C++关闭桌面,explorer.exe
#include
#include
#include"resource.h"
#pragma warning(disable:4996)
void taskkill(const char * name)
{
HANDLE info_handle = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); //拍摄系统中所有进程的快照
if (info_handle == INVALID_HANDLE_VALUE)
{
MessageBox(0, TEXT("获服务器托管网取进程句柄失败!"), TEXT("错误"), 0);
return;
}
PROCESSENTRY32W program_info;
program_info.dwSize = sizeof(PROCESSENTRY32W); //设置结构体大小
int bResult = Process32FirstW(info_handle, &program_info); //获取所有进程中第一个进程的信息
if (!bResult)
{
MessageBox(0, TEXT("获取进程句柄失败!"), TEXT("错误"), 0);
return;
}
char tmp[MAX_PATH];
HANDLE hProcess;
while (bResult)
{
wchar_t *pro_name = program_info.szExeFile;
wcstombs(tmp, pro_name, MAX_PATH);
if (!strcmp(tmp, name))
{
hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, program_info.th32ProcessID);
if (hProcess) {
TerminateProcess(hProcess, 0);
CloseHandle(hProcess);//OpenProcess打开的也要关闭
}
break;
}
//获得下一个进程的进程信息
bResult = Process32Next(info_handle, &program_info);
}
CloseHandle(info_handle);//关闭句柄
}
int WINAPI WinMain(HINSTANCE h1, HINSTANCE h2, LPSTR cmd, int show)
{
taskkill("explorer.exe");
}
方法二:
C++ 一键关闭屏幕
#include
#include "resource.h"
LRESULT CALLBACK WindowProc( HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
// 延时防止双击exe关闭屏幕后,又打开屏幕。关闭屏幕的消息,先于系统的双击消息;
Sleep(200);
::SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, (LPARAM)2);
static TCHAR szAppName[] = TEXT("HelloWin");
WNDCLASS wndClass;
wndClass.style = CS_HREDRAW | CS_VREDRAW;
wndClass.lpfnWndProc = WindowProc;
wndClass.cbClsExtra = 0;
wndClass.cbWndExtra = 0;
wndClass.hInstance = hInstance;
wndClass.hIcon = LoadIcon(hInstance, (char*)IDI_ICON1);
wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wndClass.lpszMenuName = NULL;
wndClass.lpszClassName = szAppName;
if (!RegisterClass(&wndClass))
{
MessageBox(NULL, TEXT("注册窗口失败!"), TEXT(""), 0);
return 0;
}
HWND hWnd = CreateWindow(szAppName, TEXT("Hello Program"),
WS_OVERLAPPEDWINDOW, 服务器托管网0, 0, 0, 0,
NULL, NULL, hInstance, NULL);
::SendMessage(hWnd, WM_DESTROY, 0, NULL);
return 0;
}
LRESULT CALLBACK WindowProc( HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
HDC hdc;
PAINTSTRUCT ps;
RECT rect;
switch (uMsg)
{
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
本程序使用C语言编写,调用的Windows API,所以只能在windows上运行
本程序无界面,启动后直接隐藏/显示桌面图标,运行结束后自动退出
操作系统:windows 10
开发工具:Visual Studio 2019
下面先贴源代码:
#include
#include
#include
#pragma comment( linker, "/subsystem:windows /entry:mainCRTStartup" ) // 设置入口地址
//遍历全部子窗口的子窗口 , Z序遍历
HWND findChildWindowHandleByName(HWND parent, int level, TCHAR* winNameBuf)
{
HWND child = NULL;
HWND hWnd = NULL;
TCHAR buf[MAX_PATH];
DWORD pid = 0, tid = 0;
do {
child = FindWindowEx(parent, child, NULL, NULL);
int ret = GetWindowText(child, buf, MAX_PATH);
buf[ret] = 0;
tid = GetWindowThreadProcessId(child, &pid);
for (int i = 0; i
新程序新增了隐藏任务栏的功能。
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
机房租用,北京机房租用,IDC机房托管, http://www.fwqtg.net
C语言可以用来编写爬虫程序,但是相对于其他编程语言,C语言的爬虫开发可能会更加复杂和繁琐。因为C语言本身并没有提供现成的爬虫框架和库,需要自己编写网络请求、HTML解析等功能。 不过,如果你对C语言比较熟悉,也可以尝试使用C语言编写爬虫程序,这样可以更好地掌握…