IsKindOf(RUNTIME_CLASS(CEdit)) [英] IsKindOf(RUNTIME_CLASS(CEdit))

查看:166
本文介绍了IsKindOf(RUNTIME_CLASS(CEdit))的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用CFormView视图类创建了一个 SDI 应用程序,该类包含一些基本控件.我需要在特定时间知道编辑框是否获得了关注,因此我将函数称为GetFocus();&然后从返回的CWnd*指针中调用函数IsKindOf(RUNTIME_CLASS(CEdit)).我从没有输入焦点的CEdit类.
所以我实施了这行代码来诊断问题,
AfxMessageBox(GetFocus()->GetRuntimeClass()->m_lpszClassName);
该行代码始终向我显示一个带有CTempWnd文本的消息框,&当我调用此代码时:
AfxMessageBox(GetFocus()->GetRuntimeClass()->m_pBaseClass->m_lpszClassName);它向我显示一个带有CWnd文本的消息框. &永远不会返回CEdit.

请帮助我解决此问题. :sigh:

I created an SDI application with CFormView view class that contains some basic controls. I need to know at a certain time if the Edit Boxes has gain the focus, so I called the function GetFocus(); & then called the function IsKindOf(RUNTIME_CLASS(CEdit)) from the returned CWnd* pointer. I never got an CEdit class with input focus.
So I implemented this line of code to diagnostic the issue,
AfxMessageBox(GetFocus()->GetRuntimeClass()->m_lpszClassName);
That line of code always displays to me a message box with CTempWnd text, & when I call this code:
AfxMessageBox(GetFocus()->GetRuntimeClass()->m_pBaseClass->m_lpszClassName); it displays to me a message box with CWnd text. & never the CEdit is returned.

Help me please to solve this issue. :sigh:

推荐答案

正如安德鲁所说,可以在ID级别解决:):
As Andrew said, it could be solved at the ID-level :) :
UINT uiEditIDs[] = {
  IDC_EDIT122,
  IDC_EDIT34,
  IDC_EDIT67,
  IDC_EDIT_NAME /*, ... */
};

bool CYourView::IsAnEditBoxFocused()
{
  bool bFocudes(false);
  CWnd* pcFocusedWnd(GetFocus());
  if (pcFocusedWnd->GetSafeHwnd()) {
    for (int i = 0; i < _countof(uiEditIDs) && !bFocused; i++) {
      bFocused = (uiEditIDs[i] == pcFocusedWnd->GetDlgCtrlId());
    }
  }
  return bFocused;
}


>检查焦点的ID HWND是您的一个编辑控件的ID.

实际上,我在这里忘记提及的是系统中可能还有其他具有相同ID的窗口(但不应有具有相同ID和相同父窗口的窗口).例如,如果用户打开了您的两个表单,则每个表单将有两组子窗口.

如果要确保确切知道要处理的编辑控件,则需要检查其ID,并检查其父级的HWND与CFormView的HWND相同.
> Check the ID of the focus HWND is the ID of one of your edit controls.

Actually what I forgot to mention here is that there may be other windows with the same ID in the system (but there should not be windows with the same ID and same parent window). For example, if the user had open 2 of your forms there would be two sets of child windows for each form.

If you want to make sure you know exactly which edit control you are dealing with then you need to check its ID and also that its parent''s HWND is the same as the HWND of the CFormView.


感谢大家的帮助.我还找到了另一种方法.
是调用GetClassName函数:
Thanks guys for your help. I also found another way to do this.
Is to call the GetClassName Function:
int WINAPI GetClassName(
  __in   HWND hWnd,
  __out  LPTSTR lpClassName,
  __in   int nMaxCount
);


&然后将返回的 lpClassName _T("Edit")进行比较,因此,如果它们相同,则编辑框"控件将成为焦点.


& then compare the returned lpClassName with _T("Edit"), so if they are the same, then an Edit Box Control is getting the focus.

TCHAR szClassName[32];
GetClassName(GetFocus()->GetSafeHwnd(), szClassName, sizeof(szClassName));
if (!lstrcmpi(szClassName, _T("Edit")))
   // An Edit Box control has gain the focus. Do the appropriate code


NB:此代码的目的是启用主菜单中的(撤消,剪切,复制和粘贴)按钮.主工具栏(如果编辑框"控件已获得焦点)如果当前没有编辑框"控件具有焦点,请禁用.


NB: The purpose for this code is to Enable the (Undo, Cut, Copy & Paste) buttons from the main menu & the main toolbar if an Edit Box control has gain the focus & Disable them if no Edit Box control is currently having the focus.


这篇关于IsKindOf(RUNTIME_CLASS(CEdit))的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆