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. A function pointer.

A function pointer.

Scheduled Pinned Locked Moved C / C++ / MFC
help
7 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.
  • D Offline
    D Offline
    daavena
    wrote on last edited by
    #1

    Hi all, I want to use this function BOOL EnumDisplayMonitors( HDC hdc, // handle to display DC LPCRECT lprcClip, // clipping rectangle MONITORENUMPROC lpfnEnum, // callback function LPARAM dwData // data for callback function ); there is MONITORENUMPROC lpfnEnum this must be a pointer to my function. here is MONITORENUMPROC declaration: typedef BOOL (CALLBACK* MONITORENUMPROC)(HMONITOR, HDC, LPRECT, LPARAM); How should I call EnumDisplayMonitors with my fuction/pointer. I am really stuck. Thank you very much.

    M 1 Reply Last reply
    0
    • D daavena

      Hi all, I want to use this function BOOL EnumDisplayMonitors( HDC hdc, // handle to display DC LPCRECT lprcClip, // clipping rectangle MONITORENUMPROC lpfnEnum, // callback function LPARAM dwData // data for callback function ); there is MONITORENUMPROC lpfnEnum this must be a pointer to my function. here is MONITORENUMPROC declaration: typedef BOOL (CALLBACK* MONITORENUMPROC)(HMONITOR, HDC, LPRECT, LPARAM); How should I call EnumDisplayMonitors with my fuction/pointer. I am really stuck. Thank you very much.

      M Offline
      M Offline
      Maximilien
      wrote on last edited by
      #2

      I googled "EnumDisplayMonitors" and it returned a code snippet with an example on how to use it.

      D 1 Reply Last reply
      0
      • M Maximilien

        I googled "EnumDisplayMonitors" and it returned a code snippet with an example on how to use it.

        D Offline
        D Offline
        daavena
        wrote on last edited by
        #3

        Thanks for your reply, I can't find snippet, but I found this and it looks like it's working. Thanks BOOL CALLBACK _MyPaintEnumProc(HMONITOR hMonitor,HDC hdc,LPRECT lprcMonitor, LPARAM data){ int a = 10; return TRUE; } int main(int argc, char* argv[]) { MONITORENUMPROC lpfnEnum = _MyPaintEnumProc; EnumDisplayMonitors(NULL,NULL, lpfnEnum, 0); }

        D 1 Reply Last reply
        0
        • D daavena

          Thanks for your reply, I can't find snippet, but I found this and it looks like it's working. Thanks BOOL CALLBACK _MyPaintEnumProc(HMONITOR hMonitor,HDC hdc,LPRECT lprcMonitor, LPARAM data){ int a = 10; return TRUE; } int main(int argc, char* argv[]) { MONITORENUMPROC lpfnEnum = _MyPaintEnumProc; EnumDisplayMonitors(NULL,NULL, lpfnEnum, 0); }

          D Offline
          D Offline
          daavena
          wrote on last edited by
          #4

          I have found out it works only when I don't use it in a Class. Could someone help me to implement into my class? Thanks.

          R M 2 Replies Last reply
          0
          • D daavena

            I have found out it works only when I don't use it in a Class. Could someone help me to implement into my class? Thanks.

            R Offline
            R Offline
            Roger Stoltz
            wrote on last edited by
            #5

            Declare the function as a static member function. If you provide the 'this'-pointer as the dwData parameter in the call to EnumDisplayMonitors, you can type cast it into a pointer of your class to get the correct instance of your class when the static function is called.

            "It's supposed to be hard, otherwise anybody could do it!" - selfquote
            "High speed never compensates for wrong direction!" - unknown

            D 1 Reply Last reply
            0
            • D daavena

              I have found out it works only when I don't use it in a Class. Could someone help me to implement into my class? Thanks.

              M Offline
              M Offline
              Michael Dunn
              wrote on last edited by
              #6

              From the C++ FAQ Lite: [33.2] How do I pass a pointer-to-member-function to a signal handler, X event callback, system call that starts a thread/task, etc?[^]

              --Mike-- Visual C++ MVP :cool: LINKS~! CP SearchBar v3.0 | C++ Forum FAQ I work for Keyser Söze

              1 Reply Last reply
              0
              • R Roger Stoltz

                Declare the function as a static member function. If you provide the 'this'-pointer as the dwData parameter in the call to EnumDisplayMonitors, you can type cast it into a pointer of your class to get the correct instance of your class when the static function is called.

                "It's supposed to be hard, otherwise anybody could do it!" - selfquote
                "High speed never compensates for wrong direction!" - unknown

                D Offline
                D Offline
                daavena
                wrote on last edited by
                #7

                It's working. Thank you.

                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