请大家给些思路,我需要通过一个应用程序来隐藏或者显示其它应用程序的窗口……(在线讨论)

alfwolf 2002-03-18 02:53:15
如题。
...全文
61 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
shinka 2002-03-18
  • 打赏
  • 举报
回复
其实实现不困难,先找到要隐藏窗口的句柄,再使用一个API函数。ShowWindow

HWND hwnd=FindWindow(null,"这里是窗口名");
if(hwnd!=NULL)
ShowWindow(hwnd,SW_HIDE);
...

ShowWindow(hwnd,SW_SHOW);
...

其它的例如最小化显示,普通显示,请参考下面的参数:

Value Meaning
SW_HIDE Hides the window and activates another window.
SW_MAXIMIZE Maximizes the specified window.
SW_MINIMIZE Minimizes the specified window and activates the next top-level window in the Z order.
SW_RESTORE Activates and displays the window. If the window is minimized or maximized, Windows restores it to its original size and position. An application should specify this flag when restoring a minimized window.
SW_SHOW Activates the window and displays it in its current size and position.
SW_SHOWDEFAULT Sets the show state based on the SW_ flag specified in the STARTUPINFO structure passed to the CreateProcess function by the program that started the application.
SW_SHOWMAXIMIZED Activates the window and displays it as a maximized window.
SW_SHOWMINIMIZED Activates the window and displays it as a minimized window.
SW_SHOWMINNOACTIVE Displays the window as a minimized window. The active window remains active.
SW_SHOWNA Displays the window in its current state. The active window remains active.
SW_SHOWNOACTIVATE Displays a window in its most recent size and position. The active window remains active.
SW_SHOWNORMAL Activates and displays a window. If the window is minimized or maximized, Windows restores it to its original size and position. An application should specify this flag when displaying the window for the first time.

以上。
strip 2002-03-18
  • 打赏
  • 举报
回复
阿蒙说的应该改为:
HWND hwnd=FindWindow(szClassName,szWindowName);
if(hwnd!=NULL)
{
ShowWindow( hwnd, SW_SHOW ); // SW_HIDE, SetForegroundWindow
}

如果是特定的窗口的话,用上面的方法,但是事先要知道szClassName, szWindowName(就是caption, title), 可以用spy++来看窗口的这两个值
另外,如果开了两个(qq)窗口的,只会返回找到的第一个,这个要注意

alfwolf 2002-03-18
  • 打赏
  • 举报
回复
明白了,谢谢
strip 2002-03-18
  • 打赏
  • 举报
回复
离开了???

BOOL IsTaskbarWindow( HWND hwnd )
{
BOOL bReturn = FALSE;
BOOL bParent = (::GetParent( hwnd ) != NULL );
BOOL bOwner = (::GetWindow(hwnd, GW_OWNER) != 0);
BOOL bVisible = ::IsWindowVisible( hwnd );
BOOL bToolWindow = ( (::GetWindowLong(hwnd, GWL_EXSTYLE)&WS_EX_TOOLWINDOW) != 0 );
BOOL bAppWindow = ( (::GetWindowLong(hwnd, GWL_EXSTYLE)&WS_EX_APPWINDOW) != 0 );
if( !bParent && bVisible )
{
if( ( bOwner && bAppWindow ) || ( !bOwner && !bToolWindow) )
{
bReturn = TRUE;
}
}
return bReturn;
}

BOOL CALLBACK EnumWindowsProc( HWND hwnd, LPARAM lParam )
{
if( IsTaskbarWindow( hwnd ) )
{
char szClassName[255];
char szTitle[255];
GetClassName( hwnd, szClassName, 255 );
GetWindowText( hwnd, szTitle, 255 );
TRACE("%d.(%s)%s\n", aaa++, szClassName, szTitle );
}
return TRUE;
}

void PrintWindow( HWND hwnd )
{
char szClassName[255];
char szTitle[255];
GetClassName( hwnd, szClassName, 255 );
GetWindowText( hwnd, szTitle, 255 );
TRACE("(%s)%s\n", szClassName, szTitle );
}
然后调用EnumWindows( EnumWindowsProc, 0 );
你就可以得到所有的应用程序窗口了,和任务条上的一样
用ShowWindow( SW_SHOW )/ShowWindow( SW_HIDE )来隐藏和显示
用GetForegroundWindow把某个窗口送到前面来
delphihero 2002-03-18
  • 打赏
  • 举报
回复
HWND hwnd=FindWindow(null,"qq登陆程序");
if(hwnd!=NULL)
WinExec(hwnd,SW_HIDE);
strip 2002-03-18
  • 打赏
  • 举报
回复
给email, 就这150了,我不贪心
alfwolf 2002-03-18
  • 打赏
  • 举报
回复
呵呵,老兄要多少?
strip 2002-03-18
  • 打赏
  • 举报
回复
我有sample, 你拿多少分来换?

16,550

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Creator Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧