mfc >> one handle multiple threads

by Torsten Curdt » Tue, 02 Dec 2003 22:42:55 GMT

Is it ok to open a handle (e.g. file) in one
thread and then use it in another thread
as long as access is synchronized (e.g. through
a mutex)?


mfc >> one handle multiple threads

by Doug Harrison [MVP] » Wed, 03 Dec 2003 02:15:27 GMT






In general, yes. Windows HANDLEs are associated with the process, not the
thread.

--
Doug Harrison
Microsoft MVP - Visual C++



mfc >> one handle multiple threads

by xmontyx » Wed, 03 Dec 2003 14:56:48 GMT

Yes



Similar Threads

1. Most efficient way to process thousands of files using multiple threads (dealing with thread handling)

2. One ManualResetEvent, multiple threads waiting - CSharp/C#

3. one processor with multiple core and threads

Hi!

If you have a computer with one processor and multiple core and you lock a 
section is it then possible
that two threads can lock this section simultaneously.
 I mean when you have one processor with multiple core you can have two 
threads executing simultaneously so
this would be possible.
What would happen you can't have two threads own the lock to a section of 
code at the same time.

//Tony


4. One DDE connection for multiple threads?

5. How i can receive thread handle from ID one

6. Exception Handling in Multiple Threads

7. Handle messages of one CWindow in another one

I have the following situation: I have a background window that is
using UpdateLayeredWindowAttributes to give it an alpha-blended shape.
Since you cannot have standard Windows controls on such window (paint
messages are not sent) I have placed another window with a color-keyed
background (SetLayeredAttributes) on top of this background window
that contains the controls. Since the windows do not have a title bar
I have this trick in the background window:
 UINT OnNcHitTest(WTL::CPoint point) {
    if (draggable) {
      LRESULT result = CallWindowProc();
      if (result == HTCLIENT) {
        return HTCAPTION;
      }
    }
    SetMsgHandled(false);
    return 0;
  }

This allows me to move the background window. But of course it does
not move the accompanied control window, sitting on top of the
background window. Currently I hold a reference in the background
window to the control window and move the control window inside a
void OnWindowPosChanging(LPWINDOWPOS windowPos) {
  if (controlWindow.IsWindow()) {
        ATLVERIFY(controlWindow.SetWindowPos(0, windowPos->x,
windowPos->y, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER |
SWP_NOREDRAW));
      }
}

Now I would like to handle all the messages of the background window
in the control window. I tried to host the background window inside my
control window using CContainedWindowT but it only caused access
violations on start of the app.

Is there a way to handle the background windows messages in my control
window in any way?

Thanks for any help!
Phil

8. Multiple processes vs multiple threads with SMP under XP