Topic: MSVC 6: Getting and handling new messages while in a for loop

Okay, first time I have actually asked for help on this project, and I will probably find the answer in a few minutes, but oh well..

I am converting the program Rainbow Crack to use a Windows GUI, and have it mostly working, but there is one problem I am having.
When I am in the for loop that generates all of the hashes, I need it to check to see if there are any new messages. If I don't do this, then a user cannot press any buttons (stop, pause, etc.), and it causes Windows to list the program as unresponsive.

I tried using

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

I tried this, but I assume that TranslateMessage or DispatchMessage is exiting the huge for loop that I need it to stay in, so when I run it, the table file is made, and then it just stops the for loop (the file stays at 0kb).

If you don't know what Rainbow Crack is, just pretend this is a program that is in a huge for loop, and makes a file bigger every second tongue

Indocron
$theQuestion = (2*b) || !(2*b);

2 (edited by Mediator 2005-07-11 00:55)

Re: MSVC 6: Getting and handling new messages while in a for loop

Put the loop in a new thread


//Thready.h
#include "stdafx.h"


class Thready {
protected:
    bool terminateThreadFlag;
    HANDLE threadHandle;

public:
    Thready();

    void begin();

    void end();

    virtual void threadProc() = 0;
};
#endif
//Thready.cpp
#include "Thready.h"

Thready::Thready() {
    terminateThreadFlag = false;
    threadHandle = NULL;
}


void Thready::end() {
    terminateThreadFlag = true;

    WaitForSingleObject(threadHandle, INFINITE);
}


void WindowsThreadFunction(Thready* theThread) {
    theThread->threadProc();
}



void Thready::begin() {
    terminateThreadFlag = false;
    threadHandle = CreateThread(NULL,0, (LPTHREAD_START_ROUTINE) WindowsThreadFunction, this, 0, NULL);
}
//somefile.h
#include "Thready.h"
class MyClass : public Thready {
    public:
           Myclass();
    private:
            void threadProc();
      };
//Somefile.cpp
#include "somefile.h"
MyClass::MyClass() {
    //Penis
}
void MyClass::threadProc() {
//Do loop
}
//Main.cpp
#include "somefile.h";
MyClass t;
SomeStartFunction () {
t.begin();
}

Or something like that... I'm a c++ newb wink

I enjoy pie :)

Re: MSVC 6: Getting and handling new messages while in a for loop

Now maybe you could give me WORKING code tongue
I don't know much about C++, let alone threads..

Also, I found a few files on my HDD called stdafx.h, but none of them worked and let this program compile.
I will upload the entire source code soon...

Indocron
$theQuestion = (2*b) || !(2*b);

Re: MSVC 6: Getting and handling new messages while in a for loop

there's stuff you can put in the loop to update/keepalive the giu in windows ... I used it when I did some C# stuff ... just that I've forgotten what the commands were (and I also think a 1ms sleep in the loop will make other programs get time aswell)

Re: MSVC 6: Getting and handling new messages while in a for loop

Well, giving the other programs time shouldn't be a problem. There is code to make it the lowest priority process already...

Indocron
$theQuestion = (2*b) || !(2*b);