Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Stephens' C# Programming with Visual Studio 2010 24-Hour Trainer
This is the forum to discuss the Wrox book Stephens' C# Programming with Visual Studio 2010 24-Hour Trainer by Rod Stephens; ISBN: 9780470596906
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Stephens' C# Programming with Visual Studio 2010 24-Hour Trainer section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 11th, 2011, 02:41 PM
Registered User
 
Join Date: Jun 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Lesson 19 Exercise 4

How do I have the console window come up? Just typing: "Console.WriteLine(whatever)" doesn't.

Edit: I've figured out who to do it, but I don't really understand what is going on. Is this the most simplified that I could have the code to activate and deactivate the console window?
Code:
" using System.Runtime.InteropServices;
[DllImport("kernel32.dll", EntryPoint = "GetStdHandle", SetLastError = true, CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]

private static extern IntPtr GetStdHandle(int nStdHandle);

[DllImport("kernel32.dll", EntryPoint = "AllocConsole", SetLastError = true, CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]


[DllImport("kernel32.dll", EntryPoint = "FreeConsole", SetLastError = true, CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]

public static extern int FreeConsole();
"

Last edited by mpthemaster; June 11th, 2011 at 03:09 PM.. Reason: found more information
  #2 (permalink)  
Old June 11th, 2011, 04:08 PM
Rod Stephens's Avatar
Wrox Author
Points: 3,187, Level: 23
Points: 3,187, Level: 23 Points: 3,187, Level: 23 Points: 3,187, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 646
Thanks: 2
Thanked 96 Times in 95 Posts
Default

Normally you can use the console window in two ways. First, while developing a program, anything you write using Console.WriteLine appears in the Output window. If you can't find it (for example, if you closed it), then you can get it back by looking in the Debug menu's Windows submenu (I think).

Second, if you make a console application, then input and output go to a separate console window similar to what you get by running cmd.exe. When you start the program, this window will just appear and output written by Console.WriteLine will go there.

When the program ends, the window closes. A common mistake is the program runs very quickly, displays output, and the window closes, possibly before you even see it. You can use Console.ReadLine to make it wait until you press Enter. Then you can see everything before it closes.

Let me know if neither of these scenarios is what you had in mind.

(And post a review when you have a chance!)
__________________
Rod

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)
  #3 (permalink)  
Old June 11th, 2011, 05:25 PM
Registered User
 
Join Date: Jun 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

******Just to let you know, the above is spam about how to make a hookah and not help at all*********

Thank you. I'm guessing you meant for me to use the output window for that exercise. I didn't realize that Console.WriteLine appears there.

The scenario that I thought you meant for the exercise was to have a console application pop-up from the windows form application when the "List Items" button is pressed. Then in the console application, all the list view items would be displayed as specified in the exercise to the user. The code I posted before allows for me to "enable" or "disable" the console application within the windows form application. I was now just wondering if you could tell me if that code only contains what is necessary to "enable" or "disable" the console application. I was on msdn, but this is still too complex for me to understand myself.

Thanks again for the quick reply. (do you want me to post a review on here or where I bought it?)

Last edited by mpthemaster; June 11th, 2011 at 05:30 PM.. Reason: Noticed spam, curtesy of google translate.
  #4 (permalink)  
Old June 11th, 2011, 08:54 PM
Rod Stephens's Avatar
Wrox Author
Points: 3,187, Level: 23
Points: 3,187, Level: 23 Points: 3,187, Level: 23 Points: 3,187, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 646
Thanks: 2
Thanked 96 Times in 95 Posts
Default

Yes, it's a bit confusing that Microsoft uses Console.WriteLine to write to the Output window.

Writing there is useful for displaying debugging messages but I hardly ever make console applications. They're just not that interesting. Some authors have you start by making them because that lets them ignore the user interface so they can just cover things like variables and loops, but I think that approach is backward. The large majority of Windows applications use a user interface not a console window so why should you start by learning something you'll hardly ever use again? My opinion, anyway ;-)

Quote:
The scenario that I thought you meant for the exercise was to have a console application pop-up from the windows form application when the "List Items" button is pressed.
The point of that exercise was really to just let you loop through the items in a list. A more realistic example would create a printout showing the items in a bill of sale, but printing isn't until Lesson 33.

Quote:
I was now just wondering if you could tell me if that code only contains what is necessary to "enable" or "disable" the console application.
I'm actually not sure what you could do with that code. It's mainly a declaration of methods provided in external libraries and doesn't actually contain code to do anything with them. My guess is you could use it to create a new console window. It's pretty low-level stuff. It might be the sort of thing that a console application does automatically for you.

Quote:
Thanks again for the quick reply. (do you want me to post a review on here or where I bought it?)
Feel free to ask any questions you have and I'll try to answer as quickly as I can.

The best places to post reviews are places like Amazon where lots of people can see them.

Thanks!
__________________
Rod

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Lesson 5 exercises. thelemur BOOK: Java Programming 24-Hour Trainer by Yakov Fain 9 March 29th, 2013 11:56 PM
Lesson 6 Try It zavodney BOOK: Stephens' Visual Basic Programming 24-Hour Trainer 2 June 6th, 2011 10:07 PM
Lesson 3 question soneal777 BOOK: Stephens' C# Programming with Visual Studio 2010 24-Hour Trainer 1 August 30th, 2010 06:17 PM
Chapter 19 Exercise CharlieChan BOOK: Beginning Visual C++ 6 0 June 19th, 2005 05:15 PM
Problem with exercise in chapter 19 backslash BOOK: Beginning Visual C++ 6 4 September 5th, 2003 11:46 AM



All times are GMT -4. The time now is 08:02 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.