原帖:http://hi.baidu.com/ciw%5Fblue/blog/item/be15143195fd541eeac4afe3.html
#include "stdafx.h"
#include "resource.h"
#include <stdio.h>
int CALLBACK About(HWND, UINT, WPARAM, LPARAM);
int GetAnimalPos(int nAnimalData[], int nData, int n);
void Move(int nAnimal[][8], int& x1, int& y1, int& nDir);
int Eat(int nAnimal[][8], int x, int y, int nDir1, int nOrg);
void Convert(int nAnimal[][8]);
int nXMouseStep = 65535 / GetSystemMetrics(SM_CXFULLSCREEN);
int nYMouseStep = 65535 / GetSystemMetrics(SM_CYSCREEN);
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
DialogBox(NULL, MAKEINTRESOURCE(IDD_ABOUTBOX), NULL, About);
return 0;
}
HMODULE hModule = NULL;
bool bIsStart = false;
HWND hGameWnd;
typedef void(*SetHookDef)();
SetHookDef pSetHook;
int CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
UNREFERENCED_PARAMETER(lParam);
switch (message)
{
case WM_INITDIALOG:
if(lParam != 1)
{
SetWindowText(GetDlgItem(hDlg, IDC_EDIT1), "欢迎使用本软件.");
MoveWindow(hDlg, 800, 200, 220, 180, false);
SetTimer(hDlg, 1, 800, NULL);
SetTimer(hDlg, 2, 10, NULL);
hModule = LoadLibrary("TestDll.dll");
pSetHook = (SetHookDef)GetProcAddress(hModule, "SetHook");
pSetHook();
}
return (INT_PTR)TRUE;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDC_BTN_START:
hGameWnd = FindWindow(NULL, "对对碰角色版");
RECT stGameRect;
GetWindowRect(hGameWnd, &stGameRect);
if(hGameWnd == NULL)
{
SetWindowText(GetDlgItem(hDlg, IDC_EDIT1), "请启动游戏,再继续.");
break;
}
bIsStart = true;
MoveWindow(hGameWnd, 0, 0, stGameRect.right - stGameRect.left, stGameRect.bottom - stGameRect.top, true);
MoveWindow(hDlg, stGameRect.right, stGameRect.top + 50, 220, 180, true);
break;
case IDC_BUTTON1:
EndDialog(hDlg, 0);
break;
#include "stdafx.h"
#include "resource.h"
#include <stdio.h>
int CALLBACK About(HWND, UINT, WPARAM, LPARAM);
int GetAnimalPos(int nAnimalData[], int nData, int n);
void Move(int nAnimal[][8], int& x1, int& y1, int& nDir);
int Eat(int nAnimal[][8], int x, int y, int nDir1, int nOrg);
void Convert(int nAnimal[][8]);
int nXMouseStep = 65535 / GetSystemMetrics(SM_CXFULLSCREEN);
int nYMouseStep = 65535 / GetSystemMetrics(SM_CYSCREEN);
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
DialogBox(NULL, MAKEINTRESOURCE(IDD_ABOUTBOX), NULL, About);
return 0;
}
HMODULE hModule = NULL;
bool bIsStart = false;
HWND hGameWnd;
typedef void(*SetHookDef)();
SetHookDef pSetHook;
int CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
UNREFERENCED_PARAMETER(lParam);
switch (message)
{
case WM_INITDIALOG:
if(lParam != 1)
{
SetWindowText(GetDlgItem(hDlg, IDC_EDIT1), "欢迎使用本软件.");
MoveWindow(hDlg, 800, 200, 220, 180, false);
SetTimer(hDlg, 1, 800, NULL);
SetTimer(hDlg, 2, 10, NULL);
hModule = LoadLibrary("TestDll.dll");
pSetHook = (SetHookDef)GetProcAddress(hModule, "SetHook");
pSetHook();
}
return (INT_PTR)TRUE;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDC_BTN_START:
hGameWnd = FindWindow(NULL, "对对碰角色版");
RECT stGameRect;
GetWindowRect(hGameWnd, &stGameRect);
if(hGameWnd == NULL)
{
SetWindowText(GetDlgItem(hDlg, IDC_EDIT1), "请启动游戏,再继续.");
break;
}
bIsStart = true;
MoveWindow(hGameWnd, 0, 0, stGameRect.right - stGameRect.left, stGameRect.bottom - stGameRect.top, true);
MoveWindow(hDlg, stGameRect.right, stGameRect.top + 50, 220, 180, true);
break;
case IDC_BUTTON1:
EndDialog(hDlg, 0);
break;