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

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.

Related

Trying to write a c++ console program to change a setting controlled by a windows checkbox

Is it possible to create a keyboard shortcut to switch between the monitor and portion selection of this wacom preferences window, via a c++ console program?
Sorry if this is poorly worded, I've had trouble trying to find the right words to search for ways to do it.
I think it should be possible, although a bit tedious. You should be able to use the Windows API, and try to EnumWindows/EnumDesktopWindows to identify the respective application Window, and its respective controls (which are also Windows).
You should identify the window title, and class ids, for the app window, and the checkbox button controls, then when you enumerate through all the desktop windows, you can identify the ones you are interested in.
Then you can use the SendMessage() API to send messages to the controls (Windows) of interest to manipulate them.
It's a bit tedious, but sounds possible.
An example of use here to get an idea:
http://www.cplusplus.com/forum/windows/25280/

Make a custom taskbar and shell area for my own custom explorer program?

What I would like to do is to create my own custom explorer instead of windows explorer.exe but I would like to be able to create my own taskbar with the active programs and the shell area with the icons as well.
I looked online for a day and can't find anything out about. My main language is c++ and I am very familiar with the windows api calls, resources, and even extracting resources from dlls as well.
I just don't know how to start with the task bar.
Like I said I want to be able to make my own explorer program for windows with the taskbar and all.
I just don't know where to look or start.
Thank you all :)

How to paste from system clipboard content to an arbitrary window using Qt

I have the same question with this but in Qt.
How to paste clipboard content to arbitrary locations ***** (simulate CTRL+V) in Qt?
***** paste the clipboard outside of your Qt application without pressing CTRL+V
I'm pretty sure you're gonna have to resort to platform specifics for this.
First, you will somehow have to get the id/handle of the previously active application. In Windows, this can be done with GetWindow(), as outlined here. IN EWMH window managers, you can use the _NET_CLIENT_LIST_STACKING property.
Second, you'll have to ask that window to perform a paste action. Again, in Windows, SendMessage(window, WM_PASTE, 0, 0) (docs for [SendMessage] and WM_PASTE). I'm actually not sure how you would accomplish this in X11.
There are problaby about 70 000 cases where the above approach won't work, but perhaps it can get you started?
You need to use the QClipboard class.
But I'm not sure to understand the question. What does "arbitrary location" means? Do you want to paste the clipboard outside of your Qt application? (I don't think that X11 and ICCCM and
EWMH enables that).

Console App Whereabouts c++

How would you set the initial position of a Console App on your Screen?
It's a console app, so it has no concept of where its window is, as it doesn't know what a window is.
For Windows, you could use the GetConsoleWindow function followed by SetWindowPos with the SWP_NOSIZE and SWP_NOZORDER flags set.
I think that you're going to be more specific. With a console app, the output goes to stdout without any real control over how the console deals with it. The console deals with displaying it and normally just prints it out.
If you want more control over the console like being able to reposition the cursor or being able to erase or redraw portions of the console, then you'll likely need to look into a library like ncurses.
You can't. Put simply. If you use non-standard extensions, for example, if you made your own console via WinAPI, you might be able to make such an effect. However, within terms of just cin/cout, then you can't.
If you're in windows, then you have to set the position of the final executable. If you click the application icon and then click "Defaults" on the resulting menu, one of the options is for position.
Unfortunately, no idea how to do that on other platforms.

How do I write a console application in Windows that would minimize to the system tray?

I have a written a Visual C++ console application (i.e. subsystem:console) that prints useful diagnositic messages to the console.
However, I would like to keep the application minimized most of the time, and instead of minimizing to the taskbar, appear as a nice icon on the system tray. I would also like to restore the console when the system tray icon is clicked.
How should I change my program to do this?
This is going to be an ugly hack.
First, you have to retrieve the hWnd / hInstance of you console application. Right now, I can only come up with one way:
Create a Guid with CoCreateGuid()
Convert it to a string
Set the title of the console window to this guid with SetConsoleTitle()
Find the hWnd of the your window with the Guid as the tile with FindWindow()
And you can do it from the usual way from this point. See http://www.gidforums.com/t-9218.html for more info.
Don't forget the rename your console window to the original title once you're done.
As you can see, even though this is possible to do, it's a horrible and painful solution. Please don't do it. Please do not minimize console applications to the system tray. It is not something you are supposed to be able to do in the Windows API.
You might want to write a separate gui to function as a log reader. You will then find it much easier to make this minimize to the tray. It would also let you do some other stuff you might find useful, such as changing which level of logging messages are visible on the fly.
To learn the console's hWnd you have two choices:
On Windows 2000 or later you can use the GetConsoleWindow() function. Don't forget to define _WIN32_WINNT as 0x0500 or greater before including windows.h to have access to this function.
If you want to run your program on earlier Windows versions as well then you must use something like the GUID trick described above.
Probably your best bet is to create a "Message-only window" (a message queue without a visible window) to receive the Notification Area messages.
The answer with a GUID is completely ridiculous (no sense at all)
The Console hWnd is of course given by GetConsoleWindow() (!)