Why private DC does not retain attributes across threads ?

Why private DC does not retain attributes across threads ?

Post by Radek Tomi » Tue, 11 Sep 2001 23:12:14



Hello,

GetDC manual page:

" Remarks:
"
"   For class and private DCs, GetDC leaves the previously assigned
"   attributes unchanged.

This is not true (at least on W2k SP2 English) when the DC is
retrieved/set from different threads.

For example, one thread retrieves DC ('GetDC()') from window with
'CS_OWNDC' class style set and then set a font for this DC
('SelectObject()'). Then, different thread retrieves the DC ('GetDC()')
from the same window and outputs text ('TextOut()'). The text is
output using default font, not the font set by the first thread.
The values of DC handles retrieved by these two threads are different.
These two DC handle values are same if they are retrieved from the same
thread. The difference is probably due to the following info
from 'Remarks' section of 'GetDC' manual page:

" Note that the handle to the DC can only be used by a single thread
" at any one time.

but why should two different private DC handle values, that refer to the
same window, have different set of attributes (cited remark above) ?

Am I missing something or is this just an incorrect documentation or bug ?

Thanks for your thoughts.

--
Radek Tomis

Help stop world hunger -- visit <http://www.thehungersite.org>
Is The Hunger Site real? <http://www.umich.edu/~virus-busters/hunger.html>

 
 
 

Why private DC does not retain attributes across threads ?

Post by Radek Tomi » Tue, 11 Sep 2001 23:18:25



> GetDC manual page:

> " Remarks:
> "
> "   For class and private DCs, GetDC leaves the previously assigned
> "   attributes unchanged.

> This is not true (at least on W2k SP2 English) when the DC is
> retrieved/set from different threads.

> For example, one thread retrieves DC ('GetDC()') from window with
> 'CS_OWNDC' class style set and then set a font for this DC
> ('SelectObject()'). Then, different thread retrieves the DC ('GetDC()')
> from the same window and outputs text ('TextOut()'). The text is
> output using default font, not the font set by the first thread.

I forgot to explicitly mention that if I save the DC handle value retrieved
from the first thread in a global variable and then use it from the second
thread, the text is output using the font set in first thread, which is
okay.

 
 
 

1. private member is not private ? why

Hello, there,

I wrote a matrix class (a two dimension array). It compiles and runs ( on
Visual C 5). But I find something strange in my copy constructor.

m_nRows and m_nCols are private members, how come I can directly access them
in copy constructor as m.m_nRows, m.m_nCols and m.m_TPtr without getting any
compiler error.

I believe that it is C++ thing rather than VC5 one. I would be grateful if
anyone can help.

Many thanks.

J. Zhou

ps: although I am a regular reader of these news groups, the colleage only
keeps news for two days.  Could you be so kind to send me a copy of your

----------------------------------------------------------------------------
------------------------------------------
in matrix.h I have:

template< class T >
class CMatrix
{
     unsigned m_nRows, m_nCols;
     unsigned m_nNumElements;
     T *m_TPtr;

public:
     CMatrix(unsigned nRow=1, unsigned nCol=1);
     CMatrix(const CMatrix<T> & m);           // copy constructor
     virtual ~CMatrix() { delete[] m_TPtr; }

    ....

in matrix.cpp I have a copy constructor:

template<class T>
CMatrix<T>::CMatrix(const CMatrix<T>& m)
    :m_nRows(m.m_nRows),m_nCols(m.m_nCols)        // NOTE: direct access to
m.m_nRows & m.m_nCols

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
{
     m_nNumElements = m_nRows*m_nCols;
     m_TPtr = new T[m_nNumElements];
     memcpy(m_TPtr, m.m_TPtr, m_nNumElements*sizeof(T));  // NOTE: direct
access to m.m_TPtr

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
template class CMatrix<int>;
----------------------------------------------------------------------------
------------------------------------------------


      [ about comp.lang.c++.moderated. First time posters: do this! ]

2. Oregon launches palm-sized mobile computer

3. retain or not retain on init?

4. Batteries for C140?

5. Help!! Retaining Device Context Attributes

6. Opening a specific document

7. Why replace original DC objects after changing the DC ?

8. Award Winning Software Engineering Web Site

9. Using New and Delete across processes (not threads)

10. What? private is not private anymore??

11. constant initializers for members ... why not, why not

12. Printer DC's and Enhanced Metafile DC's and Memory DC's

13. DC across processes in Win2k