• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 195
  • Last Modified:

How not to end a proggy??

Hello,

I made a win32 program :


#include "stdafx.h"

int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
//my code.....
return 0;
}


How can I not end it (I know I can make that it never reaches the return by using an "untightened loop" like
while(1){Sleep(200);}
But I want to do it more elegant...

thx
0
lapijn
Asked:
lapijn
  • 3
  • 3
1 Solution
 
Jaime OlivaresCommented:
Please explain your intentions to give you the best alternative.....
0
 
lapijnAuthor Commented:
Well, I want to make a program which stays "loaded", and when I press ALT+KEY it just calls  a WinExec with parameters I choosed.
0
 
stuartdehaanCommented:
You could not call a function to terminate the process after WM_CLOSE or WM_DESTROY.

It is, however, possible to do this same thing (ALT+KEY starts a program) with windows. You can add a shortcut with the desired parameters to a program to your desktop or taskbar and set a hotkey.

Stuart
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
lapijnAuthor Commented:
thanks staurtdekip, but I don't call a function now either (see example in my question). I only have a return....
I know it can be done in windows, but I'm just curious how I can do that....
0
 
stuartdehaanCommented:
You just wrote
// my code
which does not exclude a process termination call.
However, since you don't have this call, you probably don't have a GetMessage-loop either, which is the usual way of creating an indefinate loop.

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

If you just don't respond to the quit messages, this is indefinate...

ps. it is only fair to show your real name in your account, so that I can greet you too or call you old or something...  :)

Stuart
0
 
lapijnAuthor Commented:
Thanks a lot, Stuart. This seems to work indeed.

What is the filosophy of it (I searched the functions on msdn, but I'm only a beginner ...) and what are the advantages over a "while(1){Sleep(1000);}"  ?

PS. I've lost the hotmail adres with which I made this account long ago, so don't think I can change my profile :(


Grtz, Hans Devroe.
0
 
stuartdehaanCommented:
The GetMessage function reads a message (obviously) and than it's send to a window in your process after you call DispatchMessage.
These functions are the most common way to give input to your program.
The while(1){Sleep(1000);} loop will cause the program to run indefinately, but you can't accept user input like ALT+KEY, in fact, the program will halt.

BTW, you giving me a grade A for the answer is an acceptable substitute for me calling you Hans Hetvroe or something :)

Stuart
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now