A function pointer.
-
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.
-
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.
I googled "EnumDisplayMonitors" and it returned a code snippet with an example on how to use it.
-
I googled "EnumDisplayMonitors" and it returned a code snippet with an example on how to use it.
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); }
-
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); }
-
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.
Declare the function as a
static
member function. If you provide the 'this'-pointer as thedwData
parameter in the call toEnumDisplayMonitors
, 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 -
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.
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
-
Declare the function as a
static
member function. If you provide the 'this'-pointer as thedwData
parameter in the call toEnumDisplayMonitors
, 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