|
When performance is not an issue and when all that we want is just a snapshot of the desktop, we can consider the GDI option. This mechanism is based on the simple principle that the desktop is also a window - that is it has a window Handle (HWND) and a device context (DC). If we can get the device context of the desktop to be captured, we can just blit those contents to our application defined device context in the normal way. And getting the device context of the desktop is pretty straightforward if we know its window handle - which can be achieved through the function GetDesktopWindow(). Thus, the steps involved are:
Acquire the Desktop window handle using the function GetDesktopWindow();
Get the DC of the desktop window using the function GetDC();
Create a compatible DC for the Desktop DC and a compatible bitmap to select into that compatible DC. These can be done using CreateCompatibleDC() and CreateCompatibleBitmap(); selecting the bitmap into our DC can be done with SelectObject();
Whenever you are ready to capture the screen, just blit the contents of the Desktop DC into the created compatible DC - that's all - you are done. The compatible bitmap we created now contains the contents of the screen at the moment of the capture.
Do not forget to release the objects when you are done. Memory is precious (for the other applications).
Void CaptureScreen()
{
int nScreenWidth = GetSystemMetrics(SM_CXSCREEN);
int nScreenHeight = GetSystemMetrics(SM_CYSCREEN);
HWND hDesktopWnd = GetDesktopWindow();
HDC hDesktopDC = GetDC(hDesktopWnd);
HDC hCaptureDC = CreateCompatibleDC(hDesktopDC);
HBITMAP hCaptureBitmap =CreateCompatibleBitmap(hDesktopDC,
nScreenWidth, nScreenHeight);
SelectObject(hCaptureDC,hCaptureBitmap);
BitBlt(hCaptureDC,0,0,nScreenWidth,nScreenHeight,
hDesktopDC,0,0,SRCCOPY|CAPTUREBLT);
SaveCapturedBitmap(hCaptureBitmap); //Place holder - Put your code
//here to save the captured image to disk
ReleaseDC(hDesktopWnd,hDesktopDC);
DeleteDC(hCaptureDC);
DeleteObject(hCaptureBitmap);
}
In the above code snippet, the function GetSystemMetrics() returns the screen width when used with SM_CXSCREEN, and returns the screen height when called with SM_CYSCREEN. Refer to the accompanying source code for details of how to save the captured bitmap to the disk and how to send it to the clipboard. Its pretty straightforward. The source code implements the above technique for capturing the screen contents at regular intervals, and creates a movie out of the captured image sequences.
In consideration to the above code please let me know how to capture the network PC`s desktop to my software..
I want to capture it continously i dont want to save it, i want it`s Rectangular Area in ma software...
Please let me know how to do this(of course sockets are used) or create a method for this...
|
|
|
|
|
A process running on the remote system would call CaptureScreen() at regular intervals (however
many frames-per-second you want). Instead of SaveCapturedBitmap(), you would probably want to
SendCapturedBitmap(...). A SendCapturedBitmap() implementaion would transfer the serialized
bitmap bits over a socket to a remotely connected process.
That's the basics but there's some issues...
Getting the bitmap bits. I prefer using DIBSections but GetDIBits() is fine too.
Bandwidth. Multiply the number of bytes per frame by the frames per second. Is it possible to
send that many bytes-per-second over the network without compression?
Which part is giving you trouble? What have you tried so far?
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Actually i cant get the main idea how to send on sockets..
void SaveBitmap(char *szFilename,HBITMAP hBitmap)
{
HDC hdc=NULL;
FILE* fp=NULL;
LPVOID pBuf=NULL;
BITMAPINFO bmpInfo;
BITMAPFILEHEADER bmpFileHeader;
do{
hdc=GetDC(NULL);
ZeroMemory(&bmpInfo,sizeof(BITMAPINFO));
bmpInfo.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
GetDIBits(hdc,hBitmap,0,0,NULL,&bmpInfo,DIB_RGB_COLORS);
if(bmpInfo.bmiHeader.biSizeImage<=0)
bmpInfo.bmiHeader.biSizeImage=bmpInfo.bmiHeader.biWidth*abs(bmpInfo.bmiHeader.biHeight)*(bmpInfo.bmiHeader.biBitCount+7)/8;
if((pBuf=malloc(bmpInfo.bmiHeader.biSizeImage))==NULL)
{
MessageBox(NULL,_T("Unable to Allocate Bitmap Memory"),_T("Error"),MB_OK|MB_ICONERROR);
break;
}
bmpInfo.bmiHeader.biCompression=BI_RGB;
GetDIBits(hdc,hBitmap,0,bmpInfo.bmiHeader.biHeight,pBuf,&bmpInfo,DIB_RGB_COLORS);
if((fp=fopen(szFilename,"wb"))==NULL)
{
MessageBox(NULL,_T("Unable to Create Bitmap File"),_T("Error"),MB_OK|MB_ICONERROR);
break;
}
bmpFileHeader.bfReserved1=0;
bmpFileHeader.bfReserved2=0;
bmpFileHeader.bfSize=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+bmpInfo.bmiHeader.biSizeImage;
bmpFileHeader.bfType='MB';
bmpFileHeader.bfOffBits=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER);
fwrite(&bmpFileHeader,sizeof(BITMAPFILEHEADER),1,fp);
fwrite(&bmpInfo.bmiHeader,sizeof(BITMAPINFOHEADER),1,fp);
fwrite(pBuf,bmpInfo.bmiHeader.biSizeImage,1,fp);
}while(false);
if(hdc)
ReleaseDC(NULL,hdc);
if(pBuf)
free(pBuf);
if(fp)
fclose(fp);
}
This is the implementation of savebitmap..... and how to sendbitmap i dont know... Please help me.. I want to submit it by 3rd may... else ma 30 numbers would be ruined.
|
|
|
|
|
In theory, you should be able to replace the fwrite() calls with socket send() calls.
In practice, you can improve your protocol by sending the headers only once. This information
only changes if you change the capture rect size or the screen resolution and/or bitdepth changes
so for each captured frame you only need to send the pixel data.
Also, I'm not sure about this calculation:
bmpInfo.bmiHeader.biSizeImage=bmpInfo.bmiHeader.biWidth*abs(bmpInfo.bmiHeader.biHeight)*(bmpInfo.bmiHeader.biBitCount+7)/8;
The pixel data is aligned to a DWORD (4-byte) boundary for each row so maybe something like this:
long lStride = ((bmpInfo.bmiHeader.biWidth * (long)bmpInfo.bmiHeader.biBitCount + 31L) & ~31L) / 8L;
bmpInfo.bmiHeader.biSizeImage = lStride * abs(bmpInfo.bmiHeader.biHeight);
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
HassanKU wrote: In consideration to the above code please let me know how to capture the network PC`s desktop to my software..
Do you have a process running on the remote machine that is capturing its screen and sending it back to the calling machine?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Actually can i send u my application.... ???
Please give me ur email address...
|
|
|
|
|
Yes server is requesting da desktop of network Pc...
and the capturing method is running on network PC.
|
|
|
|
|
HassanKU wrote: ...and the capturing method is running on network PC.
Is this part working?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
|
You need to scale this large problem down into several smaller problems. I would be inclined to first get the actual communication working at a very basic level before anything else. The calling machine(s) should be able to send multiple requests to the remote machine without any of them being lost. The remote machine could simply write "Received request from xxx." to a file of some sort.
Then I would have the remote machine "answer" those requests by being able to take a snapshot of its desktop. Simply send a 0 or 1 back to the calling machine to indicate success or failure. Have the calling machine display this acknowledgment.
More to come...
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
|
Morning guys.I need help with micromedia.
I want to edit the text on an existing button, and when I looked on the tutorials, its said that I have to click anywhere on the button instance.I tried that, but cant find this button instance.Someone help.Just to remove the text on the button and put mine.Im using micromedia fireworks by the way
-- modified at 3:06 Monday 30th April, 2007
kagiso
|
|
|
|
|
I'm not sure if this is the proper section, but....
I'm working on a project right now where i need PNG support for texturing our models and i heard from many sources that libpng was the way to go for it. However, I don't have much experience with libraries and have never installed one and am completely lost right now.
I have read through most of the .txt files included with it and still don't know what to do, I've tried building the zlib and libpng projects but they tell me there are .h files missing that need to be there.
I have no idea what a makefile is which another part tells me I can try (I tried running some of the files in the scripts folder where the makefiles are located, but they just crash).
I downloaded the .zip file for it from : http://www.libpng.org/pub/png/libpng.html
Any help would be appreciated.
|
|
|
|
|
make sure your IDE or your project points to the include directory of any add-on library. We use both libpng, and zlib and others. When you get into the habit of using 3rd party libraries you will get into the habit of adding to your include list.
I prefer adding the libraries to the project rather than the IDE since it gets ported with the project rather than having to set up everything all over again each computer.
_________________________
Asu no koto o ieba, tenjo de nezumi ga warau.
Talk about things of tomorrow and the mice in the ceiling laugh. (Japanese Proverb)
|
|
|
|
|
Thanks for the reply, I forgot to come here and tell people I finally got it working with the help of one of my professors yesterday afternoon (april 30th). Sorry about that...
|
|
|
|
|
so expedite
I use openGl + visual 6.
how I can carve part from ground then throwing away by the hand of car?can you help me about it by code?and I need it in this 2day
this is my code that I mean ..you can copy&paste to see what I mean.
#include <windows.h>
#include <gl\gl.h>
#include <gl\glu.h>
#include <gl\glut.h>
#include <math.h>
#include <stdlib.h>
int x=1,y=1;
float tranx=0;
float trany=0;
void init (void)
{
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
gluOrtho2D (-200.0, 200.0, -200.0,200.0);
}
void forklift (void)
{
glClear (GL_COLOR_BUFFER_BIT);
glPushMatrix();
x-=1;
y-=1;
/////////////sunset//////////////////
glTranslatef(x,y,0);
glClear (GL_COLOR_BUFFER_BIT);
glColor3f(1.0,0.0,0.0);
glBegin(GL_POLYGON);
{ int tran,x2=50,y2=50,r=50;
for (tran= 1000 ; tran<=10000; tran++)
glVertex2f(x2 + sin(tran) * r, y2 + cos(tran) * r);
}
glEnd ();
glPopMatrix();
glPushMatrix();
/////////////circle//////////////////
glColor3f(1,0,1);
glTranslatef(tranx,1,0);
glBegin(GL_POLYGON);
{ int tran,x2=-20,y2=-30,r=10;
for (tran= 0 ; tran<= 360 ; tran++)
glVertex2f(x2 + sin(tran) * r, y2 + cos(tran) * r);
}
glEnd ();
glColor3f(1,0,1);
glBegin(GL_POLYGON);
{ int tran,x2=20,y2=-30,r=10;
for (tran= 0 ; tran<= 360 ; tran++)
glVertex2f(x2 + sin(tran) * r, y2 + cos(tran) * r);
}
glEnd ();
////////////////////////car1 ///////////////////////////
glColor3f(0,0,6.6);
glBegin(GL_POLYGON);
glVertex2i(-40,-20);
glVertex2i(40,-20);
glVertex2i(40,20);
glVertex2i(-40,20);
glEnd();
///////////// high of car ////////////////////
glColor3f(0,1,1.6);
glBegin(GL_POLYGON);
glVertex2i(-40,20);
glVertex2i(20,20);
glVertex2i(20,20);
glVertex2i(-20,40);
glEnd();
//////////// hand /////////////
glRotatef(trany,0,0,0.5);
glLineWidth(6);
glBegin(GL_LINE_STRIP);
glVertex2i(20,20);
glVertex2i(30,80);
glVertex2i(90,10 );
glVertex2i(100,10);
glEnd();
if(tranx<1000&&tranx>30)
{ if(trany>-50&&trany<200){
glClearColor (0.0, 0.0, 0.0, 0.);
trany-=.01;
}
else
trany+=100;}
else
{ glClearColor (1.16, 7.0, 0.0, 0.0);
tranx+=.01;
}
///////////////////////////////
glPopMatrix();
///////////////// arith*////////////////////
glColor3f(0,9,0.06);
glBegin(GL_POLYGON);
glVertex2i(200,-200);
glVertex2i(200,-40);
glVertex2i(-200,-40);
glVertex2i(-200,-200);
glEnd();
glutSwapBuffers();
}
void main(int argc, char **argv)
{
glutInit(&argc,argv);
glMatrixMode(GL_PROJECTION);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowPosition(100,100);
glutInitWindowSize(500,500);
glutCreateWindow("*miss looole*");
glutDisplayFunc(forklift);
glutIdleFunc(forklift);
glMatrixMode(GL_PROJECTION);
glMatrixMode(GL_MODELVIEW);
init();
glutMainLoop();
}
-- modified at 12:18 Saturday 28th April, 2007
|
|
|
|
|
hi..plz i need to know a presice definition about Dihedral angel or reference's name talks about that angel regards
miss maria
|
|
|
|
|
Even spelling it 'angel' instead of 'angle', google gave me the definition in seconds.
http://en.wikipedia.org/wiki/Dihedral_angle[^]
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Thanx alot for that website..im Ph.D student i was need info. about that angel..! sorry angle ...angel and angle share something is that: both, they have wings .. thanx again .... Petrovna
|
|
|
|
|
Miss_ petrovna wrote: im Ph.D student...
I'm not sure you should be openly admitting this.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
hi..U can b sure that im admitted what u wrote openly ..
if u read my question(of subject:help) u'll discover that im simple person..my question was very simple compared to my study..but im always like asking people around me..& im glad 2 give answer about any question asked to me ..
second sentence its very nice. Petrovna
|
|
|
|
|
helloo brothers..my program like paint (drawing lines,ellipse,...) the problem that i cant zooooming ..so plz what should i do...
note : iam using v.s (2003)..
Regards;
|
|
|
|
|
Try using the Scaling Transformation on the Graphics object. You can reference the method like this: g.ScaleTransform(2.0f,3.0f)
Cheers!
Richard
may your code be error free
|
|
|
|
|
i wanna to make aprogram that can draw (ellips , line,..) but i have problems with the save & open ..thats apart of the code:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Serialization;
namespace graphics_practis
{
///
/// Summary description for Form1.
///
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.Button line;
private System.Windows.Forms.Button square;
private System.Windows.Forms.Button circle;
private System.Windows.Forms.Button ellipse;
private System.Windows.Forms.Button polygon;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button ok;
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItem2;
private System.Windows.Forms.MenuItem menuItem3;
private System.Windows.Forms.MenuItem menuItem4;
private System.Windows.Forms.MenuItem menuItem5;
private BinaryFormatter formtter = new BinaryFormatter();
private FileStream str_reader;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.SaveFileDialog saveFileDialog1;
private System.Windows.Forms.OpenFileDialog openFileDialog1;
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
dr = new draw(this.pictureBox1);
}
static void Main()
{
Application.Run(new Form1());
}
private void menuItem4_Click(object sender, System.EventArgs e)
{
//saving
FileStream outStream=File.Create(saveFileDialog1.FileName);//To create text file
Stream streamWriter=new StreamWriter(outStream);
}
private void menuItem3_Click(object sender, System.EventArgs e)
{
//opening
FileStream outStream=File.Create(saveFileDialog1.FileName);//To create text file
StreamWriter streamWriter=new StreamWriter(outStream);
}
the error...>>(cannot implicity convert type 'System.IO.StreamWritet'to 'System.IO.Stream'.
|
|
|
|
|
Seriously, stop this project and go pickup a book on beginning C#. You've got some serious "C# and .NET Framework 101" issues to contend with. Just getting something as simple as a StreamWriter to work is giving to fits. Actually doing some drawing is about 10 times more difficult.
Besides, how are you going to save you're image? Are you really going to try to write binary data to a text file??
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|