|
I was wondering how I could take screenshots using PrintWindow() on Windows XP and get the transparency information, so I don't get an ugly black border around all my individual window screenshots. This seems to be possible from looking at other programs (e.g. TopDesk, http://www.otakusoftware.com/topdesk/). I played with calling GetLayeredWindowAttributes to find out transparency information, but it only succeeds for app that initially set the transparency information in the first place.
|
|
|
|
|
I haven't tried this, but what happens if you create a 32-bit ARGB DIB section and select it into the destination DC?
Fill it with transparent pixels before the PrintWindow() call.
Of course, to preserve the transparency when saving to a file, you'll need to use a file
format that supports transparency, like PNG or TIFF.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I'm using C# with interop. I'm not too sure what you mean by "dib section," although I am creating a 32-bit ARGB bitmap where the image is written to. I tried making the bitmap transparent first, and also tried something like coloring all the pixels red first. Neither worked; every pixel is always overwritten. There is always a black border, and when I try to access the pixel at 0,0 (which on my computer should be transparent, because its a Windows XP rounded corner), it is always black with an alpha value of 255.
My C# code looks like this:
Rect rc;
GetWindowRect(hwnd, out rc);
if (rc.Width == 0 && rc.Height == 0)
{
return null;
}
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap((int)rc.Width, (int)rc.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
bitmap.MakeTransparent();
System.Drawing.Graphics gfxBitmap = System.Drawing.Graphics.FromImage(bitmap);
IntPtr hdcBitmap = gfxBitmap.GetHdc();
PrintWindow(hwnd, hdcBitmap, 0);
gfxBitmap.ReleaseHdc(hdcBitmap);
gfxBitmap.Dispose();
|
|
|
|
|
You're doing the same thing I was referring to
MakeTransparent() isn't going to help here. I would try actually clearing the bitmap to
transparent pixels with a transparent brush before calling PrintWindow().
What are you doing after the code you've shown? How do you check and see the undesired black border?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Ok, I think I figured it out. The reason why the windows I was interested in were transparent wasn't because they were layered-- they had clipping window regions! Your hint about clearing the bitmap to transparent pixels was also helpful (I was drawing a transparent rectangle, but that doesn't work; you need to call clear).
Here is my final code. You can get the Win32/GDI functions through pinvoke.net
Rect rc;
GetWindowRect(hwnd, out rc);
if (rc.Width == 0 && rc.Height == 0)
{
return null;
}
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap((int)rc.Width, (int)rc.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
System.Drawing.Graphics gfxBitmap = System.Drawing.Graphics.FromImage(bitmap);
IntPtr hdcBitmap = gfxBitmap.GetHdc();
PrintWindow(hwnd, hdcBitmap, 0);
gfxBitmap.ReleaseHdc(hdcBitmap);
IntPtr hRgn = CreateRectRgn(0, 0, 0, 0);
GetWindowRgn(new IntPtr(hwnd), hRgn);
System.Drawing.Region region = System.Drawing.Region.FromHrgn(hRgn);
if (!region.IsEmpty(gfxBitmap))
{
gfxBitmap.ExcludeClip(region);
gfxBitmap.Clear(System.Drawing.Color.Transparent);
}
gfxBitmap.Dispose();
|
|
|
|
|
Cool! Thanks for the update
I'll try to remember that the next time it comes up!
Cheers,
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Dear All
i am about to start a project something like download manager Like FlashGet....etc
i need to know how to start ??
i need any info. about the following :
"limit download speed"
"resume, pause, stop"
i need any tips
thanks
bye
|
|
|
|
|
Adore C++ wrote: i need to know how to start ??
Maybe with something a little less ambitious. Not to dull your knife or anything, but you can't jump into the deep end of the pool and then immediately ask for help. Start small and build upon that.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
DavidCrow wrote: you can't jump into the deep end of the pool and then immediately ask for help.
Sweet, let's make an acronym out of that: The Internet
|
|
|
|
|
|
I installed Norton Antivirus a few days ago, and I was pretty surprised to find that it can't be terminated. Tried the End Process thing, and all I get is a msgbox telling me that "Access is denied".
My question: Is there a way to do this in a MFC app? Either by making the app a system process or by starting another process that somehow isn't endable?
And is there any way to end processes like these? Sometimes Norton takes up so much CPU it's annoying, and yet I can't end the process...
Thanks in advance.
Edit: I don't want to start another topic, so I'm just going to add another unrelated question: By using ::SendMessage(), is there any way to tell a listbox (like the one in task manager) to remove ONE entry if I know the contents of that entry?
-- modified at 14:24 Monday 19th November, 2007
|
|
|
|
|
This is intentionally difficult to do.
Part of how virus programs protect themselves is by terminating the anti-virus programs. And anti-virus programs protect themselves by making them very difficult to terminate.
If it's that annoying to you, I suggest you uninstall it in favor of some other program.
I'm not quite sure how Norton does it though...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
<A HREF="http://www.soonr.com">SoonR Inc -- PC Power delivered to your phone</A>
|
|
|
|
|
Norton accomplished this with a kernel hook from a device driver.
Normally here is what happens:
1.) User program invokes TerminateProcess() is called from kernel32.
2.) TerminateProcess() calls NtTerminateProcess() exported from NTDLL.DLL.
3.) NtTerminateProcess() invokes ZwTerminateProcess()
4.) ZwTerminateProcess() will mov 0x101 into eax and mov edx,esp.
5.) SYSENTER instruction is executed.
Looks something like:
TerminateProcess()
...
call ds:NtTerminateProcess
...
mov eax, 101h
mov edx, 7FFE0300h
call edx
.text 7FFE0300: mov edx,esp
systenter
ret
However, Norton has implemented a ZwTerminateProcess hook by modifying the SDT (Service Descriptor Table) so at this point they have intercepted the call and their code executes instead, blocking you from terminating the application.
|
|
|
|
|
Could you give an example of how I might do this in my code?
Thanks.
|
|
|
|
|
I'm trying to load data into a vector and simply can't fiquire out how to do it.
Here's the class that holds (should) hold the data:
class CMyTrailer {
public:
// Varables
CString m_csData;
CMyTrailer();
~CMyTrailer();
};
#include <vector>
using std::vector;
using std::copy;
using std::iterator;
using std::string;
Here's my error from the compiler:
error C2653: 'vector<class CMyTrailer,class std::allocator<class CMyTrailer> >' : is not a class or namespace name
error C2653: 'vector<class CMyTrailer,class std::allocator<class CMyTrailer> >' : is not a class or namespace name
error C2955: 'iterator' : use of class template requires template argument list
Here's my vector declaration:
vector<CMyTrailer> TRL_MFG;
vector<CMyTrailer>::iterator TRL_ITItem;
Can any one help, Please!
-- modified at 14:17 Monday 19th November, 2007
A C++ programming language novice, but striving to learn
|
|
|
|
|
Did you include the file where CMyTrailer is declared in the file where you are declaring your vector ?
|
|
|
|
|
I think the answer is yes: here's the header:
// Trailer.h
#if !defined(AFX_TRAILER_H)
#define AFX_TRAILER_H
#include "MyTrailer.h"
#include <vector>
using std::vector;
using std::copy;
using std::iterator;
using std::string;
class CTrailer {
public:
CTrailer(int nIsPage=0);
~CTrailer();
// Varables:
// Vectors:
// Setup vectors:
vector<CMyTrailer> TRL_ITEM;
vector<CMyTrailer> TRL_MFG;
vector<CMyTrailer> TRL_ID;
vector<CMyTrailer>::iterator TRL_ITItem;
vector<CMyTrailer>::iterator TRL_ITMFG;
vector<CMyTrailer>::iterator TRL_ITID;
vector<CMyTrailer> m_vITEM; // Item
vector<CMyTrailer> m_MFG; // MFG vector
vector<CMyTrailer> m_IDNUM; // Part#/ID#
// Iterators:
vector<CMyTrailer>::iterator m_ITItem;
vector<CMyTrailer>::iterator m_ITMFG;
vector<CMyTrailer>::iterator m_ITID;
//Functions:
};
#endif
-- modified at 21:55 Monday 19th November, 2007
A C++ programming language novice, but striving to learn
|
|
|
|
|
Hi
Put this code
using namespace std;
instead of
using std::vector;
using std::copy;
using std::iterator;
using std::string;
and I hope it works fine.
Warm Regards
Bhawna
|
|
|
|
|
I never use using namespace in a header file. This will 'propagate' the namespace across all files that include this specific header file, leading to potential conflicts. In header files, I just put the namespace with the class declaration:
std::vector<MyClass> ....
|
|
|
|
|
Use this code
using std::vector<CMyTrailer>;
Thanks
Bhawna
|
|
|
|
|
Hi,
I have the following code:
typedef std::map<std::string, std::string> MyMapType;
MyMapType myMap;
myMap["abc"] = "def";
This works as expected. But I want my map to be on the heap, so I tried this:
MyMapType *myNewMap = new MyMapType;
myNewMap["abc"] = "def";
*myNewMap["abc"] = "def";
The two lines are commented with the compile time errors it generates. What have I missed?
- Dy
|
|
|
|
|
A pair of braces:
(*myNewMap)["abc"] = "def";
compiles well.
BTW, you also missed to properly format your code (have a look at typedef statement in the OP).
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.
|
|
|
|
|
CPallini wrote: A pair of braces
D'oh! Thanks very much for helping me out.
- Dy
|
|
|
|
|
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.
|
|
|
|
|
Hello,
i have a ms access database, there is information written in cyrillic encoding. When i read the text from c++ using Ado, it cannt read proper text, it reads only "???????????????", what should i do to read correct text in c++?
here is the code
<br />
CString strItem; <br />
strItem = (char *) (_bstr_t) pRecordPtr->Fields->GetItem("name")->Value;<br />
strItem is "?????" if when encoding is cyrillic.
thanks
|
|
|
|