回复:wincc 中如何用C脚本获取一个外部程序的运行状态以及如何把一个运行的外部程序置于前端显示?

城外之人

版主

  • 帖子

    8685
  • 精华

    18
  • 被关注

    218

论坛等级:至圣

注册时间:2003-09-23

钻石 钻石 如何晋级?

发布于 2012-05-14 08:56:30

5楼

下面是将指定窗口句柄置前的项目函数:

BOOL ForceForegroundWindow(HWND hWnd)
{
#pragma code("user32.dll")
DWORD GetWindowThreadProcessId(
HWND hWnd, // handle to window
LPDWORD lpdwProcessId // address of variable for process identifier
);

BOOL AttachThreadInput(
DWORD idAttach, // thread to attach
DWORD idAttachTo, // thread to attach to
BOOL fAttach // attach or detach
);

HWND GetForegroundWindow(VOID);

BOOL SetForegroundWindow(
HWND hWnd // handle to window to bring to foreground
);

BOOL IsIconic(
HWND hWnd // handle to window
);

BOOL ShowWindow(
HWND hWnd, // handle to window
int nCmdShow // show state of window
);

#pragma code()

long int ThreadID1,ThreadID2;
BOOL bRet;

// Nothing to do if already in foreground.
if (hWnd == GetForegroundWindow()) return TRUE;

// First need to get the thread responsible for this window,
// and the thread for the foreground window.
ThreadID1=GetWindowThreadProcessId(GetForegroundWindow(),NULL);
ThreadID2=GetWindowThreadProcessId(hWnd,NULL);

// By sharing input state,thread share their concept of the active window.
if (ThreadID1 != ThreadID2)
{
AttachThreadInput(ThreadID1,ThreadID2,TRUE);
bRet = SetForegroundWindow(hWnd);
AttachThreadInput(ThreadID1,ThreadID2,FALSE);
}
else bRet = SetForegroundWindow(hWnd);

// Restore and repaint
if (IsIconic(hWnd))
ShowWindow(hWnd,SW_RESTORE);
else ShowWindow(hWnd,SW_SHOWNORMAL);

return bRet;
}
无论成与败,无论甜与苦,我还是我。
评论
编辑推荐: 关闭

请填写推广理由:

本版热门话题

SIMATIC WinCC / Panel

共有32566条技术帖

相关推荐

热门标签

相关帖子推荐

guzhang

恭喜,你发布的帖子

评为精华帖!

快扫描右侧二维码晒一晒吧!

再发帖或跟帖交流2条,就能晋升VIP啦!开启更多专属权限!

  • 分享

  • 只看
    楼主

top
您收到0封站内信:
×
×
信息提示
很抱歉!您所访问的页面不存在,或网址发生了变化,请稍后再试。