Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > Coding Releases > Coding Snippets
You last visited: Today at 05:16

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



Find the Bitmapcursor you need Class C++

Discussion on Find the Bitmapcursor you need Class C++ within the Coding Snippets forum part of the Coding Releases category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Apr 2014
Posts: 2
Received Thanks: 5
Post Find the Bitmapcursor you need Class C++

Heya Another post,

This class will find any bitmap cursor you specify in Resources as ID_BITMAP_1.

I removed some code, but I guess you will figure out how it get going.

KEEP IN MIND I did not compile this code for months And some parts are Removed.

Here we Go:

Header :

Code:
#include "resource.h"
#include <Windows.h>
#include <iostream>

using namespace std;
class CCursor
{
private:
	HBITMAP FloatOrg;

	bool CompareBitmaps(HBITMAP HBitmapLeft, HBITMAP HBitmapRight);

	bool CompareCursors();
public:
	

	CCursor(void);
	~CCursor(void);
}
Cpp File

Code:
#include "CCursor.h"

CCursor::CCursor(void)
{
	FloatOrg = LoadBitmap (GetModuleHandle(NULL),  MAKEINTRESOURCE (IDB_BITMAP1));
}
bool CCursor::CompareCursors()
{
	HBITMAP curCursor ;

	CURSORINFO cursorInfo = { 0 };
	cursorInfo.cbSize = sizeof(cursorInfo);

	GetCursorInfo(&cursorInfo);
	ICONINFO ii = {0};
	GetIconInfo(cursorInfo.hCursor, &ii);
	curCursor =	 ii.hbmColor;
	if(CompareBitmaps(FloatOrg,curCursor))
	{
     	curCursor= NULL;
		return true;
	}
	else
	{
		curCursor= NULL;
		return false;
	}
}

bool CCursor::CompareBitmaps(HBITMAP HBitmapLeft, HBITMAP HBitmapRight)
{
	if (HBitmapLeft == HBitmapRight)
    {
        return true;
    }

    if (NULL == HBitmapLeft || NULL == HBitmapRight)
    {
        return false;
    }

    bool bSame = false;

    HDC hdc = GetDC(NULL);
    BITMAPINFO BitmapInfoLeft = {0};
    BITMAPINFO BitmapInfoRight = {0};

    BitmapInfoLeft.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    BitmapInfoRight.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);

    if (0 != GetDIBits(hdc, HBitmapLeft, 0, 0, NULL, &BitmapInfoLeft, DIB_RGB_COLORS) &&
        0 != GetDIBits(hdc, HBitmapRight, 0, 0, NULL, &BitmapInfoRight, DIB_RGB_COLORS))
    {
        // Compare the BITMAPINFOHEADERs of the two bitmaps

        if (0 == memcmp(&BitmapInfoLeft.bmiHeader, &BitmapInfoRight.bmiHeader, 
            sizeof(BITMAPINFOHEADER)))
        {
            // The BITMAPINFOHEADERs are the same so now compare the actual bitmap bits

            BYTE *pLeftBits = new BYTE[BitmapInfoLeft.bmiHeader.biSizeImage];
            BYTE *pRightBits = new BYTE[BitmapInfoRight.bmiHeader.biSizeImage];
            BYTE *pByteLeft = NULL;
            BYTE *pByteRight = NULL;

            PBITMAPINFO pBitmapInfoLeft = &BitmapInfoLeft;
            PBITMAPINFO pBitmapInfoRight = &BitmapInfoRight;

            // calculate the size in BYTEs of the additional

            // memory needed for the bmiColor table

            int AdditionalMemory = 0;
            switch (BitmapInfoLeft.bmiHeader.biBitCount)
            {
            case 1:
                AdditionalMemory = 1 * sizeof(RGBQUAD);
                break;
            case 4:
                AdditionalMemory = 15 * sizeof(RGBQUAD);
                break;
            case 8:
                AdditionalMemory = 255 * sizeof(RGBQUAD);
                break;
            case 16:
            case 32:
                AdditionalMemory = 2 * sizeof(RGBQUAD);
            }

            if (AdditionalMemory)
            {
                // we have to allocate room for the bmiColor table that will be

                // attached to our BITMAPINFO variables

                pByteLeft = new BYTE[sizeof(BITMAPINFO) + AdditionalMemory];
                if (pByteLeft)
                {
                    memset(pByteLeft, 0, sizeof(BITMAPINFO) + AdditionalMemory);
                    memcpy(pByteLeft, pBitmapInfoLeft, sizeof(BITMAPINFO));
                    pBitmapInfoLeft = (PBITMAPINFO)pByteLeft;
                }

                pByteRight = new BYTE[sizeof(BITMAPINFO) + AdditionalMemory];
                if (pByteRight)
                {
                    memset(pByteRight, 0, sizeof(BITMAPINFO) + AdditionalMemory);
                    memcpy(pByteRight, pBitmapInfoRight, sizeof(BITMAPINFO));
                    pBitmapInfoRight = (PBITMAPINFO)pByteRight;
                }
            }

            if (pLeftBits && pRightBits && pBitmapInfoLeft && pBitmapInfoRight)
            {
                // zero out the bitmap bit buffers

                memset(pLeftBits, 0, BitmapInfoLeft.bmiHeader.biSizeImage);
                memset(pRightBits, 0, BitmapInfoRight.bmiHeader.biSizeImage);

                // fill the bit buffers with the actual bitmap bits

                if (0 != GetDIBits(hdc, HBitmapLeft, 0, 
                    pBitmapInfoLeft->bmiHeader.biHeight, pLeftBits, pBitmapInfoLeft, 
                    DIB_RGB_COLORS) && 0 != GetDIBits(hdc, HBitmapRight, 0, 
                    pBitmapInfoRight->bmiHeader.biHeight, pRightBits, pBitmapInfoRight, 
                    DIB_RGB_COLORS))
                {
                    // compare the actual bitmap bits of the two bitmaps

                    bSame = 0 == memcmp(pLeftBits, pRightBits, 
                        pBitmapInfoLeft->bmiHeader.biSizeImage);
                }
            }

            // clean up

            delete[] pLeftBits;
            delete[] pRightBits;
            delete[] pByteLeft;
            delete[] pByteRight;
        }
    }

    ReleaseDC(NULL, hdc);

    return bSame;
}
oxie is offline  
Thanks
1 User
Reply


Similar Threads Similar Threads
Kbot Could not find the main class:ibot/Main FiX [Solution]
07/02/2013 - DarkOrbit - 5 Replies
https://www.youtube.com/watch?v=mzbJku4eo8s https://www.youtube.com/watch?v=455ViRNL0n4
[JAVA] .jar-File [,,Could not find the main class - program will exit"]
10/28/2011 - General Coding - 6 Replies
Hallo. Habe heute mit Eclipse eine kleine GUI (swing) Anwendung geschrieben und wollte diese in ein .jar.Archiv packen. (IDE : eclipse). Nun suche ich schon seit Stunden nach einer Lösung für das Problem, denn wenn ein Freund von mir auf seinem Rechner diese jar Datei starten möchte, erscheint die Fehlermeldung : "could not find the main class - program will exit". Vllt. weiß jemand von euch weiter... lg



All times are GMT +1. The time now is 05:17.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.