子窗口如何动态创建控件CWND指针如何获取

wjm1990 2015-08-07 03:20:35
单文档视图分割弄了很多子对话框,现在相对子对话框动态添加控件
CWND*用的是AfxGetMainWnd(),所以控件都添到视图里了,没在子对话框上
应该怎么操作
...全文
220 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
阿源是少年 2015-08-07
  • 打赏
  • 举报
回复
你把对话框指针保存在数组里这个不困难吧,这个数组你搞成全局变量都可以
阿源是少年 2015-08-07
  • 打赏
  • 举报
回复
引用 3 楼 wjm1990 的回复:
[quote=引用 2 楼 pcradio 的回复:] AfxGetMainWnd返回的不是框架主窗口指针就是活动视图指针,你网对画框添加控件,需要对话框的指针,对话框是你自己创建的,你应该在创建他们的时候把它们的指针保存起来,这样你才能动态创建子控件的时候对号入座
我用的creatview创建视图,这个怎么操作[/quote] 关视图什么事情?要对话框指针, 你如果是在子对话框类里面创建子控件,用this指针,对话框ID是它的资源模版ID,不是控件ID,通过这个ID拿不到对话框指针和句柄
wjm1990 2015-08-07
  • 打赏
  • 举报
回复
[quote=引用 4 楼 zhao4zhong1 的回复:] [/quote 有没有简单的,我知道子对话框ID ,而且直接在子对话框类下面写
赵4老师 2015-08-07
  • 打赏
  • 举报
回复
FindWindowEx The FindWindowEx function retrieves a handle to a window whose class name and window name match the specified strings. The function searches child windows, beginning with the one following the given child window. This function does not perform a case-sensitive search. HWND FindWindowEx( HWND hwndParent, // handle to parent window HWND hwndChildAfter, // handle to a child window LPCTSTR lpszClass, // pointer to class name LPCTSTR lpszWindow // pointer to window name ); Parameters hwndParent Handle to the parent window whose child windows are to be searched. If hwndParent is NULL, the function uses the desktop window as the parent window. The function searches among windows that are child windows of the desktop. Windows NT 5.0 and later: If hwndParent is HWND_MESSAGE, the function searches all message-only windows. hwndChildAfter Handle to a child window. The search begins with the next child window in the Z order. The child window must be a direct child window of hwndParent, not just a descendant window. If hwndChildAfter is NULL, the search begins with the first child window of hwndParent. Note that if both hwndParent and hwndChildAfter are NULL, the function searches all top-level and message-only windows. lpszClass Pointer to a null-terminated string that specifies the class name or is an atom that identifies the class-name string. If this parameter is an atom, it must be a global atom created by a previous call to theGlobalAddAtom function. The atom, a 16-bit value, must be placed in the low-order word of lpszClass; the high-order word must be zero. lpszWindow Pointer to a null-terminated string that specifies the window name (the window's title). If this parameter is NULL, all window names match. Return Values If the function succeeds, the return value is a handle to the window that has the specified class and window names. If the function fails, the return value is NULL. To get extended error information, callGetLastError. QuickInfo Windows NT: Requires version 4.0 or later. Windows: Requires Windows 95 or later. Windows CE: Unsupported. Header: Declared in winuser.h. Import Library: Use user32.lib. Unicode: Implemented as Unicode and ANSI versions on Windows NT. See Also Windows Overview, Window Functions, EnumWindows, FindWindow, GetClassName,GlobalAddAtom
wjm1990 2015-08-07
  • 打赏
  • 举报
回复
引用 2 楼 pcradio 的回复:
AfxGetMainWnd返回的不是框架主窗口指针就是活动视图指针,你网对画框添加控件,需要对话框的指针,对话框是你自己创建的,你应该在创建他们的时候把它们的指针保存起来,这样你才能动态创建子控件的时候对号入座
我用的creatview创建视图,这个怎么操作
阿源是少年 2015-08-07
  • 打赏
  • 举报
回复
AfxGetMainWnd返回的不是框架主窗口指针就是活动视图指针,你网对画框添加控件,需要对话框的指针,对话框是你自己创建的,你应该在创建他们的时候把它们的指针保存起来,这样你才能动态创建子控件的时候对号入座
sumos 2015-08-07
  • 打赏
  • 举报
回复
把子对话框记录下来, std::map<std::wstring, CDialogEx*> windows_; 根据id去找到对应的对话框,然后在对话框上创建CWND。

16,472

社区成员

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

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

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