Please help with MFC cross-threaded window access

This is a discussion on Please help with MFC cross-threaded window access within the C++ Programming forums, part of the General Programming Boards category; Hello, I cannot figure out how to solve this one problem for my life... I have an MFC CRichEditCtrl that ...

  1. #1
    Registered User
    Join Date
    Jul 2012
    Posts
    4

    Please help with MFC cross-threaded window access

    Hello,

    I cannot figure out how to solve this one problem for my life... I have an MFC CRichEditCtrl that I would like to change the text of from another thread in my application. This thread consists of a CALLBACK function that's being used for SetWindowsHookEx. If you've done C++ Windows hooking before, you know exactly what I'm talking about.

    My instinctive reaction is to make the CRichEditCtrl be public and static (and maybe make the Dialog that it's in be static too), but obviously that hasn't worked out very well for me. I've also tried making static "access" functions and such.

    I prefer not to have some lame workaround like magically passing in a pointer to my CALLBACK function or anything. Maybe I could access properties in the Dialog by accessing the current Dialog running, from "theApp" (which is declared inside "[ProgramNameHere].cpp")?

    Yes, I've Googled this problem, looked at MSDN documentation, etc. etc. etc. If you know the answer, please give me a simple explanation of how I can access the CRichEditCtrl in my Dialog.

    Thanks you.

  2. #2
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,763
    Depending on how often you need to do that it seems like it would make sense just to join the threads first.

  3. #3
    Registered User
    Join Date
    Jul 2012
    Posts
    4
    That won't work with a Windows hook - it's required that you make a separate thread for it.

  4. #4
    Registered User
    Join Date
    Jul 2012
    Posts
    4
    I found a solution for myself. I still would like to know how cross threaded access could work for non-static variables in an MFC application though!


    For those of you with a similar problem to mine:

    My solution was to make the Windows hook CALLBACK functions be static (note: only put "static " before the function declarations in the header file - don't place them in the actual code) and to make the CRichEditCtrl static as well. Also, I had to move the CRichEditCtrl declaration outside of the header file (outside of the class), and I didn't place "[ProgramNameHere]::" before the variable names. So basically, I made CRichEditCtrl a global static variable, in normal-people talking terms.


    This website helped me a little bit:


    If anyone knows the answer to my question above (at the top of this post), please let me know!

    Thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Threaded callbacks...
    By megrez80 in forum C Programming
    Replies: 2
    Last Post: 11-29-2011, 11:56 AM
  2. Access Function in Child Window From Parent Window
    By Welder in forum Windows Programming
    Replies: 3
    Last Post: 05-20-2008, 04:06 AM
  3. Going from single-threaded to multi-threaded
    By Dino in forum C Programming
    Replies: 11
    Last Post: 03-23-2008, 02:14 PM
  4. Threaded models under VC++?
    By zopiro in forum C++ Programming
    Replies: 1
    Last Post: 05-31-2007, 12:42 AM
  5. Replies: 2
    Last Post: 07-24-2002, 12:27 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21