William Hemsworth 1,339 Posting Virtuoso

Do you meen actually emulating keypresses ?
Here is an example of how to do that:

#include<iostream>
#include<windows.h>
using namespace std;

void SendKeysWait(char *text, int interval);

int main() {
	system("start C:\\Windows\\notepad.exe");
	Sleep(1000);
	SendKeysWait("Hello world!", 30);
	cin.ignore();
	return 0;
}

void SendKeysWait(char *text, int interval) {
	int ch;
	int ch2 = -1;
	bool SHIFTDOWN = 0;
	for (int i = 0;  text[i]; i++) {
		SHIFTDOWN= 0;
		switch (text[i]) {
			case '\"':{ch = VkKeyScan('\"');ch2= VK_SHIFT; SHIFTDOWN = 1;} break;
			case '£': {ch = VkKeyScan('£');ch2 = VK_SHIFT; SHIFTDOWN = 1;} break;
			case '$': {ch = VkKeyScan('$');ch2 = VK_SHIFT; SHIFTDOWN = 1;} break;
			case '%': {ch = VkKeyScan('%');ch2 = VK_SHIFT; SHIFTDOWN = 1;} break;
			case '^': {ch = VkKeyScan('^');ch2 = VK_SHIFT; SHIFTDOWN = 1;} break;
			case '&': {ch = VkKeyScan('&');ch2 = VK_SHIFT; SHIFTDOWN = 1;} break;
			case '*': {ch = VkKeyScan('*');ch2 = VK_SHIFT; SHIFTDOWN = 1;} break;
			case '_': {ch = VkKeyScan('_');ch2 = VK_SHIFT; SHIFTDOWN = 1;} break;
			case '+': {ch = VkKeyScan('+');ch2 = VK_SHIFT; SHIFTDOWN = 1;} break;
			case '{': {ch = VkKeyScan('{');ch2 = VK_SHIFT; SHIFTDOWN = 1;} break;
			case '}': {ch = VkKeyScan('}');ch2 = VK_SHIFT; SHIFTDOWN = 1;} break;
			case '@': {ch = VkKeyScan('@');ch2 = VK_SHIFT; SHIFTDOWN = 1;} break;
			case '~': {ch = VkKeyScan('~');ch2 = VK_SHIFT; SHIFTDOWN = 1;} break;
			case '?': {ch = VkKeyScan('?');ch2 = VK_SHIFT; SHIFTDOWN = 1;} break;
			case '<': {ch = VkKeyScan('<');ch2 = VK_SHIFT; SHIFTDOWN = 1;} break;
			case '>': {ch = VkKeyScan('>');ch2 = VK_SHIFT; SHIFTDOWN = 1;} break;
			case '|': {ch = VkKeyScan('|');ch2 = …
William Hemsworth 1,339 Posting Virtuoso

sum1 plz
wna no
fank u

Use real words...

William Hemsworth 1,339 Posting Virtuoso

Well, programs used to always be made in console windows for example, Turbo C++ from before I was born would have fully text based menus and therefore need to be able to detect the cursor positions and mouse clicks.

http://www.weiqigao.com/blog/images/turbo-cpp.png

William Hemsworth 1,339 Posting Virtuoso

Not only that, most people think that it is entirely impossible to do graphics in console applications. Heres the proof againts that:

#define _WIN32_WINNT 0x0500
#include<windows.h>
#include<iostream>
using namespace std;

int main() {
	HWND console = GetConsoleWindow();
	HDC hdc = GetDC(console);
	SelectObject(hdc, CreatePen(0, 30, RGB(255,255,255)));
	POINT p;
	GetCursorPos(&p);
	ScreenToClient(console, &p);
	MoveToEx(hdc, p.x, p.y, NULL);
	for (;;) {
		GetCursorPos(&p);
		ScreenToClient(console, &p);
		LineTo(hdc, p.x, p.y);
		Sleep(1);
	}
	ReleaseDC(console, hdc);
	cin.ignore();
	return 0;
}
jephthah commented: good stuff +2
William Hemsworth 1,339 Posting Virtuoso

It works with me :-/

As long as you include the window header I think you can still use any of the functions there.
heres an example of what you can do with a console application.

#include <windows.h>
#include <cmath>

int main() {
	system("start c:\\windows\\system32\\mspaint.exe");
	HWND paint;

	do {
		paint = FindWindow("MSPaintApp", "Untitled - Paint");
		Sleep(10);
	} while (paint == NULL);

	Sleep(200);
	RECT r;
	GetWindowRect(paint, &r);
	RECT cr;
	GetClientRect(paint, &cr);

	int x = r.left + (cr.right / 2);
	int y = r.top + (cr.bottom / 2);

	SetCursorPos(x,y);

	POINT p;
	GetCursorPos(&p);
	paint = WindowFromPoint(p);

	GetWindowRect(paint, &r);
	GetClientRect(paint, &cr);

	x = r.left + (cr.right / 2);
	y = r.top + (cr.bottom / 2);

	SetCursorPos(x,y);

	int radius = 0;
	double angle = 0;

	int max = min(cr.right/2,cr.bottom/2);

	mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);

	for (; radius < max; radius++, angle += 0.1) {
		SetCursorPos(x+(cos(angle)*radius), y+(sin(angle)*radius));
		Sleep(20);
	}

	mouse_event(MOUSEEVENTF_LEFTUP, x, y, 0, 0);

	return 0;
}
Ancient Dragon commented: excellent example :) +29
mitrmkar commented: a nice one +2
William Hemsworth 1,339 Posting Virtuoso

does this work?

Yes it does :)

William Hemsworth 1,339 Posting Virtuoso

It looks to me like the code you wrote never releases the click. This is how you fully emulate a mouse click:

mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0); // Left click
mouse_event(MOUSEEVENTF_RIGHTDOWN | MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0); // Right click
William Hemsworth 1,339 Posting Virtuoso

thats it ^^ havent done .NET in a long time

William Hemsworth 1,339 Posting Virtuoso

can you just do

Form2->Text = "write something";
William Hemsworth 1,339 Posting Virtuoso

I happened to have already made quite a few functions to help do this.
for example:

GetWord(char *text, char *gaps, int bzIndex /* 0 based index */);
cout << GetWord(  "#[]Hello_{World::"  ,   "#[]_{:"  , 0); // Returns "Hello"
cout << GetWord(  "#[]Hello_{World::"  ,   "#[]_{:"  , 1); // Returns "World"

This code does what your asking:

#include<iostream>
using namespace std;

inline char *SubStr(char *text, int beg, int end) {
	register int len = end - beg;
	char *cut = new char[len];
	memcpy_s(cut,(rsize_t)len, &text[beg], (size_t)len);
	cut[len] = '\0';
	return cut;
}

inline bool TextContains(char *txt, char ch) {
	while(*txt++)if (*(txt-1)==ch)return 1;
	return 0;
}

char *GetWord(char *text, char *gaps, int bzIndex) {
	int i = 0, sc = 0, ec = 0, g = 0;
	for (; text[i] && TextContains(gaps, text[i]); i++);
	for (sc = i; text[i]; i++) {
		if (TextContains(gaps, text[i])) {
			while (text[i] && TextContains(gaps, text[i+1])) i++;
			if (++g == bzIndex) sc=i+1;
		} else if (g == bzIndex) {
			while (text[i] && !TextContains(gaps, text[i])) i++;
			ec = i;
			break;
		}
	}
	return SubStr(text, sc, ec);
}

int CountWords(char *text, char *gaps) {
	register bool t = 0, ot = 0;
	register int wc = 0, i = 0;
	while (TextContains(gaps, text[i])) i++;
	for (;text[i];i++) {
		t = TextContains(gaps, text[i]);
		if (t != ot) wc++;
		ot = t;
	}
	return (wc/2)+1;
}

int main() {
	char str[] = " this is a string ";
	for (int i = CountWords(str, " ")-1; i >= 0; i--) {
		cout << …
William Hemsworth 1,339 Posting Virtuoso

If you are using MSVC you can just add:

#pragma once

at the start of your code.

William Hemsworth 1,339 Posting Virtuoso

I see nothing wrong with the function isUpperCase except from what mitrmkar sead, it would not work if you passed the function the characters 'A' or 'Z'.

William Hemsworth 1,339 Posting Virtuoso

This would have been very easy for you to test yourself, just made a quick test program:

int i = 5;
cout << i++; // Still 5
int i = 5;
cout << ++i; // Now 6
William Hemsworth 1,339 Posting Virtuoso

try

Int32::Parse(stringname)
William Hemsworth 1,339 Posting Virtuoso

Here's how to hide the console window

You might have to add

#define _WIN32_WINNT 0x0500

before you include the windows library to use the GetConsoleWindow() function.

William Hemsworth 1,339 Posting Virtuoso

You could also insert std::system("PAUSE"); between 18 and 19

http://www.gidnetwork.com/b-61.html

William Hemsworth 1,339 Posting Virtuoso

It is also possible to do graphics in a console window but I dont know if it what you are looking for. You could easily use BitBlt instead of just LineTo but here is an example:

#define _WIN32_WINNT 0x0500
#include<windows.h>
#include<iostream>
using namespace std;

int main() {
	HWND console = GetConsoleWindow();
	HDC hdc = GetDC(console);
	SelectObject(hdc, CreatePen(0, 30, RGB(255,255,255)));
	POINT p;
	GetCursorPos(&p);
	ScreenToClient(console, &p);
	MoveToEx(hdc, p.x, p.y, NULL);
	for (;;) {
		GetCursorPos(&p);
		ScreenToClient(console, &p);
		LineTo(hdc, p.x, p.y);
		Sleep(1);
	}
	ReleaseDC(console, hdc);
	cin.ignore();
	return 0;
}
William Hemsworth 1,339 Posting Virtuoso

I'm not here for people to be asking me why at the last minute.

Perhaps we wouldent if you didn't leave it to the last minute... If you had started this earlier and realized that you need help mabey some of us would be more inclined to help you.

William Hemsworth 1,339 Posting Virtuoso

Try this.

template<class type> inline
bool IsPrime(type val) {
	if (val==2)return 1;
	else if (val == 1) return 0;
	else if (val%2==0) return 0;
	register bool prime = 1;
	for (register type i = 3; i < val/2;i+=2) {
		if (!(val%i)) {
			prime = 0;
			break;
		}
	}
	return prime;
}
William Hemsworth 1,339 Posting Virtuoso

And to let the user enter the binary you dont need more than 50 chars.

int main() {
	cout<<"Enter the binnary number: ";
	char bin[50];
	cin >> bin;
	cout << (toBase(fromBase<int>(bin, 2, "01"), 8, "012345678"));
	cin.ignore();
	cin.ignore();
	return 0;
}
William Hemsworth 1,339 Posting Virtuoso

btw, binary is spelt with 1 'n' :)
heres my code:

#include<iostream>
using namespace std;

template<class t> inline
char *toBase(t val, int base, char *values) {
	register char d = 1;
	t c;
	register bool _signed = val < 0;
	if(val >= 0) for (c = base; c <= val; c *= base, d++);
	else for (c = -base; c>=val; c*=base, d++);
	register char i = d + _signed;
	char *bin = new char[i+1];
	if (_signed)
		bin[0]='-';
	for (val *= base; i - _signed;i--)
		bin[i-1] = values[
			(val /= base,(char) ((val % base) < 0 
			? -(val%base) : (val%base)))
		];
	bin[d + _signed]='\0';
	return bin;
}


// Returns index of first matched char
inline char GetIndex(char *str, char c) {
	for (char i = 0;str[i];i++) {
		if (str[i]==c)
			return i;
	}
	return 0;
}


template<class t> inline
t fromBase(char *val, char base, char *values) {
	t v = 0;
	for (char i=0;val[i];i++) {
		v *= base;
		v += GetIndex(values, val[i]);
	}
	return v;
}

int main() {
	char *bin = "100101";
	cout << (toBase(fromBase<int>(bin, 2, "01"), 8, "012345678")); // output 45
	cin.ignore();
	return 0;
}

In your code there is no need to allocate 10000 chars.

William Hemsworth 1,339 Posting Virtuoso

I learned C++ off "C++ A Beginner's Guide", its a very good book and it is probably what your looking for.
http://www.amazon.co.uk/Beginners-Guide-Second-Guides-McGraw-Hill/dp/0072232153

William Hemsworth 1,339 Posting Virtuoso

Thats good if your just trying to print the values, but to actually convert between the different bases I think you have to make your own functions. I have already made them :)

#include<iostream>
using namespace std;



template<class t> inline
char *toBase(t val, int base, char *values) {
	register char d = 1;
	t c;
	register bool _signed = val < 0;
	if(val >= 0) for (c = base; c <= val; c *= base, d++);
	else for (c = -base; c>=val; c*=base, d++);
	register char i = d + _signed;
	char *bin = new char[i+1];
	if (_signed)
		bin[0]='-';
	for (val *= base; i - _signed;i--)
		bin[i-1] = values[
			(val /= base,(char) ((val % base) < 0 
			? -(val%base) : (val%base)))
		];
	bin[d + _signed]='\0';
	return bin;
}


// Returns index of first matched char
inline char GetIndex(char *str, char c) {
	for (char i = 0;str[i];i++) {
		if (str[i]==c)
			return i;
	}
	return 0;
}


template<class t> inline
t fromBase(char *val, char base, char *values) {
	t v = 0;
	for (char i=0;val[i];i++) {
		v *= base;
		v += GetIndex(values, val[i]);
	}
	return v;
}



int main() {
	/// BINARY
	char *str1 = toBase(255, 2, "01");
	cout << str1 << '\n'; // 11111111
	cout << fromBase<int>(str1, 2, "01") << "\n\n"; // Back to 255

	// OCTAL
	char *str2 = toBase(255, 8, "012345678");
	cout << str2 << '\n'; // 337
	cout << fromBase<int>(str2, 8, "012345678") << "\n\n"; // Back to 255

	// HEX
	char *str3 = toBase(255, 16, "0123456789ABCDEF"); …
William Hemsworth 1,339 Posting Virtuoso

Dont know why.., but I made the entire class for you (and me), including a parser and just about every operator available :)

Some examples on how it works:

  • fraction(33,99) automaticly turns into 1/3
  • Parser will work with spaces e.g
    fraction f = "1 /2 /    3";

    is the same as 1/2/3 (1.66666)

  • fraction f = 12.2; // f will cout "12/1/5"

Code is getting abit big so I have attached the code.
If you find any problems with it, let me know :icon_wink:

William Hemsworth 1,339 Posting Virtuoso

Thats a great site, ive played on some of their games before. I like this one :)
http://www.ferryhalim.com/orisinal/g3/bells.htm

William Hemsworth 1,339 Posting Virtuoso

Its a book.

William Hemsworth 1,339 Posting Virtuoso

Quote:

I love this book, its simply fantastic. I have tried another C++ Beginners book and i *thought* c++ was ridiculously hard and i would never acomplish it. ( sams teach yourself c++ in 21 days ) i mean i had read like 2 hundred pages of this book and it was still on the basics - i think i hadn't even reached the cin >> command !! this one however does move at an okay pace. Herb Shild really knows his stuff, sometimes however he explains it a little TOO thoughrouly and i end up having to re-read certain parts of the chapter again. There is a learning cve towards the end of this book though. it suddenly becomes a lot more comlicated once you hit the pointers, although im pretty sure this is because i had a little experience in the BASIC language, and nothing at all like pointers ever came up. I attempt to read 1 chapter in a go, although after i feel my brain has been fried in the latter parts of the book.

William Hemsworth 1,339 Posting Virtuoso

Black Magic, I recommend you get a book on basic C++ because it seems like you could really use one. I can recommend the book I learned C++ with when I was about 12 years old. It explains everything very well and will solve most of your problems.

http://www.amazon.co.uk/Beginners-Guide-Second-Guides-McGraw-Hill/dp/0072232153

William Hemsworth 1,339 Posting Virtuoso

'0100' is not a string. "0100" is.
Only use ' ' for single chars, use "" for strings;

William Hemsworth 1,339 Posting Virtuoso

And the multiplication is faily easy:

fraction operator *(fraction &fraction2) {
	int n1 = Numerator;
	int d1 = Denominator;
	int n2 = fraction2.Numerator;
	int d2 = fraction2.Denominator;
	fraction f(n1 * n2, d1 * d2);
	f.Shrink();
	return f;
}
William Hemsworth 1,339 Posting Virtuoso

Heres the corrected code:

#include<iostream>
using namespace std;

class fraction {
public:
	int Numerator;
	int Denominator;
	fraction(int n, int d) {
		Numerator = n;
		Denominator = d;
	}
	bool Shrink() {
		bool sucessful = 0;
		for (int i = min(Numerator, Denominator); i; i--) {
			if ((Numerator % i == 0) && (Denominator % i == 0)) {
				Numerator /= i;
				Denominator /= i;
				sucessful = 1;
			}
		}
		return sucessful;
	}
	fraction operator +(fraction &fraction2) {
		int n1 = Numerator;
		int d1 = Denominator;
		int n2 = fraction2.Numerator;
		int d2 = fraction2.Denominator;
		int MatchedDenominator = d1 * d2;
		fraction f(
			((MatchedDenominator / d1) * n1) + 
			((MatchedDenominator / d2) * n2)
			,MatchedDenominator);
		f.Shrink();
		return f;
	}
	void Display() {
		cout << Numerator << '/' << Denominator;
	}
};

int main() {
	fraction f1(235, 1000);
	fraction f2(2, 10);
	fraction f3 = f1 + f2;
	f3.Display();
	cin.ignore();
	return 0;
}

Should work perfectly :)

William Hemsworth 1,339 Posting Virtuoso

You might have correct abit of that ^^, but its the right idea. My maths isn't that amazing.

William Hemsworth 1,339 Posting Virtuoso

Perhaps a class like this might help.. Ive done abit for you.

#include<iostream>
using namespace std;

class fraction {
public:
	int Numerator;
	int Denominator;
	fraction(int n, int d) {
		Numerator = n;
		Denominator = d;
	}
	bool Shrink() {
		bool sucessful = 0;
		for (int i = min(Numerator, Denominator); i; i--) {
			if ((Numerator % i == 0) && (Denominator % i == 0)) {
				Numerator /= i;
				Denominator /= i;
				sucessful = 1;
			}
		}
		return sucessful;
	}
	fraction operator +(fraction &fraction2) {
		int n1 = Numerator;
		int d1 = Denominator;
		int n2 = fraction2.Numerator;
		int d2 = fraction2.Denominator;
		int MatchedDenominator = d1 * d2;
		n1 = MatchedDenominator / d1;
		n2 = MatchedDenominator / d2;
		fraction f(n1+n2,MatchedDenominator);
		f.Shrink();
		return f;
	}
};

int main() {
	fraction num1(1, 2);
	fraction num2(1, 3);
	fraction num3 = num1 + num2;
	cout << num3.Numerator << '/' << num3.Denominator;
	cin.ignore();
	return 0;
}
William Hemsworth 1,339 Posting Virtuoso

Thanks :), some more options on it:

  • Megashift makes the balls shift to the right and re-appear when a column is blank
  • You can change the dimensions to a maximum of 40, 30

I also found out that if your on max dimensions, with only two balls colours and megashift the game will never end.. unless your REALLY unlucky :D

William Hemsworth 1,339 Posting Virtuoso

Good luck...:D

William Hemsworth 1,339 Posting Virtuoso

Ooooo, I made a game very similar to this in C++.. try it and see what score you can get.
:)

William Hemsworth 1,339 Posting Virtuoso

This is quite sad.. You want to learn a programming language just to cheat on games like runescape. First of all these kinds of games will trace it unless you have good enough programming skills to make in untraceable, and theres no easy way to do it unless you learn a reasonable amount of C++.

Salem commented: Quite so, figuring out how to hide will take longer still - wait, what's that knock on the door... +16
William Hemsworth 1,339 Posting Virtuoso

Im quite anoyed I named myself Williamhemswort by accident.. its actually ment to be WilliamHemsworth =) I might change it some day...

William Hemsworth 1,339 Posting Virtuoso

There wouldent be smilies if you had used code tags .. :icon_wink:
And stop complaining, I personally would really like to have programming lessons at school, and I wouldent leave something like this to the last minute.

William Hemsworth 1,339 Posting Virtuoso

It works because each character contains a value, for example:

'A' is equal 65 // 01100001

01000001 // 65
OR    00100000 // 32
     ----------
      01100001 // 97

97 = 'a'

William Hemsworth 1,339 Posting Virtuoso

This function converts a string to lowercase usering OR

char *ToLowerCase(char *text) {
	char *str = new char[strlen(text)];
	register int i;
	for (i=0;text[i];i++)
		str[i] = text[i] >= 'A' && text[i] <= 'Z' ?
		text[i] | 32 : text[i];
	str[i] = '\0';
	return str;
}
William Hemsworth 1,339 Posting Virtuoso

Are you sure that if you just start a new Win32 application and add '#include<windows.h>' to the start of it that it wont find it ?

William Hemsworth 1,339 Posting Virtuoso

Yeah, I know, its really does suck.
All they attempt to teach us is word, excel and publisher..:angry:

William Hemsworth 1,339 Posting Virtuoso

No problem, just found out we are both 14 years old. =)

William Hemsworth 1,339 Posting Virtuoso

This will draw a temporary rectangle on the console:

#define _WIN32_WINNT 0x0500
#include<windows.h>
#include<iostream>

int main() {
	HWND console = GetConsoleWindow();
	HDC dc = GetDC(console);
	Rectangle(dc, 50, 50, 100, 100);
	ReleaseDC(console, dc);
	std::cin.ignore();
	return 0;
}
William Hemsworth 1,339 Posting Virtuoso

You have to include the parameters in the open() function.
When opening the file just have:

myfile.open ("lover_names.txt", ios::ate | ios::app);

instead of

myfile.open ("lover_names.txt"); ios::ate;

That is all, then you can simply just write to the end of the file by using:

myfile << "Text";
William Hemsworth 1,339 Posting Virtuoso

also, it might help to have:

myfile.open ("lover_names.txt", ios::ate | ios::app);

So it automaticly seeks the end of the file before you begin writing to it.

William Hemsworth 1,339 Posting Virtuoso

Well, it is fairly obvious where the changes are, but I added

do {

where the loop should start and just before the end theres:

} while (!security);

so that the loop will only break if the variable 'security' is true.

William Hemsworth 1,339 Posting Virtuoso

Here is an exmaple to help you.

#include<iostream>
using namespace std;

int main() {
	char str[] = "one two three four five";
	bool wasSpace = 1;
	for (int i = 0; str[i]; i++) {
		if (wasSpace)
			str[i] &= str[i] >= 'a' && str[i] <= 'z' ? 223 : 0;
		wasSpace = str[i] == ' ';
	}
	cout << str;
	cin.ignore();
	return 0;
}
William Hemsworth 1,339 Posting Virtuoso
//Login

#include <iostream>
#include <string>
#include <conio.h>

using namespace std;

int main()

{
   
   
    cout << "\tWelcome to Login\n";
    int security = 0;
    

    do {
    string username;
    cout << "\nUsername: ";
    cin >> username;
    
    string 
    password;
    cout << "Password: ";
    cin >> password;
    
    if (username == "echoestroy" && password == "561654")
    {
                 cout << "\nWelcome Echoestroy.";
                 security = 5;
    }
    
        if (username == "krissyk6" && password == "spike")
    {
                 cout << "\nWelcome Krissyk6.";
                 security = 5;
    }
    
        if (username == "cjochoate" && password == "troy")
    {
                 cout << "\nWelcome cjochoate.";
                 security = 5;
    }
    
        if (username == "guest" || password == "guest")
    {    
                 cout << "\nWelcome Guest.";
                 security = 1;
    }
    
    if (!security)
       cout << "\nYour login has failed. Please check your username and password and try again";
    } while (!security);
       

    getch(); 
    return 0;

}

this should work.