The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: oex on April 13, 2011, 10:12:03 PM

Title: Console
Post by: oex on April 13, 2011, 10:12:03 PM
Are there any negative aspects to calling AllocConsole rather than creating a Console application?
Title: Re: Console
Post by: qWord on April 13, 2011, 10:23:22 PM
Quote from: oex on April 13, 2011, 10:12:03 PM
Are there any negative aspects to calling AllocConsole rather than creating a Console application?
when using CRT functions, you must assign the console, create by AllocConsole, 'by hand' to the CRT.
Some time ago I've upload some macos doing these job: CRT redirect of stdin/out/err (http://www.masm32.com/board/index.php?topic=15984.0)

qWord
Title: Re: Console
Post by: redskull on April 13, 2011, 10:36:55 PM
Starting an app from the command line will only inherit the same console if you link it as such. Otherwise you get a new window that will dissapear afterwards, along with your output
Title: Re: Console
Post by: oex on April 13, 2011, 10:40:58 PM
OK that sounds nasty.... I think that trashes that idea right off :lol.... I dont call any other application atm however I cant guarentee I never will.... If that application will destroy my command window I guess I'll just continue creating console apps for now....

Is there any way to (temporarily) hide the console in a console application?
Title: Re: Console
Post by: qWord on April 13, 2011, 10:46:48 PM
Quote from: oex on April 13, 2011, 10:40:58 PM
Is there any way to (temporarily) hide the console in a console application?
yes: GetConsoleWindow() + ShowWidow()
however, the console will be visible for a short time at start up of your program.
Title: Re: Console
Post by: oex on April 13, 2011, 10:48:17 PM
:lol ty qword, you beat me to my edit.... I used FindWindow as a test so your method is much better though :)

Edit: Aha I see there is.... Any inherent issues with using:
invoke ShowWindow, ConsolehWnd, SW_HIDE/SHOW?

Quote from: qWord on April 13, 2011, 10:46:48 PM
however, the console will be visible for a short time at start up of your program.

Would this be considered 'unprofessional'? I have seen this flash before on professional applications but a developer's take on it would be interesting....

PS. Thanks guys, this is much better for me than what I had before.... Having the Console perminently showing was really annoying me.... I had thought about sorting this for ages but never gotten around to it :lol....
Title: Re: Console
Post by: qWord on April 13, 2011, 10:57:44 PM
Quote from: oex on April 13, 2011, 10:48:17 PMWould this be considered 'unprofessional'?
IMO yes - but I've also seen some professional programs using these technique.
Title: Re: Console
Post by: redskull on April 13, 2011, 11:10:59 PM
Quote from: oex on April 13, 2011, 10:40:58 PM
OK that sounds nasty.... I think that trashes that idea right off :lol.... I dont call any other application atm however I cant guarentee I never will.... If that application will destroy my command window I guess I'll just continue creating console apps for now....

It won't destroy your command window, it will simply bring up it's own, and then return to the original once it terminates.  Depending on what you are planning on doing, this could be either totally wrong (for instance, if you are displaying to stdout), or completly appropriate (if you are starting your own text-mode editor, etc).  For instance, that's why there is both cdb.exe and ntsd.exe; exactly identical debuggers, except one makes it's own window, and the other just continues within the cmd window

-r
Title: Re: Console
Post by: oex on April 13, 2011, 11:17:02 PM
Well pretty simply I want duel edit ability into my application so either I want Console or a Window displaying for input but obviously I dont want or need both at the same time.... I have a basic toggle already but Console was always displaying....

I think SW_HIDE/SW_SHOW fixes my problem.... From your description I think loading an external program with Console requirement could make my application inaccessible to certain functionality....
Title: Re: Console
Post by: jj2007 on April 13, 2011, 11:54:22 PM
See also setting bInheritHandles=TRUE means the process uses the parent's console (http://www.masm32.com/board/index.php?topic=14824.msg120797#msg120797)
Title: Re: Console
Post by: redskull on April 14, 2011, 12:04:43 AM
jj beat me to it....You should assemble/link as as WINDOWS app, then use GetStartupInfo() to determine whether or not you should use the handles provided, and take the appropriate conditional action.
Title: Re: Console
Post by: oex on April 14, 2011, 12:09:27 AM
OK.... I will delve into this however one thing bothers me.... What happens with a multi-threaded application? Maybe I'm not understanding the description properly, something I'll doubtless get when I start with the trial and error but....

hmm lost my train of thought at this point :lol.... If you know what I was thinking feel free to answer.... Otherwise if I remember I'll update this post :bg

Ah I remember.... What I meant was what happens if you need to use the console of the calling process when using another process with a console opened in a thread? From how I understand the description at this point there can be only one console for the calling process and it's child processes at any one time (Unless it's a console app)

Edit: It's late.... Excuse this post if it makes no sense I wil work opn this further in the morning....
Title: Re: Console
Post by: dedndave on April 14, 2011, 03:28:34 AM
well, i am kinda scratchin' my head trying to figure out what it is you're trying to accomplish   :P

i have seen some installers that open a console window briefly
i guess they are too lazy to write the code - they use DOS commands to perform registration, etc
Title: Re: Console
Post by: oex on April 14, 2011, 08:04:30 AM
Quote from: dedndave on April 14, 2011, 03:28:34 AM
well, i am kinda scratchin' my head trying to figure out what it is you're trying to accomplish   :P

i have seen some installers that open a console window briefly
i guess they are too lazy to write the code - they use DOS commands to perform registration, etc

:lol atm I'm writing an admin app which uses both Console and Windows, it's a little weighty and unruly to post (over 500Kb) but I was kinda interested in the methodology generally also :bg
Title: Re: Console
Post by: dedndave on April 14, 2011, 12:34:31 PM
 :bg
i feel like i know even less, now, than i did before
Title: Re: Console
Post by: oex on April 14, 2011, 01:00:50 PM
:lol Maybe I'll post it when it's done
Title: Re: Console
Post by: dedndave on April 14, 2011, 01:06:08 PM
i didn't necessarily need to see the code
i was just wondering why you needed a console window   :P
you can run other app's with CreateProcess or ShellExecute
Title: Re: Console
Post by: oex on April 14, 2011, 01:28:09 PM
I'll play with it and see if I can work out which bit I'm not understanding.... I have some ideas in how I would get around this it just appears there are more flaws than I first thought than simply changing my compile method and calling AllocConsole.... :lol....

I use both Console and Windows because I have input/display mechanisms for both and would rather not have to recode both right now :lol.... Most of my tools are written for console and translation to Windows controls properly (if indeed I bother) will take some time.... It is an admin app (ie only I use it atm)....
Title: Re: Console
Post by: dedndave on April 14, 2011, 01:57:09 PM
i was curious because i am working on a project that is along similar lines
but, i am using a window to replace the console   :P
it offers a window that is more tailored for the application than the console
you saw the other post with the hidden window and the visible one, right ?
the hidden window is somewhat analogous to the console app
and the visible one is analogous to the console
Title: Re: Console
Post by: dedndave on April 14, 2011, 02:05:53 PM
as an example, here is a series of WM_MOUSEWHEEL messages
the values are: sequence number, uMsg, hWnd, wParam, lParam

(http://img3.imageshack.us/img3/7477/appnv.png)
Title: Re: Console
Post by: oex on April 14, 2011, 03:18:40 PM
That's a nice project and I see your thinking.... I have similar ambitions for removing the console however they will unlikely be realised in the near-term.... I have written my own basic console already however serveral key features remain missing.... You'd laugh if I showed you which ones (display cough) :lol.... It's a minimalist approach.... simply text entry :lol.... For the time being Windows Console fills that gap :bg....
Title: Re: Console
Post by: dedndave on April 14, 2011, 03:26:14 PM
well - in this app, i have no need for keyboard entry, although it would be easy to add
i do have the display working pretty much
i have a macro i call "dPrint" which is similar to the masm32 "print" macro
that all works great   :bg
i am almost done with the visible window code - looking at about 13 kb
as opposed to the ~380 kb of cmd.exe

i could have just as well used a console, but i wanted to learn to write GUI apps   :P
Title: Re: Console
Post by: oex on April 14, 2011, 03:33:05 PM
:lol I also have a >8Kb font somewhere complete with creation tool and editor.... Worked out how to create one in >1Kb also (Probably less than 100 bytes) but never implemented it :bg....

(http://www.hereford.tv/font.png)
Title: Re: Console
Post by: oex on April 14, 2011, 03:44:54 PM
I think the 8Kb font is how they draw Courier VGA font
Title: Re: Console
Post by: dedndave on April 14, 2011, 03:51:05 PM
i was going to do something like that
but, i figured out how to enumerate the regular "Terminal" font that the console uses
i wanted to use it for 2 reasons
1) it has the graphics line symbols that some use for boxes
2) it is monospaced, which greatly simplifies the WM_PAINT code   :P

(http://img140.imageshack.us/img140/2591/textsize.png)

i eliminated the sizes where the cell width is larger than the cell height - lol
Title: Re: Console
Post by: oex on April 14, 2011, 03:57:21 PM
Quote from: dedndave on April 14, 2011, 03:51:05 PM
i was going to do something like that
but, i figured out how to enumerate the regular "Terminal" font that the console uses
i wanted to use it for 2 reasons
1) it has the graphics line symbols that some use for boxes
2) it is monospaced, which greatly simplifies the WM_PAINT code   :P

:lol dont use that as an excuse.... Mine has an editor to allow you to draw the graphics line symbols and is also monospaced :bg....

It currently has only 12x16 size however :lol
Title: Re: Console
Post by: oex on April 14, 2011, 04:02:24 PM
(http://www.hereford.tv/font_editor.png)
Title: Re: Console
Post by: dedndave on April 14, 2011, 04:03:55 PM
well - there are a couple other advantages to using the Terminal font
it is on every windows machine
there are several sizes already made for you
it doesn't require the data size, which can get large if you make several sizes
a lot of work to make fonts - lol

sent you a PM Peter   :bg
Title: Re: Console
Post by: oex on April 14, 2011, 04:11:40 PM
Quote from: dedndave on April 14, 2011, 04:03:55 PM
a lot of work to make fonts - lol

:lol that is for sure....