用VC6.0 SDK方式写的一个基于模式对话框的小程序,应该是定时器工作不正常,请高手把把脉,不胜感激!!
以下为cpp全部源码:
#include "stdafx.h"
#include "resource.h"
#define Timer 1
HINSTANCE hInst;
int hDlg = NULL;
LRESULT DlgProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
hInst = hInstance;
hDlg = DialogBox(hInst, (LPCTSTR)IDD_DIALOG1, NULL,(DLGPROC)DlgProc); //创建模式对话框
return 0;
}
LRESULT DlgProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
{
DWORD xuebuffer1=0;
DWORD xuebuffer2=0;
DWORD mobuffer1=0;
DWORD mobuffer2=0;
DWORD *xue1=NULL;
DWORD *xue2=NULL;
DWORD *mo1=NULL;
DWORD *mo2=NULL;
DWORD TraviaPID=0;
HWND hTraviaWnd=0;
HANDLE hTraviaProc=0;
switch(Msg)
{
case WM_COMMAND:
{
switch(LOWORD(wParam))
{
case WM_CREATE:
SetTimer(hTraviaWnd, Timer, 1000, NULL);
break;
case IDC_BUTTON1:
hTraviaWnd = FindWindow(NULL, "Travia");
GetWindowThreadProcessId(hTraviaWnd, &TraviaPID);
hTraviaProc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, TraviaPID);
ReadProcessMemory(hTraviaProc, (LPCVOID)0x006273F0, &xuebuffer1, 4, NULL); //读取血量上限
ReadProcessMemory(hTraviaProc, (LPCVOID)0x006273E8, &xuebuffer2, 4, NULL); //读取当前血量
ReadProcessMemory(hTraviaProc, (LPCVOID)0x006273F4, &mobuffer1, 4, NULL); //读取魔量上限
ReadProcessMemory(hTraviaProc, (LPCVOID)0x006273EC, &mobuffer2, 4, NULL); //读取当前魔量
xue1=(DWORD *)&xuebuffer1;
xue2=(DWORD *)&xuebuffer2;
mo1=(DWORD *)&mobuffer1;
mo2=(DWORD *)&mobuffer2;
break;
case WM_TIMER:
switch(wParam)
{
case Timer:
if(*xue2 < *xue1)
{
keybd_event(49,0,0,0);
keybd_event(49,0,KEYEVENTF_KEYUP,0); //按键1
}
if(*mo2 < *mo1)
{
keybd_event(50,0,0,0);
keybd_event(50,0,KEYEVENTF_KEYUP,0); //按键2
}
}
break;
}
}
break;
case WM_CLOSE:
EndDialog(hDlg,TRUE); //终止模式对话框
return TRUE;
break;
case WM_DESTROY:
KillTimer(hTraviaWnd,Timer);
CloseHandle(hTraviaProc);
PostQuitMessage(0);
return TRUE;
break;
};
return FALSE;
}
[招生]科锐逆向工程师培训(2024年11月15日实地,远程教学同时开班, 第51期)