Hello Coders

I am trying to get my present desktop into a buffer in memory. Than show it on the desktop like a screen save would but it would only be a true 100% image of the present screen. Not zooming or nothing special. Just a raw accurate shot of the entire screen.

From there I'm sure i know how to make my image topmost window, lock it, kill mouse and keyboard. So if any touch my machine they would have to SHUT-IT DOWN....

But skip my details. What is the easiest and fairly fast way to do this? Lighting speed is not really needed for me .... only accuracy..

I will be reading a lot to night about it but if i don't get it at lease someone may know how and i don't have to SUFFER another month of confessing docs but will learn something tonight out of it by reading them..

Thanks in advance

PS:
To Scronty:

I am getting into your WebCam code, correction (program) in the process. But all i get is a black bitmap save to disk. All day i been quite afaird to tamper with the code because i have no clue where to start .to be honest. My question is will it do what i am trying to do and how do i get to see an image. I got your new VFW32 but i get the same results. Is WebCamApp for web related stuff only.
Posted on 2003-07-22 20:39:13 by cmax
There are thousands of threads about this. You have to be a rocket sinentic to put all the pieces together.

Anyway, While searching i founded titan code. It seem to be a good start so i put it in the Generic.asm but i can't seem to get the Screen Capture in the hwndStatic box. I know i am doing something really silly but
i have rushed though it at lease 20 times. Setting text is easy but how to i set a capture on a static box. I also found a code that make a bitmap and write it to disk and it show the same thing that WebCam does "A Big Black Bitmap" So i guest it must be under there somewhere. The Bitmaps format is a trip. I hope i don't need all of that.. and sorry about all of this...


; #########################################################################

.386
.model flat, stdcall ; 32 bit memory model
option casemap :none ; case sensitive


; #########################################################################



; #########################################################################

; include files
; ~~~~~~~~~~~~~
include \MASM32\INCLUDE\windows.inc
include \MASM32\INCLUDE\masm32.inc
include \MASM32\INCLUDE\gdi32.inc
include \MASM32\INCLUDE\user32.inc
include \MASM32\INCLUDE\kernel32.inc
include \MASM32\INCLUDE\Comctl32.inc
include \MASM32\INCLUDE\comdlg32.inc
include \MASM32\INCLUDE\shell32.inc

; libraries
; ~~~~~~~~~
includelib \MASM32\LIB\masm32.lib

includelib \MASM32\LIB\gdi32.lib
includelib \MASM32\LIB\user32.lib
includelib \MASM32\LIB\kernel32.lib
includelib \MASM32\LIB\Comctl32.lib
includelib \MASM32\LIB\comdlg32.lib
includelib \MASM32\LIB\shell32.lib

; #########################################################################
szText MACRO Name, Text:VARARG
LOCAL lbl
jmp lbl
Name db Text,0
lbl:
ENDM

m2m MACRO M1, M2
push M2
pop M1
ENDM

return MACRO arg
mov eax, arg
ret
ENDM

WinMain PROTO :DWORD,:DWORD,:DWORD,:DWORD
WndProc PROTO :DWORD,:DWORD,:DWORD,:DWORD
TopXY PROTO :DWORD,:DWORD


.data
szDisplayName db "Generic",0
CommandLine dd 0
hWnd dd 0
hInstance dd 0
StaticClassName db "static",0

.data?


rect RECT <?>

hwndStatic DWORD ?
hdc DWORD ?
cdc DWORD ?
hbmp DWORD ?
temp DWORD ?

; #########################################################################
.code
start:

invoke GetModuleHandle, NULL ; provides the instance handle
mov hInstance, eax

invoke GetCommandLine ; provides the command line address
mov CommandLine, eax

invoke WinMain,hInstance,NULL,CommandLine,SW_SHOWDEFAULT

invoke ExitProcess,eax ; cleanup & return to operating system

; #########################################################################

WinMain proc hInst :DWORD,
hPrevInst :DWORD,
CmdLine :DWORD,
CmdShow :DWORD

;====================
; Put LOCALs on stack
;====================

LOCAL wc :WNDCLASSEX
LOCAL msg :MSG

LOCAL Wwd :DWORD
LOCAL Wht :DWORD
LOCAL Wtx :DWORD
LOCAL Wty :DWORD

szText szClassName,"Generic_Class"

;==================================================
; Fill WNDCLASSEX structure with required variables
;==================================================

mov wc.cbSize, sizeof WNDCLASSEX
mov wc.style, CS_HREDRAW or CS_VREDRAW \
or CS_BYTEALIGNWINDOW
mov wc.lpfnWndProc, offset WndProc ; address of WndProc
mov wc.cbClsExtra, NULL
mov wc.cbWndExtra, NULL
m2m wc.hInstance, hInst ; instance handle
mov wc.hbrBackground, COLOR_BTNFACE+3 ; system color
mov wc.lpszMenuName, NULL
mov wc.lpszClassName, offset szClassName ; window class name
invoke LoadIcon,hInst,500 ; icon ID ; resource icon
mov wc.hIcon, eax
invoke LoadCursor,NULL,IDC_ARROW ; system cursor
mov wc.hCursor, eax
mov wc.hIconSm, 0

invoke RegisterClassEx, ADDR wc ; register the window class

;================================
; Centre window at following size
;================================

mov Wwd, 500
mov Wht, 350

invoke GetSystemMetrics,SM_CXSCREEN ; get screen width in pixels
invoke TopXY,Wwd,eax
mov Wtx, eax

invoke GetSystemMetrics,SM_CYSCREEN ; get screen height in pixels
invoke TopXY,Wht,eax
mov Wty, eax

; ==================================
; Create the main application window
; ==================================
invoke CreateWindowEx,WS_EX_OVERLAPPEDWINDOW,
ADDR szClassName,
ADDR szDisplayName,
WS_OVERLAPPEDWINDOW,
Wtx,Wty,Wwd,Wht,
NULL,NULL,
hInst,NULL

mov hWnd,eax ; copy return value into handle DWORD



invoke ShowWindow,hWnd,SW_SHOWNORMAL ; display the window
invoke UpdateWindow,hWnd ; update the display



invoke CreateWindowExA,NULL, ADDR StaticClassName, 0,\
WS_CHILD or WS_VISIBLE,\
01,01,300,300,hWnd,0,hInstance,NULL;
mov hwndStatic,eax


;===================================
; Loop until PostQuitMessage is sent
;===================================

StartLoop:
invoke GetMessage,ADDR msg,NULL,0,0 ; get each message
cmp eax, 0 ; exit if GetMessage()
je ExitLoop ; returns zero
invoke TranslateMessage, ADDR msg ; translate it
invoke DispatchMessage, ADDR msg ; send it to message proc
jmp StartLoop
ExitLoop:

return msg.wParam

WinMain endp

; #########################################################################

WndProc proc hWin :DWORD,
uMsg :DWORD,
wParam :DWORD,
lParam :DWORD
.if uMsg == WM_COMMAND


.if wParam == 1000
invoke SendMessage,hWin,WM_SYSCOMMAND,SC_CLOSE,NULL
.elseif wParam == 1900
szText TheMsg,"Assembler, Pure & Simple"
invoke MessageBox,hWin,ADDR TheMsg,ADDR szDisplayName,MB_OK
.endif

;====== end menu commands ======

.elseif uMsg == WM_CREATE



invoke CreateCompatibleDC,NULL
mov cdc,eax

invoke CreateCompatibleBitmap,hdc,rect.right,rect.bottom

mov hbmp,eax


invoke SelectObject,cdc,hbmp
invoke BitBlt,hdc,rect.left,rect.top,rect.right,rect.bottom,cdc,rect.left,rect.top,DSTINVERT

invoke BitBlt,hdc,rect.left,rect.top,rect.right,rect.bottom,cdc,rect.left,rect.top,DSTINVERT
mov hwndStatic, offset cdc

invoke SetWindowPos, hWnd, HWND_TOPMOST, NULL, NULL, NULL, NULL,SWP_SHOWWINDOW or SWP_NOSIZE or SWP_NOMOVE



.elseif uMsg == WM_CLOSE
szText TheText,"Please Confirm Exit"
invoke MessageBox,hWin,ADDR TheText,ADDR szDisplayName,MB_YESNO
.if eax == IDNO
return 0
.endif

.elseif uMsg == WM_DESTROY
invoke PostQuitMessage,NULL
return 0
.endif

invoke DefWindowProc,hWin,uMsg,wParam,lParam

ret

WndProc endp

; ########################################################################

TopXY proc wDim:DWORD, sDim:DWORD

shr sDim, 1 ; divide screen dimension by 2
shr wDim, 1 ; divide window dimension by 2
mov eax, wDim ; copy window dimension into eax
sub sDim, eax ; sub half win dimension from half screen dimension

return sDim

TopXY endp

; ########################################################################

end start
Posted on 2003-07-23 00:29:36 by cmax