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. Calling a function from another Class [newbie question]

Calling a function from another Class [newbie question]

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelp
4 Posts 3 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.
  • S Offline
    S Offline
    Schehaider_Aymen
    wrote on last edited by
    #1

    Hello all, i know it's a newbie question but i couldn't find a replic or a sample code for such stuf. I have a CFormView Class and a CTest Class Derived CEdit Class. on both of them i have the OnKeyDown function, but what i want to do is to call the OnKeyDown fucnt of the deriver CEdit Class from the first one.. I declared a var with CTest var on the CFormView class and in the ONKeyDown (of the CFormView i did like this

    void CMy01View::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
    {
    this->cd2.OnKeyDown(nChar, nRepCnt, nFlags);
    }

    and here the one of the CTest Class

    void CTest::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
    {

    MessageBox("Blood 2");
    CEdit::OnKeyDown(nChar, nRepCnt, nFlags);
    

    }

    All go right but when i run it nothing will happen ?? how could i fix it ?? Thnk you

    "The Ultimate Limit Is Only Your Imagination."

    A G 2 Replies Last reply
    0
    • S Schehaider_Aymen

      Hello all, i know it's a newbie question but i couldn't find a replic or a sample code for such stuf. I have a CFormView Class and a CTest Class Derived CEdit Class. on both of them i have the OnKeyDown function, but what i want to do is to call the OnKeyDown fucnt of the deriver CEdit Class from the first one.. I declared a var with CTest var on the CFormView class and in the ONKeyDown (of the CFormView i did like this

      void CMy01View::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
      {
      this->cd2.OnKeyDown(nChar, nRepCnt, nFlags);
      }

      and here the one of the CTest Class

      void CTest::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
      {

      MessageBox("Blood 2");
      CEdit::OnKeyDown(nChar, nRepCnt, nFlags);
      

      }

      All go right but when i run it nothing will happen ?? how could i fix it ?? Thnk you

      "The Ultimate Limit Is Only Your Imagination."

      A Offline
      A Offline
      Aescleal
      wrote on last edited by
      #2

      Did you add ON_WM_KEYDOWN to your CEdit derived classes message map? Did you use DDX_Control to bind the edit control in the dialogue template to the instance of CTest in your Form View? I've just realised I didn't mention this when I suggested you implement a derived class of CEdit. Cheers, Ash PS: I know this is complicated, hang in there!

      1 Reply Last reply
      0
      • S Schehaider_Aymen

        Hello all, i know it's a newbie question but i couldn't find a replic or a sample code for such stuf. I have a CFormView Class and a CTest Class Derived CEdit Class. on both of them i have the OnKeyDown function, but what i want to do is to call the OnKeyDown fucnt of the deriver CEdit Class from the first one.. I declared a var with CTest var on the CFormView class and in the ONKeyDown (of the CFormView i did like this

        void CMy01View::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
        {
        this->cd2.OnKeyDown(nChar, nRepCnt, nFlags);
        }

        and here the one of the CTest Class

        void CTest::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
        {

        MessageBox("Blood 2");
        CEdit::OnKeyDown(nChar, nRepCnt, nFlags);
        

        }

        All go right but when i run it nothing will happen ?? how could i fix it ?? Thnk you

        "The Ultimate Limit Is Only Your Imagination."

        G Offline
        G Offline
        Garth J Lancaster
        wrote on last edited by
        #3

        Please dont remove/delete your messages once you think they have been answered - leaving them posted means someone else can read them to see if they have the same or similar problem as yours (I noticed you deleted an earlier one) 'g'

        S 1 Reply Last reply
        0
        • G Garth J Lancaster

          Please dont remove/delete your messages once you think they have been answered - leaving them posted means someone else can read them to see if they have the same or similar problem as yours (I noticed you deleted an earlier one) 'g'

          S Offline
          S Offline
          Schehaider_Aymen
          wrote on last edited by
          #4

          @ Garth: Sorry for deleting the message, i thought it was like in other forums when it's solved we may delete it to avoid the dump. @ Aescleal: I found a wasty manner to solve my prob (OnKeyDown related) which is

          void CSdiView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
          {
          // TODO: Add your message handler code here and/or call default

          if((nChar<=0x30)&& (nChar>= 0x39))
          	AfxMessageBox("Number");
          
          CFormView::OnKeyDown(nChar, nRepCnt, nFlags);
          

          }

          BOOL CSdiView::PreTranslateMessage(MSG* pMsg)
          {
          // TODO: Add your specialized code here and/or call the base class

          BOOL bHandleNow = false;
          switch (pMsg->message)
          {
          case WM\_KEYDOWN:		
          	switch (pMsg->wParam)
          	{
          	case 0x39:
          	case 0x38:
          	case 0x37:
          	case 0x36:
          	case 0x35:
          	case 0x34:
          	case 0x33:
          	case 0x32:
          	case 0x31:
          	case 0x30:
          		bHandleNow = TRUE;
          		
          		break;
          	}
          
          	if (bHandleNow)
          		OnKeyDown(pMsg->wParam, LOWORD(pMsg->lParam), HIWORD(pMsg->lParam));
          	
          	break;
          }
          		return bHandleNow;
          

          }

          but i m only able to detected Numbers and Upper Cases Letters like A-Z and no a-z (another problem but at least i was able to detetect numbers an capital letters :rolleyes:

          "The Ultimate Limit Is Only Your Imagination."

          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