William Hemsworth 1,339 Posting Virtuoso

Sorry :-/ kinda got into the habbit of doing that.

William Hemsworth 1,339 Posting Virtuoso

Mabey this function I made will help you:

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

You can use it do convert any number to a char array of any base from 2 - 10.
for example

toBase(97, 2) // output will be "1100001"
William Hemsworth 1,339 Posting Virtuoso

not sure, but for doing clicks, you can just do:

mouse_event(MOUSEEVENTF_RIGHTDOWN | MOUSEEVENTF_RIGHTUP, x, y, 0, 0);

for a right click

William Hemsworth 1,339 Posting Virtuoso

What exactly do you need us to check?

-Something must be going wrong because I get 34 errors trying to compile this

William Hemsworth 1,339 Posting Virtuoso

I learned windows programming off that tutorial, its very good :)

William Hemsworth 1,339 Posting Virtuoso

uhm, not exactly sure, but mabey the itoa function automaticly allocates the appropriate memory?

William Hemsworth 1,339 Posting Virtuoso

I would help you If you provided abit more info on what your trying to do.

William Hemsworth 1,339 Posting Virtuoso

main() is the start of any C++ application, why do you need to do it without it ?

William Hemsworth 1,339 Posting Virtuoso

This code with print all the characters from any file to the console.

#include<iostream>
#include<fstream>
using namespace std;

const char fileName[] = "FILENAME";

int main() {
	ifstream in(fileName, ios::in | ios::binary);
	while (in) {
		cout << (char) in.get();
	}
	system("pause");
	return 0;
}
William Hemsworth 1,339 Posting Virtuoso

I just use google to search for how to use the parameters in the functions that I find in the windows library.

William Hemsworth 1,339 Posting Virtuoso

SetCursorPos(x,y) // in windows library

William Hemsworth 1,339 Posting Virtuoso

This should work for a left click:

mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
William Hemsworth 1,339 Posting Virtuoso

Why dont you say whats not working first..

William Hemsworth 1,339 Posting Virtuoso

It acts as an if-else statement for example:

a = b < 10 ? true : false;

is the same as..

if (b < 10) {
	a = true;
} else {
	b = false;
}
William Hemsworth 1,339 Posting Virtuoso

Here is a commented code that does the same as the image. :)

//Assignment 8: Pointers, Functions, and Input Validation
//By: Curtis Davenport

#include <iostream>
#include <cstdlib>

using namespace std;

bool isValid(char *name) {

	if (strlen(name) > 100)	return false;

	for (int i = 0; name[i]; i++) {
		if (name[i] < 'a')	return false;
	}

	return true;

}

int main()
{

	char firstname[1000]; // Buffer for first name
	char lastname[1000];  // Buffer for last name

	bool validName = false;

	do {

		cout << "Enter your first name is lowercase letters: ";
		cin >> firstname; // Allow user to enter first name
		validName = isValid(firstname);
		if (validName == false) cout << "Invalid entry. Try again...\n";

	} while (validName == false);

	cout << "\n"; // new line

	do {

		cout << "Enter your last name is lowercase letters: ";
		cin >> lastname;  // Allow user to enter last name
		validName = isValid(lastname);
		if (validName == false) cout << "Invalid entry. Try again...\n";

	} while (validName == false);

	cout << "\n";

	cout << "Your full name is " << firstname << " " << lastname << "\n\n";
	cout << "Your full has " << strlen(firstname) + strlen(lastname) << " characters\n";

	system("pause");

	return 0;

}
curt1203 commented: Very knowledgable +1
William Hemsworth 1,339 Posting Virtuoso

"Doctor Doctor!, I only have 50 seconds to live!"
-"Go over there and i will see you in a minute.."

William Hemsworth 1,339 Posting Virtuoso

Thanks mitrmkar!, releasing that dc fixed the problem.

William Hemsworth 1,339 Posting Virtuoso

Im quite sure its not the timers because It was leaking memory before I put those in so Im going to try your second point first.
Thanks :)

William Hemsworth 1,339 Posting Virtuoso

is this what your looking for ?

#include <iostream>
#include <windows.h>
using namespace std;
const char heart = 3, diamond = 4, club = 5, spade = 6;
int main() {
	cout << heart;
	Sleep(1000);
	system("cls"); // Clears the console
	cout << diamond;
	Sleep(1000);
	system("cls");
	cout << club;
	Sleep(1000);
	system("cls");
	cout << spade;
	Sleep(1000);
	cin.get();
	return 0;
}
William Hemsworth 1,339 Posting Virtuoso

Make a 2D array.

char fname[100][50];
fname[0] = "First Name1";
fname[1] = "First Name2";
... and so on

William Hemsworth 1,339 Posting Virtuoso

thanks mitrmkar, I did what you sead but I am still leaking memory =[

William Hemsworth 1,339 Posting Virtuoso

If I open up task manager and view the memory that SameGame is using, everytime a selection of balls are clicked, the memory usage goes up by 4-6k until it is eventually quite high. It slows down windows alot after a while.

William Hemsworth 1,339 Posting Virtuoso

I used them to turn the score (int) to a char array in this function, its in the code.
void DRAWSTATUS(HDC hdc)

William Hemsworth 1,339 Posting Virtuoso
int positionen = 0;
positionen = textBox1->SelectionStart;
this->textBox1->Select(0, 5);
this->textBox1->SelectionColor = Color::Blue;
this->textBox1->DeselectAll();
this->textBox1->SelectionStart = positionen;
this->textBox1->SelectionColor = Color::Black;

Hope it helps =]

William Hemsworth 1,339 Posting Virtuoso

Here is how I learn Win32 API, It is a very good tutorial: http://www.rohitab.com/discuss/index.php?act=Attach&type=post&id=698

William Hemsworth 1,339 Posting Virtuoso

Actually, that was a problem but its not the main memory leak. I think it takes place in WM_LBUTTONDOWN but I cant find exactly where abouts.

William Hemsworth 1,339 Posting Virtuoso

Thanks for finding it!, spent ages looking.

William Hemsworth 1,339 Posting Virtuoso

Hi

I have a memory leak somewhere in this code but I have no idea where. Can anybody help me out ?

#include <windows.h>
#include <mmsystem.h>
#pragma comment(lib, "winmm.lib")
#include <fstream>
#include <time.h>
#include <cstring>
#include "resource.h"

using namespace std;

const char cn[] = "SameGame"; // ClassName

HBITMAP BLUEBMP		= LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BLUE1));
HBITMAP GREENBMP	= LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_GREEN1));
HBITMAP REDBMP		= LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_RED1));
HBITMAP YELLOWBMP	= LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_YELLOW1));
HBITMAP BLUEBMP_S	= LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BLUE2));
HBITMAP GREENBMP_S	= LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_GREEN2));
HBITMAP REDBMP_S	= LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_RED2));
HBITMAP YELLOWBMP_S	= LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_YELLOW2));

#define EMPTY		0

#define IS_SELECTED(B)	(B > 4)
#define IS_EMPTY(B)		(B == EMPTY)

#define SELECTED	8 // 1000
#define BLUE		1 // 0001
#define GREEN		2 // 0010
#define RED			3 // 0011
#define YELLOW		4 // 0100

int width	= 15; // Grid Width
int height	= 15; // Grid Height

#define ballSize	30 // Ball Diameter

#define ID_DELAY	1
#define ID_DELAY2	2

int score = 0;
int tempScore = 0;

bool MEGASHIFT = 0;

unsigned char grid[100][100];

HPEN pen = CreatePen(PS_SOLID , 0 , RGB(255,255,255));
HPEN panel = CreatePen(PS_SOLID , 0 , RGB(0,0,0));
HDC			hdc;
HBITMAP		bmp;
BITMAP		bm;
PAINTSTRUCT	ps;
HDC			_hdc;
HDC			_hdcMem;
HBITMAP		hbmOld;

int randNum;
int RandomNumber(int high, int low) {
	return ((rand() % high - low) + low + 1);
}

int bi; // Ball Index
int bc; // Ball count

int TB; // SHIFTING TOP BALL
int BB; // SHIFTING BOTTOM BALL
int RB; // SHIFTING RIGHT BALL
int LB; // SHIFTING LEFT …