473,508 Members | 2,229 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Bitmap help

I am passing in a reference to a window handle, followed by the height
and width as well into my method. I am then creating a Device Context
using the window handle and converting the window in a bitmap saved in
memory. What I am trying to accomplish is generating a checksum value
and returning that value from the bitmap stored in memory, but I cannot
solve this problem. The method is designed to given a window handle,
height, and width, take an image of the window, and return the checksum
value. I am trying to check to see if the window changes by using the
checksum values. Any help with this method and problem is greatly
appreciated! Please see the code below for what I have done so far!
STDMETHODIMP CCaptureBitmap::BitmapResult(DWORD hWnd, int height, int
width, long *pIndex)
{
HDC hdc, hdcMem;
HBITMAP bitmap;
int y = 0;
y = (4 * height) / 5;
hdc = GetDC((HWND)hWnd);
hdcMem = CreateCompatibleDC(hdc);
bitmap = CreateCompatibleBitmap(hdcMem, width, height);
SelectObject(hdcMem, bitmap);
BitBlt(hdcMem, 0, 0, width, y, hdc, 0, 0, SRCCOPY);

//Need to add code here to generate checksum value.

ReleaseDC((HWND)hWnd, hdc);
return S_OK;
}

Nov 13 '06 #1
9 1849
this doesn't sound like a generic c++ question, rather than a win32 api
question.

Nov 13 '06 #2
Kodiak wrote:
I am passing in a reference to a window handle, followed by the height
and width as well into my method. I am then creating a Device Context
using the window handle and converting the window in a bitmap saved in
memory. What I am trying to accomplish is generating a checksum value
and returning that value from the bitmap stored in memory, but I cannot
solve this problem. The method is designed to given a window handle,
height, and width, take an image of the window, and return the checksum
value. I am trying to check to see if the window changes by using the
checksum values. Any help with this method and problem is greatly
appreciated! Please see the code below for what I have done so far!
STDMETHODIMP CCaptureBitmap::BitmapResult(DWORD hWnd, int height, int
width, long *pIndex)
{
HDC hdc, hdcMem;
HBITMAP bitmap;
int y = 0;
y = (4 * height) / 5;
hdc = GetDC((HWND)hWnd);
hdcMem = CreateCompatibleDC(hdc);
bitmap = CreateCompatibleBitmap(hdcMem, width, height);
SelectObject(hdcMem, bitmap);
BitBlt(hdcMem, 0, 0, width, y, hdc, 0, 0, SRCCOPY);

//Need to add code here to generate checksum value.

ReleaseDC((HWND)hWnd, hdc);
return S_OK;
}
Your question does not appear to be related to the C++ language proper,
which is the topic of this group (see
http://www.parashift.com/c++-faq-lit....html#faq-5.9). You
may want to ask in comp.programming (for general algorithmic questions)
or a Microsoft group (for help with their API and frameworks). Of
course, if during your development, you come upon a question about the
language itself, this is the right place to ask.

Cheers! --M

Nov 13 '06 #3
I posted to this group because I am developing the code using C++.

mlimber wrote:
Kodiak wrote:
I am passing in a reference to a window handle, followed by the height
and width as well into my method. I am then creating a Device Context
using the window handle and converting the window in a bitmap saved in
memory. What I am trying to accomplish is generating a checksum value
and returning that value from the bitmap stored in memory, but I cannot
solve this problem. The method is designed to given a window handle,
height, and width, take an image of the window, and return the checksum
value. I am trying to check to see if the window changes by using the
checksum values. Any help with this method and problem is greatly
appreciated! Please see the code below for what I have done so far!
STDMETHODIMP CCaptureBitmap::BitmapResult(DWORD hWnd, int height, int
width, long *pIndex)
{
HDC hdc, hdcMem;
HBITMAP bitmap;
int y = 0;
y = (4 * height) / 5;
hdc = GetDC((HWND)hWnd);
hdcMem = CreateCompatibleDC(hdc);
bitmap = CreateCompatibleBitmap(hdcMem, width, height);
SelectObject(hdcMem, bitmap);
BitBlt(hdcMem, 0, 0, width, y, hdc, 0, 0, SRCCOPY);

//Need to add code here to generate checksum value.

ReleaseDC((HWND)hWnd, hdc);
return S_OK;
}

Your question does not appear to be related to the C++ language proper,
which is the topic of this group (see
http://www.parashift.com/c++-faq-lit....html#faq-5.9). You
may want to ask in comp.programming (for general algorithmic questions)
or a Microsoft group (for help with their API and frameworks). Of
course, if during your development, you come upon a question about the
language itself, this is the right place to ask.

Cheers! --M
Nov 13 '06 #4
* Kodiak:
[top-posting]
Please don't.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Nov 13 '06 #5
Kodiak wrote:
>I posted to this group because I am developing the code using C++.
Win32 API code can be called from any language, and this newsgroup is only
qualified to discuss the raw C++ language itself. You will get much better
results posting to the narrowest possible newsgroup.

However, you didn't specify exactly what your problem actually is. (It could
still be a C++ question, even with all these HWND things going on!) You
might be having trouble between reading the bitmap and extracting its bits
as data. That would be Win32-side, not C++ side!
What I am trying to accomplish is generating a checksum value
and returning that value from the bitmap stored in memory, but I cannot
solve this problem.
The problem of what, the checksum?
BitBlt(hdcMem, 0, 0, width, y, hdc, 0, 0, SRCCOPY);
Now you need to get to the memory backing up the hdcMem, and point into it
with (probably) an unsigned char pointer.

If this code were on-topic, I could explain to you what it does. It is
enough to get you googling - copying the bits out of a bitmap is a FAQ on
Win32 graphics programming forums.

HBITMAP hOld = ( HBITMAP ) SelectObject( hMemDC, hBitmap );
assert( hOld );

worked = BitBlt( hMemDC, 0, 0, size.cx, size.cy, hDC, 0, 0, SRCCOPY );
assert( worked );

HGLOBAL_t storage = GlobalAlloc( GMEM_FIXED, pbih->biSizeImage );
LPBYTE lpBits = static_cast< LPBYTE >( (HGLOBAL)storage );

assert( lpBits );

// Retrieve the color table (RGBQUAD array) and the bits
// (array of palette indices) from the DIB.
BOOL worked = GetDIBits( hDC, hBMP, 0, pbih->biHeight, lpBits, pbi,
DIB_RGB_COLORS );

Note that if I tried to explain those and got anything wrong, _this_
newsgroup would not be qualified to correct me.

After you have the bits in lpBits, you need to Google for a code snippet
that shows how to generate a checksum, and you need to adapt that code to
the LPBYTE.

--
Phlip
http://www.greencheese.us/ZeekLand <-- NOT a blog!!!
Nov 13 '06 #6
Thanks phillip for pointing me in the right direction. I due apologize
for posting to the wrong newsgroup.

Phillip my probem was trying to get the bytes out of the bitmap.

Phlip wrote:
Kodiak wrote:
I posted to this group because I am developing the code using C++.

Win32 API code can be called from any language, and this newsgroup is only
qualified to discuss the raw C++ language itself. You will get much better
results posting to the narrowest possible newsgroup.

However, you didn't specify exactly what your problem actually is. (It could
still be a C++ question, even with all these HWND things going on!) You
might be having trouble between reading the bitmap and extracting its bits
as data. That would be Win32-side, not C++ side!
What I am trying to accomplish is generating a checksum value
and returning that value from the bitmap stored in memory, but I cannot
solve this problem.

The problem of what, the checksum?
BitBlt(hdcMem, 0, 0, width, y, hdc, 0, 0, SRCCOPY);

Now you need to get to the memory backing up the hdcMem, and point into it
with (probably) an unsigned char pointer.

If this code were on-topic, I could explain to you what it does. It is
enough to get you googling - copying the bits out of a bitmap is a FAQ on
Win32 graphics programming forums.

HBITMAP hOld = ( HBITMAP ) SelectObject( hMemDC, hBitmap );
assert( hOld );

worked = BitBlt( hMemDC, 0, 0, size.cx, size.cy, hDC, 0, 0, SRCCOPY );
assert( worked );

HGLOBAL_t storage = GlobalAlloc( GMEM_FIXED, pbih->biSizeImage );
LPBYTE lpBits = static_cast< LPBYTE >( (HGLOBAL)storage );

assert( lpBits );

// Retrieve the color table (RGBQUAD array) and the bits
// (array of palette indices) from the DIB.
BOOL worked = GetDIBits( hDC, hBMP, 0, pbih->biHeight, lpBits, pbi,
DIB_RGB_COLORS );

Note that if I tried to explain those and got anything wrong, _this_
newsgroup would not be qualified to correct me.

After you have the bits in lpBits, you need to Google for a code snippet
that shows how to generate a checksum, and you need to adapt that code to
the LPBYTE.

--
Phlip
http://www.greencheese.us/ZeekLand <-- NOT a blog!!!
Nov 13 '06 #7
Kodiak wrote:
mlimber wrote:
Your question does not appear to be related to the C++ language proper,
which is the topic of this group (see
http://www.parashift.com/c++-faq-lit....html#faq-5.9). You
may want to ask in comp.programming (for general algorithmic questions)
or a Microsoft group (for help with their API and frameworks). Of
course, if during your development, you come upon a question about the
language itself, this is the right place to ask.

I posted to this group because I am developing the code using C++.
[Top-posting corrected. Cf.
http://parashift.com/c++-faq-lite/ho....html#faq-5.4]

As the FAQ I cited in my previous response explains, this newsgroup is
for discussing the *language* as defined by the C++ Standard, not
platform-specific libraries or arbitrary applications of the language.
Asking "How do I convert Yen to Dollars?", for instance, is also
off-topic (even if you were intending to perform the conversion in a
C++ program) because the question deals with an algorithm that is not
part of the standard language or library.

Cheers! --M

Nov 13 '06 #8
Kodiak wrote:
I posted to this group because I am developing the code using C++.
Assuming that Minesweeper is written in C++, and that Word is written in
C++, would you then feel it appropriate to post questions about
Minesweeper or Word here?
Nov 13 '06 #9
red floyd wrote:
Kodiak wrote:
>I posted to this group because I am developing the code using C++.

Assuming that Minesweeper is written in C++, and that Word is written in
C++, would you then feel it appropriate to post questions about
Minesweeper or Word here?
That's a flawed analogy. You need to formulate one that involves a
something akin to USING C++ and not being relevant to this group.
Nov 14 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
16812
by: VicVic | last post by:
Hello Experts, I have 3 questions about Image and Bitmap, and hope you can help me. 1. Could any one tell me the difference between Image and Bitmap? I did take a look of the 2 classes, but...
5
7348
by: Lance | last post by:
I need to create a Drawing.Bitmap from an array of integer values. My current technique creates a bitmap that eventually becomes corrupt (i.e., the bitmap's pixels change to a different color...
8
3297
by: Nathan Sokalski | last post by:
I am trying to write code to rotate a graphic that I have. Here is the code I am currently using: Dim frogbitmap As New Bitmap(Drawing.Image.FromFile(Server.MapPath("images/frog.gif"))) Dim...
7
2287
by: Nathan Sokalski | last post by:
I am having a problem saving an image with the same name it originally had. I have two similar versions of my code, one in which I close the FileStream used to open the original image before saving,...
15
1811
by: Hamed | last post by:
Have I posted the message to wrong newsgroup? Or Does the question is so much strage? Would someone please kindly direct me to a true newsgroup or resource? Best Regards Hamed
0
2592
by: news.microsoft.com | last post by:
Hi guys, This text looks long and complicate but it is not, and I really really need some help here. For the last 24hs I'm trying to resolve this issue (last night I dreamed
14
11861
by: eliss.carmine | last post by:
I'm using TCP/IP to send a Bitmap object over Sockets. This is my first time using C# at all so I don't know if this is the "right" way to do it. I've already found out several times the way I was...
9
1915
by: poifull | last post by:
Hi All, I have the following task: 1. create an image object in memory (a rectangle with nothing on it) 2. write some text on the rectangle 3. rotate the image 90 degree 4. save the image to a...
0
7129
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7333
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7061
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5637
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5057
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4716
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3194
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1566
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
769
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.