GetRValue

This is a discussion on GetRValue within the Windows Programming forums, part of the Platform Specific Boards category; I need to use the GetRValue macro but it gives me the wrong values. Same with the GetBValue and GetGValue. ...

  1. #1
    Registered User cppdude's Avatar
    Join Date
    Jan 2002
    Posts
    62

    GetRValue

    I need to use the GetRValue macro but it gives me the wrong values. Same with the GetBValue and GetGValue. They all give me 255 as the colour value which is totally wrong. Any ideas?

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789

    Re: GetRValue

    Originally posted by cppdude
    I need to use the GetRValue macro but it gives me the wrong values. Same with the GetBValue and GetGValue. They all give me 255 as the colour value which is totally wrong. Any ideas?
    Chances are you are passing the wrong values....

    You would normally pass a COLORREF into each of these macros and in return you would get an 8bit BYTE valure representing the colour value......

    Can you give a little more code to show what you are really doing?

  3. #3
    Registered User cppdude's Avatar
    Join Date
    Jan 2002
    Posts
    62
    COLORREF rc1 = GetRValue(pixelcolourFF);
    COLORREF gc1 = GetGValue(pixelcolourFF);
    COLORREF bc1 = GetBValue(pixelcolourFF);

    that is what i was doing

  4. #4
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    No.....pass the COLORREF into the Macro;

    Code:
    COLORREF myColAbsolute = RGB(35,56,97);//Create a defined colourref
    
    cout << "Red - " << (int)GetRValue(myColAbsolute) << endl;
    cout << "Green - " << (int)GetGValue(myColAbsolute) << endl;
    cout << "Blue - " << (int)GetBValue(myColAbsolute) << endl;
    The return is an 8bit variable (BYTE) which of course only had 256 possible values...this is each individual colour

  5. #5
    Registered User cppdude's Avatar
    Join Date
    Jan 2002
    Posts
    62
    hang on sorry - that wasnt what i was doing. I was doing this:

    int rc1 = GetRValue(myCOLORREF);

    and it doesnt work.

  6. #6
    Registered User cppdude's Avatar
    Join Date
    Jan 2002
    Posts
    62
    yes you guys are meant to reply to this plz. I keep getting the wrong int R or G or B integer.

  7. #7
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Originally posted by cppdude
    yes you guys are meant to reply to this plz. I keep getting the wrong int R or G or B integer.
    Oh...I thought this was sorted......

    I suggest you post more code to give an idea where this could be failing....

  8. #8
    Registered User cppdude's Avatar
    Join Date
    Jan 2002
    Posts
    62
    ScreenDC = GetDC(GetForegroundWindow()); //during initialisation - get a DC to the game window


    pixelcolourFF = GetPixel(ScreenDC, (GetDeviceCaps(ScreenDC,HORZRES) / 2) -2, (GetDeviceCaps(ScreenDC,VERTRES) / 2) -1); //during a WM_TIMER message

    int rc1 = GetRValue(pixelcolourFF); //also during WM_TIMER to check for target
    int gc1 = GetGValue(pixelcolourFF);
    int bc1 = GetBValue(pixelcolourFF);

    /* as you might have guessed this is for an autofire bot. I check the int values and they are all 255 all the time. very frustrating.

  9. #9
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Have you tried casting the actual return as I did in my example earlier?



    Code:
    ScreenDC = GetDC(GetForegroundWindow()); //during initialisation - get a DC to the game window
    
    
    pixelcolourFF = GetPixel(ScreenDC, (GetDeviceCaps(ScreenDC,HORZRES) / 2) -2, (GetDeviceCaps(ScreenDC,VERTRES) / 2) -1); //during a WM_TIMER message
    
    int rc1 = (int)GetRValue(pixelcolourFF); //also during WM_TIMER to check for target
    int gc1 = (int)GetGValue(pixelcolourFF);
    int bc1 = (int)GetBValue(pixelcolourFF);
    I havent tested it mind you...give it a go and come back with the result

  10. #10
    Registered User cppdude's Avatar
    Join Date
    Jan 2002
    Posts
    62
    made no difference. GetRValue( returns an iteger anyway so the int cast is pointless. should i post my entire code? its not that long.

  11. #11
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Originally posted by cppdude
    made no difference. GetRValue( returns an iteger anyway so the int cast is pointless. should i post my entire code? its not that long.
    No....GetRValue returns a BYTE....not an int......

    Ah well...yeah you could post the code...the I will try load it and have a closer look

  12. #12
    Registered User cppdude's Avatar
    Join Date
    Jan 2002
    Posts
    62
    Code:
    #include <windows.h>
    #include "resource.h"
    #include <stdio.h> //for sprintf - puts integers into strings
    
    #define UFOVTIMER 1
    
    BOOL CALLBACK DialogProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
    BOOL CALLBACK AboutProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
    int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, char * cmdParam, int cmdShow);
    
    char buffer[11]; //used for lots of things
    int onoff = 0; //whether the Scope is on
    
    HINSTANCE hInst;
    HDC ScreenDC;
    HWND g_hwnd;
    
    COLORREF pixelcolour1, pixelcolour2, pixelcolourFF = RGB(0,0,0);
    
    int rc1, gc1, bc1, rc2, gc2, bc2 , errorcode;
    
    //--------------------------------------------------------------------------------------------
    BOOL CALLBACK DialogProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        switch (message)
    	{	
    		
    	case WM_INITDIALOG:
    		{	
    			SetDlgItemText(hwnd, IDC_STATUS, "Inactive");
    		
    			SetDlgItemText(hwnd, IDC_HOTKEY, "F12");
    			
    
    			
    			SetTimer(hwnd, UFOVTIMER, 200, NULL);
    			g_hwnd = hwnd;
    			return TRUE;
    		}
    		
    	case WM_TOGGLE:
    		{
    			if(onoff)
    			{
    				SetDlgItemText(hwnd, IDC_STATUS, "Inactive");
    				ReleaseDC(GetForegroundWindow(), ScreenDC);
    				onoff = 0;
    
    				//sprintf(buffer, "%i", errorcode);
    				//MessageBox(NULL, buffer, "NOTE", MB_OK);
    				sprintf(buffer, "red %i", rc1);
    				MessageBox(NULL, buffer, "NOTE", MB_OK);
    				sprintf(buffer, "green %i", gc1);
    				MessageBox(NULL, buffer, "NOTE", MB_OK);
    				sprintf(buffer, "blue %i", bc1);
    				MessageBox(NULL, buffer, "NOTE", MB_OK);
    			}
    			else
    			{	
    				SetDlgItemText(hwnd, IDC_STATUS, "Active");				
    				ScreenDC = GetDC(GetForegroundWindow());
    				onoff = 1;
    			}	
    			SetTimer(g_hwnd, UFOVTIMER, 200, NULL); //slow so toggle block does not run millions of times with one press
    			return TRUE;
    		}	
    		
    	case WM_COMMAND:
    		{
    			switch (LOWORD(wParam))
    			{
    				
    			case IDQUIT:
    				{
    					PostQuitMessage(0);
    					break;
    				}
    			case IDCANCEL:
    				{
    					PostQuitMessage(0);
    					break;
    				}
    			case IDABOUT:
    				{
    					DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUT), hwnd, (DLGPROC)AboutProc);
    					break;
    				} 
    			case IDC_HOTKEY:
    				{
    					
    					break;
    				}
    			} //switch loword(wParam)
    			return TRUE;
    		} //case WM_COMMAND
    		
    	case WM_QUIT:
    		{
    			KillTimer(g_hwnd, UFOVTIMER);
    			ReleaseDC(GetForegroundWindow(), ScreenDC);	
    			EndDialog(g_hwnd,NULL);
    			return TRUE;
    		}
    		
    	case WM_TIMER:
    		{	
    			switch(wParam)
    			{
    			case UFOVTIMER:
    				{	
    					if(onoff)
    					{
    						pixelcolourFF = GetPixel(ScreenDC, (GetDeviceCaps(ScreenDC,HORZRES) / 2) -2, (GetDeviceCaps(ScreenDC,VERTRES) / 2) -1);
    						
    						
    						rc1 = (int)GetRValue(pixelcolourFF);
    						gc1 = (int)GetGValue(pixelcolourFF);
    						bc1 = (int)GetBValue(pixelcolourFF);
    
    					
    						if((rc1 < 256) && (rc1 > 180) && (gc1 < 11) && (gc1 >= 0) && (bc1 < 11) && (bc1 >= 0)) //if centre is red then break;
    							{
    								MessageBox(NULL,"RED!!!", "NOTE", MB_OK);
    								mouse_event(MOUSEEVENTF_LEFTDOWN, 1, 1, 0,0);
    								return TRUE;
    							}
    					
    						
    
    					} //if(onoff)
    					
    					if(GetFocus() == g_hwnd) //check if the keyboard focus is on our dialog. GetFocus returns null if focus is on another application, inwhich case we set the focus to our dialog
    					{
    						SetFocus(g_hwnd); //so the async thingy will work
    					}
    					if(GetAsyncKeyState(VK_F12))
    					{
    						SendMessage(g_hwnd, WM_TOGGLE,0,0);
    					}
    					else
    					{
    						SetTimer(hwnd, UFOVTIMER, 1, NULL); //to send the next timer message - fast so that drawing on screen is good
    					}
    				} //case UFOVTIMER
    
    			} //switch(wParam)
    			
    		} //case WM_TIMER
    		} //(switch(message)
    		return FALSE;
    }
    //--------------------------------------------------------------------------------------------
    BOOL CALLBACK AboutProc(HWND habout, UINT message, WPARAM wParam, LPARAM lParam) //message handler for the about box
    {
    	switch(message)
    	{
    	case WM_COMMAND:
    		{
    			if (LOWORD(wParam) == IDOK || IDCANCEL)
    			{
    				EndDialog(habout, LOWORD(wParam));
    				return TRUE;
    			}
    			return FALSE;
    		}
    	}
        return FALSE;
    }
    //--------------------------------------------------------------------------------------------
    int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, char * cmdParam, int cmdShow)
    {
    	DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG), 0, (DLGPROC)DialogProc);
    	return TRUE;
    }
    That message box stuff in WM_TOGGLE is how i check the GetRValue return values.

  13. #13
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Can you post the resource too.....

  14. #14
    Registered User cppdude's Avatar
    Join Date
    Jan 2002
    Posts
    62
    ok here is my VC++ project.
    Attached Files Attached Files

  15. #15
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Hmm....havent worked out your code yet totally....

    But I added a little error error catch;

    Code:
    if(pixelcolourFF == CLR_INVALID)
         MessageBox(0,"Invalid","",MB_OK);
    And the messagebox apperaed....therefore the error is most likely not with GetRValue and the others..........

    I will try to look further to catch the error.....but you would use time more wisely to look at other possible errors

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21