Results 1 to 4 of 4
  1. #1
    .:Dark Angel:.'s Avatar
    Join Date
    Aug 2009
    Gender
    male
    Location
    In your computer
    Posts
    23
    Reputation
    10
    Thanks
    5
    My Mood
    Tired

    How to make a crosshair in c++

    Plese if u can show me the code please

  2. #2
    Pixipixel_'s Avatar
    Join Date
    Oct 2009
    Gender
    male
    Location
    VCExpress.exe || France :D
    Posts
    2,087
    Reputation
    27
    Thanks
    742
    My Mood
    Cool
    Globals :

    float ScreenCenterX = 0.0f;
    float ScreenCenterY = 0.0f;
    bool crosshair = false;
    D3DCOLOR redt = D3DCOLOR_XRGB( 255, 0, 0 );


    SetViewport :

    ScreenCenterX = ( float )pViewport->Width / 2;
    ScreenCenterY = ( float )pViewport->Height / 2;

    Endscene :

    if(xhair)
    {
    D3DRECT rec2 = {ScreenCenterX-20, ScreenCenterY, ScreenCenterX+ 20, ScreenCenterY+2};
    D3DRECT rec3 = {ScreenCenterX, ScreenCenterY-20, ScreenCenterX+ 2,ScreenCenterY+20};

    m_pD3Ddev->Clear(1, &rec2, D3DCLEAR_TARGET,redt, 0, 0);
    m_pD3Ddev->Clear(1, &rec3, D3DCLEAR_TARGET,redt, 0, 0);



    Don't forget to press thanks if i helped =)


  3. The Following 5 Users Say Thank You to Pixipixel_ For This Useful Post:

    .:Dark Angel:. (10-27-2009),edu_dudu (12-11-2009),hackerman9212 (04-14-2019),headsup (10-27-2009),Lauri (01-14-2012)

  4. #3
    .:Dark Angel:.'s Avatar
    Join Date
    Aug 2009
    Gender
    male
    Location
    In your computer
    Posts
    23
    Reputation
    10
    Thanks
    5
    My Mood
    Tired
    Thanks man but what i need to include windows.h or what tell me all the code okay and i will add u a rep+
    Last edited by .:Dark Angel:.; 10-27-2009 at 09:22 AM.

  5. #4
    Hell_Demon's Avatar
    Join Date
    Mar 2008
    Gender
    male
    Location
    I love causing havoc
    Posts
    3,976
    Reputation
    343
    Thanks
    4,320
    My Mood
    Cheeky
    full code for setpixel crosshair:
    Code:
    #include <windows.h>
    #include <iostream>
    #include <math.h>
    using namespace std;
    
    bool crosshairon=false;
    HDC ragedc = NULL;
    int crosshairsize=0;
    int cx=0;
    int cy=0;
    
    void CrossThread(void)
    {
    	while(1)
    	{
    		if(GetAsyncKeyState(VK_NUMPAD0)&1)
    		{
    			crosshairon=!crosshairon;
    			ragedc = GetDC(HWND_DESKTOP);
    			cx=GetSystemMetrics(SM_CXSCREEN)/2-((crosshairsize-1)/2);
    			cy=GetSystemMetrics(SM_CYSCREEN)/2-((crosshairsize-1)/2);
    		}
    		Sleep(1);
    	}
    }
    
    int main()
    {
    	cout<<"Crosshair size in pixels:\n";
    	cin>>crosshairsize;
    	if(crosshairsize%2==0) //check if its even
    	{
    		crosshairsize+=1; //if it is add 1
    	}
    	system("cls"); // clear the console :)
    	cout<<"Press numpad0 to toggle the crosshair on and off\n";
    	CreateThread(0,0,(LPTHREAD_START_ROUTINE)CrossThread,0,0,0);
    	while(1)
    	{
    		if(crosshairon==true)
    		{
    			for(int i=0;i<crosshairsize;i++)
    			{
    				SetPixel(ragedc, cx+i, cy+((crosshairsize-1)/2), RGB(255,0,0));
    				SetPixel(ragedc, cx+((crosshairsize-1)/2), cy+i, RGB(255,0,0));
    			}
    		}
    		Sleep(1);
    	}
    }
    compile with VC++
    Ah we-a blaze the fyah, make it bun dem!

  6. The Following 3 Users Say Thank You to Hell_Demon For This Useful Post:

    .:Dark Angel:. (10-27-2009),edu_dudu (12-11-2009),RobinC (11-25-2012)

Similar Threads

  1. How to make simple CROsshair
    By icones3 in forum CrossFire Discussions
    Replies: 1
    Last Post: 04-21-2010, 05:41 AM
  2. How to make a Crosshair on C++ that stays ontop of CA
    By hopefordope in forum Programming Tutorial Requests
    Replies: 1
    Last Post: 03-15-2010, 11:31 PM
  3. [Request] How to make a crosshair for combat arms in Visual basic?
    By trevor206 in forum Programming Tutorial Requests
    Replies: 3
    Last Post: 01-30-2010, 08:44 PM
  4. VB6 How To Make A CrossHair
    By gunnybunny in forum Visual Basic Programming
    Replies: 3
    Last Post: 07-18-2009, 05:41 PM
  5. How to make an Crosshair!
    By chard95 in forum Programming Tutorials
    Replies: 4
    Last Post: 06-29-2009, 08:04 AM

Tags for this Thread