INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

API Functions

How to copy an active form and paste into a Word document by mgagnon
Posted: 23 Sep 03

The following will copy the content of an active form into the clipborad and paste it into a Word document. It could also be used to copy and translate into a bitmap.

LOCAL oWord as word.application
#DEFINE CF_BITMAP   2    
#DEFINE SRCCOPY     13369376
DO copyActiveWindow
PRIVATE hwnd, lnLeft, lnTop, lnRight, lnBottom, lnWidth,
lnHeight
hwnd = GetFocus()
STORE 0 TO lnLeft, lnTop, lnRight, lnBottom, lnWidth,
lnHeight
= getRect (@lnLeft, @lnTop, @lnRight, @lnBottom, @lnWidth,
@lnHeight)
hdc = GetWindowDC (hwnd)  
hVdc = CreateCompatibleDC (hdc)
hBitmap = CreateCompatibleBitmap (hdc, lnWidth, lnHeight)
= SelectObject (hVdc, hBitmap)  
= BitBlt (hVdc, 0,0, lnWidth,lnHeight, hdc, 0,0, SRCCOPY)
= OpenClipboard (hwnd)
= EmptyClipboard()
= SetClipboardData (CF_BITMAP, hBitmap)
= CloseClipboard()  
= DeleteObject (hBitmap)
= DeleteDC (hVdc)
= ReleaseDC (hwnd, hdc)
oWord=CREATEOBJECT("word.application")
oWord.Documents.Add()
loSelection=oword.Selection
loselection.PasteAndFormat(2)
oword.Visible =.t.
RETURN        

PROCEDURE  copyActiveWindow   
    DECLARE INTEGER GetWindowRect IN user32 INTEGER
hwnd, STRING @ lpRect
    DECLARE INTEGER SelectObject IN gdi32 INTEGER hdc,
INTEGER hObject
    DECLARE INTEGER ReleaseDC IN user32 INTEGER hwnd,
INTEGER hdc
    DECLARE INTEGER CreateCompatibleDC IN gdi32
INTEGER hdc
    DECLARE INTEGER DeleteObject IN gdi32 INTEGER
hObject
    DECLARE INTEGER DeleteDC IN gdi32 INTEGER hdc
    DECLARE INTEGER CloseClipboard IN user32
    DECLARE INTEGER GetFocus IN user32
    DECLARE INTEGER EmptyClipboard  IN user32
    DECLARE INTEGER GetWindowDC IN user32 INTEGER hwnd
    DECLARE INTEGER OpenClipboard IN user32 INTEGER
hwnd
    DECLARE INTEGER SetClipboardData IN user32 INTEGER
wFormat, INTEGER hMem

    DECLARE INTEGER CreateCompatibleBitmap IN gdi32;
        INTEGER hdc, INTEGER nWidth, INTEGER
nHeight

    DECLARE INTEGER BitBlt IN gdi32;
        INTEGER hDestDC, INTEGER x, INTEGER y,;
        INTEGER nWidth, INTEGER nHeight, INTEGER
hSrcDC,;
        INTEGER xSrc, INTEGER ySrc, INTEGER dwRop
RETURN        
PROCEDURE  getRect(lnLeft, lnTop, lnRight, lnBottom,
lnWidth, lnHeight)
    LOCAL lpRect
    lpRect = Repli(Chr(0), 16)  
    = GetWindowRect (hwnd, @lpRect)  
    lnLeft   = buf2dword(SUBSTR(lpRect,  1,4))  
    lnTop    = buf2dword(SUBSTR(lpRect,  5,4))  
    lnRight  = buf2dword(SUBSTR(lpRect,  9,4))  
    lnBottom = buf2dword(SUBSTR(lpRect, 13,4))  
    lnWidth  = lnRight - lnLeft
    lnHeight = lnBottom - lnTop
RETURN
FUNCTION  buf2dword (lcBuffer)
RETURN Asc(SUBSTR(lcBuffer, 1,1)) + ;
    Asc(SUBSTR(lcBuffer, 2,1)) * 256 +;
    Asc(SUBSTR(lcBuffer, 3,1)) * 65536 +;
    Asc(SUBSTR(lcBuffer, 4,1)) * 16777216


Parts of this code was borrowed http://www.news2news.com/vfp/

Mike Gagnon

Back to Microsoft: Visual FoxPro FAQ Index
Back to Microsoft: Visual FoxPro Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close