Letting a Batch file Minimize a DOS window? - windows

So i'm kinda into MS-DOS and such again, but i came to ask myself, How can i minimize a DOS window?
Any kind would be ok, minimalize, shrink to a tiny blue block.
I just can't seem to find a way to let it work on my Windows XP computer, is realy evrything excluded in XP?!

You can start a program in a new minimised window using the start command:
start /min your_command_here

One thing you could do is create a windows program that will find the title of the cmd window you are running in and in that program minimize it. In Win32 you would use the FindWindow command to get a window handle, then CloseWindow to minimize it. Something like this totally untested program:
int main(int argc, char** argv)
{
HWND wnd = FindWindow(
NULL,
argv[1]
);
CloseWindow(wnd);
return 0;
}
Within the cmd window you could set the title to some string that you define (to avoid ambiguities) and then pass that name to the program to your program:
C:\>title TitleOfWindowToMiniMize
C:\>minimizeWindow TitleOfWindowToMiniMize

You can't. Not in DOS. DOS has no concepts of windows.
In Windows you could write a little program that will look up your window and send it the appropriate message causing it to minimize. The same way you could also maximize or hide/show your window.

Related

Failed to draw on DesktopWindow

I've tried to draw any thing on Desktop window using GetDC(GetDesktopWindow), like the following simple program:
#include <windows.h>
int main()
{
TextOut(GetDC(GetDesktopWindow()), 10, 10, TEXT("Test TextOut Tester!!"), 21);
return 0;
}
It seems that my current user privileges affect the drawing behavior, I am not admin on my PC, is this the reason for that? is there any documentation for this issue ?
Thanks in advance
The simple reason you can't draw on the desktop window like this is you cannot actually see the desktop window. Since Windows 95 the desktop window has been completely obscured by a cluster of windows owned by explorer.
The DC you get when you call GetDC(GetDesktopWindow()) will thus be completely clipped.
If you want to draw directly on the display GetDC(NULL) will give you a DC that you can use to draw all over the desktop and visible windows. But that, as has been mentioned, will be operating entirely outside Windows' repainting logic and the results will be, well, ugly and unsuited to any real purpose (other than, say, getting some kind of debug feedback from a windowless app you are in the process of developing).
Most applications that want do "display something on the desktop" do so by creating a window and drawing on that. Why is that not appropriate here?
This is what you should do:
HDC hdc = ::GetDC(NULL);
//draw on the desktop using the hdc
::ReleaseDC(NULL, hdc);

SetWindowPlacement not moving certain windows

I'm writing a Windows 10 C# program to save and restore the positions and sizes of open windows (whether displayed or minimized). The following loop has worked on almost all windows, but not the Resource Monitor or Computer Management windows:
foreach (KeyValuePair<HWND, InfoWindow> entry in openWindows)
{
IntPtr hWnd = entry.Key;
Rectangle rect = entry.Value.Rect;
WINDOWPLACEMENT wpl = new WINDOWPLACEMENT();
if (!GetWindowPlacement(hWnd, ref wpl)) continue;
wpl.rcNormalPosition = rect;
SetWindowPlacement(hWnd, ref wpl);
}
The SetWindowPlacement function seems to have no effect on the Resource Monitor or Computer Management windows' position or size. I've also tried using SetWindowPos, which also has no effect on those windows (but works on all the other windows I've tried).
Why do those particular windows behave differently? What alternative method is there to move those windows?
Thanks, Jonathan and Hans. That was the problem. If I run my code elevated, it works on all the windows.

How to maximize current command prompt using command

In windows I can maximize current window by keyboard shortcut Alt+space then x. When I working on command prompt, can I do same thing using commands (without using shortcuts)?
Simply I need to create a bat file , that make windows maximize after run that.
Edit:
I need to do this without restarting the command prompt. because restart lost the content of existing window.
I've not found any reliable way of doing it without a third party tool. So, if you have access to a c compiler, you can build your own
#define _WIN32_WINNT 0x0500
#include "windows.h"
int main(int argc, char **argv){
ShowWindow(
(HWND) GetConsoleWindow(),
argc > 1 ? atoi( argv[1] ) : SW_SHOWDEFAULT
);
return 0;
}
Tested with mingw/gcc. This code uses the ShowWindow api function to change the show state of the current console window (handle retrieved via GetConsoleWindow()). If compiled to showWindow.exe you can do
showWindow.exe 3 to maximize the window
showWindow.exe 6 to minimize the window
showWindow.exe to return to default mode
See the api documentation for the full list of allowed values.
i think you'll have to check for additional software like autoit or
CMDOW

How to set in Win32 program to enable size being remembered

I met this problem. I have a simple Win32 program which is like the boilerplate which I can get from selecting a "Win32 project" under Visual Studio 2010's "Template --> Visual C++".
I found all other Windows based program like Adobe Reader, Windows Explorer having the feature which is: you enlarging the main window to a new size and then select "Close" or "Exit" from File menu or system menu to close it, then you launch the program again, the main window would be of the size that you adjusted to last time. However that program I got from Visual Studio as the bootstrap does not have such feature.
I researched more on it but cannot find which setting in either WndClass or CreateWindow that I can tweak to make that happen. Does anyone know it, thank you for your help in advance.
The simplest way to do this is with the GetWindowPlacement() and SetWindowPlacement() functions. These manage the window size and state (minimized/maximized/restored) for you.
Call GetWindowPlacement() when you want to record your window's current state:
WINDOWPLACEMENT wp = {0};
wp.length = sizeof(wp);
if (GetWindowPlacement(hWnd, &wp))
{
// save wp values somewhere...
}
You can then save the values of the WINDOWPLACEMENT structure somewhere in your program's configuration files - either in the registry or on disk.
To restore your window's information, load the saved values into the WINDOWPLACEMENT structure, then call the SetWindowPlacement() function:
if (values were previously saved)
{
WINDOWPLACEMENT wp = {0};
wp.length = sizeof(wp);
// load wp values from somewhere...
SetWindowPlacement(hWnd, &wp);
}
You will need to save the position (X, Y) and size (Height, Width) of the window yourself, and set those values when the program starts up again.
Depending on the nature of the program, you might set this in a configuration file, a registry key, or a database (among other options).

Script to enable mouse shadow?

I've found people asking this question on some forums, but no solutions. This is a small but annoying cosmetic problem many people know.
Some full screen programs disable the shadow under the cursor in Windows. The shadow usually comes back, but when is doesn't (for example the program didn't close normally) the mouse appears without shadow, and you have to go and manually enable it back.
The solution I'd like to do is a .bat or .vbs to enable the shadow, only I haven't figured how.
What I did find is that it's a registry value, and there is also something to do to "refresh" the cursor and make the shadow appear. Can anyone help?
I'd like to add that I have very small experience in .bat or .vbs writing, so if you know what to do and how, please post the how too.
Using the API makes it take effect immediately.
#include <Windows.h>
int main() {
BOOL didSucceed = SystemParametersInfo(
SPI_SETCURSORSHADOW,
0,
(PVOID) TRUE,
SPIF_UPDATEINIFILE + SPIF_SENDCHANGE);
return didSucceed ? EXIT_SUCCESS : EXIT_FAILURE;
}
It's located in the famous (yet undocumented :-) "UserPreferencesMask" registry key.
Here are some pointers:
A first general link with information on this key, and how the mouse shadow setting is defined: HKCU\Control Panel\Desktop\UserPreferencesMask
And a sample that explain how to code it using VBSCript (it's another key, but the principle is the same): Set UserPreferencesMask Binary Registry Key

Resources