#include <windows.h>
#include <stdio.h>
#define ID_TIMER 1
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
HWND hFive, hChild,hChess,hMsg,hStart,hLoss;
int f_Start,f_Loss; /*按扭状态标志*/
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int nCmdShow)
{
HWND hwnd ;
WNDCLASS wndclass ;
MSG msg ;
hFive = FindWindow(NULL,"五子棋");
if (hFive==NULL){
MessageBox(NULL,"五子棋没有运行.","ERROR",MB_OK);
return 1;
}
hChild=FindWindowEx(hFive,NULL,"#32770",NULL); /*找到棋盘的父窗口*/
hChess=FindWindowEx(hChild,NULL,"Afx:400000:8",NULL); /*找到下棋窗口*/
hStart=GetDlgItem(hChess,0xCD); /*得到'开始'按扭的句柄*/
hLoss= GetDlgItem(hChess,0xCE); /*得到'认输'按扭的句柄*/
wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = "myBrush" ;
RegisterClass (&wndclass);
hwnd = CreateWindow ("myBrush","五子棋专用刷分器",WS_OVERLAPPEDWINDOW,200,200,200,200,NULL,NULL,hInstance,NULL);
ShowWindow (hwnd, nCmdShow) ;
UpdateWindow (hwnd) ;
SetTimer (hwnd, ID_TIMER, 2000, NULL) ;
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return 0;
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc ;
PAINTSTRUCT ps ;
RECT rect ;
switch (message)
{
case WM_PAINT:
hdc = BeginPaint (hwnd, &ps) ;
GetClientRect (hwnd, &rect) ;
EndPaint (hwnd, &ps) ;
break;
case WM_DESTROY:
KillTimer (hwnd, ID_TIMER) ;
PostQuitMessage (0) ;
break;
case WM_TIMER:
if (f_Start=IsWindowEnabled(hStart))
SendMessage(hChess, WM_COMMAND,0xCD,BN_CLICKED); //点击开始
if (hMsg=FindWindowEx(NULL,NULL,"#32770","五子棋"))
{
SendMessage(hMsg, WM_COMMAND,IDOK,BN_CLICKED); //确认认输
break;
}
if (f_Loss=IsWindowEnabled(hLoss))
SendMessage(hChess, WM_COMMAND,0xCE,BN_CLICKED); //点击认输
break;
default:
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
return 0;
}
我想做一个QQ游戏 五子棋的自动认输程序
用了一个TIMER,间隔为2秒
TIMER事件就只给五子棋窗口发送3条消息
开始,认输,确认
这样一个循环
调试发现当我3条消息都运行时,确认消息始终不能执行,就是永远找不到确认认输窗口的句柄.
而当我把那条消息注释后,另两条开始认输可以执行.
把开始,认输消息注释后,确认消息能正确发送.
这是怎么回事?????