Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Looking for panacea...Type of the control...I have only CWnd pointer

Looking for panacea...Type of the control...I have only CWnd pointer

Scheduled Pinned Locked Moved C / C++ / MFC
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Ahmad99
    wrote on last edited by
    #1

    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

    R J A 3 Replies Last reply
    0
    • A Ahmad99

      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

      R Offline
      R Offline
      Rickard Andersson20
      wrote on last edited by
      #2

      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! :) ------------------------------

      1 Reply Last reply
      0
      • A Ahmad99

        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

        J Offline
        J Offline
        Jon Hulatt
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • A Ahmad99

          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

          A Offline
          A Offline
          Alvaro Mendez
          wrote on last edited by
          #4

          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

          J 1 Reply Last reply
          0
          • A Alvaro Mendez

            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

            J Offline
            J Offline
            Jon Hulatt
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups