Click here to Skip to main content
15,905,785 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: First-chance exception: Mem violation Pin
Hans Ruck13-Jan-03 23:11
Hans Ruck13-Jan-03 23:11 
GeneralRe: First-chance exception: Mem violation Pin
boon kian13-Jan-03 23:17
boon kian13-Jan-03 23:17 
Generalendless loop interruption Pin
geluionescu13-Jan-03 22:46
geluionescu13-Jan-03 22:46 
GeneralRe: endless loop interruption Pin
Joaquín M López Muñoz13-Jan-03 23:48
Joaquín M López Muñoz13-Jan-03 23:48 
GeneralRe: endless loop interruption Pin
geluionescu14-Jan-03 1:08
geluionescu14-Jan-03 1:08 
GeneralRe: endless loop interruption Pin
Ceri14-Jan-03 0:04
Ceri14-Jan-03 0:04 
GeneralRe: endless loop interruption Pin
geluionescu14-Jan-03 3:21
geluionescu14-Jan-03 3:21 
GeneralRe: endless loop interruption Pin
Ceri14-Jan-03 4:55
Ceri14-Jan-03 4:55 
Try this

[code]

#include "stdafx.h"

#define CUSTOMSTOPMSG WM_USER + 1

DWORD WINAPI ThreadProc(LPVOID lpParameter);
void StartThread();
void StopThread();

//the thread ID. Must give this ID to PostThreadMessage
DWORD dwThreadID = 0;


//this function is the thread function - contains the infine loop
DWORD WINAPI ThreadProc(LPVOID lpParameter)
{

MSG msg;
int iRetVal = 1;
PeekMessage(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE); //forces creation of non windowed message loop

while(!(PeekMessage(&msg, NULL, CUSTOMSTOPMSG, CUSTOMSTOPMSG, PM_REMOVE)))
{
//....do processing here

};


//.... do clean up here

return(iRetVal);

}



//execute this function from your standard thread
void StartThread()
{

HANDLE hThread;

//you can use this to pass a parameter to your thread
//(usualy a pointer to a struct or some other kind of user data)
LPVOID pParam = NULL;

hThread = CreateThread(NULL,0,ThreadProc,pParam,0,&dwThreadID);
}

void StopThread()
{

//obviously wParam and lParam in the PostThreadMessage could be some value also

if(dwThreadID)
PostThreadMessage(dwThreadID,CUSTOMSTOPMSG,0,0);

}

[/code]

Call StartThread when you want to initialize the loop and StopThred when you want to stop (I guess you would use your button for this)

Let me know how you get on
GeneralRe: endless loop interruption Pin
geluionescu14-Jan-03 5:45
geluionescu14-Jan-03 5:45 
GeneralRe: endless loop interruption Pin
Ceri14-Jan-03 22:06
Ceri14-Jan-03 22:06 
QuestionHow can I get the standard size of a control before creation ? Pin
JohnMcL13-Jan-03 22:46
JohnMcL13-Jan-03 22:46 
AnswerRe: How can I get the standard size of a control before creation ? Pin
Alvaro Mendez14-Jan-03 7:10
Alvaro Mendez14-Jan-03 7:10 
GeneralRe: How can I get the standard size of a control before creation ? Pin
JohnMcL15-Jan-03 14:10
JohnMcL15-Jan-03 14:10 
GeneralNon ascii character in CSV file Pin
Alberto Bar-Noy13-Jan-03 22:30
Alberto Bar-Noy13-Jan-03 22:30 
GeneralRe: Non ascii character in CSV file Pin
Ted Ferenc13-Jan-03 22:43
Ted Ferenc13-Jan-03 22:43 
Generalnew&delete, malloc&free Pin
raner13-Jan-03 22:26
raner13-Jan-03 22:26 
GeneralRe: new&delete, malloc&free Pin
jhwurmbach13-Jan-03 22:46
jhwurmbach13-Jan-03 22:46 
GeneralRe: new&delete, malloc&free Pin
raner14-Jan-03 0:19
raner14-Jan-03 0:19 
GeneralRe: new&delete, malloc&free Pin
jhwurmbach14-Jan-03 1:08
jhwurmbach14-Jan-03 1:08 
GeneralThks jhwurmbach & AlexO Pin
raner14-Jan-03 20:56
raner14-Jan-03 20:56 
GeneralRe: Thks jhwurmbach & AlexO Pin
jhwurmbach14-Jan-03 22:59
jhwurmbach14-Jan-03 22:59 
GeneralRe: Thks jhwurmbach & AlexO Pin
raner15-Jan-03 3:54
raner15-Jan-03 3:54 
GeneralRe: new&delete, malloc&free Pin
AlexO14-Jan-03 4:20
AlexO14-Jan-03 4:20 
GeneralWord Automation Pin
Exceter13-Jan-03 18:56
Exceter13-Jan-03 18:56 
GeneralRe: Word Automation Pin
Anonymous13-Jan-03 20:40
Anonymous13-Jan-03 20:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.