Copy text in Memory DC.
-
I am working with win32 application. I wanted to copy text using TextOut( ) in to temp DC (not original DC). then after BitBlt( ) copy temp DC in to original DC. Here is my code please correct it. case WM_PAINT: { HDC hdc; hdc= CreateCompatibleDC(NULL); TextOut( hdc,0,0, "Check Text", strlen( "Check Text" ) ); BitBlt(GetDC(hWnd), m_rect.left, m_rect.top, m_rect.right - m_rect.left, m_rect.bottom-m_rect.top,hdc, m_rect.left, m_rect.top, SRCCOPY); }
-
I am working with win32 application. I wanted to copy text using TextOut( ) in to temp DC (not original DC). then after BitBlt( ) copy temp DC in to original DC. Here is my code please correct it. case WM_PAINT: { HDC hdc; hdc= CreateCompatibleDC(NULL); TextOut( hdc,0,0, "Check Text", strlen( "Check Text" ) ); BitBlt(GetDC(hWnd), m_rect.left, m_rect.top, m_rect.right - m_rect.left, m_rect.bottom-m_rect.top,hdc, m_rect.left, m_rect.top, SRCCOPY); }
From documentation [^]:
Remarks A memory DC exists only in memory. When the memory DC is created, its display surface is exactly one monochrome pixel wide and one monochrome pixel high. Before an application can use a memory DC for drawing operations, it must select a bitmap of the correct width and height into the DC. To select a bitmap into a DC, use the CreateCompatibleBitmap function, specifying the height, width, and color organization required.
:)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
From documentation [^]:
Remarks A memory DC exists only in memory. When the memory DC is created, its display surface is exactly one monochrome pixel wide and one monochrome pixel high. Before an application can use a memory DC for drawing operations, it must select a bitmap of the correct width and height into the DC. To select a bitmap into a DC, use the CreateCompatibleBitmap function, specifying the height, width, and color organization required.
:)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]Modified code: case WM_PAINT: { HDC hdc; hdc= CreateCompatibleDC(NULL); HBITMAP hBit = CreateCompatibleBitmap( hdc,m_rect.right- m_rect.left, m_rect.bottom - m_rect.top ); SelectObject( hdc, hBit ); TextOut( hdc,0,0, "Check Text", strlen( "Check Text" ) ); BitBlt(GetDC(hWnd), m_rect.left, m_rect.top, m_rect.right - m_rect.left, m_rect.bottom-m_rect.top,hdc, m_rect.left, m_rect.top, SRCCOPY); } Still the code is not working. Thank You :)
-
Modified code: case WM_PAINT: { HDC hdc; hdc= CreateCompatibleDC(NULL); HBITMAP hBit = CreateCompatibleBitmap( hdc,m_rect.right- m_rect.left, m_rect.bottom - m_rect.top ); SelectObject( hdc, hBit ); TextOut( hdc,0,0, "Check Text", strlen( "Check Text" ) ); BitBlt(GetDC(hWnd), m_rect.left, m_rect.top, m_rect.right - m_rect.left, m_rect.bottom-m_rect.top,hdc, m_rect.left, m_rect.top, SRCCOPY); } Still the code is not working. Thank You :)
zakkas2483 wrote:
HBITMAP hBit = CreateCompatibleBitmap( hdc,m_rect.right- m_rect.left, m_rect.bottom - m_rect.top );
I would use (see, for instance, ... documentation [^] :rolleyes: ):
HDC hdcScreen = CreateDC("DISPLAY", NULL, NULL, NULL);
HBITMAP hBit = CreateCompatibleBitmap( hdcScreen,m_rect.right- m_rect.left, m_rect.bottom -
m_rect.top );
CreateCompatibleBitmap( hdcScreen, m_rect.right- m_rect.left, m_rect.bottom -
m_rect.top );(I don't know if the
CreateCompatibleBitmap( NULL, m_rect.right- m_rect.left, m_rect.bottom -
m_rect.top );'shortcut' would work). :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]