William Hemsworth 1,339 Posting Virtuoso

C++ is my language of choice, with Java second. The language I dislike since "hate" is such a strong word would be VB. It just takes longer to write an application.

I agree with you there, VB in my opinion goes overboard with simplicity, removing line breaks, brackets, and curly braces (usually replacing them with lengthy words), for me that makes it hard to tell apart code blocks and scopes making stuff even more confusing.

But I guess everybody has their own preferences.

William Hemsworth 1,339 Posting Virtuoso

The easy way, at the very start of your code, add this line:

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

Yep, nezachem is correct, the prototypes in that header mean nothing if they aren't linked with the right library. Try linking to comctl32.lib.

William Hemsworth 1,339 Posting Virtuoso

The file doesn't need to appear in the solution explorer. Do you know how to work with resource files? You can put any kind of file into a resource file, you just need the right commands to read them.

So, first you need to create a resource file for your project by right clicking on your project name and adding a resource file.

Then double click on your resource file in the solution explorer to open it, then right click on resource.rc and click "Add resource", then press 'Import'.

If you do all those steps right, it will work.

Hope this helps.

William Hemsworth 1,339 Posting Virtuoso

See example code and attachments.

#include <windows.h>
#include "resource.h"
#pragma comment(lib,"Winmm.lib")

int WINAPI WinMain(
      HINSTANCE hInstance,
      HINSTANCE hPrevInstance,
      LPSTR lpCmdLine,
      int nShowCmd)
{
  PlaySound( (char*)IDR_WAVE1, NULL, SND_RESOURCE | SND_ASYNC ); 
  MessageBox( NULL, "", "", MB_OK );
  return 0;
}
William Hemsworth 1,339 Posting Virtuoso

Well, to use that line of code, the .wav file has to be in the same directory as the executable/project folder if you're running directly from Visual Studio. If you want to attach it to your resouce file, that's easy too.

William Hemsworth 1,339 Posting Virtuoso

You forgot the SND_FILENAME argument, change that line to:

PlaySound((LPCWSTR)"tone.wav", 0, SND_LOOP|SND_ASYNC|[B]SND_FILENAME[/B]);

and it should work.

Carrots commented: Thanks for the help :) +1
William Hemsworth 1,339 Posting Virtuoso

0 = false
1 = true

William Hemsworth 1,339 Posting Virtuoso

I haven't seen much effort from you in this thread. To change my code to work with vectors is very simple, you could literally change two lines of my code and it would work with vectors instead.

Try it yourself.

William Hemsworth 1,339 Posting Virtuoso

I also feel raw code style programming is probably best for me as well instead of using resource editors that are provided in VStudio.

If you want to learn how to program resource files, you're more than welcome to, but at the end of the day it isn't really necessary. I've only ever looked inside my resource files a couple of times when doing some very specific things, but otherwise it's a good idea to let Visual Studio handle them.

It's all a matter of personal coding preference I guess, feel free to do what you like :icon_lol:

William Hemsworth 1,339 Posting Virtuoso

I don't see how this is urgent in any way whatsoever.
Putting that in your thread title wont make anyone more inclined to help you.

As for your actual question, I guess you could make a new array, and insert them in ordered one number at a time.

William Hemsworth 1,339 Posting Virtuoso

Your code runs without a problem for me, maybe it's a compiler setting?
Also, you can use the GetWindowText and SetWindowText to make life simpler.

William Hemsworth 1,339 Posting Virtuoso

I told you that was up to you. If i did that, you wouldn't have done anything. In fact, most members would probably think i've already given you too much code there.

William Hemsworth 1,339 Posting Virtuoso

I wrote this snippet some time ago, it's the bare minimum and should be fairly easy to understand. [link]

William Hemsworth 1,339 Posting Virtuoso

Think about how you would find the running average on a piece of paper, then apply it to code. Seeing as you're required to do this with while loops, I don't see much harm in showing you how to do it with for loops.

#include <stdio.h>

int main() {
  const int sequence[] = {1, 3, 5, 7, 9};
  const int numCount = sizeof(sequence) / sizeof(int);
  
  int i, j;
  int average;

  for (i = 0; i < numCount; ++i) {
    average = 0;

    // Add numbers from sequence up to i
    for (j = i; j >= 0; --j) {
      average += sequence[j];
    }

    // Divide by how many numbers we added up
    average /= (i+1);

    printf( "%d %d\n", sequence[i], average );
  }

  getchar();
  return 0;
}

It's up to you to understand the code, and change it to work with while loops instead.

Hope this helps.

William Hemsworth 1,339 Posting Virtuoso

This [link] :icon_razz:
Already been ordered I think.

William Hemsworth 1,339 Posting Virtuoso

No idea why you get that error, I compiled your code and the resource, worked flawlessly.

William Hemsworth 1,339 Posting Virtuoso

Show some code, and I'll try to help.

William Hemsworth 1,339 Posting Virtuoso

Not sure, but does this work?

Datetime^ curDate = gcnew Datetime();
curDate = DateTime::Now;
William Hemsworth 1,339 Posting Virtuoso

Yep, almost all spaces (except those between keywords) are ignorable, so in the end the compiler would just see it as

int*a

anyway.

William Hemsworth 1,339 Posting Virtuoso

So you want to swap keys around, for example the user presses 'INSERT', 'A' is pressed instead? You don't need to use SendInput, it's much simpler to use keybd_event, so you can change that case to:

case VK_INSERT:
  {
      whichbuttonpressed = 1;
      cout << "hey you this is insert \n\n";
      keybd_event( 'A',0,0,0 );
      return 1;
  }

Other than that, I'm not entirely sure what it is you're asking for.

William Hemsworth 1,339 Posting Virtuoso

Misread the question, but that's still a great way to detect keypresses, the rest shouldn't be hard.

William Hemsworth 1,339 Posting Virtuoso

Really not the best way to detect keystrokes, I'd suggest a Windows hook, because you can actually change what the output of that key will be. For example, here's how you could turn the Space bar into the Return Key.

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

LRESULT CALLBACK keyboardHookProc(int nCode, WPARAM wParam, LPARAM lParam) {
	PKBDLLHOOKSTRUCT p = (PKBDLLHOOKSTRUCT) (lParam);
  if (wParam == WM_KEYDOWN) {
		switch (p->vkCode) {
      case VK_SPACE:
        {
          // Space pressed

          // Press ENTER instead
          keybd_event( VK_RETURN, 0, 0, 0 );

          // Dont let windows process SPACE
          return 1;
        }
        break;
    }
  }
  return CallNextHookEx(NULL, nCode, wParam, lParam);
}

int main() {
  // Set windows hook
  HHOOK keyboardHook = SetWindowsHookEx(
      WH_KEYBOARD_LL,
      keyboardHookProc,
      GetModuleHandle( 0 ),
      0);

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

Hope this helps.

William Hemsworth 1,339 Posting Virtuoso

Isn't it easy enough to do an IP check?

William Hemsworth 1,339 Posting Virtuoso

niek_e: What's your problem? You can't give people infractions for no reason.

I think he used his common sense, and you might have come along as being offensive.

William Hemsworth 1,339 Posting Virtuoso

I'm sure there will be a point where he finally loses interest. I think he's banned faster than the time it takes him to make another account.

William Hemsworth 1,339 Posting Virtuoso

I'd stay with Windows 7 until it becomes out-of-date enough to need a different OS such as Linux (which would probably greatly increase in popularity).

William Hemsworth 1,339 Posting Virtuoso

I guess there's always age of mythology, I played that on lan against my brother a couple years back, that was pretty great :)

William Hemsworth 1,339 Posting Virtuoso

1) mostly work, not much free time for much else thanks to taking an extra A-level
2) something arty, i do love photography - though i'm currently lacking a camera until christmas :P
3) Go iceskating whenever I can, or an icehockey session whenever there's one on
4) Coding, only really do C/C++ and Flash Actionscript 2, but you can see here. [link]
5) Be with friends
6) Read books and magazines

Play games - generally lan with friends - Age of empires 2, Unreal tournamenent etc..

Age of empires is a great classic, still have it :) haven't played it since I was about 12 though.

William Hemsworth 1,339 Posting Virtuoso

Good (: You can flag the thread as solved at the bottom.

William Hemsworth 1,339 Posting Virtuoso

Tried both ways It doesn't save anything to the output file :(. It is completely blank.

I edited my post maybe before you tried that code, try again. There's no reason why that function shouldn't work, if it still doesn't work, show me the code you're using.

William Hemsworth 1,339 Posting Virtuoso

Either turn UNICODE off, or change the code to:

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

void saveCaption(HWND hwnd, TCHAR *filename) {
  int length = GetWindowTextLength( hwnd ) + 1;
  TCHAR *caption = new TCHAR[length];

  GetWindowText( hwnd, caption, length );

  std::wofstream out( filename );
  out << caption;

  delete[] caption;
}

int main() {
  saveCaption( GetConsoleWindow(), TEXT("caption.txt") );
}
William Hemsworth 1,339 Posting Virtuoso

Wouldn't usually give away code, but it's just so small.

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

void saveCaption(HWND hwnd, char *filename) {
  int length = GetWindowTextLength( hwnd ) + 1;
  char *caption = new char[length];

  GetWindowText( hwnd, caption, length );

  std::ofstream out( filename );
  out << caption;

  delete[] caption;
}

int main() {
  saveCaption( GetConsoleWindow(), "caption.txt" );
}
William Hemsworth 1,339 Posting Virtuoso

Got it working with objects and bitmaps, I think with some optimizations I could use this to make some neat games :)

William Hemsworth 1,339 Posting Virtuoso

Why was what I suggested another problem?

Because, installing a new OS creates dozens of new problems, finding substitutes for your current applications, backing up old files, compatability and many more... when just removing the trojan is far simpler.

William Hemsworth 1,339 Posting Virtuoso

Why am I running a Mac?

Good question, why are you running a Mac?
Either way, you seem to love trying to 'convert' people from Windows to Linux.

William Hemsworth 1,339 Posting Virtuoso

tell him beyond that I can't help him any further.

If you're not a Windows user, don't try to solve a Windows problem, simple as that.

It's about the equivalent of me going to a Linux forum and telling every person to switch to Windows because of a problem they have with linux, it's stupid.

You pop up a day later, tell him he posted in the wrong area, offer no suggestions, and then tell me I have an obsession?

His post was far more helpful than yours, he set him in the right direction where he can actually recieve some good help, you do have a linux obsession.

William Hemsworth 1,339 Posting Virtuoso

Well, something's sure happened to AD. [link] There's no way he deserved 6506 downvotes :P

William Hemsworth 1,339 Posting Virtuoso

Well in that case :P having a late breakfast followed immediately by lunch, then going iceskating with a friend.

William Hemsworth 1,339 Posting Virtuoso

Everybody's reply to this thread should ultimately be "Replying to this thread".

William Hemsworth 1,339 Posting Virtuoso

Another really nice effect using this method :icon_smile:

William Hemsworth 1,339 Posting Virtuoso

Here's a speed test :) mine stays at about 480fps with only 2-3% CPU.

William Hemsworth 1,339 Posting Virtuoso

Quite a while ago, I made this snippet. This code is basically the same, except that it adds animation.

This method of blitting is very fast assuming you don't use a surface that's too large. On a 500 x 500 surface, I managed 350fps using only 0-1% of the cpu. This snippet may appear much slower because of the amount of CPU it's applying to each pixel, but the blitting itself is very fast. Also, don't forget that an average game will only redraw parts of the window that need redrawing, this redraws the whole surface every time.

So, as long as you know what you're doing, Windows GDI isn't actually that slow :icon_lol:

Attached executable:

GDI Animation.zip


Preview Image:

edit: Running in Debug may reduce speed by a lot, set it as Release.

William Hemsworth 1,339 Posting Virtuoso

Animation can be done using the Windows API, but you have to really know what you're doing. Unfortunately there isn't many very simple graphic libraries out there, but you'd probably have most luck with SDL or OpenGL.

William Hemsworth 1,339 Posting Virtuoso

Avoid Qt (not used anymore in Europe (expensive and slow))
Either use Win32 api (Win32 gurus use it) or .NET

Of course Win32 Gurus would use the Win32 API, it's what they're good at, that doesn't mean it's the best thing to use.

Qt is multi-platform, whereas the Windows API isn't, if the platform doesn't matter then the Windows API is a nice choice, but otherwise don't just say Qt is slow (without any evidence) and say the Windows API is the best choice.

i think WinApi like MFC is old and obsolete!

You thought wrong, I still use the Windows API because it's low-level, fast and doesn't require a netframe installed to run the application.

William Hemsworth 1,339 Posting Virtuoso

Check variables that you allocated memory on, and make sure you deleted it somewhere else in the code. If you forget to free any memory, that's a memory leak.

William Hemsworth 1,339 Posting Virtuoso

Oops, sorry AD :icon_eek: that was supposed to be +rep!

William Hemsworth 1,339 Posting Virtuoso

What sort of things do you plan on doing? Are you looking to be able to manage an animation? or just draw shapes/text on a window.

William Hemsworth 1,339 Posting Virtuoso

Words aren't wrapping correctly, if one word exceeds the line length, you should wrap it anyway. Problem happens in my Control Panel under 'My Recently Viewed Threads' from this link.

William Hemsworth 1,339 Posting Virtuoso

Any useless junk that's there would have been a result of your programming, the generated assembly is pretty efficient.