Part 1. PrintWindow and Qweerdy's pngskins
------------------------------------------------------

Bad news: it seems to me PrintWindow breaks wonderful Qweerdy's pngskins

http://chime.student.utwente.nl/qweerdy/ppa.zip
http://chime.student.utwente.nl/qweerdy/pngskin.zip
http://chime.student.utwente.nl/qweerdy/pngskin3.zip
http://chime.student.utwente.nl/qweerdy/pngskin4.zip
http://chime.student.utwente.nl/qweerdy/pngskin5.zip
http://chime.student.utwente.nl/qweerdy/scrollblend.zip
also search forum.

Compile this code (window snapshot):

.386
.model flat,stdcall
option casemap:none

include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\gdi32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\gdi32.lib

.data
_PrintWindow db "PrintWindow",0
_user32 db "user32",0

.data?
point POINT <>
rect RECT <>
hwnd HWND ?
hdc HDC ?
hdcmem HDC ?
hbmp HBITMAP ?
hobj dd ?

.code

start:
invoke GetCursorPos,addr point
invoke WindowFromPoint,point.x,point.y
mov hwnd,eax
; invoke MessageBox,0,offset _PrintWindow,0,40000h
invoke GetWindowRect,hwnd,addr rect
invoke GetWindowDC,hwnd
mov hdc,eax
invoke CreateCompatibleDC,hdc ; we can use hdcDesktop also.
mov hdcmem,eax
mov eax,rect.right
sub eax,rect.left
mov ecx,rect.bottom
sub ecx,rect.top
invoke CreateCompatibleBitmap,hdc,eax,ecx
mov hbmp,eax
invoke SelectObject,hdcmem,hbmp
mov hobj,eax

; invoke PrintWindow,hwnd,hdcmem,0
invoke GetModuleHandle,offset _user32
invoke GetProcAddress,eax,offset _PrintWindow
push 0
push hdcmem
push hwnd
call eax

invoke OpenClipboard,hwnd
invoke EmptyClipboard
invoke SetClipboardData,CF_BITMAP,hbmp
invoke CloseClipboard

invoke SelectObject,hdcmem,hobj
invoke DeleteDC,hdcmem
invoke DeleteObject,hbmp
invoke ReleaseDC,hwnd,hdc
invoke ExitProcess,0
end start

Make a shortcut with hotkey assignment to compiled exe,
run PngSkin or 'Per-Pixel Alpha',
place cursor over this layered window
and hit hotkey.

I'm afraid you get same dismal result...

If so - what do you think:
is my code wrong ? are the pngskins wrong ? or maybe PrintWindow isn't ideal ?

Posted on 2005-11-27 02:49:46 by kero
(use shortcut as above)

start:
invoke GetCursorPos,addr point
invoke WindowFromPoint,point.x,point.y
mov hwnd,eax
invoke GetWindowLong,hwnd,GWL_EXSTYLE
push eax
or eax,WS_EX_COMPOSITED
invoke SetWindowLong,hwnd,GWL_EXSTYLE,eax
invoke SetWindowPos,hwnd,0,0,0,0,0,SWP_NOZORDER or SWP_NOSIZE or SWP_NOMOVE or SWP_NOACTIVATE or SWP_FRAMECHANGED
invoke MessageBox,0,offset _text,0,40000h
pop eax
invoke SetWindowLong,hwnd,GWL_EXSTYLE,eax
invoke SetWindowPos,hwnd,0,0,0,0,0,SWP_NOZORDER or SWP_NOSIZE or SWP_NOMOVE or SWP_NOACTIVATE or SWP_FRAMECHANGED
invoke ExitProcess,0
end start

MSDN -> CreateWindowEx Function -> Remarks:
Windows XP:  With WS_EX_COMPOSITED set, all descendants of a window get bottom-to-top painting order using double-buffering.
Bottom-to-top painting order allows a descendent window to have translucency (alpha) and transparency (color-key) effects,
but only if the descendent window also has the WS_EX_TRANSPARENT bit set. Double-buffering allows the window and its descendents
to be painted without flicker.

But note: 1st and 2nd ways arn't equal for ScrollBlend.

Screenshots: PngSkin before and after PrintWindow or +WS_EX_COMPOSITED
Posted on 2005-11-29 11:23:09 by kero
For 'Per-Pixel Alpha':

ppa.asm -> WinMain -> wc.style
Original = CS_HREDRAW or CS_VREDRAW
Protector = CS_CLASSDC (or CS_PARENTDC).

Btw you can do it without re-compilation.
Just open original ppa.exe in hex editor and change one byte only:
find 2nd binary block '03000000' and replace it with '43000000'
(CS_HREDRAW+CS_VREDRAW=00000003h, CS_CLASSDC=00000040h).

Now try 1st and 2nd tests above... OK ?

But it is very strange, because
MSDN -> CreateWindowEx Function ->
WS_EX_LAYERED
[...] Also, this cannot be used if the window has a class style of either CS_OWNDC or CS_CLASSDC.
Attachments:
Posted on 2005-12-01 13:13:55 by kero
Here is specific window spy:  http://www.geocities.com/xmemor/2lz/printlayered.zip (with source, 16 kb).

This utility can help to get further unexpected info about different kinds of layered windows, about window printing, and more.

Current version is draft yet and has some problems, but though works. Say you'll ascertain that XP API PrintWindow can't print window
(top-level or control) if it has CS_CLASSDC or CS_PARENTDC style (for example - buttons of calc.exe). Try to find this fact in MSDN :-)

Also  this utility offers ways to print window with these styles (even covered): PrintWindow_M (based on PrintWindow, for XP)
and AlphaPrintWindow procedure (used temporary window layering, for 2k/XP).

P.S. Also this tester shows greate GDI leakage in Qweerdy's pngskins (test resizing or scrolling)...
Posted on 2006-02-05 22:07:27 by kero