Skip to main content

[原创软件] 人人网自动抢沙发(附源码)

· 3 min read

2011年9月的时候,我们网络部的同学和学长们在人人网开始了抢沙发比赛。于是写了一个人人网自动抢沙发的小工具,让我们部门永远都能坐上沙发。今天分享下源码,仅供学习参考。

功能说明

  • 自动检测人人网好友发的新状态
  • 自动点击抢沙发按钮
  • 自动关闭留言窗口

实现原理

通过 Windows API 检测特定窗口类名和尺寸,模拟鼠标点击实现自动留言。

主要源码分享

#include <windows.h>
#include <process.h>
#include "resource.h"

#define CW_SCREEN 1
#define CW_WORKAREA 3

// 窗口居中显示
BOOL WINAPI CenterMainWindow(HWND hWnd, DWORD dwFlags)
{
RECT rtWindow = {0};
RECT rtContainer = {0};

GetWindowRect(hWnd, &rtWindow);
rtWindow.right -= rtWindow.left;
rtWindow.bottom -= rtWindow.top;

switch(dwFlags)
{
case CW_SCREEN:
rtContainer.right = GetSystemMetrics(SM_CXSCREEN);
rtContainer.bottom = GetSystemMetrics(SM_CYSCREEN);
break;
case CW_WORKAREA:
SystemParametersInfo(SPI_GETWORKAREA, 0, &rtContainer, 0);
break;
}

return SetWindowPos(hWnd, HWND_TOP,
(rtContainer.right - rtWindow.right) / 2,
(rtContainer.bottom - rtWindow.bottom) / 2,
0, 0, SWP_NOSIZE | SWP_HIDEWINDOW);
}

// 检测是否为人人网留言窗口
bool IsRenrenCommentWindow(HWND hwnd)
{
TCHAR buff[256];
GetClassName(hwnd, buff, 255);
if (wcscmp(buff, L"GTK2-W") == 0)
{
RECT rct;
GetClientRect(hwnd, &rct);
if(rct.right == 272 && rct.bottom > 110)
{
return true;
}
}
return false;
}

POINT cursorPos; // 鼠标位置
RECT commentWndRect; // 留言窗口位置

// 自动点击留言按钮并关闭窗口
BOOL CALLBACK AutoPostComment(HWND hwnd, LPARAM lParam)
{
if(IsRenrenCommentWindow(hwnd))
{
OutputDebugString(L"找到留言窗口");
GetWindowRect(hwnd, &commentWndRect);
GetCursorPos(&cursorPos);

// 点击发送按钮
int sendBtnX = commentWndRect.right - commentWndRect.left - 10;
int sendBtnY = commentWndRect.bottom - commentWndRect.top - 30;
for (int i = 0; i < 5; i++)
{
SendMessage(hwnd, WM_LBUTTONDOWN, 0, (sendBtnY << 16) + sendBtnX);
SendMessage(hwnd, WM_LBUTTONUP, 0, (sendBtnY << 16) + sendBtnX);
}

// 点击关闭按钮
int closeBtnX = commentWndRect.right - commentWndRect.left - 100;
int closeBtnY = commentWndRect.bottom - commentWndRect.top - 50;
SendMessage(hwnd, WM_LBUTTONDOWN, 0, (closeBtnY << 16) + closeBtnX);
SendMessage(hwnd, WM_LBUTTONUP, 0, (closeBtnY << 16) + closeBtnX);

PostMessage(hwnd, WM_CLOSE, 0, 0);
}
return 1;
}

// 查找并处理所有留言窗口
void ProcessCommentWindows()
{
EnumWindows(AutoPostComment, NULL);
}

// 安装定时器钩子
void InstallCommentHook(PVOID pvoid)
{
OutputDebugString(L"开始监控留言窗口");
SetTimer(NULL, 0, 200, (TIMERPROC)ProcessCommentWindows);

MSG msg;
while (GetMessage(&msg, 0, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}

// 主窗口消息处理
LRESULT MainDlgProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
MSG msg;
HWND hDlg = CreateDialog(hInstance, (LPCTSTR)IDD_DIALOG1, 0, (DLGPROC)MainDlgProc);
ShowWindow(hDlg, nCmdShow);

_beginthread(InstallCommentHook, 0, NULL);

while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}

// 主窗口过程
LRESULT MainDlgProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
switch (Msg)
{
case WM_CLOSE:
DestroyWindow(hDlg);
return TRUE;

case WM_DESTROY:
PostQuitMessage(0);
return TRUE;

case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
switch (wmId)
{
// 添加按钮处理
}
break;

case WM_INITDIALOG:
CenterMainWindow(hDlg, CW_SCREEN);
break;
}
return FALSE;
}


迎新晚会

· One min read

迎新晚会发微博会在大屏幕滚动

#武测迎新#国软国软,完爆遥感!!!!! ​​​
(来自 短信)


Restorator

· One min read

Win7安装Restorator后,竟然打开不了任何程序了,更悲剧的是右键的打开选项也消失了![挖鼻屎] 解决方法:在记事本里编辑,然后保存为.reg,双击打开。 ​​​


360 安全套

· One min read

希望360安全套能"永久免费"![嘻嘻] //@周鸿祎:360牙刷和我们有什码关系?你怎么不买360安全套表示支持呢

> 
```[@许单单-互联网分析师](https://weibo.com/u/1558247760)

牙刷结果:根据博友的评论反馈,买了狮王软毛。另外为了支持[@周鸿祎](https://weibo.com/n/周鸿祎) 同学,买了360牙刷 ​​​

明天要不要围观

· One min read

明天要不要围观参加高考的同学呢?[思考] ​​​


建立Win8资讯网

· One min read

关注Windows 8已有一段时间。最近注册了个与Win8相关的域名:win8ok.com(链接已失效),让大家分享各自了解到的Win8系统的消息。

欢迎访问论坛:bbs.win8ok.com (链接已失效) !!


[原创软件] ChinaZ自动顶贴机

· One min read

更新:

终于完成了,发上来共享

下载地址:blog.pp93.com/soft/chinaz.zip (链接已失效)


最近混ChinaZ论坛,想混点金币实在不容易,自己也没那么多时间在坛子里面水。

正在制作一ChinaZ款自动顶贴机,做完了发上来共享,嘿嘿~


个人博客重新起航

· One min read

一直想重新开通个人博客,可一个高中生的时间,若不珍惜,很容易从指尖溜走。

不过很幸运,作为保送生的我终于有时间能干我想干的事!

域名暂时就用这个二级域名:blog.pp93.com(域名更换为:https://xieyonglin.com/ )。

服务器由旱鱼工作室(链接已失效)友情赞助!

AD:  泡泡导航 是我的导航站,欢迎设为主页!o(∩_∩)o