Visual Studio Community 2019 C++ Console App template closes instantly - c++

Edit:1 There have been a lot of good suggestions to help me out. The answer by Jeaninez has helped my Hello World stay on the screen instead of blinking for a microsecond.
But my initial question stands, why does Visual Studio 2019 default Hello World Console App not hold the Hello World open and instead open two windows. Here is a video with the fixed version and the one with the default template: https://www.youtube.com/watch?v=LVUsHp9K8Tw
Original Question
I'm sure this question has been asked a million times, but my issue seems to be quite different. I am using the
Console App Template which is by default a hello world, but when I Ctrl+F5 it to see how it works it blinks on the screen then shows this:
I tried putting in a return 0; and made sure my project was set to Console. The only thing that I've found that helps a tiny bit is `system("pause");

It's not closing. You know that - you took a picture of it.
It is, however, really small. And in addition VS 2019 (unlike earlier versions) adds this text about "press any key" to close the window. So you're not seeing your own output at all.
Here's what to do. Click the little icon in the title bar:
You will get a menu, choose Properties. This gets you a tabbed dialog: choose Layout. Change to a larger height and width and you'll be able to see what is going on.
When you like it, after you have finished running the app and closed the console window, close Visual Studio and re-open it. Now you'll consistently get that window size.

"system("pause");" is part of Windows API and so it won't work in other operation systems.You should try to use just objects from C++ standard library. I suggest you could try to use :
std::cin.get();
return 0;

Related

Visual studio MFC dialog editor seems broken on my HiDPI monitor - is this a known problem?

I am coding a C++ project using MFC in Visual Studio (v16.5.4). The dialog editor seems badly broken on my HiDPI monitor (Lenovo ThinkVision 2880x1800 at 175%). It works fine on two other computers with standard monitors.
The dialogs get resized apparently randomly, and controls do not move correctly when I try to edit them. When I try to align controls the dotted selection rectangle may move, but the control often does not (in the editor). Sometimes, re-opening the editor shows that the control has in fact moved. When I build the project, the final display layout cannot be predicted from what appears in the resource editor.
I reported this to Microsoft using Visual Studio feedback, but they closed the report, saying it was "By design"!!!! They posted a link describing a feature which disables HiDPI awareness, but the link was for the Windows Forms Designer, not the MFC resource editor - there is no equivalent feature in the latter that I could find.
Does anyone else have this problem, or know of a decent work-around? At the moment I am transferring to my other computer with the standard display whenever I need to edit a dialog, which is monumentally inefficient for quite a large project.
I know this is an older post, but I thought what I found might help someone. I experienced the same issue today. It just happens that I have one monitor setup for 125% and one setup for 100%. The MFC dialog editor alignment operations do not work correctly on the 125% monitor but work fine on the 100% monitor. It would appear Microsoft isn't properly handling DPI in the dialog editor.

Dockable windows are not reinstated correctly

This is my first question in this community. I always search a lot when having problems and I always find an answer. But not in this one. Maybe I am not asking Google correctly.
Anyways this looks like a bug to me but I might get it wrong.
Using VS2012 (or 2013) I create the default Multiple documents MFC application. I do not write a single line of code. I compile and run. Then as a user I dock the properties window which by default is at the right to the output window as shown below .
Then I close the application and restart. The window is where it should be but with different width as shown below
If you dock the window to the right (in the view and not in another window) then there is no problem. The position and width are restored just fine. Also this only happens if the main window is maximized. The behaviour, if the main window is not, is as expected.
Do you think it is actually how Microsoft wanted to make this work or they missed that? Is there a workaround for this?
Again forgive me if this question has been asked before but really...
I couldn't find anything.
Appreciate any kind of help.

How do I make console application run after clicking "ok" from mfc dialog box in visual studio 2010?

In my visual studio 2010 project, I included two solutions. I have an mfc application, which is a dialog box, and another visual c++ application that just prints out text. What I want to happen is for the dialog box to pop up, then the user will input x values, y values, etc, and once the user clicks okay the second application will do calculations on these variables and then give an output. I have the two projects made already, but I'm having trouble combining them. The first thing to pop up when the combined project runs is simply a dialog box, and once the user clicks ok, something that looks like this: http://i.imgur.com/pziViRp.png?1 should appear. Any help would be appreciated - sorry if my explanation was unclear.
Your picture is a console app. So you want to make sure your second app is created as a console app and accepts its inputs in the argc, argv command line.
The first app would call CreateProcess to start the second app, passing its path and its command line.

Is it possible to embed a command prompt in a win32 app?

In linux and when installing packages etc. There are some installers that have a progress bar and a dos window which shows the files being extracted etc. How can i add this window to my C++ Win32 programs so that i can have it showing the tasks im doing? I cannot find any documentation on MSDN.
Question: How can i add a console window (if that's what its called, sure looks like one) in my program to show the details of the task at hand being done?
Here is a window with what i am asking.. (personal info so I erased the details. :]
You cannot embed a real console window inside another window (although a windowed process can have a separate console window). While it looks like a console window / command prompt, it is just a matter of appearances. What you want to do is create a sub-window/control with similar characteristics as a console window and then redirect the console output from the application(s) being run to append to that sub-window. For more information on how to do redirect the console output in Windows, see http://support.microsoft.com/kb/190351.
That "dos window" is a regular edit control: CreateWindow(ES_MULTILINE, EDIT, ...
However, it has the font set to a fixed-width one (Looks like courier). This is done by sending WM_SETFONT to the edit control.
#user995048 says "You cannot embed a real console window inside another window". But "cannot" is a strong word! I can run an entire virtualized computer in a window if I wish. :) So one can quite reasonably intuit that there are ways of doing what you say.
Sure, it is true that what you've seen are almost certainly cases of output redirection into a custom widget, designed to mimic the simple appearance of a terminal. However...if you want to embed one application's window inside another, there are things you can look into which might fit. Cooperative methods exist like GtkPlug, for instance:
http://developer.gnome.org/gtk/2.24/GtkPlug.html
To actually capture a not-designed-to-cooperate app's window and throw it in your app would be trickier. But possible, just as screen captures and virtual machines are possible. Probably best to avoid that sort of thing unless there's really a cause for it, though...
Try this
http://www.codeguru.com/cpp/misc/misc/article.php/c277/
link. I think the solution provided is what you need.
I tried it many years ago and it worked. I have not tried it in newer versions of windows though.

Visual C++ 2005: How to view the window during a debugging session

Is this possible? When I'm debugging a program I can't bring the window up to see any changes. It's minimized during the debugging while I step through the program and I'd like to see the program changes while I step.
The only way I might see it is in Windows 7 you can hover over the task-bar to get a look at the program but the preview image gets in the way and It's just a weird way to see my program.
I've been trying to search for this problem but all I get is irrelevant results. Maybe I'm missing a few keywords or something. I don't know what to call my problem.
Two choices:
Don't maximize the IDE window and make it smaller until you can see the program window.
Have two monitors and put the program window on the secondary monitor.