不知什么时候起,
冒险岛在启动的时候会有画面,要等一会儿,然后点画面上的开始(或者按ALT+F4)才能进游戏.
这样好麻烦啊,于是我想到写一个<<冒险岛启动器>>一次性搞定
编程思路:
1.从注册表读出冒险岛启动文件的路径.
2.因为我发现用WinExec去启动的话,在程序的同目录下会出现一个** 文件,
所以要用CreateProcess,需要在lpCurrentDirectory函数中传入那个可执行文件所在文件夹路径.
3.用FindWindow寻找那个启动画面,找到的话用SendMessage发送WM_CLOSE消息关闭,这样就直接进入游戏了.
#include <windows.h>
#include <stdio.h>
void HandleError(UINT uErrorCode)
{
char pszError[30];
sprintf(pszError,"错误码:%02u",uErrorCode);
MessageBox(0,pszError," ",0);
ExitProcess(0);
}
void GetDirFromFilePath(char* pszFilePath,char* pszDirPath)
{
char *pszFirst = pszFilePath; //pszFilePath的第一个字符的地址
char *pszEnd = pszFilePath;
char *pszDir = pszDirPath;
while(*pszEnd) pszEnd++; //出while循环后,保存字符串末尾的 00 的地址
while(*pszEnd != '\\') pszEnd--; //出while循环后,保存字符串从尾向前第一个 \ 的地址
while(pszFirst != pszEnd){
*pszDir = *pszFirst;
pszDir++;
pszFirst++;
}
*pszDir = 0;
}
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCme)
{
HKEY hKey = NULL;
char pszMxdPath[MAX_PATH];
char pszMxdDir[MAX_PATH];
DWORD dw = 0xFFFFFFFF;
STARTUPINFO startUpInfo = {sizeof(STARTUPINFO)};
PROCESS_INFORMATION Process_Information;
HWND h=0;
long ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\\snda\\MapleStory",NULL,KEY_QUERY_VALUE,&hKey);
if(ret != ERROR_SUCCESS) HandleError(1);
ret = RegQueryValueEx(hKey,"Loader",NULL,NULL,(LPBYTE)pszMxdPath,&dw);
if(ret != ERROR_SUCCESS) HandleError(2);
RegCloseKey(hKey);
GetDirFromFilePath(pszMxdPath,pszMxdDir);
CreateProcess(pszMxdPath,NULL,NULL,NULL,false,0,NULL,pszMxdDir,&startUpInfo,&Process_Information);
do
h=FindWindow("StartUpDlgClass","MapleStory");
while(!h); //FindWindow返回值非零,找到了那个启动画面
SendMessage(h,WM_CLOSE,0,0); //发送WM_CLOSE消息
return 1;
}