March 29, 2024, 03:15:02 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Need a fast method of copying the contents of one window to another.

Started by plurald, January 21, 2011, 11:05:49 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

plurald

Hi,

I've got two regular windows (say w and w1) with standard graphic drawing in w (not 2D drawing).   At times I want to copy the contents of w to w1.  Is there a fast way to do this or do I have to resort to a routine to copy pixel by pixel (rather slow)?

Also, is there a way to write the contents of w to a JPG file?

Thanks.

sapero

Hi plurald, check out these two subroutines: (it will not work if the source window has @NOAUTODRAW style)
$include "windowssdk.inc"

sub CopyWindow(WINDOW wTo, WINDOW wFrom)
HDC hdcTo   = GETHDC(wTo)
HDC hdcFrom = GETHDC(wFrom)
int cx = GetSystemMetrics(SM_CXSCREEN)
int cy = GetSystemMetrics(SM_CYSCREEN)
BitBlt(hdcTo,0,0,cx,cy,hdcFrom,0,0,SRCCOPY)
RELEASEHDC(wTo,hdcTo,TRUE)
RELEASEHDC(wFrom,hdcFrom,FALSE)
endsub

sub SaveWindowToJpg(WINDOW w, wstring path)
declare MyEncoderParameters_jpeg
declare MyGdiplusStartupInput
declare MyImageEncoderJpeg

HINSTANCE hgdiplus = LoadLibrary("gdiplus.dll")
if (hgdiplus)
declare GDIPSTARTUP(int token byref, pointer in, pointer out),int
declare GDIPSHUTDOWN(int token),int
declare GDIPFROMBITMAP(int hbm, int hpal, pointer ppv),int
declare GDIPSAVETOFILE(pointer image, pointer filename, pointer clsidEncoder, pointer encoderParams),int
declare GDIPDISPOSE(pointer pImage),int

UINT fnGdiplusStartup = GetProcAddress(hgdiplus, "GdiplusStartup")
UINT fnGdiplusShutdown = GetProcAddress(hgdiplus, "GdiplusShutdown")
UINT fnGdipCreateBitmapFromHBITMAP = GetProcAddress(hgdiplus, "GdipCreateBitmapFromHBITMAP")
UINT fnGdipSaveImageToFile = GetProcAddress(hgdiplus, "GdipSaveImageToFile")
UINT fnGdipDisposeImage = GetProcAddress(hgdiplus, "GdipDisposeImage")

if (fnGdiplusStartup & fnGdiplusShutdown & fnGdipCreateBitmapFromHBITMAP & fnGdipSaveImageToFile & fnGdipDisposeImage)
int token
if (! !<GDIPSTARTUP>fnGdiplusStartup(token, &MyGdiplusStartupInput, 0))
WINRECT rc
HDC hdc = GETHDC(w)
HDC cdc = CreateCompatibleDC(hdc)
GetClientRect(w.hWnd, &rc)
HBITMAP hbm = SelectObject(cdc, CreateCompatibleBitmap(hdc, rc.right, rc.bottom))
BitBlt(cdc,0,0,rc.right, rc.bottom,hdc,0,0,SRCCOPY)
hbm = SelectObject(cdc, hbm)
RELEASEHDC(w,hdc,FALSE)
DeleteDC(cdc)

pointer image
if (! !<GDIPFROMBITMAP>fnGdipCreateBitmapFromHBITMAP(hbm, 0, &image))
!<GDIPSAVETOFILE>fnGdipSaveImageToFile(image, path, &MyImageEncoderJpeg, &MyEncoderParameters_jpeg)
!<GDIPDISPOSE>fnGdipDisposeImage(image)
endif
DeleteObject(hbm)

!<GDIPSHUTDOWN>fnGdiplusShutdown(token)
endif
endif
FreeLibrary(hgdiplus)
endif
endsub


_asm
segment .data
align 4

MyImageEncoderJpeg:
dd 0x557CF401
dw 0x1A04, 0x11D3
db 0x9A, 0x73, 0x0, 0x0, 0xF8, 0x1E, 0xF3, 0x2E

MyGdiplusStartupInput:
dd 1,0,0,0

g_jpgquality:
dd 90 ; jpg quality value, 0-100

MyEncoderParameters_jpeg:
dd 2
dd 0x1d5be4b5
dw 0xfa4a,0x452d
db 0x9c,0xdd,0x5d,0xb3,0x51,0x05,0xe7,0xeb
dd 1
dd 4
dd g_jpgquality

   dd 0x292266fc
dw 0xac40,0x47bf
db 0x8c,0xfc,0xa8,0x5b,0x89,0xa6,0x55,0xde
dd 0
dd 4
dd 0
segment .text
_endasm

plurald

Thanks Sapero,

Haven't used windows sdk package before.  Is there good documentation of all the calls you can make to it?  For general programming and graphics, is there a lot of useful stuff to use in it?


LarryMc

The "windows sdk package " as you call it contains no documentation.
It is simply a set of include files with declarations for functions and constants (in the IWBasic format) for using MS Windows APIs.

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library