Thanks for all the responses, I looked into what you had all said and went with the _beginthread method, further below is my code which now works as whilst in the loop you can press a North button which displays a message in the the outbox box while the combat function is running.
I do have a couple of questions though if you can spare an answer..
at the moment I can only figure out how to provide 1 parameter to my function because I have to pass the parameters in the _beginthread function. If i had a prototype like void func(int a, int b) how would i specify to pass 2 arguments in beginthread ? ive tried various forms of syntax but keep getting incorrect parameter errors when trying to compile.
Also im aware that im opening a new thread but do you need to close this and free up the memory afterwards ?
Anyway thanks very much for your help.
Mr Pickle.
Heres my code :
Code:
#include <windows.h>
#include <process.h>
#include "resource.h"
#define Display(s) SendDlgItemMessage(DialogWindow,\
IDC_OUTPUT,EM_REPLACESEL,0,(LPARAM)((LPSTR)s))
VOID CombatLoop(HWND DialogWindow)
{
int counter;
char Temp[100];
for(counter=0;counter<=10;counter++) {
wsprintf(Temp, "In Loop Number %d\r\n", counter);
Display(Temp);
Sleep(1000);
}
wsprintf(Temp, "Thread Has Finished\r\n");
Display(Temp);
}
LRESULT CALLBACK ClientDlgProc(HWND DialogWindow,
UINT Message,
WPARAM wParam,
LPARAM lParam)
{
switch(Message) {
case WM_INITDIALOG:
Display("Started Up..\r\n\r\n");
return FALSE;
break;
case WM_COMMAND:
switch (wParam) {
case ID_QUIT:
EndDialog(DialogWindow, FALSE);
break;
case ID_START:
_beginthread (CombatLoop, 0, DialogWindow);
break;
case ID_NORTH:
Display("North Button Pressed\r\n");
break;
default:
break;
}
break;
default:
break;
}
return FALSE;
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
DialogBox((HINSTANCE) hInstance,
MAKEINTRESOURCE(IDD_DIALOG),
NULL, (DLGPROC) ClientDlgProc);
return 0;
}