(高分悬赏)获取当前获焦控件的句柄(控件在内嵌的对话框中)

yuweifamily 2016-12-14 11:28:47

期末作业,要求写一个公式编辑器。如图所示,这是基于对话框的小程序,其中红线区域是一个内嵌的对话框,在这个内嵌对话框中会根据不同情况生成很多不同位置和大小的文本框,当点击上面按钮时,需要将相应的文本写入此时获焦的文本框。小弟,通过GetFocus()函数获取句柄,但是句柄不正确,不能操作文本框。在线等大神解答,为谢!!!!!!
...全文
319 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
对话框不是有个类吗,给这个对话框定义相应的类变量,发消息给这个变量就可以了
凌乱哥 2016-12-15
  • 打赏
  • 举报
回复
就放一个RichEdit就行了,点击按钮往那个内嵌的对话框发消息,对话框收到消息就往那个RichEdit输入字符就行了
赵4老师 2016-12-15
  • 打赏
  • 举报
回复
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
schlafenhamster 2016-12-15
  • 打赏
  • 举报
回复
"当点击上面按钮时" pDlg->GetDlgItem(IDC_EDITX);
zgl7903 2016-12-15
  • 打赏
  • 举报
回复
自己的程序, 只要关联控件, 访问控件变量就好了
  • 打赏
  • 举报
回复
1楼的方法应该可以,另外建议考虑用RichEdit,一个控件就够了,可以显示各种符号,就不用这样动态弄好多edit了。
阿源是少年 2016-12-15
  • 打赏
  • 举报
回复
你点按钮,焦点不就跑到按钮上了吗,拿到按钮句柄了,我猜是这样?你内嵌那个对话框的代码改进一下,当某个文本框点击后就把句柄保存下来,然后你点按钮就往当前保存下的句柄对应的文本框操作

15,980

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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