· Начало · Отвђтить · Статистика · Поиск · FAQ · Правила · Установки · Язык · Выход · WASM.RU · Noir.Ru ·

 WASM Phorum —› WASM.WIN32 —› Sreen Log

Посл.отвђт Сообщенiе


Дата: Авг 14, 2004 19:25:30

Пытаюсь сделать прогу, которая делает снимок экрана. У меня есть исходник подобной вещи, но не работает. Вот что есть:
.486

.model flat, stdcall
option casemap:none

CapScreen proto :DWORD

include E:\masm32\INCLUDE\windows.inc
include E:\masm32\INCLUDE\user32.inc
include E:\masm32\INCLUDE\kernel32.inc
include E:\masm32\INCLUDE\gdi32.inc
include E:\masm32\INCLUDE\masm32.inc
include E:\masm32\INCLUDE\debug.inc
includelib E:\masm32\LIB\user32.lib
includelib E:\masm32\LIB\kernel32.lib
includelib E:\masm32\LIB\gdi32.lib
includelib E:\masm32\LIB\masm32.lib
includelib E:\masm32\LIB\debug.lib

.const
szFile		  db "my.bmp",0
szDisplay     db "DISPLAY",0
szNoDC        db "Couldn''t create device context.",0
szNoMemDC     db "Couldn''t create compatible device context.",0
szNoBMP       db "Couldn''t create compatible bitmap.",0
szNoObj       db "Couldn''t select bitmap.",0
szNoCopy      db "Couldn''t copy bitmap.",0
szNoFile      db "Couldn''t write file to disk.",0
szDone        db "Bitmap captured to disk file.",0

.code
CapScreen Proc lpFileName:DWORD
    LOCAL hdc:HDC
    LOCAL memdc:HDC
    LOCAL hFile:HANDLE
    LOCAL dwBytes:DWORD
    LOCAL bitmapfileheader:BITMAPFILEHEADER
    LOCAL bitmapinfoheader:BITMAPINFOHEADER
    LOCAL colors[2]:RGBQUAD
    LOCAL bmpinfo:BITMAPINFO
    LOCAL hBitmap:HBITMAP
    LOCAL pBits:DWORD
    LOCAL dwWidth:DWORD
    LOCAL dwHeight:DWORD
    LOCAL dwNumColors:DWORD
    LOCAL dwBPP:DWORD
    LOCAL ColorSize:DWORD
    
            invoke CreateDC, addr szDisplay, NULL, NULL, NULL
            mov hdc,eax
            .IF (eax==NULL)
                invoke MessageBox, 0, addr szNoDC, NULL, 0
                jmp ExitFunc
            .ENDIF
            invoke GetDeviceCaps, hdc, HORZRES
            mov dwWidth,eax
            invoke GetDeviceCaps, hdc, VERTRES
            mov dwHeight,eax
            invoke GetDeviceCaps, hdc, BITSPIXEL
            ;mov dwBPP,eax
            mov dwBPP, 1h
            PrintHex dwBPP
            .IF (eax<=8)
                invoke GetDeviceCaps, hdc, NUMCOLORS
                mov dwNumColors,eax
                mov dwNumColors,256	;this one looks bad
            .ELSE
                mov dwNumColors,0
            .ENDIF
            invoke CreateCompatibleDC, hdc
            mov memdc,eax
            .IF (eax==NULL)
                invoke DeleteDC, hdc
                invoke MessageBox, 0, addr szNoMemDC, NULL, 0
                jmp ExitFunc
            .ENDIF
            mov bmpinfo.bmiHeader.biSize,sizeof BITMAPINFOHEADER
            mov eax,dwWidth
            mov bmpinfo.bmiHeader.biWidth,eax
            mov eax,dwHeight
            mov bmpinfo.bmiHeader.biHeight,eax
            mov bmpinfo.bmiHeader.biPlanes,1
            mov ax,word ptr [dwBPP]
            ;mov ax, 1
            mov bmpinfo.bmiHeader.biBitCount,ax
            PrintHex bmpinfo.bmiHeader.biBitCount
            mov bmpinfo.bmiHeader.biCompression,BI_RGB
            mov bmpinfo.bmiHeader.biSizeImage,0
            mov bmpinfo.bmiHeader.biXPelsPerMeter,0
            mov bmpinfo.bmiHeader.biYPelsPerMeter,0
            mov eax,dwNumColors
            mov bmpinfo.bmiHeader.biClrUsed,eax
            PrintHex bmpinfo.bmiHeader.biClrUsed
            mov bmpinfo.bmiHeader.biClrImportant,eax
            ;invoke CreateDIBSection,hdc,addr bmpinfo, DIB_PAL_COLORS,addr pBits, NULL, 0
            invoke CreateDIBSection,hdc,addr bmpinfo, DIB_RGB_COLORS,addr pBits, NULL, 0
            mov hBitmap,eax
            .IF (eax==NULL)
                invoke DeleteDC, hdc
                invoke DeleteDC, memdc
                invoke MessageBox, 0, addr szNoBMP, NULL, 0
                jmp ExitFunc
            .ENDIF
            invoke SelectObject, memdc, hBitmap
            .IF (eax==NULL) || (eax==GDI_ERROR)
                invoke DeleteDC, hdc
                invoke DeleteDC, memdc
                invoke MessageBox, 0, addr szNoObj, NULL, 0
                jmp ExitFunc
            .ENDIF
            invoke BitBlt, memdc, 0,0, dwWidth, dwHeight, hdc, 0,0, SRCCOPY
            .IF (!eax)
                invoke DeleteDC, hdc
                invoke DeleteDC, memdc
                invoke MessageBox, 0, addr szNoCopy, NULL, 0
                jmp ExitFunc
            .ENDIF
            mov eax,dwNumColors
            .IF (eax!=0)
                invoke GetDIBColorTable, memdc, 0, dwNumColors, addr colors
                mov dwNumColors,eax
            .ENDIF
            mov bitmapfileheader.bfType,4D42h
            mov eax,dwNumColors
            xor edx,edx
            mov ecx,sizeof RGBQUAD
            mul ecx
            mov ColorSize,eax
            mov eax,dwWidth
            xor edx,edx
            mov ecx,dwHeight
            mul ecx
            xor edx,edx
            mov ecx,dwBPP
            mul ecx
            shr eax,3
            add eax,ColorSize
            add eax,sizeof BITMAPFILEHEADER
            add eax,sizeof BITMAPINFOHEADER
            mov bitmapfileheader.bfSize,eax
            mov bitmapfileheader.bfReserved1,0
            mov bitmapfileheader.bfReserved2,0
            mov eax,ColorSize
            add eax,sizeof BITMAPFILEHEADER
            add eax,sizeof BITMAPINFOHEADER
            mov bitmapfileheader.bfOffBits,eax
            mov bitmapinfoheader.biSize,sizeof BITMAPINFOHEADER
            mov eax,dwWidth
            mov bitmapinfoheader.biWidth,eax
            mov eax,dwHeight
            mov bitmapinfoheader.biHeight,eax
            mov bitmapinfoheader.biPlanes,1
            mov ax,word ptr [dwBPP]
            mov bitmapinfoheader.biBitCount,ax
            mov bitmapinfoheader.biCompression,BI_RGB
            mov bitmapinfoheader.biSizeImage,0
            mov bitmapinfoheader.biXPelsPerMeter,0
            mov bitmapinfoheader.biYPelsPerMeter,0
            mov eax,dwNumColors
            mov bitmapinfoheader.biClrUsed,eax
            mov bitmapinfoheader.biClrImportant,0
            invoke CreateFile, lpFileName,GENERIC_WRITE,0, NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL
            mov hFile,eax
            .IF (eax==INVALID_HANDLE_VALUE)
                invoke DeleteObject, hBitmap
                invoke DeleteDC, memdc
                invoke DeleteDC, hdc
                invoke MessageBox, 0, addr szNoFile, NULL, 0
                jmp ExitFunc
            .ENDIF
            invoke WriteFile, hFile, addr bitmapfileheader, sizeof BITMAPFILEHEADER, addr dwBytes, NULL
            invoke WriteFile, hFile, addr bitmapinfoheader, sizeof BITMAPINFOHEADER, addr dwBytes, NULL
            mov eax,dwNumColors
            .IF (eax!=0)
                invoke WriteFile, hFile, addr colors, ColorSize, addr dwBytes,NULL
            .ENDIF
            mov eax,dwWidth
            xor edx,edx
            mov ecx,dwHeight
            mul ecx
            xor edx,edx
            mov ecx,dwBPP
            mul ecx
            shr eax,3
            mov ColorSize,eax
            invoke WriteFile, hFile, pBits, ColorSize, addr dwBytes,NULL
            invoke CloseHandle, hFile
            invoke MessageBox, 0, addr szDone, NULL, 0
            invoke DeleteObject ,hBitmap
            invoke DeleteDC, memdc
            invoke DeleteDC, hdc
ExitFunc:
            ret
CapScreen endp

start:
	invoke CapScreen, addr szFile
	invoke  ExitProcess, 0
end start


Дата: Авг 16, 2004 05:07:32

xsnatch
Сделал так:
mov dwBPP,eax
;mov dwBPP, 1h
проверял под w2ksp4 1280x1024x32bpp - работает.


Powered by miniBB 1.6 © 2001-2002
Время загрузки страницы (сек.): 0.044