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. how to call a function from a different class?

how to call a function from a different class?

Scheduled Pinned Locked Moved C / C++ / MFC
3 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
    sowhat_82
    wrote on last edited by
    #1

    Hi all, lets say i have this function in a ReadWrite.cpp file: void CReadWriteDlg::OnButton4() { AfxMessageBox("test"); } how do i call this function from a function in a different file altogether, say, SystemTray.cpp: void CSystemTray::OnMyDeviceChange(WPARAM wParam, LPARAM lParam) { CReadWriteDlg::OnButton4(); //whats the correct syntax for this??? . . . . } any help is greatly appreciated! thanks!

    H K 2 Replies Last reply
    0
    • S sowhat_82

      Hi all, lets say i have this function in a ReadWrite.cpp file: void CReadWriteDlg::OnButton4() { AfxMessageBox("test"); } how do i call this function from a function in a different file altogether, say, SystemTray.cpp: void CSystemTray::OnMyDeviceChange(WPARAM wParam, LPARAM lParam) { CReadWriteDlg::OnButton4(); //whats the correct syntax for this??? . . . . } any help is greatly appreciated! thanks!

      H Offline
      H Offline
      Hamid Taebi
      wrote on last edited by
      #2

      Is this code helpfuls

      CMain *m_Main=(CMain*)GetParent();
      m_Main->Variable for function;


      WhiteSky


      1 Reply Last reply
      0
      • S sowhat_82

        Hi all, lets say i have this function in a ReadWrite.cpp file: void CReadWriteDlg::OnButton4() { AfxMessageBox("test"); } how do i call this function from a function in a different file altogether, say, SystemTray.cpp: void CSystemTray::OnMyDeviceChange(WPARAM wParam, LPARAM lParam) { CReadWriteDlg::OnButton4(); //whats the correct syntax for this??? . . . . } any help is greatly appreciated! thanks!

        K Offline
        K Offline
        KarstenK
        wrote on last edited by
        #3

        If you work with Dialogs then have CWnd and handles. So it is right to use PostMessage with user defined messages ( ->RegisterMessage ). PostMessage is better then SendMessage because it puts the message in the internal message queue. Read the fine MSDN. :zzz:

        Greetings from Germany

        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