Console application freezes until key pressed / mouse clicked [duplicate] - console-application

This question already has answers here:
How and why does QuickEdit mode in Command Prompt freeze applications?
(2 answers)
Closed 4 years ago.
Sometimes it works great, but usually after i started application (after log)- nothing happen. Just after i press key- consumers start to work (that's not displaying problem, because there are messages in queues and they are not going to be free before i press keyboard key).
At this demonstration i started current service. It took some messages and went to sleep. After that i sent more messages (using Web API application), but nothing happen in service. Just after i pressed key in service console window it woke up.

I've just unchecked the Property > Options > Edit Options > QuickEdit Mode checkbox.
Possible duplicate answer: How and why does QuickEdit mode in Command Prompt freeze applications?

Related

Force windows 10 tray icons to be visible [duplicate]

This question already has answers here:
Force Windows to show a system tray icon
(5 answers)
How to always show program tray icons in Windows by *default*?
(3 answers)
Set tray icon to always show
(5 answers)
Closed 2 years ago.
I have an issue with a software I wrote (Delphi) that is minimized to Windows 10 tray icon locations. There are two possible locations, one at the end of arrow #1 and another into arrow #2.
When a new application is installed, by default when minimized (and code written to take care of this), it goes to location #2 by default, and some user are confused and thinks the software has crashed (because this is hidden). My question is simple, is there a piece of code that forcefully put the minimized app icon into location #1 directly without any action from the user ?
C++ code is OK, or Delphi would be very nice.

How to detect that a window is currently running a modal dialog? [duplicate]

This question already has answers here:
Detecting modal dialogs in MFC
(4 answers)
Closed 4 years ago.
I have a wizard interface (so a property sheet with property pages).
On one of the pages, I am running a background timer to keep detecting whether a given external thing is true or not (well, I compile a list of attached visible USB security dongles).
But when this page shows a modal dialog box - e.g. a MessageBox, I want to suspend/ignore the timer notifications.
I can do that by simply killing the timer - running the message box - then starting the timer anew. That works perfectly but requires that all calls to MessageBox remember to do this. Not a huge deal, but inelegant.
Now, I could also wrapper MessageBox so that I use a helper wrapper function which does the suspend / resume timer for the caller. That's a valid thought - but it still requires maintenance coders to always remember to call my wrapper function, and this doesn't work well for other modal dialog boxes that might need to be run which also would need to have the suspend/resume timer dance performed.
What I believe is ideal is to leave the timer running, but have the timer handler itself check if we're currently running a modal dialog, and if so, simply ignore the timer notification (the timer will continue to spew notifications in a few moments - and eventually we'll be done with the modal dialog [message box] and we can go ahead and handle the timer notification then).
But what I do not see is a mechanism by which to ask "Am I running a modal dialog right now?"
From the POV of the page's timer handler - it doesn't know if a modal dialog box is in progress or not. IsWindowEnabled() returns true - so at least the standard windows MessageBox() does NOT disable the parent window... which leaves me mildly confused as to how it is locking out button clicks on its parent window (my mind is a sieve these days - maybe the answer is obvious and I'm just getting old ;) )
Anyway - what am I missing? What is a simple test for "Is a modal dialog box running right now in this thread / as a child of this window?"
Thanks for any gentle clues you might have to offer
So, I was asking IsWindowEnabled() from the context of the property page - which is a child window within the wizard dialog.
Changing that to GetParent()->IsWindowEnabled() does return false while running a modal dialog.

Windows Phone 8 manual application exit c++

I am writing a C++ DirectX application without XAML for Windows Phone 8. I have met on difficulty. In the certifications requirements it is mentioned that:
"Verify that either the app closes without error, or allows the user
to confirm closing the app with a menu or dialog."
When on the main screen user presses back button I show the yes-no dialog. When user presses Yes how should I make the app exit?
In this topic there are some solutions but they seem to work only with XAML.
http://social.msdn.microsoft.com/Forums/en-US/wpdevelop/thread/fdedf8f6-e691-4df6-92c7-ed3dc97bddc0/
How should I close the app?
Looking at that MSDN forum link it seems that the back key press logic in C++/DirectX works in the same way as C#/XAML.
I.e. If you set the handled flag command->Handled = true; in the Back key press handler the application framework will not close the app.
If you don't set the flag then the application framework will close the app.

AttachConsole from a GUI app when the console is closed [duplicate]

This question already has answers here:
Why does closing a console that was started with AllocConsole cause my whole application to exit? Can I change this behavior?
(4 answers)
Closed 9 years ago.
I needed to be able to output to a console from my GUI-based app written in C++, so I chose to use the AttachConsole(ATTACH_PARENT_PROCESS) API and this code to do so. That method works great, except that when I start my GUI app from a command prompt window the GUI app starts just fine but when I close the command prompt window my GUI app is terminated (note, not closed, but terminated.) Is there any way to prevent this app termination?
You can prevent your application from closing when somebody closes the console window.
It involves calling SetConsoleCtrlHandler to set a HandlerRoutine that intercepts those events.
If you want the console window to close, but leave your app running, you might be able to call FreeConsole in your HandlerRoutine. If that doesn't work, then handle the message to prevent the console window from being destroyed, and set a flag or a timer that will cause your app to call FreeConsole after returning from the handler.
As I recall, you can't prevent the window from closing when the user hits the X on the window. What I did to prevent that is modify the window menu. See http://blog.mischel.com/2008/07/14/going-too-far-back/ for some details.
I was able to resolve this issue by attaching to the parent console right before posting the text to the stdout stream and then by detaching from it. This way the text is posted alright and the console remains separate from my GUI app.
Here's the MFC/C++ class with the full implementation for those who want to use it.

Check whether key is pressed down in Windows console [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
C++ console keyboard events
I want a Windows console program to do something if a certain key is pressed down,
something like
while(1)
{
....
if(the key 'o' is pressed down)
....
}
but I don't know what to put in the if statement. How do I check if the key 'o' is pressed down?
I'm using Windows 7 64-bit and Visual Studio Professional 2008.
You can use the std::cin.get() or you can use the windows.h GetAsyncKeyState, depending on what exactly you want to do.
If you want lower level stuff, look into hooks and events from the WinAPI.
Rather than busy-polling for a keypress, you should register for key events in your application (assuming this is a Windows GUI app), and check for the keys you're interested in.
If you are actually making a console app, see here: C++ console keyboard events