William Hemsworth 1,339 Posting Virtuoso

For a windows solution, you could try this which will allow the user to press any key to continue (not just enter):

void Pause(char *message = "Press any key to continue . . . ") {
  std::cout << message;
  HANDLE hStdin; 
  DWORD cNumRead; 
  INPUT_RECORD irInBuf[1];

  if ( HANDLE(hStdin = GetStdHandle( STD_INPUT_HANDLE )) == INVALID_HANDLE_VALUE )
    return;

  while ( true )  { 
    if (! ReadConsoleInput( hStdin, irInBuf, 1, &cNumRead) )
      return;

    for (DWORD i = 0; i < cNumRead; ++i)
      if ( irInBuf[i].EventType == KEY_EVENT && irInBuf[i].Event.KeyEvent.bKeyDown ) {
        std::cout << '\n';
        return;
      }
  }
}

To remove the message, simply call it like this.

Pause("");
William Hemsworth 1,339 Posting Virtuoso

>Its just a chrome bug
Yep, I remember having the same problem when I was using chrome (gone back to firefox), and I reported the problem to chrome. Hopefully the problem will some day be fixed ;)

William Hemsworth 1,339 Posting Virtuoso

Look up the Sleep function to use as a delay for the message. To clear the screan, you can either use the "system("cls"), or better, do it manually:

void Clear() {
  DWORD n;
  DWORD size;
  COORD coord = {0};
  CONSOLE_SCREEN_BUFFER_INFO csbi;

  HANDLE h = GetStdHandle ( STD_OUTPUT_HANDLE );

  GetConsoleScreenBufferInfo ( h, &csbi );

  size = csbi.dwSize.X * csbi.dwSize.Y;

  FillConsoleOutputCharacter ( h, TEXT ( ' ' ), size, coord, &n );
  GetConsoleScreenBufferInfo ( h, &csbi );
  FillConsoleOutputAttribute ( h, csbi.wAttributes, size, coord, &n );

  SetConsoleCursorPosition ( h, coord );
}
William Hemsworth 1,339 Posting Virtuoso

So, I guess you dont plan on having this made using the windows API then, because of that, it wont be easy to allow shortcut keys like ctrl-f. Here is your code cleaned up a little with some unneeded code removed.

#include "iostream"
#include "fstream"
#include "string"

#define nula   0;

using namespace std;

char filename[_MAX_PATH];
char strings[100000001]="";

int main(int argc, char* argv[])
{
  system("CLS");
  system("color 8");

  cout << "\n//////////// WELCOME TO MUNEEB'S TEXT EDITOR \\\\\\\\\\\\\\\n\n";
  cout << "(PRESS ENTER WHEN YOU ARE DONE)\n\n\n\n";

  cin.getline(strings,100000001);

  system("color 16");

  cout << "\n\n\n------SAVE AS:-------\n";
  cout << "\nPLEASE WAIT.................................\n";   // Is this really necessary?
  cout << "ENTER THE FILNAME:";

  cin >> filename;

  ofstream go;
  go.open(filename);
  go << strings;

  system("CLS");
  cout << "TO END THIS PROGRAM\n";
  system("pause");
}

On line 10, you are making an array of characters with a size of 100000001, instead of using a ridiculously oversized array, simply use the standard std::string which will make everything a whole lot simpler. This is what the updated program should look like:

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

char filename[_MAX_PATH];
[B]std::string text;[/B]

int main(int argc, char* argv[])
{
  system("CLS");
  system("color 8");

  cout << "\n//////////// WELCOME TO MUNEEB'S TEXT EDITOR \\\\\\\\\\\\\\\n\n";
  cout << "(PRESS ENTER WHEN YOU ARE DONE)\n\n\n\n";

  [B]getline( cin, text, '\n' );[/B]

  system("color 16");

  cout << "\n\n\n------SAVE AS:-------\n";
  cout << "\nPLEASE WAIT.................................\n";
  cout << "ENTER THE FILNAME:";

  cin >> filename;

  ofstream go;
  go.open(filename);
  [B]go << text;[/B]

  system("CLS");
  cout << "TO END THIS PROGRAM\n";
  system("pause");
}

As for the shortcut keys, …

William Hemsworth 1,339 Posting Virtuoso

Nice find ; )

William Hemsworth 1,339 Posting Virtuoso

Why dont you ask google that, and we will help with any specific problems you have.

William Hemsworth 1,339 Posting Virtuoso

You're kidding me? :icon_eek:

Your home planet is: Silbob Silbob is a square planet roughly 64 million light years away from Earth. It's covered in trees and smells strongly of cheese and tomato. The inhabitants of Silbob are all governed by "The Voice", which tells them what to do (but don't worry, because it's qite quite really - it just means you don't have to think much). They all have really short hair (it's the fashion there) and quite like swimming, when "The Voice" lets them. At last, you finally know where you come from : )

William Hemsworth 1,339 Posting Virtuoso

Please use code-tags.

William Hemsworth 1,339 Posting Virtuoso

ohh guys plz..it is of ten important marks.. i dont have any time now.. i have to submit it tomorrow plz help me out.. and i dont even know how to start.. plz make me a a program of the text editor.. i would be very thankful.

We show no mercy :icon_twisted:

William Hemsworth 1,339 Posting Virtuoso

>I'd prefer to keep things simple, so would'nt like to use vectors + classes until I go thru it at uni.
Well, that wont work the way your trying, so if you want to keep things simple, stick with std::vector.

But if you need a solution that doesn't require a vector, do something like this:

#include <iostream>

int main() {
  // Init vector
  int nums[3];

  // Add objects to vector
  nums[0] = 5;
  nums[1] = 6;
  nums[2] = 7;

  // Add them all together
  int total = 0;
  int count = sizeof(nums) / sizeof(int);

  for (size_t i = 0; i < count; ++i)
    total += nums[i];

  // Display total
  std::cout << total;
}

Though, in this example, the array will not be resizable. If you make the nums array larger to begin with than you actually need, then you need to make sure each integer has a value of 0 so that when totalling up the values, they aren't included. It can be done like this:

int nums[10] = { 0 };

Hope this helps.

William Hemsworth 1,339 Posting Virtuoso

>let VC compiler generate them.
I don't like the code that's generated, I generally like to start everything from scratch. I like knowing I could still make an entire windows program with nothing more than notepad and a compiler :icon_cheesygrin:

William Hemsworth 1,339 Posting Virtuoso

How about the use of an std::vector, heres a small example.

#include <iostream>
#include <vector>

int main() {
  // Init vector
  std::vector<int> nums;

  // Add objects to vector
  nums.push_back( 5 );
  nums.push_back( 6 );
  nums.push_back( 7 );

  // Add them all together
  int total = 0;
  for (size_t i = 0; i < nums.size(); ++i)
    total += nums[i];

  // Display total
  std::cout << total;
}
William Hemsworth 1,339 Posting Virtuoso

>but i have an assignment to give
Hense the I. You have to do it, not us.

Comatose commented: Exactly +8
William Hemsworth 1,339 Posting Virtuoso

It's not exactly hard to memorize the code to make a window :P What's hard is being able to make the window do something interesting or useful.

William Hemsworth 1,339 Posting Virtuoso

Oh.. My.. God.

William Hemsworth 1,339 Posting Virtuoso

Create your own font, and you can change the font size yourself. Try changing your MDIChildWndProc's WM_CREATE message handler like this:

case WM_CREATE:
{
   char szFileName[MAX_PATH];
   HWND hEdit;

   hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "",
      WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL | ES_MULTILINE |
         ES_WANTRETURN,
      CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
      hwnd, (HMENU)IDC_CHILD_EDIT, g_hInst, NULL);

   HFONT font = CreateFont(14, 0, 0, 0, FW_DONTCARE, false, false, false, OEM_CHARSET,
                  OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
                  DEFAULT_PITCH | FF_DONTCARE, "Arial");

   SendMessage(hEdit, WM_SETFONT, (WPARAM)font, MAKELPARAM(TRUE, 0));

   GetWindowText(hwnd, szFileName, MAX_PATH);
   if(*szFileName != '[')
   {
      if(!LoadFile(hEdit, szFileName))
      {
         MessageBox(hwnd, "Couldn't Load File.", "Error.",
            MB_OK | MB_ICONEXCLAMATION);

         return -1; //cancel window creation
      }
   }
}
break;

Hope this helps.

William Hemsworth 1,339 Posting Virtuoso

If your new to C++, you should start on something much easier. I don't even know how to do this, but I can guess it involves some pretty complex stuff, so I don't think you're going to get this done unless someone literally gives you the entire code.

William Hemsworth 1,339 Posting Virtuoso

Well, what have you got sofar?

William Hemsworth 1,339 Posting Virtuoso

Doesn't anybody read the rules anymore? :icon_neutral:

William Hemsworth 1,339 Posting Virtuoso

Congratulations, 3 posts in a row without using code-tags.

William Hemsworth 1,339 Posting Virtuoso

What your trying to do with trimleft will only work with a reference to a pointer which is pointing at an array of chars, like this:

void trimLeft(char *&a)
{
  while (*a++ == ' ');
  a--;
}


int main() {
  char a[11] = "  smith";
  char *ptr = a;
  trimLeft(ptr);
  cout << ptr << endl;
}

You must realize that no data has been moved at all, however ptr is just pointing to a different part of the array you created to begin with. If you want to actually alter the array of characters, you will have to do something similar to what Ancient Dragon mentioned.

edit: I guess this thread should be moved to the C++ forum now ;)

William Hemsworth 1,339 Posting Virtuoso

Basically, inside the limits.h file, there will be lots of macros which define the maximum value for many different data types, It would look something like this.

#define MB_LEN_MAX    5             /* max. # bytes in multibyte char */
#define SHRT_MIN    (-32768)        /* minimum (signed) short value */
#define SHRT_MAX      32767         /* maximum (signed) short value */
#define USHRT_MAX     0xffff        /* maximum unsigned short value */
#define INT_MIN     (-2147483647 - 1) /* minimum (signed) int value */
#define INT_MAX       2147483647    /* maximum (signed) int value */
#define UINT_MAX      0xffffffff    /* maximum unsigned int value */
#define LONG_MIN    (-2147483647L - 1) /* minimum (signed) long value */
#define LONG_MAX      2147483647L   /* maximum (signed) long value */
#define ULONG_MAX     0xffffffffUL  /* maximum unsigned long value */
#define LLONG_MAX     9223372036854775807i64       /* maximum signed long long int value */
#define LLONG_MIN   (-9223372036854775807i64 - 1)  /* minimum signed long long int value */
#define ULLONG_MAX    0xffffffffffffffffui64       /* maximum unsigned long long int value */

You don't have to worry about all that, but as you are using the data type unsigned long int and want to know the maximum value it holds, the maximum value will be defined as ULONG_MAX like MosaicFuneral said. If this data type isn't big enough for you, try using a larger one like unsigned long long (with ULLONG_MAX as the macro containing it's maximum possible value).

Hope this helps clear things up for you.

William Hemsworth 1,339 Posting Virtuoso

You can't use a variable in a string like that, you have to manually add it to the string.

void title(const char *myTitle) // &mode?
{
   std::string command = "title ";
   command += myTitle;
   system( command.c_str() );
}

Also, what is the "&mode" there for?

William Hemsworth 1,339 Posting Virtuoso

>maybe I should just return the default constructor for T?
You could do that, and add a parameter for the caller to check if anything was found, like this:

template <class T>
T find(char x, T array[], bool &found){
  string str = "hello";
  found = true;
  for(int i = 0; i < str.length(); i++){
     if(x == str[i]) return array[i];
  }
  found = false;
  // Return default constructor
}
William Hemsworth 1,339 Posting Virtuoso

Maybe return an index or value that will never be used, for example, if T = int, return (-1 for example), and then the caller can do a check to see if a value was found, if not, -1 is returned.

William Hemsworth 1,339 Posting Virtuoso

Try using your head, or even a search engine. Link

William Hemsworth 1,339 Posting Virtuoso

Pretty amazing :)

William Hemsworth 1,339 Posting Virtuoso

I think what your looking for is a grid control, not a list box. They can be tricky to understand, but with the help of google, it shoulden't be too hard. Here is a good example on how to make one.

Hope this helps.

William Hemsworth 1,339 Posting Virtuoso

You don't need any library on Windows, GIF (animated or not) are native with Win32 api

It's not the fact that you can do it without any library's, it's just much easier to use them as it saves you a lot of trouble.

i dont get it, im using dark GDK with VC++ 2008 and they use that pic in one of the tutorials and it spins around with dbCreateAnimatedSprite(); and dbSprite(); like its supposed to but what im asking is if there is some program or something that you can do animations like that in

I've done that tutorial before, and know how it works, but I don't understand what it is you want. "some program or something that you can do animations", do you want to make a program to create your own animations? or just play them? You may have to be a bit more specific in your post what it is you want.

William Hemsworth 1,339 Posting Virtuoso

>able to make pictures capable of animating
If by that, you mean making an animated GIF image, you will have to download a library especially made for the GIF format. As for splitting up the image into 16 smaller ones, you can either use another bitmap library, or you can find a way to do it with the windows API (I'd use a bitmap library to make stuff easier).

William Hemsworth 1,339 Posting Virtuoso

Percept, Pirate, Repeat.

Haemoglobin.

William Hemsworth 1,339 Posting Virtuoso

FindWindow will only return a handle to one window, to do this you will have to loop through all opened applications and hide them one at a time. Try looking up the EnumWindows function, it may provide your solution.

William Hemsworth 1,339 Posting Virtuoso

An Alpen Bar :)

William Hemsworth 1,339 Posting Virtuoso

I will be happy once I leave my highschool and go to college :icon_cheesygrin:
Heh, but what really makes me happy is music, being with/talking to friends and going on holiday.

William Hemsworth 1,339 Posting Virtuoso
void swapLines(int j, int k)
{
  char *temp = malloc(sizeof(char) * 1000);
  temp = strings[j]; // What happened to the 1000 chars you just allocated?
  strings[j] = strings[k];
  strings[k] = temp;
}

Memory leak!

Remember to free any data you allocate using the free function.

William Hemsworth 1,339 Posting Virtuoso

Another way:

#include <iostream>

template<typename t, size_t s>
struct Array {
  t buffer[s];

  operator t*() {
    return buffer;
  }
};

Array<int, 5> getNums() {
  Array<int, 5> nums;
  nums[0] = 0;
  nums[1] = 1;
  nums[2] = 2;
  nums[3] = 3;
  nums[4] = 4;
  return nums;
}

int main() {
  Array<int, 5> nums = getNums();
}
StuXYZ commented: elegantly minimal +3
William Hemsworth 1,339 Posting Virtuoso

Of course...

Do you prefer cats more than dogs?

William Hemsworth 1,339 Posting Virtuoso
unsigned long double result = 0.0;
unsigned long double x = 1.0;
unsigned long double y = 1.0;
unsigned long double result2 = 0.0;

There is no such thing as an unsigned double.

As you only need to use integers, you should try using a 64-bit integer variable type instead of a double, as using a double will also give you inaccurate results. But you wont be able to get accurate big numbers using just the standard C++ library, you will need to use a seperate big number library or class such as this .

Hope this helps.

William Hemsworth 1,339 Posting Virtuoso

Try this instead:

//empresas[i].nome_empresa = "a string";
strcpy( empresas[i].nome_empresa, "a string" );
William Hemsworth 1,339 Posting Virtuoso

>I guess blocking input might be a bad idea since then you have no way of using the ctrl
Well, I still have the right control key on my keyboard.

But the point I was making is, in my keyboard hook, I made it so windows completely ignores that the control key was ever pressed, so no need to send the release key message, but for some reason... it didn't work, which is why i'm going to try Block Input :)

William Hemsworth 1,339 Posting Virtuoso

I will take your advice, and improve it. But cut me some slack :icon_lol: ...
I made this when I was 14 I think, didn't seem too bad at the time. XD

As for the control key always being left on, I could never quite figure out why that was happening, the keyboard hook stopped windows from processing it. I will try Block Input though, hopefully this is still helping chrischavez solve his problem (as well as mine) :D .

William Hemsworth 1,339 Posting Virtuoso

To begin with, I created a windows hook for the keyboard. This enables you to catch messages related to the keyboard and handle them before windows does.

bool ld = 0, // Left button down
rd = 0,      // Right button down
ud = 0,      // Up button down
dd = 0,      // Down button down
lcd = 0;     // Left Control key down

These are flags to show if any of the arrow keys or the left control key is being pressed, they are kept up to date in the keyboard hook.

I also set up a timer in the main windows message loop with an interval of 5ms. So every 5ms it checks if any of the arrow keys are down, if any of them are, then it will change the velocity the cursor is moving in the appropriate direction.

case WM_TIMER:
{

  // Check if keys are down
  if (ld) vx -= cursorSpeed;  // Left key
  if (rd) vx += cursorSpeed;  // Right key
  if (ud) vy -= cursorSpeed;  // Up key
  if (dd) vy += cursorSpeed;  // Down key

  GetCursorPos(&mousePos);

  // Add velocity to current coordinates
  x += vx;
  y += vy;

  // Slows the velocity of the cursor down
  vx *= cursorFriction;
  vy *= cursorFriction;

  // Calculate the average speed
  avSpeed = sqrt( vx * vx + vy * vy );

  if (avSpeed > 0.2) {
    // If cursor isn't almost stopped
    SetCursorPos(x, y);

  } else {
    // Allow user to move …
William Hemsworth 1,339 Posting Virtuoso

I made the same program once, but much more complex. In the end I used a similar technique to what Freaky_Chris mentioned, though I went the extra mile and added velocity & friction to make it look a little smoother.
On top of that, it allowed the user the left click using only the keyboard. I originally made this for a friend who had a problem and wasn't able to use his mouse, so I realize it might be slightly buggy in some areas, but overall it works pretty well.

I've attached the project & executable, it might help you improve yours. Move the cursor with the arrow keys, and use the left ctrl button to emulate a left click. You can change the options by right clicking on the notification icon (picture of a cursor) in your task bar.

Hope this helps :)

William Hemsworth 1,339 Posting Virtuoso

Just finished a plate of Gnocchi! :icon_razz:

William Hemsworth 1,339 Posting Virtuoso

>If you're desperate for small code, and you're in Windows there's MASM; but that's obviously a very different language from C++.

And you can use an executable compressor like nPack, see the attachment.

Just another option :icon_rolleyes:, but i've used it for compressing some programs/games before, and it works surprisingly well.

William Hemsworth 1,339 Posting Virtuoso

Try posting these in the Thoughts Of The Day thread ;)

Same applies for this one.

William Hemsworth 1,339 Posting Virtuoso

Next time, check the date that the thread was created before you post a couple hundred lines of badly formatted code which doesn't even work, especially without code-tags to somebody who probably had their problem solved a couple of years ago. Read this.

William Hemsworth 1,339 Posting Virtuoso

As far as I know, you have to put it before every function. I suppose you could save yourself a few keystrokes by doing this though.

#define DLLEXP __declspec( dllexport )

DLLEXP void someFunct() {
  // Code here
}
William Hemsworth 1,339 Posting Virtuoso

This question seems suspisiously similar to this one?

William Hemsworth 1,339 Posting Virtuoso
// delete any previous data
delete [] inStart;

This is a very bad idea, and no data needs to be deleted, just overwrite it.

inLast = inStart = new inType[size]; // = new T[size]?

Both inLast and inStart are not pointers and therefore you can not assign a pointer to them, they are references. Make sure you know the difference between the two.

I hope this helps you understand your problem a little better.