如何使用GetTopWindow?

czhsdhs 2004-12-03 11:08:52
在一个多文档应用程序中,能用GetTopWindow得到CMainFrame的子窗口吗?如何去的到呢?能不能详细说说GetTopWindow的用法。MSDN中的意思不是很明白。谢谢。
...全文
609 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
oyljerry 2004-12-03
  • 打赏
  • 举报
回复
看是否获得窗口handle
koko1998 2004-12-03
  • 打赏
  • 举报
回复
gz
czhsdhs 2004-12-03
  • 打赏
  • 举报
回复
在CMainFrame中有一个菜单的映射消息,在函数里有如下代码:
void CMainFrame::OnHelpTest2()
{
// TODO: Add your command handler code here

CString strText;

GetTopWindow()->GetWindowText(strText);
AfxMessageBox(strText);
}
为什么strText老是空呀。我想它应该是我已经打开的在前面的子窗口名称呀。
luxin24 2004-12-03
  • 打赏
  • 举报
回复
GetTopWindow Function

--------------------------------------------------------------------------------

The GetTopWindow function examines the Z order of the child windows associated with the specified parent window and retrieves a handle to the child window at the top of the Z order.

Syntax

HWND GetTopWindow( HWND hWnd
);
Parameters

hWnd
[in] Handle to the parent window whose child windows are to be examined. If this parameter is NULL, the function returns a handle to the window at the top of the Z order.
Return Value

If the function succeeds, the return value is a handle to the child window at the top of the Z order. If the specified window has no child windows, the return value is NULL. To get extended error information, use the GetLastError function.
xuzheng318 2004-12-03
  • 打赏
  • 举报
回复
CWND类有个变量m_hwnd,可以直接用
CWND还有如下函数,具体情况具体用
GetDesktopWindow Retrieves the Windows desktop window.
GetForegroundWindow Returns a pointer to the foreground window (the top-level window with which the user is currently

GetTopWindow Returns the first child window that belongs to the CWnd.
GetWindow .....

FindWindow Returns the handle of the window, which is identified by its window name and window class.

或者GetDlgItem,用于对话框与子窗口

在CWindo与SDK中还有GetWindowLong用与找父窗口
kingzai 2004-12-03
  • 打赏
  • 举报
回复
GetTopWindow()其参数是指这个窗口的父窗口,返回的是最上面的窗口句柄,如你想要找DESKTOP上的最上面的窗口,你可以这样做GetTopWindow(GetDesktopWindow()),垂直于屏幕的方向就是z order
DentistryDoctor 2004-12-03
  • 打赏
  • 举报
回复
...
if ( !lstrcmpi( szBuf, _T( "ComboBox" ) ) )
{
// Special case for simple comboboxes
if ( ( dwStyle & 0x03 ) == CBS_SIMPLE )
{
hWnd = GetTopWindow( hWnd );
while ( hWnd )
{
AddControl( hWnd );
hWnd = GetNextWindow( hWnd, GW_HWNDNEXT );
}
return FALSE;
}
}
...
lzzqqq 2004-12-03
  • 打赏
  • 举报
回复
CMainFrame* pFrm=(CMainFrame*)AfxGetApp()->m_pMainWnd;
if (pFrm==NULL)
return;
pFrm->GetActiveFrame();//这里就得到了child frame了。
DentistryDoctor 2004-12-03
  • 打赏
  • 举报
回复
GetTopWindow得到是Z-Order在前的第一个子窗口。
Creating Windows CreateMDIWindow CreateWindow CreateWindowEx RegisterClass RegisterClassEx UnregisterClass Message Processing BroadcastSystemMessage CallNextHookEx CallWindowProc DefFrameProc DefMDIChildProc DefWindowProc DispatchMessage GetMessage GetMessageExtraInfo GetMessagePos GetMessageTime GetQueueStatus InSendMessage PeekMessage PostMessage PostQuitMessage PostThreadMessage RegisterWindowMessage ReplyMessage SendMessage SendMessageCallback SendMessageTimeout SendNotifyMessage SetMessageExtraInfo SetWindowsHookEx TranslateMessage UnhookWindowsHookEx WaitMessage Window Information AnyPopup ChildWindowFromPoint ChildWindowFromPointEx EnableWindow EnumChildWindows EnumPropsEx EnumThreadWindows EnumWindows FindWindow FindWindowEx GetClassInfoEx GetClassLong GetClassName GetClientRect GetDesktopWindow GetFocus GetForegroundWindow GetNextWindow GetParent GetProp GetTopWindow GetWindow GetWindowLong GetWindowRect GetWindowText GetWindowTextLength IsChild IsIconic IsWindow IsWindowEnabled IsWindowUnicode IsWindowVisible IsZoomed RemoveProp SetActiveWindow SetClassLong SetFocus SetForegroundWindow SetParent SetProp SetWindowLong SetWindowText WindowFromPoint Processes and Threads CreateEvent CreateMutex CreateProcess CreateSemaphore CreateThread DeleteCriticalSection DuplicateHandle EnterCriticalSection ExitProcess ExitThread GetCurrentProcess GetCurrentProcessId GetCurrentThread GetCurrentThreadId GetExitCodeProcess GetExitCodeThread GetPriorityClass GetThreadPriority GetWindowThreadProcessId InitializeCriticalSection InterlockedDecrement InterlockedExchange InterlockedIncrement LeaveCriticalSection OpenEvent OpenMutex OpenProcess OpenSemaphore PulseEvent ReleaseMutex ReleaseSemaphore ResetEvent ResumeThread SetEvent SetPr

16,472

社区成员

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

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

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