Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Copy text in Memory DC.

Copy text in Memory DC.

Scheduled Pinned Locked Moved C / C++ / MFC
performance
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    zakkas2483
    wrote on last edited by
    #1

    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); }

    CPalliniC 1 Reply Last reply
    0
    • Z zakkas2483

      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); }

      CPalliniC Offline
      CPalliniC Offline
      CPallini
      wrote on last edited by
      #2

      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]

      In testa che avete, signor di Ceprano?

      Z 1 Reply Last reply
      0
      • CPalliniC CPallini

        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]

        Z Offline
        Z Offline
        zakkas2483
        wrote on last edited by
        #3

        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 :)

        CPalliniC 1 Reply Last reply
        0
        • Z zakkas2483

          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 :)

          CPalliniC Offline
          CPalliniC Offline
          CPallini
          wrote on last edited by
          #4

          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]

          In testa che avete, signor di Ceprano?

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups