|
If by "snapshot" you mean capture its bitmap to the clipboard, you might want to try this:/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
Here is a win32 code:
<br />
int Screenshot(HDC hdc, char *pszflname)<br />
{<br />
HDC memdc;<br />
HANDLE hfl;<br />
DWORD dwBytes, dwWidth, dwHeight, dwNumColors, dwBPP, ColorSize;<br />
void *pBits;<br />
HBITMAP hbmp;<br />
BITMAPFILEHEADER fileheader;<br />
BITMAPINFOHEADER infoheader;<br />
RGBQUAD colors[256];<br />
BITMAPINFO bmpinfo;<br />
HGDIOBJ hret;<br />
<br />
dwWidth = GetDeviceCaps(hdc, HORZRES);<br />
dwHeight = GetDeviceCaps(hdc, VERTRES);<br />
dwBPP = GetDeviceCaps(hdc, BITSPIXEL);<br />
if (dwBPP <= 8)<br />
dwNumColors = 256;<br />
else<br />
dwNumColors = 0;<br />
if (!(memdc = CreateCompatibleDC(hdc)))<br />
return (0);<br />
bmpinfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);<br />
bmpinfo.bmiHeader.biWidth = dwWidth;<br />
bmpinfo.bmiHeader.biHeight = dwHeight;<br />
bmpinfo.bmiHeader.biPlanes = 1;<br />
bmpinfo.bmiHeader.biBitCount = (WORD)dwBPP;<br />
bmpinfo.bmiHeader.biCompression = BI_RGB;<br />
bmpinfo.bmiHeader.biSizeImage = 0;<br />
bmpinfo.bmiHeader.biXPelsPerMeter = 0;<br />
bmpinfo.bmiHeader.biYPelsPerMeter = 0;<br />
bmpinfo.bmiHeader.biClrUsed = dwNumColors;<br />
bmpinfo.bmiHeader.biClrImportant = dwNumColors;<br />
hbmp = CreateDIBSection(hdc, &bmpinfo, DIB_PAL_COLORS, &pBits, NULL, 0);<br />
if (!hbmp)<br />
{<br />
DeleteDC(memdc);<br />
return (0);<br />
}<br />
hret = SelectObject(memdc, hbmp);<br />
if (!hret || (hret == HGDI_ERROR))<br />
{<br />
DeleteDC(memdc);<br />
return (0);<br />
}<br />
if (!BitBlt(memdc, 0, 0, dwWidth, dwHeight, hdc, 0, 0, SRCCOPY))<br />
{<br />
DeleteDC(memdc);<br />
return (0);<br />
}<br />
if (dwNumColors)<br />
dwNumColors = GetDIBColorTable(memdc, 0, dwNumColors, colors);<br />
fileheader.bfType = 0x4D42;<br />
ColorSize = dwNumColors * sizeof(RGBQUAD);<br />
fileheader.bfSize = ((dwWidth*dwHeight*dwBPP) >> 3) + ColorSize + sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);<br />
fileheader.bfReserved1 = fileheader.bfReserved2 = 0;<br />
fileheader.bfOffBits = ColorSize + sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);<br />
infoheader.biSize = sizeof(BITMAPINFOHEADER);<br />
infoheader.biWidth = dwWidth;<br />
infoheader.biHeight = dwHeight;<br />
infoheader.biPlanes = 1;<br />
infoheader.biBitCount = (WORD)dwBPP;<br />
infoheader.biCompression = BI_RGB;<br />
infoheader.biSizeImage = infoheader.biClrImportant = 0;<br />
infoheader.biXPelsPerMeter = infoheader.biYPelsPerMeter = 0;<br />
infoheader.biClrUsed = dwNumColors;<br />
hfl = CreateFile(pszflname, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);<br />
if (hfl == INVALID_HANDLE_VALUE)<br />
{<br />
DeleteObject(hbmp);<br />
{<br />
DeleteDC(memdc);<br />
return (0);<br />
}<br />
}<br />
WriteFile(hfl, &fileheader, sizeof(BITMAPFILEHEADER), &dwBytes, 0);<br />
WriteFile(hfl, &infoheader, sizeof(BITMAPINFOHEADER), &dwBytes, 0);<br />
if (!dwNumColors)<br />
WriteFile(hfl, colors, ColorSize, &dwBytes, 0);<br />
ColorSize = (dwWidth * dwHeight * dwBPP) >> 3;<br />
WriteFile(hfl, pBits, ColorSize, &dwBytes, 0);<br />
CloseHandle(hfl);<br />
DeleteObject(hbmp);<br />
DeleteDC(memdc);<br />
return (1);<br />
}<br />
and you can use it like this
<br />
Screenshot(GetDC(GetDesktopWindow()), "myscreenshot.bmp");<br />
I hope this helps....
Well... I am a beginner ...
|
|
|
|
|
Simply Great!!!
A very useful code snippet.
Thanks a lot...
Regards,
Jijo.
________________________________
Yesterday is history,
Tomorrow is a mystery,
But today is a present.
|
|
|
|
|
Hi,
I have a C++ DLL ( not MFC )which has a static method
say
class Test
{
static GetData();
Static GetParams();
bool TestDatat();
};
I am exporting this class and using in another DLL.
I built Test.dll,Test.lib.
Now i included in another DLL(say Samp.DLL):
Test.dll,Test.lib abd Test.h
in Samp.h file i inclued "Test.h" and linkedTest.lib and Placed Test.dll in Release/Debug folder.
I am calling Test::GetData() in Samp.DLL.
But after compiling Samp.DLL giving error like:
"error LNK 2001: unresolved external symbol. _declspec(dllimport) public:static bool _stdcall Test::GetDatta(char const *,bool)(_imp_?GetData@Test@SG_NPBD_N@Z)".
while building if i change project setttings "_cdecl*" in calling conventions, DLL is building fine,but failing to call a value from Samp.DLL by passing value to Test.DLL.
If i what to build my Samp.DLL by "_stdcall" convention how can i build this ?
Any help on this..
Thank you.
|
|
|
|
|
Have you exported using _declspec(dllexport) and imported using _declspec(dllimport)?
Can you show how you are importing and exporting?
Jaime
|
|
|
|
|
[edit] Regular DLLs don't You shouldn't [/edit] expose objects in a regular DLL (only ActiveX or MFC Extension DLLs) if you want the calling code to be something besides C++. You'll need to export a regular C-style function that serves as a wrapper to the method/property you are trying to invoke.
Jeremy Falcon
|
|
|
|
|
He's exporting a regular C++ class. Nothing magical about that, and is certainly possible with DLLs.
--
Ich bin Joachim von Hassel, und ich bin Pilot der Bundeswehr.
Welle: Erdball - F104-G Starfighter
|
|
|
|
|
Possible, but not practical and in poor practice IMO. Because, if you do that, then your calling language has to be C++.
Jeremy Falcon
|
|
|
|
|
Hello,
I have a hevey problem your you out there,
I need to right a app that handle the "%1" %*
when a app start.
When a app start my app should start and then i want
to check what app thats realy starded how do i do that?
|
|
|
|
|
Please rephrase your question because I really don't understand what you are asking !!!
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
Ok I Sorry,
That I need is,
When you start a app t:ex = "Notepad.exe"
I want my app to start but i need to see that it is notepad
and start the notepad with my app or that app that starts.
|
|
|
|
|
And i Need to do it with a MFC APP,
So this is what i want to do.
1) Put my app to exefiles So when you start a exe file my app will start.
2) Byt when my app(MFC) start i need to now what app realy started.
3) So if it is "Notepad" that starts i what to start notepad from my app.
But i dont now ho to do this can you help me?
|
|
|
|
|
I'm still not sure ...
Are you talking about file association ? for example, when double clicking on a text file it will start notepad.exe ? but you want to start your own application ?
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
Yes that is what i want,
But i want to start the exefile in my app.
And it most be in a MFC app
|
|
|
|
|
You mean the register-setting in de CLASSES part of the registry, where there's a key called exefile.
You want to set a program in front of "%1" %* so it is called when an executable is started.
I think you mean you need the __argc en __argv[] vars. Read them out and you'll get you're arguments.
__argc = argument count
__argv[] = arguments, 0 = the program-file, 1,2,3,... the arguments.
Loading...
|
|
|
|
|
Yes that what i mean,
But how do i do this? And it must be a MFC app.
|
|
|
|
|
When an MFC app starts you can call GetCommandLIne() in the InitInstance() too see what parameters were passed to you when you were called.
If you vote me down, my score will only get lower
|
|
|
|
|
Hai,
In WinCE these two are not supporting, is there any option to replace this:
LR_DEFAULTSIZE | LR_LOADFROMFILE
with regards
|
|
|
|
|
I have created a structure to hold all the GUI settings that the program current state is in; i.e. check boxes, text filed entries, button states.
Now I want to save the file as Save Settings...
I have been using the CFileDialog to speficy a save file and also using a CFile to create and open a file.
I did try and use iostream but got in a mess with deprecated warning and namespace problems.
extern void _OLD_IOSTREAMS_ARE_DEPRECATED();
c:\SSIC_Example\SSIC_ExampleDlg.cpp(768): error C2065: 'ofstream' : undeclared identifier
What is the simplest way to save these settings and load them when the user selects to Load Project...
But I got in another mess with trying to open an already open file with Cfile.
I am using Visual Studio .Net 2002.
|
|
|
|
|
If I were you I would save the settings in an ini file which contained an xml format. This way you could easily parse and access data in the file using DOM. You can download XERCES which contains a perfectly acceptable DOM implementation and is widely available.
|
|
|
|
|
Have you used #include <fstream> without the .h? Have you used std::ofstream to use the stream? Why are you using CFile and ofstream together? why don't you decide to use only CFile?
Jaime
|
|
|
|
|
I have stoped using CFile and just trying to get the streams working;
i.e. Outfile << buttonOne.setting;
etc and do the same for input.
But still in a mess with headers to use and namespace.
It was OK doing this sort of thing with C++ Version 6.0.
|
|
|
|
|
If I use the header:-
#include <<fstream>>
I get the error:-
C:\Program Files\Microsoft Visual Studio .NET\Vc7\include\wchar.h(438): error C2011: '_stat' : 'struct' type redefinition
For Output:
std::ofstream Out;<br />
Out.open(file1);
For input:
std::ifstream In;<br />
In.open (file1);
How do I get rid of this error?!
|
|
|
|
|
hello,
i need to make a function that accept the same parameters of the Format function of CString and create a formatted string with them
so i've declared
void OutputMessage(const char* pMessage, ...);
and
void CNetConnection::OutputMessage(const char* pMessage, ...)
{
CString msg;
va_list argList;
va_start( argList, pMessage );
msg.Format(pMessage, argList);
va_end( argList );
// next use msg string to do things
}
The problem is that the output string has incorrect values in the %s %d etc values.
I've made something wrong?
Thanks
|
|
|
|
|