赞
踩
按一定格式分解字符串的函数是哪个?如分解"aaa,bbb,ccc",
AfxExtractSubString
重启计算机
void RestartPC()
{
char szInfo[1024];
memset(szInfo,0,sizeof(szInfo));
sprintf(szInfo,"重新启动!");
OutputDebugString(szInfo);
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
BOOL fResult;
//打开与当前进程相关联的存取标识
if (!::OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES
|TOKEN_QUERY,&hToken))
OutputDebugString("OpenProcessToken failed");
//查出本机系统的当前特权的Luid
::LookupPrivilegeValue(NULL,SE_SHUTDOWN_NAME,&tkp.Privileges[0].Luid);
tkp.PrivilegeCount =1;
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
::AdjustTokenPrivileges(hToken,FALSE,&tkp,0,(PTOKEN_PRIVILEGES) NULL,0);
if (::GetLastError()!=ERROR_SUCCESS)
OutputDebugString("AdjustTokenPrivileges enable failed");
fResult = ::InitiateSystemShutdown(NULL,"即将关机",8,TRUE,TRUE);
if (!fResult)
OutputDebugString("InitiateSystemShutDown failed");
tkp.Privileges[0].Attributes = 0;
::AdjustTokenPrivileges(hToken,FALSE,&tkp,0,(PTOKEN_PRIVILEGES) NULL,0);
if (::GetLastError()!=ERROR_SUCCESS)
OutputDebugString("AdjustTokenPrivileges disable failed");
}
拷贝文件夹
SHFILEOPSTRUCT fo;
char szFrom[500]={0},szTo[500]={0};
fo.hwnd=m_hWnd;
::lstrcpy(szFrom,"c://abc//*.*");
::lstrcpy(szTo,"d://jqk");
fo.pFrom=szFrom;
fo.pTo=szTo;
fo.wFunc=FO_COPY;
fo.fAnyOperationsAborted=TRUE;
fo.fFlags=FOF_NOCONFIRMMKDIR | FOF_NOCONFIRMATION;
fo.hNameMappings=NULL;
fo.lpszProgressTitle=NULL;
::SHFileOperation(&fo);
同时按下了CTRL+F键
msg.message==WM_KEYDOWN && msg.wParam='F' && ( 0x8000&GetKeyState(VK_CONTROL))
有一段字符串(CString)前后都有汉字中间是英文,如何将英文提取出来?
IsDBCSLeadByte(str.GetAt(i));这样的形式
判断文件是否存在
1.PathFileExists || PathIsDirectory
2.GetFileAttributes
3.
include <io.h>
if(_access(filename,0)!=-1)
{
printf("file exit");
}
唤醒计算机
BOOL RequestWakeupLatency(
LATENCY_TIME latency // latency requirement
);
使计算机休眠
#define RTN_ERROR 13
void PERR(LPTSTR szAPI, DWORD dwLastError) //休眠时调用到的一个函数,用来
记录休眠中遇到的错误
{
LPTSTR MessageBuffer;
DWORD dwBufferLength;
fprintf(stderr,"%s error! (rc=%lu)/n", szAPI, dwLastError);
if(dwBufferLength=FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
dwLastError,
LANG_NEUTRAL,
(LPTSTR) &MessageBuffer,
0,
NULL))
{
DWORD dwBytesWritten;
WriteFile(GetStdHandle(STD_ERROR_HANDLE),
MessageBuffer,
dwBufferLength,
&dwBytesWritten,
NULL);
LocalFree(MessageBuffer);
}
}
int SetPower() //主要功能函数
{
TOKEN_PRIVILEGES tp;
HANDLE hToken;
LUID luid;
LPTSTR MachineName=NULL;
if(!OpenProcessToken(GetCurrentProcess(), 从这里
TOKEN_ADJUST_PRIVILEGES,
&hToken ))
{
PERR("OpenProcessToken", GetLastError() );
return RTN_ERROR;
}
if(!LookupPrivilegeValue(MachineName, SE_SHUTDOWN_NAME, &luid))
{
PERR("LookupPrivilegeValue", GetLastError() );
return RTN_ERROR;
}
tp.PrivilegeCount = 1;
tp.Privileges[0].Luid = luid;
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(TOKEN_PRIVILEGES),
NULL, NULL ); 到这里,是取得权限//
SetSystemPowerState(FALSE,TRUE);
return 0;
}
void CDrawfromDlg::OnButton1()
{
SetPower();
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。