Click here to Skip to main content
12,818,050 members (37,683 online)
Rate this:
Please Sign up or sign in to vote.
See more: C++ image Bitmap Mouse
In my application I want to write a function that capture the mouse cursor image and return it as a buffered image(I hope to use that buffered image to receive from a java application via jni to construct the image for later use). I used below code snippet to get the mouse cursor image. bmi variable will get the image color information. I printed blue component of RGB color information of cursor bit map. I got binary like result in console. I should get hexdecimal values.shouldn't I?what is the wrong in my code according to my purpose here? can someone pointed me how to get the buffered image so that I can construct it in java application

#include "stdafx.h"
#include <iostream>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
	 HBITMAP hbitmap;
	 BITMAP bitmap;
	 HDC hdcScreen = GetDC(NULL);
	 HDC hdcMem = CreateCompatibleDC(hdcScreen);

	 CURSORINFO cursorInfo = { 0 };
         cursorInfo.cbSize = sizeof(cursorInfo);
	 ICONINFO ii = {0};
	 GetIconInfo(cursorInfo.hCursor, &ii);
	 hbitmap = ii.hbmColor;	
	 SelectObject(hdcMem, hbitmap);
	 GetObject(hbitmap, sizeof(BITMAP), &bitmap);

	 GetDIBits(hdcMem, hbitmap, 0, 32, NULL, &bmi, DIB_RGB_COLORS);

	 for(int i = 0;i<4096;i++){

	 return 0;
Posted 17-Jul-12 2:17am
Updated 17-Jul-12 3:51am
Code-o-mat 17-Jul-12 8:21am
Not completely sure what the actual question is. Printing the numbers in hexadecimal is all you want?
Maximilien 17-Jul-12 8:48am
You wan to use the cursor of an application (that you don't own?) in a Java application ?
Malli_S 17-Jul-12 8:56am
Do you wanna capture the cursor information or the cursor image ?
lakshman udayakantha 17-Jul-12 9:21am
I want to capture the cursor image
lakshman udayakantha 17-Jul-12 9:24am
yes.but getting the cursor should happen in c or c++ because of the speed is a concern
lakshman udayakantha 17-Jul-12 9:36am
nope. I posted all the work I have done so far. but the result is unexpected. so I want to know what is wrong in my code?
Malli_S 19-Jul-12 13:21pm
Then you should better look into BitBlt function. That's what you need.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

The following should give you hex values:
cout << hex << bmi.bmiColors[i].rgbBlue;

Good luck!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170308.1 | Last Updated 17 Jul 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100