Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    258456's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    ghjghj
    Posts
    1,222
    Reputation
    18
    Thanks
    300
    My Mood
    Relaxed

    [SOLVED]Help with DrawText()

    Hey guys, well i am reading Charle Petzold's Programming windows, and i learned about the DrawText() and TextOut () functions, so i got an idea to make a program that would write on other windows, not the window i make, so here is my code, and for this project i made it a console app not a win32 for this app, here is my code:

    Code:
    #include <Windows.h>
    #include <iostream>
    int main()
    {
    	PAINTSTRUCT ps;
    	HDC hdc;
    	HWND ss = FindWindow(NULL, TEXT("Spider Solitaire"));
    	RECT rect;
    	if(ss == NULL)
    		{
    			std::cout<<"Window NOT Found.";
    		}
    		else if (!ss ==0)
    		{
    			std::cout<<"you're good to go.";
    		}
    	
    
    	while(true)
    	{
    		hdc = BeginPaint(ss, &ps);
    		GetClientRect(ss, &rect);
    		DrawText(hdc, TEXT("YOU WON"), -1, &rect, DT_CENTER);
    		EndPaint(ss, &ps);
    		
    	}
    }
    Can someone point out what is wrong with this. Cuz i am pretty frustrated.
    Last edited by Hell_Demon; 10-15-2010 at 08:05 AM.

  2. #2
    Gab's Avatar
    Join Date
    Jul 2010
    Gender
    male
    Posts
    6,716
    Reputation
    1755
    Thanks
    1,543
    I don't no, but you better use
    Code:
    using namespace std;

  3. #3
    258456's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    ghjghj
    Posts
    1,222
    Reputation
    18
    Thanks
    300
    My Mood
    Relaxed
    wow, you just pointed out how bad ur c++ skills are, i clearly wrote "std::cout<<"blahblah";" therefore i don't need "using namespace std;" unless i am lazy and don't want to waste 10 seconds to write std::


    Can someone answer my question about the winapi part not c++.

    Somebody like Void, HD, schim, brinuz, freedompeace, kallisti, melodia, people who actually know what i am talking about not just posting stupid crap.

  4. #4
    Void's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Location
    Inline.
    Posts
    3,198
    Reputation
    205
    Thanks
    1,445
    My Mood
    Mellow
    Try using GetDC on the window you want to draw over. BeginPaint doesn't return the same device context that the window itself uses.

    Post results.

  5. #5
    258456's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    ghjghj
    Posts
    1,222
    Reputation
    18
    Thanks
    300
    My Mood
    Relaxed
    nope didn't work, well it's not drawing on the spider solitaire window.

    here is the code:
    Code:
    while(true)
    	{
    		hdc = GetDC(ss);
    		BeginPaint(ss, &ps);
    		GetClientRect(ss, &rect);
    		DrawText(hdc, TEXT("YOU WON"), -1, &rect, DT_CENTER);
    		EndPaint(ss, &ps);
    		ReleaseDC(ss, hdc);
    	}

  6. #6
    Void's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Location
    Inline.
    Posts
    3,198
    Reputation
    205
    Thanks
    1,445
    My Mood
    Mellow
    I don't see the point of using BeginPaint here, also, try using TextOut instead. I remember I used TextOut to render text before.

  7. #7
    258456's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    ghjghj
    Posts
    1,222
    Reputation
    18
    Thanks
    300
    My Mood
    Relaxed
    ok i will try now.

    ok not working still here is my code

    Code:
     while(true)
    	{
    		if(GetAsyncKeyState(VK_LBUTTON) &1)
    		{
    			GetCursorPos(&p);
    		hdc = GetDC(ss);
    		std::cout<<p.x<<p.y;
    		GetClientRect(ss, &rect);
    		TextOut(hdc, p.x, p.y, TEXT("YOU WON"), 0);
    		ReleaseDC(ss, hdc);
    		}
    	
    		
    	}
    All i want is it to write YOU WON on the spider solitaire window

    come on guys

    if you guys can't help me then can someone give me an example of how you would write text ontop of another window?
    Last edited by 258456; 10-13-2010 at 07:56 PM.

  8. #8
    258456's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    ghjghj
    Posts
    1,222
    Reputation
    18
    Thanks
    300
    My Mood
    Relaxed
    really guys?

  9. #9

  10. #10
    258456's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    ghjghj
    Posts
    1,222
    Reputation
    18
    Thanks
    300
    My Mood
    Relaxed
    omg, i never thought it was that hard, you are writing like crazy programs that i can't even understand but i am writing a simple winapi program. Well, i guess i will wait for a solution.

  11. #11
    faceofdevil's Avatar
    Join Date
    Jul 2009
    Gender
    female
    Posts
    77
    Reputation
    9
    Thanks
    6
    I believe its the way you call DrawText (arguments )

    You should always draw inside WM_PAINT.

    Code:
    #include <windows.h>
    #include <iostream>
    using namespace std;
    
    int DrawOnSC(char szBuffer[], int bottom, int left, int right, int top, RECT& rect, HDC& hdc, HWND& hwnd, int& iLength) 
    {
    	SetRect(&rect, bottom, left, right + 34, top + 34);
            DrawText(hdc, szBuffer, iLength, &rect, 32);
    	return 0;
    
    }
    
    int main()
    {
    	char WindowName[] = "Spider Solitaire";         
            TCHAR szBuffer[50] = {0};                
    	RECT rect;                               
    	HWND hwnd = FindWindow(0, WindowName);   
    	HDC hdc = GetDC(hwnd);                   
    
    	int iLength = 0;
    
            iLength = wsprintf(szBuffer, "YOU WON");
    
    	if (!FindWindow(0, WindowName)) { MessageBox(0, WindowName, "Window not found", 0); exit(0); }
    	
    	while (true) {
    
            DrawOnSC(szBuffer, 0, 0, 0, 0, rect, hdc, hwnd, iLength);
    		if ( ( (GetAsyncKeyState(VK_END)) ? 1 : 0) ) { return 0; }
    
      }
    
    
    
      return 0;
    
    }

  12. The Following User Says Thank You to faceofdevil For This Useful Post:

    258456 (10-14-2010)

  13. #12
    258456's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    ghjghj
    Posts
    1,222
    Reputation
    18
    Thanks
    300
    My Mood
    Relaxed
    nope, doesn't work. Have you tried it on spider solitaire? on my comp it doesn't write anything on the window and i am getting pissed. lol

  14. #13
    .::SCHiM::.'s Avatar
    Join Date
    Sep 2010
    Gender
    male
    Posts
    733
    Reputation
    180
    Thanks
    880
    My Mood
    Twisted
    I've once used d3d to write on other windows, that worked pretty good for me, although it was slow. Lemme get the code for you...

    Oops, I don't have the code anymore, But I remember it being verry easy, so try and do it with d3d (it is possible using wb_paint though) but I don't know how ... :S

    I'm SCHiM

    Morals derive from the instinct to survive. Moral behavior is survival behavior above the individual level.

    Polymorphic engine
    Interprocess callback class
    SIN
    Infinite-precision arithmetic
    Hooking dynamic linkage
    (sloppy)Kernel mode Disassembler!!!

    Semi debugger




  15. The Following User Says Thank You to .::SCHiM::. For This Useful Post:

    258456 (10-15-2010)

  16. #14
    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
    CreateDC then draw on that
    Ah we-a blaze the fyah, make it bun dem!

  17. The Following User Says Thank You to Hell_Demon For This Useful Post:

    258456 (10-15-2010)

  18. #15
    258456's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    ghjghj
    Posts
    1,222
    Reputation
    18
    Thanks
    300
    My Mood
    Relaxed
    i have figured it out. I used GetDC(), then i just used BeginPaint(), but before the loop i made it sleep for 3 seconds and it worked. Thanks guys.

  19. The Following User Says Thank You to 258456 For This Useful Post:

    Hell_Demon (10-15-2010)

Page 1 of 2 12 LastLast

Similar Threads

  1. [SOLVED] help with 13.37a alter iw
    By amd_74 in forum Call of Duty Modern Warfare 2 Help
    Replies: 3
    Last Post: 07-18-2010, 06:11 AM
  2. [SOLVED]Help with a code
    By lolbie in forum Call of Duty Modern Warfare 2 Help
    Replies: 4
    Last Post: 06-14-2010, 01:04 PM
  3. [SOLVED] Help with making a mod
    By lolbie in forum Call of Duty Modern Warfare 2 Help
    Replies: 5
    Last Post: 06-11-2010, 04:20 AM
  4. [SOLVED] Help with VAC chaos
    By aninsanepyro in forum Call of Duty Modern Warfare 2 Help
    Replies: 8
    Last Post: 06-07-2010, 04:14 AM
  5. [SOLVED] Help with aimbot
    By karloxxx in forum Call of Duty Modern Warfare 2 Help
    Replies: 3
    Last Post: 05-25-2010, 03:53 PM