user-0 提问: 控制台应用程序只运行一个实例

回复:
user: user-1
content: SetForegroundWindow The SetForegroundWindow function puts the thread that created the specified window into the foreground and activates the window. Keyboard input is directed to the window, and various visual cues are changed for the user. The system assigns a slightly higher priority to the thread that created the foreground window than it does to other threads.   BOOL SetForegroundWindow(   HWND hWnd   // handle to window to bring to foreground );   Parameters hWnd  Handle to the window that should be activated and brought to the foreground.  Return Values If the window was brought to the foreground, the return value is nonzero.  If the window was not brought to the foreground, the return value is zero.   Remarks The foreground window is the window at the top of the Z order. It is the window that the user is working with. In a preemptive multitasking environment, you should generally let the user control which window is the foreground window.   Windows NT 5.0 and later: An application cannot force a window to the foreground while the user is working with another window. Instead, SetForegroundWindow will activate the window (see SetActiveWindow) and call theFlashWindowEx function to notify the user.  Windows CE: The thread that owns the window is not given a priority boost.   QuickInfo   Windows NT: Requires version 3.1 or later.   Windows: Requires Windows 95 or later.   Windows CE: Requires version 1.0 or later.   Header: Declared in winuser.h.   Import Library: Use user32.lib.  See Also Windows Overview, Window Functions,FlashWindowEx, GetForegroundWindow, SetActiveWindow    SetActiveWindow The SetActiveWindow function activates a window. The window must be associated with the calling thread's message queue.   HWND SetActiveWindow(   HWND hWnd   // handle to window to activate );   Parameters hWnd  Handle to the top-level window to be activated.  Return Values If the function succeeds, the return value is the handle to the window that was previously active.   If the function fails, the return value is NULL. To get extended error information, callGetLastError.  Remarks The SetActiveWindow function activates a window, but not if the application is in the background. The window will be brought into the foreground (top of Z order) if the application is in the foreground when it sets the activation.   If the window identified by the hWnd parameter was created by the calling thread, the active window status of the calling thread is set to hWnd. Otherwise, the active window status of the calling thread is set to NULL.  The SetForegroundWindow window function, on the other hand, activates a window and forces it into the foreground. An application should only call SetForegroundWindow if it needs to display critical errors or information that needs the user's immediate attention .   By using theAttachThreadInput function, a thread can attach its input processing to another thread. This allows a thread to call SetActiveWindow to activate a window associated with another thread's message queue.   QuickInfo   Windows NT: Requires version 3.1 or later.   Windows: Requires Windows 95 or later.   Windows CE: Requires version 1.0 or later.   Header: Declared in winuser.h.   Import Library: Use user32.lib.  See Also Keyboard Input Overview, Keyboard Input Functions, GetActiveWindow, SetForegroundWindow, WM_ACTIVATE

user: user-0
content: 这个思路了解过，枚举系统中的process, 然后根据根据名称来匹配，不知道效率怎么样 我这特殊之处在于还需要解决系统中同时有同名service在运行的问题  回头尝试一下   谢谢

user: user-2
content: http://blog.csdn.net/luxiaoyu_sdc/article/details/6534783   --- 根据进程名获取句柄  SetWindowPos ---移动窗口。  没有实际试过，你可以试一下

user: user-0
content: http://blog.csdn.net/luheng2006/article/details/5578483  HWND WINAPI FindWindowEx(     _In_opt_  HWND hwndParent,     _In_opt_  HWND hwndChildAfter,     _In_opt_  LPCTSTR lpszClass,     _In_opt_  LPCTSTR lpszWindow   );  FindWindowEx用于查找正在运行的窗口的句柄，那么对于cmd程序，lpszClass和lpszWindow这两个参数各应该是什么呢？

user: user-2
content: 不明白，在windows中，控制台也是窗口，为啥不能像其它窗口那样激活呢?比如激活cmd.exe?