Looking for panacea...Type of the control...I have only CWnd pointer
-
Suppose IDC_EDIT1 is the ID of the edit box, so if i do if (GetDlgItem(IDC_EDIT1)->IsKindOf(RUNTIME_CLASS(CEdit))) AfxMessageBox("Type of the class is CEdit"); Message should be displayed.but it is not displaying. I want to check the type of control, and i have only CWnd pointer , what should i do. EXPLANATION ............ I have a CWnd Pointer and from this pointer i want to check what was the type of the control,whether it is CEdit, or CButton etc. what should i do
-
Suppose IDC_EDIT1 is the ID of the edit box, so if i do if (GetDlgItem(IDC_EDIT1)->IsKindOf(RUNTIME_CLASS(CEdit))) AfxMessageBox("Type of the class is CEdit"); Message should be displayed.but it is not displaying. I want to check the type of control, and i have only CWnd pointer , what should i do. EXPLANATION ............ I have a CWnd Pointer and from this pointer i want to check what was the type of the control,whether it is CEdit, or CButton etc. what should i do
The use of RUNTIME_CLASS may not return the right stuff for ya because you perhaps haven't declared DECLARE_DYNAMIC, DECLARE_DYNCREATE, or DECLARE_SERIAL in your class: "RUNTIME_CLASS returns a pointer to a CRuntimeClass structure for the class specified by class_name. Only CObject-derived classes declared with DECLARE_DYNAMIC, DECLARE_DYNCREATE, or DECLARE_SERIAL will return pointers to a CRuntimeClass structure." <-- From MSDN Library ------------------------------ ©0d3 ©®4©k3® - That's me! :) ------------------------------
-
Suppose IDC_EDIT1 is the ID of the edit box, so if i do if (GetDlgItem(IDC_EDIT1)->IsKindOf(RUNTIME_CLASS(CEdit))) AfxMessageBox("Type of the class is CEdit"); Message should be displayed.but it is not displaying. I want to check the type of control, and i have only CWnd pointer , what should i do. EXPLANATION ............ I have a CWnd Pointer and from this pointer i want to check what was the type of the control,whether it is CEdit, or CButton etc. what should i do
if (GetDlgItem(IDC_EDIT1)->IsKindOf(RUNTIME_CLASS(CEdit)))
AfxMessageBox("Type of the class is CEdit");...is never going to work because...
CWnd *p_MyWnd=GetDlgItem(IDC_EDIT1);
CRuntimeClass *p_RTC=p_MyWnd->GetRuntimeClass();in the debugger shows p_RTC to be a kind of CTempWnd. Your class is of no particular type until your pointer is cast as the desired type. Basically, GetDlgItem(IDC_EDIT1) is NOT a CEdit, until you cast it as CEdit. Of course, this doesn't help you much, but it might help you sleep at night :) My tuppence aimed at actually solving your problem though: work out the window class (not the same as a C++ class. Sorry to dissapoint you all with my lack of a witty or poignant signature.
-
Suppose IDC_EDIT1 is the ID of the edit box, so if i do if (GetDlgItem(IDC_EDIT1)->IsKindOf(RUNTIME_CLASS(CEdit))) AfxMessageBox("Type of the class is CEdit"); Message should be displayed.but it is not displaying. I want to check the type of control, and i have only CWnd pointer , what should i do. EXPLANATION ............ I have a CWnd Pointer and from this pointer i want to check what was the type of the control,whether it is CEdit, or CButton etc. what should i do
I recommend you use the window's class name instead:
CString strClassName;
::GetClassName(GetDlgItem(IDC_EDIT1).GetSafeHwnd(), strClassName.GetBuffer(100), 100);
strClassName.ReleaseBuffer();if (strClassName == "EDIT")
AfxMessageBox("It's an edit box");Take a look at CreateWindow for a list of possible class names. Regards, Alvaro
-
I recommend you use the window's class name instead:
CString strClassName;
::GetClassName(GetDlgItem(IDC_EDIT1).GetSafeHwnd(), strClassName.GetBuffer(100), 100);
strClassName.ReleaseBuffer();if (strClassName == "EDIT")
AfxMessageBox("It's an edit box");Take a look at CreateWindow for a list of possible class names. Regards, Alvaro
Take a look at CreateWindow for a list of possible class names.... .... or play with Spy++. Spy++ really is great. Anyone want to form the Spy++ appreciation society with me? Sorry to dissapoint you all with my lack of a witty or poignant signature.