Results 1 to 7 of 7
  1. #1
    yodaliketaco's Avatar
    Join Date
    Jan 2010
    Gender
    male
    Location
    winsock.dll
    Posts
    645
    Reputation
    45
    Thanks
    515
    My Mood
    Tired

    [Help] I need help with my first c++ program

    As my first c++ program, I am making a crosshair that will show on top of all other programs. I finished designing a cool shape pixel by pixel and coded it to show up, but whenever I go fullscreen, it dissapears. This means I can't use it for it's original purpose: FPS games. Here is the source, tell me if you have any ideas to fix this problem.

    #include<windows.h>
    #include<iostream>
    int main()
    {
    int x = 960; /*This is just 1/2 the horizontal resolution, for possible development to work on multiple resolutions*/
    int y = 600; /*same as previous but for y*/
    HDC hdc=GetDC(NULL);
    while(1)
    {
    SetPixel(hdc,x,y,255);
    Sleep(1);
    SetPixel(hdc,x+1,y,255);
    Sleep(1);
    SetPixel(hdc,x-1,y,255);
    Sleep(1);
    SetPixel(hdc,x,y+1,255);
    Sleep(1);
    SetPixel(hdc,x,y-1,255);
    Sleep(1);
    SetPixel(hdc,x+2,y,255);
    Sleep(1);
    SetPixel(hdc,x-2,y,255);
    Sleep(1);
    SetPixel(hdc,x,y+2,255);
    Sleep(1);
    SetPixel(hdc,x,y-2,255);
    Sleep(1);
    SetPixel(hdc,x-1,y-1,255);
    Sleep(1);
    SetPixel(hdc,x+1,y+1,255);
    Sleep(1);
    SetPixel(hdc,x+1,y-1,255);
    Sleep(1);
    SetPixel(hdc,x-1,y+1,255);
    Sleep(1);
    SetPixel(hdc,x-3,y,255);
    Sleep(1);
    SetPixel(hdc,x-2,y,255);
    Sleep(1);
    SetPixel(hdc,x-4,y,255);
    Sleep(1);
    SetPixel(hdc,x-3,y+1,255);
    Sleep(1);
    SetPixel(hdc,x-3,y-1,255);
    Sleep(1);
    SetPixel(hdc,x-1,y,255);
    Sleep(1);
    SetPixel(hdc,x-5,y,255);
    Sleep(1);
    SetPixel(hdc,x-3,y+2,255);
    Sleep(1);
    SetPixel(hdc,x-3,y-2,255);
    Sleep(1);
    SetPixel(hdc,x-4,y-1,255);
    Sleep(1);
    SetPixel(hdc,x-2,y+1,255);
    Sleep(1);
    SetPixel(hdc,x-2,y-1,255);
    Sleep(1);
    SetPixel(hdc,x-4,y+1,255);
    Sleep(1);
    SetPixel(hdc,x+3,y,255);
    Sleep(1);
    SetPixel(hdc,x+4,y,255);
    Sleep(1);
    SetPixel(hdc,x+2,y,255);
    Sleep(1);
    SetPixel(hdc,x+3,y+1,255);
    Sleep(1);
    SetPixel(hdc,x+3,y-1,255);
    Sleep(1);
    SetPixel(hdc,x+5,y,255);
    Sleep(1);
    SetPixel(hdc,x+1,y,255);
    Sleep(1);
    SetPixel(hdc,x+3,y+2,255);
    Sleep(1);
    SetPixel(hdc,x+3,y-2,255);
    Sleep(1);
    SetPixel(hdc,x+2,y-1,255);
    Sleep(1);
    SetPixel(hdc,x+4,y+1,255);
    Sleep(1);
    SetPixel(hdc,x+4,y-1,255);
    Sleep(1);
    SetPixel(hdc,x+2,y+1,255);
    Sleep(1);
    SetPixel(hdc,x,y+3,255);
    Sleep(1);
    SetPixel(hdc,x+1,y+3,255);
    Sleep(1);
    SetPixel(hdc,x-1,y+3,255);
    Sleep(1);
    SetPixel(hdc,x,y+4,255);
    Sleep(1);
    SetPixel(hdc,x,y+2,255);
    Sleep(1);
    SetPixel(hdc,x+2,y+3,255);
    Sleep(1);
    SetPixel(hdc,x-2,y+3,255);
    Sleep(1);
    SetPixel(hdc,x,y+5,255);
    Sleep(1);
    SetPixel(hdc,x,y+1,255);
    Sleep(1);
    SetPixel(hdc,x-1,y+2,255);
    Sleep(1);
    SetPixel(hdc,x+1,y+4,255);
    Sleep(1);
    SetPixel(hdc,x+1,y+2,255);
    Sleep(1);
    SetPixel(hdc,x-1,y+4,255);
    Sleep(1);
    SetPixel(hdc,x,y-3,255);
    Sleep(1);
    SetPixel(hdc,x+1,y-3,255);
    Sleep(1);
    SetPixel(hdc,x-1,y-3,255);
    Sleep(1);
    SetPixel(hdc,x,y-2,255);
    Sleep(1);
    SetPixel(hdc,x,y-4,255);
    Sleep(1);
    SetPixel(hdc,x+2,y-3,255);
    Sleep(1);
    SetPixel(hdc,x-2,y-3,255);
    Sleep(1);
    SetPixel(hdc,x,y-1,255);
    Sleep(1);
    SetPixel(hdc,x,y-5,255);
    Sleep(1);
    SetPixel(hdc,x-1,y-4,255);
    Sleep(1);
    SetPixel(hdc,x+1,y-2,255);
    Sleep(1);
    SetPixel(hdc,x+1,y-4,255);
    Sleep(1);
    SetPixel(hdc,x-1,y-2,255);
    Sleep(1);
    SetPixel(hdc,x+6,y,255);
    Sleep(1);
    SetPixel(hdc,x+7,y,255);
    Sleep(1);
    SetPixel(hdc,x+5,y,255);
    Sleep(1);
    SetPixel(hdc,x+6,y+1,255);
    Sleep(1);
    SetPixel(hdc,x+6,y-1,255);
    Sleep(1);
    SetPixel(hdc,x+8,y,255);
    Sleep(1);
    SetPixel(hdc,x+4,y,255);
    Sleep(1);
    SetPixel(hdc,x+6,y+2,255);
    Sleep(1);
    SetPixel(hdc,x+6,y-2,255);
    Sleep(1);
    SetPixel(hdc,x+5,y-1,255);
    Sleep(1);
    SetPixel(hdc,x+7,y+1,255);
    Sleep(1);
    SetPixel(hdc,x+7,y-1,255);
    Sleep(1);
    SetPixel(hdc,x+5,y+1,255);
    Sleep(1);
    SetPixel(hdc,x-6,y,255);
    Sleep(1);
    SetPixel(hdc,x-5,y,255);
    Sleep(1);
    SetPixel(hdc,x-7,y,255);
    Sleep(1);
    SetPixel(hdc,x-6,y+1,255);
    Sleep(1);
    SetPixel(hdc,x-6,y-1,255);
    Sleep(1);
    SetPixel(hdc,x-4,y,255);
    Sleep(1);
    SetPixel(hdc,x-8,y,255);
    Sleep(1);
    SetPixel(hdc,x-6,y+2,255);
    Sleep(1);
    SetPixel(hdc,x-6,y-2,255);
    Sleep(1);
    SetPixel(hdc,x-7,y-1,255);
    Sleep(1);
    SetPixel(hdc,x-5,y+1,255);
    Sleep(1);
    SetPixel(hdc,x-5,y-1,255);
    Sleep(1);
    SetPixel(hdc,x-7,y+1,255);
    Sleep(1);
    SetPixel(hdc,x,y+6,255);
    Sleep(1);
    SetPixel(hdc,x+1,y+6,255);
    Sleep(1);
    SetPixel(hdc,x-1,y+6,255);
    Sleep(1);
    SetPixel(hdc,x,y+7,255);
    Sleep(1);
    SetPixel(hdc,x,y+5,255);
    Sleep(1);
    SetPixel(hdc,x+2,y+6,255);
    Sleep(1);
    SetPixel(hdc,x-2,y+6,255);
    Sleep(1);
    SetPixel(hdc,x,y+8,255);
    Sleep(1);
    SetPixel(hdc,x,y+4,255);
    Sleep(1);
    SetPixel(hdc,x-1,y+5,255);
    Sleep(1);
    SetPixel(hdc,x+1,y+7,255);
    Sleep(1);
    SetPixel(hdc,x+1,y+5,255);
    Sleep(1);
    SetPixel(hdc,x-1,y+7,255);
    Sleep(1);
    SetPixel(hdc,x,y-6,255);
    Sleep(1);
    SetPixel(hdc,x+1,y-6,255);
    Sleep(1);
    SetPixel(hdc,x-1,y-6,255);
    Sleep(1);
    SetPixel(hdc,x,y-5,255);
    Sleep(1);
    SetPixel(hdc,x,y-7,255);
    Sleep(1);
    SetPixel(hdc,x+2,y-6,255);
    Sleep(1);
    SetPixel(hdc,x-2,y-6,255);
    Sleep(1);
    SetPixel(hdc,x,y-4,255);
    Sleep(1);
    SetPixel(hdc,x,y-8,255);
    Sleep(1);
    SetPixel(hdc,x-1,y-7,255);
    Sleep(1);
    SetPixel(hdc,x+1,y-5,255);
    Sleep(1);
    SetPixel(hdc,x+1,y-7,255);
    Sleep(1);
    SetPixel(hdc,x-1,y-5,255);
    Sleep(1);
    }
    return 0;
    }

  2. #2
    'Bruno's Avatar
    Join Date
    Dec 2009
    Gender
    male
    Location
    Portugal
    Posts
    2,883
    Reputation
    290
    Thanks
    1,036
    My Mood
    Busy
    using

    Code:
    This
    might get you help faster
    Light travels faster than sound. That's why most people seem bright until you hear them speak.

  3. #3
    Void's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Location
    Inline.
    Posts
    3,198
    Reputation
    205
    Thanks
    1,445
    My Mood
    Mellow
    Most games block trying to draw topmost. You're going to have to hook onto the functions the game uses to draw and use it to draw your crosshair. Well, as far as I know, that's the only way.

  4. #4
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,203
    My Mood
    Flirty
    This is why programmers invented loops. :L

    Try using a drawline function as well as it would be a lot easier, also not sure if this will work for Games since they write directly to the screen buffer.

    "Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."
    - Dwight D. Eisenhower

  5. #5
    Void's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Location
    Inline.
    Posts
    3,198
    Reputation
    205
    Thanks
    1,445
    My Mood
    Mellow
    Quote Originally Posted by why06 View Post
    This is why programmers invented loops. :L

    Try using a drawline function as well as it would be a lot easier, also not sure if this will work for Games since they write directly to the screen buffer.
    Pshh, who uses loops these days? Insufficient code for the win.

    Is this seriously your first C++ program? If it is, it's pretty good. I can't seem to believe it though.

  6. #6
    KABLE's Avatar
    Join Date
    Dec 2009
    Gender
    male
    Location
    California
    Posts
    2,863
    Reputation
    192
    Thanks
    282
    My Mood
    Pensive
    My "Hello World" pwns his crosshair

    Quote Originally Posted by TOXIN
    Shit, now I have to enter this chapacha shit.
    my tumblr
    How To: Not Get Banned Botting

    "Had a dream I was king. I woke up, still king."
    .................................................-Eminem

  7. #7
    Retoxified's Avatar
    Join Date
    Feb 2010
    Gender
    male
    Posts
    148
    Reputation
    8
    Thanks
    171
    Notepad tells me you have 234 lines within your while loop.
    234/2 = 117 Sleep(1)'s.
    That would be about 120 miliseconds per draw loop, 1000/120 = 8.34 per second.
    Lag up your game so you have less then 8 fps and you should see it just fine(or just remove all Sleep(1)'s except for the very last one :P)

Similar Threads

  1. [Info] Need help with AlterIW? READ HERE FIRST!
    By master131 in forum Call of Duty Modern Warfare 2 Private Servers
    Replies: 0
    Last Post: 05-05-2011, 12:53 AM
  2. [Help Request] need help with modding
    By BayBee Alyn in forum Combat Arms Help
    Replies: 0
    Last Post: 04-27-2011, 09:06 PM
  3. Need help with visual basic PHISHING program
    By mariofan901 in forum Visual Basic Programming
    Replies: 14
    Last Post: 10-10-2009, 11:27 AM
  4. Help with my First Hack C++ No Menu
    By killerld in forum C++/C Programming
    Replies: 4
    Last Post: 07-24-2009, 07:30 AM
  5. help with my first stamina hack
    By berki69 in forum WarRock - International Hacks
    Replies: 5
    Last Post: 03-06-2008, 12:18 AM