• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 200
  • 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 OlivaresSoftware ArchitectCommented:
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
 
Member_3480671Commented:
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
Identify and Prevent Potential Cyber-threats

Become the white hat who helps safeguard our interconnected world. Transform your career future by earning your MS in Cybersecurity. WGU’s MSCSIA degree program was designed in collaboration with national intelligence organizations and IT industry leaders.

 
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
 
Member_3480671Commented:
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
 
Member_3480671Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Network Scalability - Handle Complex Environments

Monitor your entire network from a single platform. Free 30 Day Trial Now!

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