发布于 2010-11-18 16:10:52
5楼
用API ShellExecute可以以文件的关联方式打开文件,以下代码以打开WinCC帮助文件并置顶为例,打开其他文件要修改对应的窗口标题
#pragma code("shell32.dll")
long ShellExecuteA(HWND hwnd,LPCTSTR lpOperation,LPCTSTR lpFile,LPCTSTR lpParameters,LPCTSTR lpDirectory,INT nShowCmd);
#pragma code()
#pragma code("kernel32")
void Sleep(long dwMilliseconds);
#pragma code()
HWND h;
h=FindWindow(NULL,"WinCC信息系统"); //查找标题为“WinCC信息系统”的窗口
if (h==0)
{
ShellExecuteA(NULL,"open","E:\\Program Files\\Siemens\\WinCC\\Documents\\chinese\\WinCCInformationSystem.chm",NULL,NULL,SW_SHOWNORMAL);
Sleep(1000);
h=FindWindow(NULL,"WinCC信息系统");
}
if (h!=0) //找到窗口句柄则将窗口置顶
{
ShowWindow(h,SW_SHOW);
SetWindowPos(h,HWND_NOTOPMOST,0,0,0,0,SWP_NOSIZESWP_NOMOVE);
SetWindowPos(h,HWND_TOPMOST,0,0,0,0,SWP_NOSIZESWP_NOMOVE);
}