console-application

Handle CTRL+C on Win32

折月煮酒 提交于 2019-11-26 20:40:33
问题 I have some problems with the handling of CTRL + C events, in a Win32 C++ console program. Basically my program looks like this: (based on this other question: Windows Ctrl-C - Cleaning up local stack objects in command line app) bool running; int main() { running = true; SetConsoleCtrlHandler((PHANDLER_ROUTINE) consoleHandler, TRUE); while (running) { // do work ... } // do cleanup ... return 0; } bool consoleHandler(int signal) { if (signal == CTRL_C_EVENT) { running = false; } return true;

How to receive Plug & Play device notifications without a windows form

霸气de小男生 提交于 2019-11-26 19:53:30
I am trying to write a class library that can catch the windows messages to notify me if a device has been attached or removed. Normally, in a windows forms app I would just override the WndProc method but there is not WndProc method in this case. Is there another way I can get the messages? You'll need a window, there's no way around that. Here's a sample implementation. Implement an event handler for the DeviceChangeNotifier.DeviceNotify event to get notifications. Call the DeviceChangeNotifier.Start() method at the start of your program. Call DeviceChangeNotifier.Stop() at the end of your

Windows Console Application Getting Stuck (Needs Key Press) [duplicate]

夙愿已清 提交于 2019-11-26 19:42:17
问题 This question already has an answer here: How and why does QuickEdit mode in Command Prompt freeze applications? 2 answers I have a console program that has different components that run like this: void start() { while(true){ DoSomething(); Thread.Sleep(1000*5); } } My main entry point looks like [pseudo-ish code] Thread.Start(Componenet1.Start); Thread.Start(Componenet2.Start); while(true){ Console.Writeline("running"); Thread.Sleep(1000*5); } There are no Console.Reads anywhere. My problem

System.drawing namespace not found under console application

隐身守侯 提交于 2019-11-26 19:22:41
问题 I selected console application as my C# project. But the imports that seemed to work under windows form project doesnt seem to work here. It says that the drawing namespace does not exist. using System.Drawing; using System.Drawing.Imaging; My problem is that i need to have the bitmap class. I am trying to make a command line app that does bitmap manipulations to a image. That's why i didn't chose my project to be a windows form's one. 回答1: Right click on properties of Console Application.

Can I write into console in a unit test? If yes, why the console window is not opened?

拈花ヽ惹草 提交于 2019-11-26 19:15:52
问题 I have a test project in Visual Studio. I use Microsoft.VisualStudio.TestTools.UnitTesting. I add this line in one of my unit tests: Console.WriteLine("Some foo was very angry with boo"); Console.ReadLine(); When I run the test, test passes but console window is not opened at all. Is there a way to make the Console window available to be interacted via a unit test? 回答1: NOTE: The original answer below should work for any version of VS up through VS2012. VS2013 does not appear to have a Test

Colorized Ruby output [closed]

◇◆丶佛笑我妖孽 提交于 2019-11-26 19:11:13
Is there a gem to perform background and foreground text colorization for output in terminal? I remember, when programming Pascal we all used to play with textcolor(...) procedures to make our small educational programs look more pretty and presentational. Is there anything similar in Ruby? jaredmdobson Colorize is my favorite gem! :-) Check it out: https://github.com/fazibear/colorize Installation: gem install colorize Usage: require 'colorize' puts "I am now red".red puts "I am now blue".blue puts "Testing".yellow Erik Skoglund Combining the answers above, you can implement something that

Why does closing a console that was started with AllocConsole cause my whole application to exit? Can I change this behavior?

陌路散爱 提交于 2019-11-26 18:46:02
What I want to have happen is that the console window just goes away, or better yet that it is hidden, but I want my application to keep running. Is that possible? I want to be able to use Console.WriteLine and have the console serve as an output window. I want to be able to hide and show it, and I don't want the whole app to die just because the console was closed. EDIT Code: internal class SomeClass { [DllImport("kernel32")] private static extern bool AllocConsole(); private static void Main() { AllocConsole(); while(true) continue; } } EDIT 2 I tried the accepted solution here [ Capture

How do you clear the console screen in C?

痴心易碎 提交于 2019-11-26 18:41:38
Is there a "proper" way to clear the console window in C, besides using system("cls") ? Tom Well, C doesn't understand the concept of screen. So any code would fail to be portable. Maybe take a look at conio.h or curses , according to your needs? Portability is an issue, no matter what library is used. Avinash Katiyar printf("\e[1;1H\e[2J"); This function will work on ANSI terminals, demands POSIX. I assume there is a version that might also work on window's console, since it also supports ANSI escape sequences. #include <unistd.h> void clearScreen() { const char *CLEAR_SCREEN_ANSI = "\e[1;1H

Why computing factorial of realtively small numbers (34+) returns 0

前提是你 提交于 2019-11-26 18:40:56
问题 int n = Convert.ToInt32(Console.ReadLine()); int factorial = 1; for (int i = 1; i <= n; i++) { factorial *= i; } Console.WriteLine(factorial); This code runs in Console Application, but when a number is above 34 application returns 0. Why 0 is returned and what can be done to compute factorial of large numbers? 回答1: You're going out of range of what the variable can store. That's effectively a factorial, which grows faster than the exponential. Try using ulong (max value 2^64 = 18,446,744,073

itextsharp: How to generate a report with dynamic header in PDF using itextsharp?

徘徊边缘 提交于 2019-11-26 18:39:52
问题 I'm generating a PDF report with itextsharp, the header of the report has the information of the Customer, In the body of the report contains a list of customer transactions. My doubt is: How to generate a header dynamically for each client? I need an example to generate a header dynamically to the report. Every new page Header need to have the data that client when changing client header should contain information on the new client. 回答1: Your question risks down-voting or at least comments