How to create a console application that does not terminate?
Posted
by John
on Stack Overflow
See other posts from Stack Overflow
or by John
Published on 2010-04-07T10:57:12Z
Indexed on
2010/04/07
12:33 UTC
Read the original article
Hit count: 391
Hello,
In C++,a console application can have a message handler in its Winmain procedure.Like this:
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
HWND hwnd;
MSG msg;
#ifdef _DEBUG
CreateConsole("Title");
#endif
hwnd = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_DIALOG1), NULL, DlgProc);
PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
while(msg.message != WM_QUIT)
{
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if(IsDialogMessage(hwnd, &msg))
continue;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return 0;
}
This makes the process not close until the console window has received WM_QUIT message. I don't know how to do something similar in delphi.
My need is not for exactly a message handler, but a lightweight "trick" to make the console application work like a GUI application using threads. So that, for example, two Indy TCP servers could be handled without the console application terminating the process.
My question: How could this be accomplished?
© Stack Overflow or respective owner