Help printing on screen

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2006
Posts: 179
Reputation: HLA91 is an unknown quantity at this point 
Solved Threads: 2
HLA91 HLA91 is offline Offline
Junior Poster

Help printing on screen

 
0
  #1
Nov 7th, 2007
Hi all
My friend sent me this C++ program that opens up notepad and starts typing, its a joke he made to scare his little brother, I tried to modify it to display more of the message "Im watching you" but when I do it wont compile and I dont understand the error message, Im a noob lol
Heres the code all I did was copy and paste the spooky message a few more times underneath the original spooky messages, so instead of displaying the message 4 times it displayed it 6 times
  1. #include <windows.h>
  2. #include <cstdlib>
  3. using namespace std;
  4.  
  5.  
  6. int main(int argc,char *argv[])
  7. {
  8.  
  9. //hides your program from the desktop
  10. HWND hwnd1 = FindWindow(NULL,argv[0]);
  11. ShowWindow(hwnd1,SW_HIDE);
  12.  
  13. //array for your messge
  14. char text[75]= {'i','m',' ','w','a','t','c','h','i','n','g'
  15. ,' ','y','o','u','.','.','.'
  16. ,' ','i','m',' ','w','a','t','c','h','i','n','g'
  17. ,' ','y','o','u','.','.','.'
  18. ,' ','i','m',' ','w','a','t','c','h','i','n','g'
  19. ,' ','y','o','u','.','.','.'
  20. ,' ','i','m',' ','w','a','t','c','h','i','n','g'
  21. ,' ','y','o','u','.','.','.'};
  22.  
  23. //this allows your program to execute a minute later
  24. Sleep(15000);
  25.  
  26.  
  27. //plays the scary file - must link libwinmm.a
  28. PlaySound("C:/scary1.wav",NULL, SND_FILENAME);
  29.  
  30.  
  31. //Sleep(3000);
  32. //opens Microsoft Word
  33. ShellExecute(NULL, "open","C:/WINDOWS/system32/notepad.exe"
  34. , NULL, NULL, SW_SHOWNORMAL);
  35.  
  36. HWND hwnd2= FindWindow(NULL,"Untitled - Notepad");
  37. //makes Word the active window
  38. SetActiveWindow(hwnd2);
  39.  
  40. Sleep(2000);
  41. //simulates a mouse left click
  42. mouse_event(MOUSEEVENTF_LEFTDOWN,200,200,0,0);
  43. mouse_event(MOUSEEVENTF_LEFTUP,200,200,0,0);
  44.  
  45. // Sleep(1000);
  46. //writes your scary message
  47. for(int i=0;i<75;i++){
  48. keybd_event(VkKeyScan(text[i]),0,0,0);
  49. Sleep(rand() %200);
  50. }
  51.  
  52.  
  53.  
  54. return 0;
  55. }

Many thanks

HLA91
You know your a geek, if you introduce your wife as "mylady@home.wife"
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,734
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 738
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Help printing on screen

 
0
  #2
Nov 7th, 2007
>it wont compile and I dont understand the error message
And we're supposed to divine what that error message is? Maybe you should post it.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 179
Reputation: HLA91 is an unknown quantity at this point 
Solved Threads: 2
HLA91 HLA91 is offline Offline
Junior Poster

Re: Help printing on screen

 
0
  #3
Nov 7th, 2007
Sorry stupid me here they are 3 of them
In function 'int main(int,char**)':
too many initializers for 'char[75]'
[Build Error] [ghost4school.o] Error1

I thought the second message meant too many letters because I had only declared 75 but I counted the original number of letters and that went over 75 so I have no other ideas
Last edited by HLA91; Nov 7th, 2007 at 4:37 pm.
You know your a geek, if you introduce your wife as "mylady@home.wife"
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,734
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 738
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Help printing on screen

 
0
  #4
Nov 7th, 2007
>too many initializers for 'char[75]'
By my count you have exactly 75, so either the code you posted isn't the same code you've compiled, or you're getting a strange error. In fact, it compiles okay for me. Try removing the array size and using sizeof text in the loop instead of 75. That should sidestep the problem.
Last edited by Narue; Nov 7th, 2007 at 4:49 pm.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 179
Reputation: HLA91 is an unknown quantity at this point 
Solved Threads: 2
HLA91 HLA91 is offline Offline
Junior Poster

Re: Help printing on screen

 
0
  #5
Nov 7th, 2007
What am I supposed to count becasue at the moment im counting anyhting between the ' ' marks that includes spaces what are you counting?
You know your a geek, if you introduce your wife as "mylady@home.wife"
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,734
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 738
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Help printing on screen

 
0
  #6
Nov 7th, 2007
>what are you counting?
I'm counting the number of character literals. Alternatively, you can count the number of commas and add one. Anyway, you're making this harder on yourself because you could just do this:
  1. const char *text =
  2. "i'm watching you... "
  3. "i'm watching you... "
  4. "i'm watching you... "
  5. "i'm watching you...";
Then instead of counting the number of characters, just traverse until you find '\0'. Much easier.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 179
Reputation: HLA91 is an unknown quantity at this point 
Solved Threads: 2
HLA91 HLA91 is offline Offline
Junior Poster

Re: Help printing on screen

 
0
  #7
Nov 7th, 2007
OK i got the *text part sorted and it works now thankyou but when it prints it does im watching you 4 times but on the fourth one it only prints
i'm watching yo
and then it re opens one of the windows i minimized
here is the code now
  1. #include <windows.h>
  2. #include <cstdlib>
  3. using namespace std;
  4.  
  5.  
  6. int main(int argc,char *argv[])
  7. {
  8.  
  9. //hides your program from the desktop
  10. HWND hwnd1 = FindWindow(NULL,argv[0]);
  11. ShowWindow(hwnd1,SW_HIDE);
  12.  
  13. //array for your messge
  14. const char *text =
  15. "i'm watching you... "
  16. "i'm watching you... "
  17. "i'm watching you... "
  18. "i'm watching you...";
  19.  
  20. //this allows your program to execute a minute later
  21. Sleep(15000);
  22.  
  23.  
  24. //plays the scary file - must link libwinmm.a
  25. PlaySound("C:/scary1.wav",NULL, SND_FILENAME);
  26.  
  27.  
  28. //Sleep(3000);
  29. //opens Microsoft Word
  30. ShellExecute(NULL, "open","C:/WINDOWS/system32/notepad.exe"
  31. , NULL, NULL, SW_SHOWNORMAL);
  32.  
  33. HWND hwnd2= FindWindow(NULL,"Untitled - Notepad");
  34. //makes Word the active window
  35. SetActiveWindow(hwnd2);
  36.  
  37. Sleep(2000);
  38. //simulates a mouse left click
  39. mouse_event(MOUSEEVENTF_LEFTDOWN,200,200,0,0);
  40. mouse_event(MOUSEEVENTF_LEFTUP,200,200,0,0);
  41.  
  42. // Sleep(1000);
  43. //writes your scary message
  44. for(int i=0;i<75;i++){
  45. keybd_event(VkKeyScan(text[i]),0,0,0);
  46. Sleep(rand() %200);
  47. }
  48.  
  49.  
  50.  
  51. return 0;
  52. }

thanks for help

HLA91
You know your a geek, if you introduce your wife as "mylady@home.wife"
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,734
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 738
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Help printing on screen

 
0
  #8
Nov 8th, 2007
You neglected to make all of the changes I suggested. Change this:
  1. for(int i=0;i<75;i++){
To this:
  1. for ( int i = 0; text[i] != '\0'; i++ ) {
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 179
Reputation: HLA91 is an unknown quantity at this point 
Solved Threads: 2
HLA91 HLA91 is offline Offline
Junior Poster

Re: Help printing on screen

 
0
  #9
Nov 8th, 2007
OK thanks its runs fine for about 9 messages and then it just prints '''''''''''''''''''''''''''''''''''''''''''''
here is the code now
  1. #include <windows.h>
  2. #include <cstdlib>
  3. using namespace std;
  4.  
  5.  
  6. int main(int argc,char *argv[])
  7. {
  8.  
  9. //hides your program from the desktop
  10. HWND hwnd1 = FindWindow(NULL,argv[0]);
  11. ShowWindow(hwnd1,SW_HIDE);
  12.  
  13. //array for your messge
  14. const char *text=
  15. "I'm Watching you..."
  16. "I'm Watching you..."
  17. "I'm Watching you..."
  18. "I'm Watching you...";
  19.  
  20. //this allows your program to execute a minute later
  21. Sleep(15000);
  22.  
  23.  
  24. //plays the scary file - must link libwinmm.a
  25. PlaySound("C:/scary1.wav",NULL, SND_FILENAME);
  26.  
  27.  
  28. //Sleep(3000);
  29. //opens Microsoft Word
  30. ShellExecute(NULL, "open","C:/WINDOWS/system32/notepad.exe"
  31. , NULL, NULL, SW_SHOWNORMAL);
  32.  
  33. HWND hwnd2= FindWindow(NULL,"Untitled - Notepad");
  34. //makes Word the active window
  35. SetActiveWindow(hwnd2);
  36.  
  37. Sleep(2000);
  38. //simulates a mouse left click
  39. mouse_event(MOUSEEVENTF_LEFTDOWN,200,200,0,0);
  40. mouse_event(MOUSEEVENTF_LEFTUP,200,200,0,0);
  41.  
  42. // Sleep(1000);
  43. //writes your scary message
  44. for ( int i = 0; text[i] != '\0'; i++ ) {
  45. keybd_event(VkKeyScan(text[i]),0,0,0);
  46. Sleep(rand() %200);
  47. }
  48.  
  49.  
  50.  
  51. return 0;
  52. }
here is what is printed part of one of the messages is cut becasue msn popped up and it started writing in the search box lol


Im watching you… im watching you… im watching you… im watching you… im watching you… im watching you… you… im watching you… im watching you… im watching’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’

I dont understand where it is getting the ''''''''' from can somebody help me again please?

Many thanks for time

HLA91
You know your a geek, if you introduce your wife as "mylady@home.wife"
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,734
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 738
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Help printing on screen

 
0
  #10
Nov 8th, 2007
>OK thanks its runs fine for about 9 messages
>and then it just prints '''''''''''''''''''''''''''''''''''''''''''''
It should only print four messages, because that's how many you've defined. In fact, that's precisely what it does for me. Did you post the actual code you're using?
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC