Click here to Skip to main content
15,512,456 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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


C++
#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
Updated 17-Jul-12 3:51am
v3
Comments
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?
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?
Maximilien 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 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 17-Jul-12 8:56am    
Do you wanna capture the cursor information or the cursor image ?

1 solution

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


Good luck!
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900