News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Starting a console program minimized, is it possible ?

Started by dsouza123, March 29, 2007, 12:43:28 PM

Previous topic - Next topic

dsouza123

What is needed to create a console program that starts in the minimized state ?

How can this be done using assembly code (along with options, directives etc)
and assembler and linker options.

If needed, an alternate linker such as polink or golink is OK.   
Maybe even using poasm if ml can't do it.

Tedd

use CreateProcess - you can set the position/size/state of the window created in the STARTUPINFO struct
No snowflake in an avalanche feels responsible.

dsouza123

Thanks Tedd

Wouldn't that require two programs, one just to launch the intended one ?

Following links from the screen with the CreateProcess function
the function GetStartupInfo is mentioned, is it possible to get the info
modify it and have it take affect ?

What are other ways of getting a console program to start minimized ?

Tedd

Yeh, pretty much (normally the 'starter' program is windows' shell)

GetStartupInfo gives you the values used to start the program - but it's already started, so you're modifying them a bit late :P

If you can get the console window's handle then you can minimize it yourself :wink

Quick guess..
invoke GetActiveWindow
invoke ShowWindow, eax,SW_MINIMIZE


..but that doesn't work ::)
GetActiveWindow returns the thread's current active window, but apparently a console doesn't count.
So you need to get the console's window handle.... somehow. I don't think you're really allowed to get it from 'inside' the console (FindWindow seems a bit of a hacky solution.)
No snowflake in an avalanche feels responsible.

Vortex

Here is a quick demo based on Tedd's method:

.386
.model flat,stdcall
option casemap:none

include     \masm32\include\windows.inc
include     \masm32\include\kernel32.inc
include     \masm32\include\user32.inc
include     \masm32\include\masm32.inc

includelib  \masm32\lib\kernel32.lib
includelib  \masm32\lib\user32.lib
includelib  \masm32\lib\masm32.lib


.data
ClassName   db 'ConsoleWindowClass',0
msg1        db 'Press ENTER to minimize the console window',0
msg2        db 'Console window minimized',0
capt        db 'Status',0

.data?
hWnd        dd ?
buffer      db 100 dup(?)

.code

start:

    invoke  FindWindow,ADDR ClassName,0
    mov     hWnd,eax
    invoke  StdOut,ADDR msg1
    invoke  StdIn,ADDR buffer,100
    invoke  StdOut,ADDR msg2
    invoke  ShowWindow,hWnd,SW_SHOWMINIMIZED
    invoke  MessageBox,0,ADDR msg2,ADDR capt,MB_OK
    invoke  ExitProcess,0

END start


The only trick is to specify the correct classname of a console window to find the handle.

[attachment deleted by admin]

dsouza123


Tedd

But note that FindWindow will get the handle of the first console window it finds - which may not necessarily be yours (if there is more than one console window open at the same time.)
Do GetConsoleTitle, and then use that as the window-title parameter for FindWindow :wink
No snowflake in an avalanche feels responsible.

dsouza123

That is true Tedd, an alternative is to fill the second parameter of FindWindow
with the caption of the desired console window.


Issue, if there are multiple copies of the console running it will only get one
and it doesn't always work, example if other windows are on top of the console window(s).

Any ideas on console windows that aren't top most and if there are multiple copies running ?

dsouza123

Did a forum search, found code that finds visible windows, modified it quite a bit.

It will minimize any visible (not minimized) console windows, can also restore them.


[attachment deleted by admin]

hutch--

dsouza123,

To handle multiple instances of the console, see if the console window(s) show up in an enumeration of windows running in the system. If it does then you have a simple mechanism to handle all copies of the console.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

dsouza123

Thanks Hutch

If I understand enumeration correctly that means using EnumWindows,
that is how the visible windows are found in the min_rest program.
Or is it something else ?

dsouza123

Finally got a self minimizing console program working.

It is a regular program but linked as a console program.
It starts, immediately minimizes itself, then sleeps forever.

The sleeping forever doesn't matter since it is an example,
and can be exited by restoring and clicking on the close button.



[attachment deleted by admin]