<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Text in einem CWnd markierbar machen]]></title><description><![CDATA[<p>Hi Leute !</p>
<p>Ich hab hier ne fremde CTitleTip Klasse (die glaub ich irgendwo frei<br />
verfügbar ist im web) und möchte den Text im Titletip Fenster<br />
markierbar und kopierbar machen.</p>
<p>Aber ich hab keinen Schimmer wie man da macht, weiß jemand<br />
von Euch wie das geht ? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /></p>
<p>Falls es hilfreich ist hab ich mal die dafür wahrscheinlich<br />
wichtigstens Methoden angehängt. Eventuell reicht es schon<br />
irgendwo spezielle Flags zu setzen um den Text markierbar<br />
zu machen ? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title="=/"
      alt="😕"
    /></p>
<p>Danke für jede Hilfe !<br />
GastDC</p>
<pre><code class="language-cpp">// CTitleTip message handlers

BOOL CTitleTip::Create(CWnd * pParentWnd)
{
	ASSERT_VALID(pParentWnd);

	DWORD dwStyle = WS_BORDER | WS_POPUP; 
	DWORD dwExStyle = WS_EX_TOOLWINDOW | WS_EX_TOPMOST;
	m_pParentWnd = pParentWnd;

	return CreateEx(dwExStyle, TITLETIP_CLASSNAME, &quot;WLAN Titletip&quot;, dwStyle, 
					CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 
					NULL, NULL, NULL );
}

// Show 		 - Show the titletip if needed
// rectTitle	 - The rectangle within which the original 
//					title is constrained - in client coordinates
// lpszTitleText - The text to be displayed
// xoffset		 - Number of pixel that the text is offset from
//				   left border of the cell
void CTitleTip::Show(CRect rectTitle, LPCTSTR lpszTitleText, 
                     int xoffset /*=0*/, int nMaxChars /*=-1*/, 
					 LPRECT lpHoverRect /*=NULL*/,
					 LPLOGFONT lpLogFont /*=NULL*/)
{
	ASSERT( ::IsWindow( GetSafeHwnd() ) );

	if (rectTitle.IsRectEmpty())
		return;

	// If titletip is already displayed, don't do anything.
	if( IsWindowVisible() ) 
		return;

	m_rectHover = (lpHoverRect != NULL)? lpHoverRect : rectTitle;
	m_rectHover.right++; m_rectHover.bottom++;

	m_pParentWnd-&gt;ClientToScreen( m_rectHover );
	ScreenToClient( m_rectHover );

	// Do not display the titletip is app does not have focus
	 if( GetFocus() == NULL )	return;

	// Define the rectangle outside which the titletip will be hidden.
	// We add a buffer of one pixel around the rectangle
	m_rectTitle.top    = -1;
	m_rectTitle.left   = -xoffset-1;
	m_rectTitle.right  = rectTitle.Width()-xoffset;
	m_rectTitle.bottom = rectTitle.Height()+1;

	// Determine the width of the text
	m_pParentWnd-&gt;ClientToScreen( rectTitle );

	CClientDC dc(this);
	m_strTitle = _T(&quot;&quot;);
	// m_strTitle += _T(&quot; &quot;);
	m_strTitle += lpszTitleText; 
	m_strTitle += _T(&quot; &quot;);

	CFont font, *pOldFont = NULL;
	if (lpLogFont)
	{
		font.CreateFontIndirect(lpLogFont);
		pOldFont = dc.SelectObject( &amp;font );
	}
	else
	{
		// use same font as ctrl
		pOldFont = dc.SelectObject( m_pParentWnd-&gt;GetFont() );
	}

	CSize size = dc.GetTextExtent( m_strTitle );

	TEXTMETRIC tm;
	dc.GetTextMetrics(&amp;tm);
	size.cx += tm.tmOverhang;

	dc.SelectObject( pOldFont );

	m_rectDisplay = rectTitle;
	m_rectDisplay.left += xoffset-1;
    m_rectDisplay.top  += 2;
	m_rectDisplay.right = m_rectDisplay.left + size.cx + xoffset;
    m_rectDisplay.bottom = m_rectDisplay.top + size.cy;

	// Do not display if the text fits within available space
	//if ( m_rectDisplay.right &lt;= rectTitle.right-xoffset )
   //     return;

	// We will use avg char width to set max tooltip width
    int nMaxTooltipWidth = -1;
    if (nMaxChars &gt; 0)
    {
	    int nMaxTooltipWidth = (tm.tmAveCharWidth * nMaxChars);
		if (nMaxTooltipWidth &lt; 0)
			nMaxTooltipWidth *= -1;

	    // Rect display to be set to max chars
	    if (m_rectDisplay.Width() &gt; nMaxTooltipWidth)
            m_rectDisplay.right = m_rectDisplay.left + nMaxTooltipWidth;
	}

    //***************************************************************************************
    //Adjust the dimensions of the rect to fit within the client

    // Get the coordinates of the parents client area. (In this case the ListView's client
    // area) and convert coordinates to those of the tooltip.
    CRect rectClient;
    m_pParentWnd-&gt;GetClientRect( rectClient );
    m_pParentWnd-&gt;ClientToScreen( rectClient );

	// ------------------------------------------------------------------------------
	// Use the screen's right edge as the right hand border, not the right edge of the client.
	// You can comment this out to use the right client as the border.
	CWindowDC wdc(NULL);
	rectClient.right = GetDeviceCaps(wdc, HORZRES) - 8;
	rectClient.bottom = GetDeviceCaps(wdc, VERTRES) - 8;
	//---------------------------------------------------------------------------------------

    //If the right edge exceeds the right edge of the client:
    //          see how much room there is to move the display to the left and adjust the
    //          rectangle that far to the left. If the rect still exceeds the right edge, clip
    //          the right edge to match the client right edge.
    //
    // Does the right display edge exceed the right client edge?
    if (m_rectDisplay.right &gt; rectClient.right)
    {
        // establish what is available left shift wise and what is needed
        int nAvail = 0;
        int nNeeded = m_rectDisplay.right - rectClient.right;

        if (m_rectDisplay.left &gt; rectClient.left)
            nAvail = m_rectDisplay.left - rectClient.left;

        // is there room to move left?
        if (nAvail &gt;= nNeeded)
        {
            m_rectDisplay.OffsetRect(-nNeeded,0);  // yes, move all that is needed
            // increase the size of the window that will be inspected to see if the 
            // cursor has gone outside of the tooltip area by the number of units we
            // offset our display rect.
            m_rectTitle.right += nNeeded;
        }
        else
        {
            m_rectDisplay.OffsetRect(-nAvail,0);   // no, at least move to left edge of client
            // increase the size of the window that will be inspected to see if the 
            // cursor has gone outside of the tooltip area by the number of units we
            // offset our display rect.
            m_rectTitle.right += nAvail;
        }

        // Did we move enough? If not, clip right edge to match client right edge
        if (m_rectDisplay.right &gt; rectClient.right)
            m_rectDisplay.right = rectClient.right;
    }

    //If the left edge exceeds the left edge of the client:
    //          see how much room there is to move the display to the right and adjust the
    //          rectangle that far to the right. If the rect still exceeds the left edge, clip
    //          the left edge to match the client left edge.
    //
    // Does the left display edge exceed the left client edge?
    if (m_rectDisplay.left &lt; rectClient.left)
    {
        // establish what is available right shift wise and what is needed
        int nAvail = 0;
        int nNeeded = rectClient.left - m_rectDisplay.left;

        if (m_rectDisplay.right &lt; rectClient.right)
            nAvail = rectClient.right - m_rectDisplay.right;

        // is there room to move left?
        if (nAvail &gt;= nNeeded)
        {
            m_rectDisplay.OffsetRect(+nNeeded,0);  // yes, move all that is needed
            // increase the size of the window that will be inspected to see if the 
            // cursor has gone outside of the tooltip area by the number of units we
            // offset our display rect.
            m_rectTitle.left -= nNeeded;
        }
        else
        {
            m_rectDisplay.OffsetRect(+nAvail,0);   // no, at least move to left edge of client
            // increase the size of the window that will be inspected to see if the 
            // cursor has gone outside of the tooltip area by the number of units we
            // offset our display rect.
            m_rectTitle.left -= nAvail;
        }

        // Did we move enough? If not, clip left edge to match client left edge
        if (m_rectDisplay.left &lt; rectClient.left)
            m_rectDisplay.left = rectClient.left;        
    }

	// if the calculated width &gt; maxwidth set above then truncate 
    if (nMaxTooltipWidth &gt; 0 &amp;&amp; m_rectDisplay.Width() &gt; nMaxTooltipWidth)
        m_rectDisplay.right = m_rectDisplay.left + nMaxTooltipWidth;

    //***************************************************************************************

    // Use a &quot;work&quot; rect to calculate the bottom. This work rect will be inset 
    // slightly from the rect we have just created so the tooltip does not touch
    // the sides.
    CRect rectCalc = m_rectDisplay;

    rectCalc.top += 1;

    /*int nHeight = dc.DrawText(m_strTitle,&amp;rectCalc,0 
        | DT_CALCRECT
        | DT_LEFT
        | DT_NOCLIP
        | DT_EDITCONTROL
        | DT_NOPREFIX
        | DT_WORDBREAK
        );*/

    if (lpLogFont)
        pOldFont = dc.SelectObject( &amp;font );
    else
        pOldFont = dc.SelectObject( m_pParentWnd-&gt;GetFont() );

    int nHeight = dc.DrawText(m_strTitle,&amp;rectCalc,0
        | DT_CALCRECT
        | DT_LEFT
        | DT_NOCLIP
        | DT_EDITCONTROL
        | DT_NOPREFIX
        | DT_WORDBREAK
        );

    pOldFont = dc.SelectObject( pOldFont );

	// If this is a single line, shorten the display to get rid of any excess blank space
	if (nHeight == tm.tmHeight)
		rectCalc.right = rectCalc.left + size.cx + 3;

    m_rectDisplay.bottom = m_rectDisplay.top + nHeight;

	// ensure the tooltip does not exceed the bottom of the screen
	if (m_rectDisplay.bottom &gt; rectClient.bottom)
    {
		m_rectDisplay.bottom = rectClient.bottom;
        rectCalc.bottom = rectClient.bottom; 
    }

	SetWindowPos( &amp;wndTop, 
        m_rectDisplay.left-3, 
        m_rectDisplay.top-1, 
		m_rectDisplay.Width()+3, 
        m_rectDisplay.Height(),
		SWP_SHOWWINDOW|SWP_NOACTIVATE );
    SetCapture();
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/150433/text-in-einem-cwnd-markierbar-machen</link><generator>RSS for Node</generator><lastBuildDate>Wed, 22 Jul 2026 10:58:45 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/150433.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 16 Jun 2006 12:56:58 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Text in einem CWnd markierbar machen on Fri, 16 Jun 2006 12:56:58 GMT]]></title><description><![CDATA[<p>Hi Leute !</p>
<p>Ich hab hier ne fremde CTitleTip Klasse (die glaub ich irgendwo frei<br />
verfügbar ist im web) und möchte den Text im Titletip Fenster<br />
markierbar und kopierbar machen.</p>
<p>Aber ich hab keinen Schimmer wie man da macht, weiß jemand<br />
von Euch wie das geht ? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /></p>
<p>Falls es hilfreich ist hab ich mal die dafür wahrscheinlich<br />
wichtigstens Methoden angehängt. Eventuell reicht es schon<br />
irgendwo spezielle Flags zu setzen um den Text markierbar<br />
zu machen ? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title="=/"
      alt="😕"
    /></p>
<p>Danke für jede Hilfe !<br />
GastDC</p>
<pre><code class="language-cpp">// CTitleTip message handlers

BOOL CTitleTip::Create(CWnd * pParentWnd)
{
	ASSERT_VALID(pParentWnd);

	DWORD dwStyle = WS_BORDER | WS_POPUP; 
	DWORD dwExStyle = WS_EX_TOOLWINDOW | WS_EX_TOPMOST;
	m_pParentWnd = pParentWnd;

	return CreateEx(dwExStyle, TITLETIP_CLASSNAME, &quot;WLAN Titletip&quot;, dwStyle, 
					CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 
					NULL, NULL, NULL );
}

// Show 		 - Show the titletip if needed
// rectTitle	 - The rectangle within which the original 
//					title is constrained - in client coordinates
// lpszTitleText - The text to be displayed
// xoffset		 - Number of pixel that the text is offset from
//				   left border of the cell
void CTitleTip::Show(CRect rectTitle, LPCTSTR lpszTitleText, 
                     int xoffset /*=0*/, int nMaxChars /*=-1*/, 
					 LPRECT lpHoverRect /*=NULL*/,
					 LPLOGFONT lpLogFont /*=NULL*/)
{
	ASSERT( ::IsWindow( GetSafeHwnd() ) );

	if (rectTitle.IsRectEmpty())
		return;

	// If titletip is already displayed, don't do anything.
	if( IsWindowVisible() ) 
		return;

	m_rectHover = (lpHoverRect != NULL)? lpHoverRect : rectTitle;
	m_rectHover.right++; m_rectHover.bottom++;

	m_pParentWnd-&gt;ClientToScreen( m_rectHover );
	ScreenToClient( m_rectHover );

	// Do not display the titletip is app does not have focus
	 if( GetFocus() == NULL )	return;

	// Define the rectangle outside which the titletip will be hidden.
	// We add a buffer of one pixel around the rectangle
	m_rectTitle.top    = -1;
	m_rectTitle.left   = -xoffset-1;
	m_rectTitle.right  = rectTitle.Width()-xoffset;
	m_rectTitle.bottom = rectTitle.Height()+1;

	// Determine the width of the text
	m_pParentWnd-&gt;ClientToScreen( rectTitle );

	CClientDC dc(this);
	m_strTitle = _T(&quot;&quot;);
	// m_strTitle += _T(&quot; &quot;);
	m_strTitle += lpszTitleText; 
	m_strTitle += _T(&quot; &quot;);

	CFont font, *pOldFont = NULL;
	if (lpLogFont)
	{
		font.CreateFontIndirect(lpLogFont);
		pOldFont = dc.SelectObject( &amp;font );
	}
	else
	{
		// use same font as ctrl
		pOldFont = dc.SelectObject( m_pParentWnd-&gt;GetFont() );
	}

	CSize size = dc.GetTextExtent( m_strTitle );

	TEXTMETRIC tm;
	dc.GetTextMetrics(&amp;tm);
	size.cx += tm.tmOverhang;

	dc.SelectObject( pOldFont );

	m_rectDisplay = rectTitle;
	m_rectDisplay.left += xoffset-1;
    m_rectDisplay.top  += 2;
	m_rectDisplay.right = m_rectDisplay.left + size.cx + xoffset;
    m_rectDisplay.bottom = m_rectDisplay.top + size.cy;

	// Do not display if the text fits within available space
	//if ( m_rectDisplay.right &lt;= rectTitle.right-xoffset )
   //     return;

	// We will use avg char width to set max tooltip width
    int nMaxTooltipWidth = -1;
    if (nMaxChars &gt; 0)
    {
	    int nMaxTooltipWidth = (tm.tmAveCharWidth * nMaxChars);
		if (nMaxTooltipWidth &lt; 0)
			nMaxTooltipWidth *= -1;

	    // Rect display to be set to max chars
	    if (m_rectDisplay.Width() &gt; nMaxTooltipWidth)
            m_rectDisplay.right = m_rectDisplay.left + nMaxTooltipWidth;
	}

    //***************************************************************************************
    //Adjust the dimensions of the rect to fit within the client

    // Get the coordinates of the parents client area. (In this case the ListView's client
    // area) and convert coordinates to those of the tooltip.
    CRect rectClient;
    m_pParentWnd-&gt;GetClientRect( rectClient );
    m_pParentWnd-&gt;ClientToScreen( rectClient );

	// ------------------------------------------------------------------------------
	// Use the screen's right edge as the right hand border, not the right edge of the client.
	// You can comment this out to use the right client as the border.
	CWindowDC wdc(NULL);
	rectClient.right = GetDeviceCaps(wdc, HORZRES) - 8;
	rectClient.bottom = GetDeviceCaps(wdc, VERTRES) - 8;
	//---------------------------------------------------------------------------------------

    //If the right edge exceeds the right edge of the client:
    //          see how much room there is to move the display to the left and adjust the
    //          rectangle that far to the left. If the rect still exceeds the right edge, clip
    //          the right edge to match the client right edge.
    //
    // Does the right display edge exceed the right client edge?
    if (m_rectDisplay.right &gt; rectClient.right)
    {
        // establish what is available left shift wise and what is needed
        int nAvail = 0;
        int nNeeded = m_rectDisplay.right - rectClient.right;

        if (m_rectDisplay.left &gt; rectClient.left)
            nAvail = m_rectDisplay.left - rectClient.left;

        // is there room to move left?
        if (nAvail &gt;= nNeeded)
        {
            m_rectDisplay.OffsetRect(-nNeeded,0);  // yes, move all that is needed
            // increase the size of the window that will be inspected to see if the 
            // cursor has gone outside of the tooltip area by the number of units we
            // offset our display rect.
            m_rectTitle.right += nNeeded;
        }
        else
        {
            m_rectDisplay.OffsetRect(-nAvail,0);   // no, at least move to left edge of client
            // increase the size of the window that will be inspected to see if the 
            // cursor has gone outside of the tooltip area by the number of units we
            // offset our display rect.
            m_rectTitle.right += nAvail;
        }

        // Did we move enough? If not, clip right edge to match client right edge
        if (m_rectDisplay.right &gt; rectClient.right)
            m_rectDisplay.right = rectClient.right;
    }

    //If the left edge exceeds the left edge of the client:
    //          see how much room there is to move the display to the right and adjust the
    //          rectangle that far to the right. If the rect still exceeds the left edge, clip
    //          the left edge to match the client left edge.
    //
    // Does the left display edge exceed the left client edge?
    if (m_rectDisplay.left &lt; rectClient.left)
    {
        // establish what is available right shift wise and what is needed
        int nAvail = 0;
        int nNeeded = rectClient.left - m_rectDisplay.left;

        if (m_rectDisplay.right &lt; rectClient.right)
            nAvail = rectClient.right - m_rectDisplay.right;

        // is there room to move left?
        if (nAvail &gt;= nNeeded)
        {
            m_rectDisplay.OffsetRect(+nNeeded,0);  // yes, move all that is needed
            // increase the size of the window that will be inspected to see if the 
            // cursor has gone outside of the tooltip area by the number of units we
            // offset our display rect.
            m_rectTitle.left -= nNeeded;
        }
        else
        {
            m_rectDisplay.OffsetRect(+nAvail,0);   // no, at least move to left edge of client
            // increase the size of the window that will be inspected to see if the 
            // cursor has gone outside of the tooltip area by the number of units we
            // offset our display rect.
            m_rectTitle.left -= nAvail;
        }

        // Did we move enough? If not, clip left edge to match client left edge
        if (m_rectDisplay.left &lt; rectClient.left)
            m_rectDisplay.left = rectClient.left;        
    }

	// if the calculated width &gt; maxwidth set above then truncate 
    if (nMaxTooltipWidth &gt; 0 &amp;&amp; m_rectDisplay.Width() &gt; nMaxTooltipWidth)
        m_rectDisplay.right = m_rectDisplay.left + nMaxTooltipWidth;

    //***************************************************************************************

    // Use a &quot;work&quot; rect to calculate the bottom. This work rect will be inset 
    // slightly from the rect we have just created so the tooltip does not touch
    // the sides.
    CRect rectCalc = m_rectDisplay;

    rectCalc.top += 1;

    /*int nHeight = dc.DrawText(m_strTitle,&amp;rectCalc,0 
        | DT_CALCRECT
        | DT_LEFT
        | DT_NOCLIP
        | DT_EDITCONTROL
        | DT_NOPREFIX
        | DT_WORDBREAK
        );*/

    if (lpLogFont)
        pOldFont = dc.SelectObject( &amp;font );
    else
        pOldFont = dc.SelectObject( m_pParentWnd-&gt;GetFont() );

    int nHeight = dc.DrawText(m_strTitle,&amp;rectCalc,0
        | DT_CALCRECT
        | DT_LEFT
        | DT_NOCLIP
        | DT_EDITCONTROL
        | DT_NOPREFIX
        | DT_WORDBREAK
        );

    pOldFont = dc.SelectObject( pOldFont );

	// If this is a single line, shorten the display to get rid of any excess blank space
	if (nHeight == tm.tmHeight)
		rectCalc.right = rectCalc.left + size.cx + 3;

    m_rectDisplay.bottom = m_rectDisplay.top + nHeight;

	// ensure the tooltip does not exceed the bottom of the screen
	if (m_rectDisplay.bottom &gt; rectClient.bottom)
    {
		m_rectDisplay.bottom = rectClient.bottom;
        rectCalc.bottom = rectClient.bottom; 
    }

	SetWindowPos( &amp;wndTop, 
        m_rectDisplay.left-3, 
        m_rectDisplay.top-1, 
		m_rectDisplay.Width()+3, 
        m_rectDisplay.Height(),
		SWP_SHOWWINDOW|SWP_NOACTIVATE );
    SetCapture();
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1078877</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1078877</guid><dc:creator><![CDATA[GastDC]]></dc:creator><pubDate>Fri, 16 Jun 2006 12:56:58 GMT</pubDate></item><item><title><![CDATA[Reply to Text in einem CWnd markierbar machen on Fri, 16 Jun 2006 17:34:57 GMT]]></title><description><![CDATA[<p>Der einfachste Trick der Welt ist es hier ein CEdit Control zu verwenden, dazu einfach das ganze auf Readonly setzen und dau WS_BORDER entfernen. Das ganze bleibt markierbar und wird inkl. Kontextmenü+Hotkeys geliefert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1079100</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1079100</guid><dc:creator><![CDATA[Martin Richter]]></dc:creator><pubDate>Fri, 16 Jun 2006 17:34:57 GMT</pubDate></item></channel></rss>