Author Topic: Need a fast method of copying the contents of one window to another.  (Read 1555 times)

0 Members and 1 Guest are viewing this topic.

Offline plurald

  • Newbie
  • *
  • Posts: 21

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?


Offline sapero

  • Senior Developer
  • Hero Member
  • *****
  • Posts: 1291
Re: Need a fast method of copying the contents of one window to another.
« Reply #1 on: January 22, 2011, 01:41:06 AM »
Hi plurald, check out these two subroutines: (it will not work if the source window has @NOAUTODRAW style)
Code: [Select]
$include ""

sub CopyWindow(WINDOW wTo, WINDOW wFrom)
HDC hdcTo   = GETHDC(wTo)
HDC hdcFrom = GETHDC(wFrom)
int cx = GetSystemMetrics(SM_CXSCREEN)
int cy = GetSystemMetrics(SM_CYSCREEN)

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

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


segment .data
align 4

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

dd 1,0,0,0

dd 90 ; jpg quality value, 0-100

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
« Last Edit: January 22, 2011, 02:17:18 AM by sapero »

Offline plurald

  • Newbie
  • *
  • Posts: 21
Re: Need a fast method of copying the contents of one window to another.
« Reply #2 on: January 22, 2011, 12:43:49 PM »
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?

Offline LarryMc

  • Administrator
  • Hero Member
  • *****
  • Posts: 5964
  • 'All I like is finishing'
Re: Need a fast method of copying the contents of one window to another.
« Reply #3 on: January 22, 2011, 01:09:44 PM »
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.

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