|
See Barry's Screen Capture[^]
I used the CodeProject "search" feature to arrive on that result.
“Follow your bliss.” – Joseph Campbell
|
|
|
|
|
Member 6864839 wrote:
How i get Screen capture?
See here for an idea.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
thanks both of you for reply.I use this code
HDC m_hdcMem,hdc;
HBITMAP m_Bitmap,m_OldBitmap,hMainBmp ;
int x=800;
int y=600;
hdc=GetDesktopWindow()->GetDC()->m_hDC;
m_hdcMem= CreateCompatibleDC(hdc);
m_Bitmap = CreateCompatibleBitmap(hdc,x,y);
m_OldBitmap=(HBITMAP) SelectObject(m_hdcMem, m_Bitmap);
BitBlt(m_hdcMem, 0,0,x,y, hdc,0,0,SRCCOPY);
hMainBmp =(HBITMAP) SelectObject(m_hdcMem, m_OldBitmap);
CImage m_Image;
m_Image.Attach(hMainBmp);
m_Image.Save("C:\\image.bmp");
m_Image.Detach();
DeleteDC(m_hdcMem);
DeleteObject(hMainBmp );
DeleteObject(m_OldBitmap);
It's working for me.
Now i want to save file in format of .DAT.
Please help me
|
|
|
|
|
Member 6864839 wrote: Now i want to save file in format of .DAT.
There's no such .DAT file. What you've got by capturing the screen is a bitmap, and you just save it to the disk by providing any extension you want to the filename. Or if by .DAT you want to have a file format that your app can only handle, encrypt (search the site) the bitmap and save it to ".DAT format".
“Follow your bliss.” – Joseph Campbell
|
|
|
|
|
ok i use this code but file not save in my disk.
m_Image.Save("C:\\image.dat");
|
|
|
|
|
Take a look at the example at the end of the documentation for CImage::Save()[^]. Because you said "image.dat", the call didn't know the format. You will need to explicitly specify it as bitmap format by doing it this way:
m_Image.Save("c:\\image.dat",ImageFormatBMP);
“Follow your bliss.” – Joseph Campbell
|
|
|
|
|
Thanks it's working.
Thanks once again...........
|
|
|
|
|
I'm glad I could help.
Shameless plug: May I please ask you to mark the helpful replies as "Good Answer" by clicking on the appropriate posts?
“Follow your bliss.” – Joseph Campbell
|
|
|
|
|
I have a dll that needs to share data among all instances. How can I accomplish this? I've tried a multitude of compiler-specific #pragma's (visual studio 2008 for anyone who's asking) and no matter what I do, I cannot share the variables across all instances.
MSDN says memory-mapped files are one of several solutions, so any info on that too would be welcome.
|
|
|
|
|
|
I've tried that, and it didn't work
I remember reading somewhere (on MSDN) that the #pragma data_seg() directive should not be used with classes that require deep copy constructors. Unfortunately, the data I want to share is an std::list.
The page you linked me to goes on to say "Because of these restrictions, Microsoft does not recommend sharing C++ objects between processes."
They also don't recommend sharing pointers, so what alternative do I have?
|
|
|
|
|
Sauce! wrote: They also don't recommend sharing pointers, so what alternative do I have?
In the same page:
In general, if you want to use C++ to share data between processes, write a class
that internally uses a memory-mapped file to share data, but do not share the class instances themselves. This might require special care in developing such a class, but it enables application developers to fully control the side effects of sharing data.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I guess I have a bit of reading to do, this sounds complicated
|
|
|
|
|
BTW, why do you need to share data across several instance of the dll ?
|
|
|
|
|
I guess (is just a guess) you may serialize objects in memory mapped files.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
You can't share a std::list as it allocates nodes on the heap and uses pointers. Boost[^]'s Boost.Interprocess[^] library might be what you're looking for. Among its numerous features are containers like STL's but which can be shared between processes.
Steve
|
|
|
|
|
I use memory mapped files to do exactly this in several places in our [XP embedded based] system. (The trick is to use a mutex to ensure that only one instance does the initializing and the rest just open the memory mapped file.)
|
|
|
|
|
It's not particularly necessary that each instance of the dll share a particular variable - I could instead have each instance of the dll send a message to my application (which loads the dll) and have my app use the message to add the new value to the end of the list. How does that sound?
I'm attempting to simulate input latency by installing a keyboard and mouse hook that records all input, blocks it, and then resends it after a specified interval. I'll probably have trouble differentiating between messages I'm recieving from the system, and messages that I have forwarded after the appropriate interval, however that is a river I'll have to cross when I get to it.
So I guess I'll see what I can do about forwarding the messages directly to my application, where they will then be pushed onto a list (it should be a fairly trivial matter)
edit: is there any way at all I can send a message using the win32 SendMessage() along with some user data, like a flag? It would make my life a hell of a lot easier :P
|
|
|
|
|
Sauce! wrote: is there any way at all I can send a message using the win32 SendMessage() along with some user data, like a flag?
If your data is two DWORDs or less (and WPARAM and LPARAM), just use a WM_USER message or see RegisterWindowMessage(). If longer, use WM_COPYDATA.
|
|
|
|
|
Unfortunately the data is larger than a DWORD or two, and I'm not sure I can use WM_COPYDATA either, as MSDN advises against passing pointers between processes (and dll instances) - with COPYDATASTRUCT using pointers to do it's thing, it pretty much counts it out.
|
|
|
|
|
I am creating an background application which runs in the background, for that i want to know which key has been pressed by user. Right now, i am using this code:
while( 1 )
{
for( int i = 0; i < 256; i++ )
{
GetAsyncKeyState( i );
}
}
But, due to while( 1 ) other applications are hanging. Is there any alternative for GetAsyncKeyState( int ) function OR can i use the same function in another way?
|
|
|
|
|
You should use a global keyboard hook (see: "Using Hooks") for the purpose.
Are you writing a keylogger?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Thanks for your reply Pallini. I was curious about how keylogger works and while searching, i got a keylogger code in c++. Now i am just trying to edit it, just for a learning purpose.
|
|
|
|
|
Here's some neat theory on hooks and DLLs and a practical example to illustrate it all, by Dr. Joseph Newcomer: Hooks and DLLs[^]
“Follow your bliss.” – Joseph Campbell
|
|
|
|
|
I see you already found a better way to do what you want, so this is just an "additional footnote" to your original problem: to make your while loop less CPU hungry you can add a Sleep(1) call somewhere inside it, or maybe use SwithToThread[^] (althorough SwitchTothread seems to be much less effective than Sleep), this way the loop yields execution to other threads and does not eat up all the CPU power. I mean something like:
while( 1 )
{
for( int i = 0; i < 256; i++ )
{
GetAsyncKeyState( i );
}
Sleep(1);
}
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
|
|
|
|