William Hemsworth 1,339 Posting Virtuoso

Im using Vista Ultimate, and it works fine on my computer :P

William Hemsworth 1,339 Posting Virtuoso

I think its about time you learn to use code tags, even though you have already been told to use them before and ignored what was said. Try again with code tags..

William Hemsworth 1,339 Posting Virtuoso

Try this.

class Point {
public:

   double x;
   double y;

   Point() {
      x = 0;
      y = 0;
   }

   Point(double _x, double _y);
      x = _x;
      y = _y;
   }

   Point &operator =(const Point &p) {
      x = p.x;
      y = p.y;
      return *this;
   }
};
William Hemsworth 1,339 Posting Virtuoso

In WinProc() I think you need to add code for WM_CREATE.

You dont need anything there, it is simply for any extra things you want to do just before the window displays.

Ok, theres quite a few problems in this code, I will list a couple of them.

  • Your window class (WinClass) structure is missing alot of variables the need setting, to register the class you need every variable assigned with a value.
  • You should use RegisterClassEx, not RegisterClass as you should using the WNDCLASSEX structure.

and quite a few more...

I have modified your code so that it compiles and works ok. I hope this helps :)

#include <windows.h>

LRESULT CALLBACK WinProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

int WINAPI WinMain (HINSTANCE hThisInst, HINSTANCE hPrevInst, LPSTR lpszCmdArgs, int nWinMode)
{
	MSG Msg;
	WNDCLASSEX WinClass;
	HWND hWnd;
	

	WinClass.hInstance = hThisInst;
	WinClass.lpszClassName = "Bhoot";
	WinClass.lpfnWndProc = WinProc;
	WinClass.style = 0;
	WinClass.cbSize = sizeof (WNDCLASSEX);
	WinClass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);

	// You missed out these
	WinClass.cbClsExtra = 0;
	WinClass.cbWndExtra = 0;
	WinClass.hCursor = LoadCursor(NULL, IDC_ARROW);
	WinClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
	WinClass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
	WinClass.lpszMenuName = NULL;

	if (!RegisterClassEx(&WinClass)) 
		return 0;
	
	hWnd = CreateWindow("Bhoot",
			"Bhoot",
			WS_OVERLAPPEDWINDOW,
			CW_USEDEFAULT,
			CW_USEDEFAULT,
			CW_USEDEFAULT,
			CW_USEDEFAULT,
			HWND_DESKTOP,
			NULL,
			hThisInst,
			NULL);

	ShowWindow(hWnd, nWinMode);
	UpdateWindow(hWnd);

	while (GetMessage(&Msg, NULL, 0, 0) > 0)
	{
		TranslateMessage(&Msg);
		DispatchMessage(&Msg);
	}

	return (int) Msg.wParam;

}


LRESULT CALLBACK WinProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
	switch (Msg)
	{
		case WM_DESTROY:
			PostQuitMessage(0);
		break;

		default:
			return DefWindowProc (hWnd, Msg, wParam, …
William Hemsworth 1,339 Posting Virtuoso

Thats not really the point ^_^ But its always good practice to make sure that there are no warnings what so ever.

William Hemsworth 1,339 Posting Virtuoso

Thanks for using code tags on your first post :) its not often that happends. Some of your indentation is a bit strange so I will fix that up, I also removed one warning to do with signed / unsigned comparisons.

#include <iostream>
#include <string>
#include <iomanip>
#include <string.h>
#include <fstream>
    
using namespace std;

void displayBinary(unsigned);

int main()
{
	string str;
	fstream file_op("c:\\test_file.txt", ios::in);

	while (file_op >> str) {
		for (size_t i = 0; i < str.length(); i++) {
			displayBinary((unsigned)str.at(i));
		}
	}

	cout << endl;
	cout << endl;

	file_op.close();
	return 0;
}

void displayBinary(unsigned u)
{
	register int b;

	for (b = 128; b > 0; b = b/2) {
		(u & b) ? (cout << '1') : (cout << '0');
	}
	cout << " ";
}

Now that its easier to read, try reading from the file byte by byte.
Heres how you would do that and pass it to your function displayBinary.

ifstream in("test_file.txt", ios::in);
char ch;

// Assign each byte to ch
// and then pass it to the function displayBinary
while (in.get(ch)) {
	displayBinary(ch);
}

in.close();

To save it back to a file you do basically the same thing, except this time use the ofstream and use ofstream::put to write it to the file.

Try modifying the displayBinary function like this.

ofstream out("output.txt", ios::out);
void displayBinary(unsigned u)
{
	register int b;
	char bit;

	for (b = 128; b > 0; b = b/2) {
		(u & b) ? (bit = '1') …
William Hemsworth 1,339 Posting Virtuoso

I'll just hope you're not in highschool yet so...here's the first function you'll need...it's pretty straightforward:

char letter( int mark ) {
     if( mark <= 39 ) return 'F';
     else if( mark <= 49 ) return 'E';
     else if( mark <= 59 ) return 'D';
     else if( mark <= 69 ) return 'C';
     else if( mark <= 79 ) return 'B';
     else if( mark <= 100 ) return 'A'; 
}

Theres one problem with this function that may give you a compiler warning.
Heres what I got:

warning C4715: 'letter' : not all control paths return a value

To fix it just add this:

char letter( int mark ) {
     if( mark <= 39 ) return 'F';
     else if( mark <= 49 ) return 'E';
     else if( mark <= 59 ) return 'D';
     else if( mark <= 69 ) return 'C';
     else if( mark <= 79 ) return 'B';
     else if( mark <= 100 ) return 'A'; 
     return 0;
}

This way the function is guaranteed to return a value.

William Hemsworth 1,339 Posting Virtuoso

This is pathetic, honestly. Instead of trying to pay people to do this simple task you could do in a couple of hours, show some effort and do it yourself. Remember we are only here to offer help, not to do it for you.

William Hemsworth 1,339 Posting Virtuoso

So because you didn't find it funny you gave 4 people unnessasery negative reputation for disagreeing with you... sort of childish :D

William Hemsworth 1,339 Posting Virtuoso

Yeh, thanks to Ancient Dragon I think theres been some moments when I have had higher reputation than post count :)

William Hemsworth 1,339 Posting Virtuoso

To be honest, that didnt really help as all the indentation has been lost (assuming it was there in the first place)

William Hemsworth 1,339 Posting Virtuoso

One time (I forget what thread) someone else mentioned that and Dani explained it is supposed to be a tongue in cheek kinda of thing.

Ahh :) ok

William Hemsworth 1,339 Posting Virtuoso

How about, when giving negative reputation, a message box appears saying "Thanks for adding Repuation to this user. May you be lucky enough to recieve the same Reputation back in turn." :P

William Hemsworth 1,339 Posting Virtuoso

muraliaa, that has got to be one of the worst written codes ever, the indentation is all messed up, you havent used code tags, and you have your void main. Also you havent added any files to include, so the functions printf, getch and clrscr are all undefined. I wouldent consider this any help at all.

William Hemsworth 1,339 Posting Virtuoso

Uhm, I think its quite obvious what my name is supposed to be, would you mind changing it to WilliamHemsworth please :) ?? It was the worst possible mistake I could do when making this account :D

William Hemsworth 1,339 Posting Virtuoso

Hey,

My problem is im not recieving instant email notifications anymore, it has just completely stopped for one moment to the next. All my settings seem to be ok and when a reply to a thread, under the Thread Subscription it is set to Instant email notification. Im not sure whats causing the problem or how to fix it.

Can anybody help :| ??

William Hemsworth 1,339 Posting Virtuoso

Pointing to a 2D array is just like pointing to a 1D array, all the pointer does it point to the very first element of the array. Heres an example that shows how you can point to multi-dimensional arrays by using pointers.

#include<iostream>
using namespace std;

void DisplayNums1D(int *nums, int length1) {
	for (int i = 0; i < length1; ++i) {
		cout << nums[i] << '\n';
	}
}

void DisplayNums2D(int *nums, int length1, int length2) {
	for (int i = 0; i < length1; ++i) {
		for (int j = 0; j < length2; ++j) {
			cout << nums[i*length2 + j] << '\n';
		}
	}
}

int main() {
	int _1D[5]    = {1, 2, 3, 4, 5};

	int _2D[5][2] = {1, 2,
			 3, 4,
			 5, 6,
			 7, 8,
			 9, 10};

	cout << "\n1D:\n\n";
	DisplayNums1D(&_1D[0], 5);

	cout << "\n2D:\n\n";
	DisplayNums2D(&_2D[0][0], 5, 2);

	cin.ignore();

	return 0;
}

To understand how it works you have to think of a 2D array as a 1D array, imagine you have this 2D array with dimensions [5][2]:

[B]index	1	2[/B]
[B]1[/B]	1	2
[B]2[/B]	3	4
[B]3[/B]	5	6
[B]4[/B]	7	8
[B]5[/B]	9	10

You can imagine it as a 1D array when stored in memory, like this.

[B]index[/B]
1	2	3	4	5	6	7	8	9	10

and by pointing to the sixth element in the array, its the same as pointing to [1][3] in the first 2D array.

Hope this helps you understand.

William Hemsworth 1,339 Posting Virtuoso

Yes, use code tags, post specific question and errors if there are any, your not going to get much help unless you do. :icon_neutral:

William Hemsworth 1,339 Posting Virtuoso

> The problem is -- how will you know which one is the browser?
Simple :) You can use Spy++ to find out the browsers class name and then you can narrow down which windows are browsers. I found out these:

Firefox's Class:	MozillaUIWindowClass
IExplorer Class:	IEFrame

Now using AD's suggestion, using EnumWindows you can narrow it down only to the internet explorers.

Another helpful function you could try, FindWindow.

If you have firefox, test out this code and the title of the browser should change, if not simply change to class name to work with IExplorer.

#include<windows.h>

int main() {
   HWND firefox = FindWindow("MozillaUIWindowClass", NULL);
   SetWindowText(firefox, "Found it!!");
   return 0;
}

but this only works with one browser, so your probably better to stick with AD's technique.

Hope this helps.

William Hemsworth 1,339 Posting Virtuoso

>I really don't understand, what you both mean by saying 'code tags'
What ?!, are you serious. There are so many places on this site that fully explains how they work.. Try reading the link I posted.

William Hemsworth 1,339 Posting Virtuoso

Oh boy, where to start..
First, learn to use code tags, its not difficult.
Give more details on your problem, and show the errors you are getting.
Dont use void main.
Try posting this again, but this time.. properly
and then I will help you with your problem.

Read this thread which you should have read anyway before posting.
Read This Before Posting

William Hemsworth 1,339 Posting Virtuoso

I suggest you change the structure of your code to look something more like this. Handle all key events and make them only change the velocity, not the actual sprite location. Then at the end, when you have done all the key event handling, then add the velocity to the current location.

I haven't tested this so dont assume that it will work

// vx = Velocity x
// vy = Velocity y

if (event.type == SDL_KEYDOWN) {
   
   static bool jumping = false;
   
   if (keystates [SDLK_RIGHT]) {
      vx += VXSPEED;
   } else
   if (keystates [SDLK_LEFT]) {
      vx -= VXSPEED;
   }

   if (!jumping && keystates [SDLK_UP]) {
      vy = -JUMPSTRENGTH; // Jump upwards
      jumping = true;
   } else

   if (jumping) {
      vy += GRAVITY;
      if (posy > FLOOR_Y) {
         // Hit the floor
         posy = FLOOR_Y;
         vy = 0; // Stop falling
         jumping = false;
      }
   }
   
} else {
   
}

// Mabey add friction to slow sprite down
// About 0.95 would be appropriate
posx *= FRICTION;

// Now apply velocity to current position
posx += vx;
posy += vy;

Remember, this is only how you should structure the code if your going to be using velocity. To be totally honest I dont even think you need velocity for the kind of game that this is, just the jumping. If this code works the way I think it should, then when you press the UP key, the sprite should jump and fall back to the ground, and when …

William Hemsworth 1,339 Posting Virtuoso

You have to use double backwards slash, try changing it to this.

CreateDirectory(_T("c:\\program files\\Testing"))

Hope this helps.

William Hemsworth 1,339 Posting Virtuoso

@williamhemswort
namespaces shouldn't end with a semicolon (though AD didn't point that out so I'm not sure I'm right about that...). I also don't think non const variables can be defined outside a function, though I could be wrong about that as well. Not sure what's wrong with the using statements.

edit: Checked cplusplus.com - right about no semi-colon, wrong about initializing non-consts.

Pfftt, not the biggest mistake in the world is it :) and I have no compiler where I am
at the moment (coulden't test) so cut me some slack ;)

iamthwee commented: For posting code with compiling /testing. -3
Alex Edwards commented: It has happened to me before too - you're not alone! =) +3
William Hemsworth 1,339 Posting Virtuoso

system() takes a char array (pointer) as an argument, if you want to run an application you could use this simple function.

void Run(char *app) {
   std::string command = "start ";
   command += app;
   system(command.c_str());
}

Now to call that function it should look something like this.

Run("notepad.exe");

and notepad should open.

This may not be the best and most portable method though.

Hope this helps.

William Hemsworth 1,339 Posting Virtuoso

While your adding numbers to the array, just check if the array already has the value, if so, then try again. This seems to do the trick.

#include <iostream>

using namespace std;

int main()
{
    int i, j, k, randomNumber[10];

    for(i = 0; i < 10; i++)
    {

            randomNumber[i] = rand() % 10 + 1;
            for (int q = 0; q < i; ++q)
            {
                    if (randomNumber[q] == randomNumber[i]) // Array already has value
                    {
                            --i; // Retry
                            break;
                    }
            }
    }

    for(k = 0; k < 10; k++)
    {
            cout << randomNumber[k] << ", ";
    }

    cin.get();
}

Hope this helps.

William Hemsworth 1,339 Posting Virtuoso

where did no change it? Looks the same to me.

include <iostream>

namespace A {
   int var = 10; <<< error here
};

namespace B {
   int var = 20; <<< error here
};

using namespace A; <<< error here
using namespace B; <<< error here
<snip>

Ehh ?? Those aren't errors.

Ancient Dragon commented: you are right :) +34
William Hemsworth 1,339 Posting Virtuoso

I know ^.^ I changed it as fast as I could, way before you posted.

William Hemsworth 1,339 Posting Virtuoso

Its your choise if you want to include namespaces, but they are there for a reason, mainly for structuring your code and avoiding name confliction. Take this example:

#include <iostream>

namespace A {
   int var = 10;
};

namespace B {
   int var = 20;
};

using namespace A;
using namespace B;

int main() {
   std::cout << var; // Which one are we talking about ??
   std::cout << A::var; // Displays  10
   std::cout << B::var; // Displays  20
   return 0;
}

Hope this helps.

William Hemsworth 1,339 Posting Virtuoso

> Also, why use 3.14 when you already defined PI ?
I get the feeling that he didn't write this code, and didn't take the time to look through it first to see what resources have already been given. If he did write the code, then im amazed that he is doing some quite complex windows stuff without knowing the very basics.

William Hemsworth 1,339 Posting Virtuoso

Stop posting in this thread o.0 its 4 years old.

William Hemsworth 1,339 Posting Virtuoso

This sounds like a tricky project, for your first question, try looking up windows hooks. It is most lightly what your looking for. For your second quesion I think you have to scan through each child window, mabey by using EnumChildWindows with the web browser and somehow read each word, mabey the GetWindowText function or WM_GETTEXT might be what your looking for, but they´re might be other (better) ways.

I hope this helps.

William Hemsworth 1,339 Posting Virtuoso

That's not a reasonable solution. If class A contains hundreds of lines of code/methods, do you really intend to duplicate all of them in class B, then try to make class B act like class A? Sorry, but IMO that is just a lousy suggestion.

You dont need to rewrite all the code / functions. Just the variables you need. Heres another example :)

#include<iostream>
using namespace std;

class A {
private:
    int a;
    int b;
    int c;
    int d;
    int e;
    int f;
    int g; // Want to acess this variable
public:
    void SetG(int value) {
        g = value;
    }
};

class B {
public:
    int unneeded[6];
    int g;
};

int main() {
    A a;
    a.SetG(100);
    
    B *b = reinterpret_cast<B*>(&a);
    
    cout << b->g;
    
    cin.ignore();
    return 0;
}

I personally dont see a problem with it, if it works.

William Hemsworth 1,339 Posting Virtuoso

Not saying you should use it, but one way is to remake the structure with the same variable types and sizes, but leave all the members public, heres an exmaple.

#include<iostream>
using namespace std;

class A {
private:
    int a;
public:
    A() { a = 10; }
};

class B {
public:
    int a;
};

int main() {
    A a;
    B *b = reinterpret_cast<B*>(&a);
    cout << b->a; // Displaying private member in a
    cin.ignore();
    return 0;
}
William Hemsworth 1,339 Posting Virtuoso

I dont think friend does anything outside of a class in this case, but you should pass MyClass as a reference because that way your always passing a 32-Bit variable, by passing the actual object it could reduce performance unless the object itself is also has 32-Bit´s.

William Hemsworth 1,339 Posting Virtuoso

A few things you should add if your defining the function within the class.

[B]friend[/B] ostream &operator<<(ostream &cout,MyClass [B]&[/B]obj)
{
     cout << "Output members here.";

    return cout;
}
William Hemsworth 1,339 Posting Virtuoso

If you want to find a name and display the telephone number you have to loop through each person in the address book and then use the strcmp function which takes two char pointers as parameters and returns 0 if they match.

It would look something similar to this:

char *nameToFind = "John";

for (int i = 0; i < peopleCount; ++i) {
   if (strcmp(names[i], nameToFind) == 0) {
      std::cout << phoneNo[i];
   }
}

The only problem with this is that if you want to search for part of a name, the code above wont work. So in order for the program to return "John Smith´s" number by just typing the name "John", you need a seperate function that checks to see whether "John Smith" contains the word "John".
For this try looking up the strstr function.

Hope this helps.

William Hemsworth 1,339 Posting Virtuoso

Just a few things I noticed here:

void Tools::setToolName(string toolNameString)
{
   // copy at most 20 characters for the tool name
    const char *toolNameValue = toolNameString.c_str();
    int length = int(toolNameString.length());
    strncpy(toolName, toolNameValue, length);
    toolName[ length ] = '\0'; // append null character to lastName
}
William Hemsworth 1,339 Posting Virtuoso

>I cannot get this string to store in the array appropriately.
exactly what do you mean by this ?? whats going wrong ? :-/

William Hemsworth 1,339 Posting Virtuoso

Oops, misread, sorry :P

William Hemsworth 1,339 Posting Virtuoso

I had this problem many times, its not vista, you have to make sure that the program configuration is set to "Release" instead of "Debug". But I came across so many of these errors when using .NET and got tyred of it, so I stopped using it and have never had any problems since :)

Wiki_Tiki commented: Helped me solve a problem i've been trying to solve for 2 years +1
William Hemsworth 1,339 Posting Virtuoso

> 2. Pointers degrade reliability of C++ programs due to security issues
I try to only use pointers when necessary, if your not going to be accessing others parts of the memory from that pointer, then simply use references. This will also make the code more readable.

William Hemsworth 1,339 Posting Virtuoso

If you really want to know how to convert a string to an array:

char strarray[100];
string str = "Hello";
for(int i = 0;i < str.length();i++)
    strarray[i] = str[i];

This will work, but in future when copying variables like this from a vector, try to do it like this:

char strarray[100];
string str = "Hello";
int arrayLength = str.length();
for (int i = 0; i < arrayLength; i++)
    strarray[i] = str[i];

By using a variable to store the array length you do not need to call the .length() function for every cycle of the loop and will speed things up in more extreme cases.

Another way to access the char array is to simply get the pointer at the start of the string like this.

string str = "Hello";
char *cstr = &str[0];

Also this way the pointer isn´t const unlike the return value from the string::c_str() function.
(The only problem with this is that it is not a seperate char array, anything you change in cstr will also change in str).

Hope this helps.

William Hemsworth 1,339 Posting Virtuoso

Try adding this:

case WM_LBUTTONDOWN:
{ 
   float mx = 0;//mousex
   float my = 0;//mousey
   mx = LOWORD(lParam);
   my = HIWORD(lParam);
   [B]POINT mp;
   mp.x = mx;
   mp.y = my;
   ScreenToClient(hwnd, &mp);
   mx = mp.x;
   my = mp.y;[/B]
   return (0);
}

For more information look here.

edit: I just realised this might not be what your looking for ;)

William Hemsworth 1,339 Posting Virtuoso

the BOOL typedef'd as an int isn't actually so bad, it allows you to set your own returns values like:

#define FALSE		0
#define TRUE		1
#define OVERFLOW	2
#define FAIL		3
#define SUCCESS		4

any many more... :P

and can be more understood when returned as BOOL instead of int.

William Hemsworth 1,339 Posting Virtuoso

Something like this perhaps ?

#pragma comment(lib, "mylib.lib")
William Hemsworth 1,339 Posting Virtuoso

Yes, windows tend to do that for alot of types, and sometimes theres no need for them, for example in one of the header files I found these:

#define CONST               const
typedef int                 INT;
typedef float               FLOAT;

and hunderds more.. ;)

William Hemsworth 1,339 Posting Virtuoso

This example will read each word from a file, allow you to make the changes you want, and then write them back. The only problem with this example is that all indentation and extra spaces will be lost. To do it properly, you will have to load the entire file into a string, and make the changes manually.

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

const char fileName[] = "test.txt";

int main() {
	ifstream in(fileName);
	
	string word;
	vector<string> words;

	while (in >> word) {
		words.push_back(word);
	}

	/* Make changes */

	ofstream out(fileName);

	size_t size = words.size();

	for (size_t i = 0; i < size; ++i) {
		out << words[i] << ' ';
	}

	return 0;
}

Hope this helps.

William Hemsworth 1,339 Posting Virtuoso

Maybe the problem is in the include you need to add (#include <string>)

#include <string>
#include <iostream>

using namespace std ;

int main()
{
 string sName;
 cin >> sName;
 return 0;
}

Ahh, I never knew you could do that :P

William Hemsworth 1,339 Posting Virtuoso

To use the srand function with time(0) you must include <ctime>. Where as for the first one, I think you have to use a plain char array and then convert that to type string.

It would also help if you showed the errors MSV was giving.