Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

Copy part of the screen to clipboard

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Copy part of the screen to clipboard

    Today we discussed a question how to copy own-drawn picture to clipboard (for PaintBrush, Word and so on).
    Bellow you can find more than simple solution (I found this solution on one of VB site).
    You can type any text, then press "Copy to clipboard", switch to Word/Paintbrush and press Ctrl-V.
    Code:
       #Compile Exe
       #Register None
       #Dim All
       #Include "Win32Api.Inc"
       Global hDlg As Long
       Sub CopyPicture(hWnd As Long)
          Static hBmpClip As Long      
          Dim hDC As Long, hDC1 As Long, hBmp As Long, rc As Rect, hBmpOld As Long
          hDC = GetDC(hWnd)
          hDC1 = CreateCompatibleDC(hDC)
          GetClientRect hWnd, rc
          hBmp = CreateCompatibleBitMap (hDC, rc.nRight, rc.nBottom)
          hBmpOld = SelectObject (hDc1, hBmp)
          BitBlt hDC1, 0, 0, rc.nRight, rc.nBottom, hDC, 0, 0, %SRCCOPY
          SelectObject hDC1, hBmpOld
          OpenClipboard ByVal 0
          EmptyClipboard
          If hBmpClip > 0 Then DeleteObject hBmpClip
          SetClipboardData %CF_BITMAP, hBMP
          CloseClipboard
          DeleteObject hDC1
          hBmpClip = hBmp
          ReleaseDC hWnd, hDC
       End Sub
    
       CallBack Function ButProc
          CopyPicture hDlg
       End Function
    
       Function PbMain () As Long
          Dialog New 0, "Polus", ,, 200, 70, %WS_SYSMENU  To hDlg
          Control Add TextBox, hDlg, 101, "", 5, 5, 190, 12
          Control Add Button, hDlg, 102, "Copy client area", 30, 30, 140, 15  Call ButProc
          Dialog Show Modal hDlg
       End Function
    [This message has been edited by Semen Matusovski (edited May 04, 2000).]
Working...
X