Click here to Skip to main content
Rate this: bad
good
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>
#include<windows.h>
using namespace std;
 
int _tmain(int argc, _TCHAR* argv[])
{
	 HBITMAP hbitmap;
	 BITMAP bitmap;
	 BITMAPINFO bmi;
	 HDC hdcScreen = GetDC(NULL);
	 HDC hdcMem = CreateCompatibleDC(hdcScreen);
 
	 CURSORINFO cursorInfo = { 0 };
         cursorInfo.cbSize = sizeof(cursorInfo);
	 
	 GetCursorInfo(&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++){
		 cout<<bmi.bmiColors[i].rgbBlue;
	 }
 
	 std::getchar();
	 return 0;
}</windows.h></iostream>
Posted 17-Jul-12 1:17am
Edited 17-Jul-12 2:51am
TorstenH.33.7K
v3
Comments
Code-o-mat at 17-Jul-12 8:21am
   
Not completely sure what the actual question is. Printing the numbers in hexadecimal is all you want?
lakshman udayakantha at 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?
Maximilien at 17-Jul-12 8:48am
   
You wan to use the cursor of an application (that you don't own?) in a Java application ?
lakshman udayakantha at 17-Jul-12 9:24am
   
yes.but getting the cursor should happen in c or c++ because of the speed is a concern
Malli_S at 17-Jul-12 8:56am
   
Do you wanna capture the cursor information or the cursor image ?
lakshman udayakantha at 17-Jul-12 9:21am
   
I want to capture the cursor image
Malli_S at 19-Jul-12 13:21pm
   
Then you should better look into BitBlt function. That's what you need.

1 solution

Rate this: bad
good
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!
  Permalink  

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



Advertise | Privacy | Mobile
Web04 | 2.8.141022.2 | Last Updated 17 Jul 2012
Copyright © CodeProject, 1999-2014
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