hi, i have been tring to get screen picture and write it back , now i know how to do that but, i'm wondering if there is faster api than Bitblt ? if anyone can help me , please thanks by the way i'm looking for a text or book on all api speed if any 1 know on sutch a thing ....
Posted on 2001-03-21 07:48:00 by eko
Using the GDI I think it's the fastest, there are others, but it depends how you are doing it, if you are taking the screen shot each time, then saving it, it can be quite costy. There are tricks to speeding it up, but I need to know more about what you are trying to do. umbongo
Posted on 2001-03-21 07:58:00 by umbongo
i want to build a program that will draw to the screen every lets say 10 sec , a picture but, the user will not see it becuase it will switch to the regular picture screen so fast . i know it doesnt sound to clear maybe because of my english but i hope u understand it , probbly its sound wierd to you that actully i want to do sutch a thing but i realy realy need to do this ,and it will be great if u could help me thanks ;]
Posted on 2001-03-21 08:32:00 by eko
If I understand you correctly (apologies if I don't) you want to draw two pictures, one on top of the other very quickly? A bit like a subliminal message would be done? What I would do is this:- Create 2 Device Contexts (hdc's) and put the two pictures you want in them, then BitBlt them onto a destination hdc (the screen) very fast :- mem1dc = first picture mem2dc = second picture screendc = the display invoke bitblt,mem1dc,.....screendc invoke bitblt,mem1dc,.....screendc thats as fast as you will get using the GDI, if you need to go faster then you'll have to use DirectX, but you can't play with windows under DirectX... I can put the code here if you like. Umbongo
Posted on 2001-03-21 10:27:00 by umbongo
yeah that's what i meant, it will be great if u put the code for it thanks ;]
Posted on 2001-03-22 05:39:00 by eko
Here you go, I've used FillRect to put something in the Bitmaps in WM_CREATE, you can put whatever you like in there, I have also offset the BitBlt slightly in the WM_PAINT message, so you can see the two images. To place them directly on each other, replace the 20,20 with 0,0 Remember to put the WM_DESTORY bit in, otherwise you will leak memory, and under 95/98 your system will fail after a few runs. any questions, gimme a shout. Umbongo

; in your data area :-

	hMem1DC		dd 0
	hMem2DC		dd 0
	hdc		dd 0
	hBitmap1	dd 0
	hBitmap2	dd 0
	hOldBitmap1	dd 0
	hOldBitmap2	dd 0


; in your WndProc:-
LOCAL rc:RECT
.elseif uMsg == WM_CREATE

	invoke	GetDC,hWin
	mov	hdc,eax

	invoke	CreateCompatibleDC,hdc
	mov	hMem1DC,eax

	invoke	CreateCompatibleDC,hdc
	mov	hMem2DC,eax

	invoke GetClientRect,hWin,ADDR rc

	invoke	CreateCompatibleBitmap,hdc,rc.right,rc.bottom
	mov	hBitmap1,eax
	invoke	CreateCompatibleBitmap,hdc,rc.right,rc.bottom
	mov	hBitmap2,eax

	invoke	SelectObject,hMem1DC,hBitmap1
	mov	hOldBitmap1,eax
	invoke SelectObject,hMem2DC,hBitmap2
	mov	hOldBitmap2,eax


	invoke	FillRect,hMem1DC,ADDR rc,COLOR_ACTIVECAPTION+1
	invoke	FillRect,hMem2DC,ADDR rc,COLOR_BTNSHADOW+1

.elseif uMsg == WM_PAINT


	invoke	GetDC,hWin
	mov	hdc,eax

	invoke GetClientRect,hWin,ADDR rc

	invoke	BitBlt,hdc,0,0,rc.right,rc.bottom,hMem1DC,0,0,SRCCOPY
	invoke	BitBlt,hdc,20,20,rc.right,rc.bottom,hMem2DC,0,0,SRCCOPY

.elseif uMsg == WM_DESTROY


	invoke	SelectObject,hMem1DC,hOldBitmap1
	invoke	SelectObject,hMem2DC,hOldBitmap2

	invoke	DeleteDC,hMem1DC
	invoke	DeleteDC,hMem2DC


This message was edited by umbongo, on 3/22/2001 7:08:41 AM
Posted on 2001-03-22 06:07:00 by umbongo
Another point to make is that the memory DC's are sized at Creation, if the user makes the windows bigger or smaller you'll have to re-init the DC's, Like this :-

.elseif uMsg == WM_SIZE

	invoke	SelectObject,hMem1DC,hOldBitmap1
	invoke	SelectObject,hMem2DC,hOldBitmap2
	invoke	DeleteDC,hMem1DC
	invoke	DeleteDC,hMem2DC

	invoke	GetDC,hWin
	mov	hdc,eax

	invoke	CreateCompatibleDC,hdc
	mov	hMem1DC,eax

	invoke	CreateCompatibleDC,hdc
	mov	hMem2DC,eax

	invoke	GetClientRect,hWin,ADDR rc

	invoke	CreateCompatibleBitmap,hdc,rc.right,rc.bottom
	mov	hBitmap1,eax
	invoke	CreateCompatibleBitmap,hdc,rc.right,rc.bottom
	mov	hBitmap2,eax

	invoke	SelectObject,hMem1DC,hBitmap1
	mov	hOldBitmap1,eax
	invoke	SelectObject,hMem2DC,hBitmap2
	mov	hOldBitmap2,eax


	invoke	FillRect,hMem1DC,ADDR rc,COLOR_ACTIVECAPTION+1
	invoke	FillRect,hMem2DC,ADDR rc,COLOR_BTNSHADOW+1
sorry I should have put that in earlier... it's basically doing what WM_DESTROY does, followed by WM_CREATE functionality, you might want to put those bits in separate functions and call them, rather than duplicating the code, but I'm a lazy sod :) Umbongo
Posted on 2001-03-22 06:24:00 by umbongo
Thanks !! you have helped me alot , i have another little question what is the faster way to refresh the screen ? i just rememberd i wanted to ask you , i saw in the source you gave me two varibles called hOldBitmap1 and hOldBitmap2 and my question do i must put them at my prog?
Posted on 2001-03-22 06:55:00 by eko
hOldBitmap1 and hOldBitmap2 are used to restore the hMem1DC & hMem2DC device contexts back to their normal state. They are used in WM_DESTROY. There is a faster way to refresh the screen, as someone once said to me "the fastest way to do something is not do it" Confusing, but look at what we are doing here, the whole window is updated each time we draw the screen. If in WM_PAINT we only draw what has changed then we will manage to draw a whole lot faster. Now, the problem we have is that you want to draw a picture, then very quickly draw over it, which will require the whole window being updated. Thats the real problem, windows isn't good at this, hence Microsoft created DirectX, which is direct access to the hardware buffers of the video cards, much quicker, but harder to use. You can have a directX window and a normal window around at the same time, but DirectX only gives you fast graphics when using it exclusively, using it in a normal window will make everything you do a headache and not give you the speed you're looking for. For normal windows programming, you won't get faster that the code I have shown you - there are slight improvements (using WS_OWNDC for the window and things, but it just won't help that much. umbongo
Posted on 2001-03-22 07:26:00 by umbongo
Thanks!!!!!!!!!!!!!!!!!!!!!1
Posted on 2001-03-23 13:23:00 by eko