| | |
Console application colors?
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Mar 2009
Posts: 4
Reputation:
Solved Threads: 0
Cheers Buddy, for anyone else out there...
C++ Syntax (Toggle Plain Text)
#include <windows.h> #include <iostream.h> #include <stdio.h> int main() //Visual C++ Console Application. to Demo Color Text. { HANDLE hOut; int a; hOut = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleTextAttribute(hOut,30); //HI yellow on BLUE. system("cls"); printf("Hello World \n\r"); printf("Press any key then enter to exit"); cin >> a; return 0; }
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
•
•
Join Date: Mar 2009
Posts: 4
Reputation:
Solved Threads: 0
hmm, those will be the same standards that took a perfectly reasonable language and loaded layer after layer of garbage on the top such that "Hello World" which used to be 5 lines long and exe at 20K is now well over 150 lines and makes an EXE of almost 1MB. My applications require speed, up till now I have used Visual Basic as an interface and built (C DLL's to control production process hardware (under Win98) . I looked at 2008 and decided it is yet another piece of software that deserves the "Emporers clothes" awards. Anyway that's a personal opinion (maybe I'm just stuck in my ways..) Thanks for the replies.
My cool "zprintf".
You can change color attributes inside string, like
<c10>Hi <c12>There<c14>!!!!
And you get rid of those SetConsoleTextAttribute -lines!
You can change color attributes inside string, like
<c10>Hi <c12>There<c14>!!!!
And you get rid of those SetConsoleTextAttribute -lines!
C++ Syntax (Toggle Plain Text)
//Do this somewhere inside your code. "hOutput" must be global. HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE); void zprintf(const char *format, ...) { char syntax[4096*2] = {0}; va_list args; va_start(args,format); vsprintf(syntax,format,args); va_end(args); char *s = syntax; char code[3] = {0}; char *end = NULL; while(*s){ if(*s == '<' && s[1] == 'c'){ int len = strcspn(s+2,">"); memcpy(code,++(++s),len); unsigned long color = strtoul(code,&end,0); SetConsoleTextAttribute(hOutput,color); s+=len+1; }else printf("%c",*s++); } }
•
•
•
•
hmm, those will be the same standards that took a perfectly reasonable language and loaded layer after layer of garbage on the top such that "Hello World" which used to be 5 lines long and exe at 20K is now well over 150 lines and makes an EXE of almost 1MB.
C++ Syntax (Toggle Plain Text)
#include <iostream> int main() { std::cout << "Hello World\n"; }
That's an oxymoron statement!! You can't get speed out of VB or Win98. Come into the 21st Century by upgrading hardware and os to XP.
Last edited by Ancient Dragon; Mar 31st, 2009 at 9:31 am.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
•
•
•
•
hmm, those will be the same standards that took a perfectly reasonable language and loaded layer after layer of garbage on the top such that "Hello World" which used to be 5 lines long and exe at 20K is now well over 150 lines and makes an EXE of almost 1MB. My applications require speed, up till now I have used Visual Basic as an interface and built (C DLL's to control production process hardware (under Win98) . I looked at 2008 and decided it is yet another piece of software that deserves the "Emporers clothes" awards. Anyway that's a personal opinion (maybe I'm just stuck in my ways..) Thanks for the replies.
Things will never happen like that don't worry. In a executable file ( windows PE exectuable ) there are file format helders. Most of the space are gone for them plus another half of space is gone to the debug information , VC++ 6.0 default build the debug. So that's why you see your'r binaries big.
Another reason for that is just your usage of static libraries. Think that you are using STL , STL is a static library in many plactforms.
Surelly in the windows.
But the code that you writes never increase the size like that. you just can open the disassembler and see how many assembly instructions your code actually get.
Just , compile and build your project. and add a break point to the int main () line.and the , press
build->start debug -> go
and the debugger will stop before executing the line that contains the main. and then
view menu -> debug windows -> disassembly
and you will see how much assembly instructions that each line takes.
Answer for the Speed:
well that's true you cannot expect the real time behaviour under a general purpose operating system( like windows XP , your 98 even, and linux ). So therefore you need to use a realtime os for that. ( if you really wish ). I think go to the old MS-DOS world back is really a bad idea. But if you really interested you can use a morden real time operating system for this. I recommand you to use ecos operating system for this. Ecos is open source and you can do many fun projects with cheap hardware even.
Last edited by NicAx64; Mar 31st, 2009 at 11:00 am.
Nothing like a kernel pannic !
for me this is only the code space that taken to that 5 lines long "Hello World" application.
C++ Syntax (Toggle Plain Text)
1: // q3stl.cpp : Defines the entry point for the console application. 2: // 3: 4: #include "stdafx.h" 5: 6: int main(int argc, char* argv[]) 7: { 00401010 push ebp 00401011 mov ebp,esp 00401013 sub esp,40h 00401016 push ebx 00401017 push esi 00401018 push edi 00401019 lea edi,[ebp-40h] 0040101C mov ecx,10h 00401021 mov eax,0CCCCCCCCh 00401026 rep stos dword ptr [edi] 8: printf("Hello World!\n"); 00401028 push offset string "Hello World!\n" (0042001c) 0040102D call printf (00401060) 00401032 add esp,4 9: return 0; 00401035 xor eax,eax 10: } 00401037 pop edi 00401038 pop esi 00401039 pop ebx 0040103A add esp,40h 0040103D cmp ebp,esp 0040103F call __chkesp (004010e0) 00401044 mov esp,ebp 00401046 pop ebp 00401047 ret
Nothing like a kernel pannic !
![]() |
Similar Threads
- My taskbar changes colors and I lose my volume (Viruses, Spyware and other Nasties)
- Console Application (C)
- Graphics in C (C)
- Help, i suppose (C++)
- Major problem with C++ compiler (C++)
- I need special stuff in my project like system("cls") (C++)
Other Threads in the C++ Forum
- Previous Thread: compiler errors lnk2019, lnk1120
- Next Thread: Help with header file
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays beginner binary bmp c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete desktop directshow dll download dynamic encryption error file forms fstream function functions game givemetehcodez google graph gui iamthwee ifstream input int java lib library lines linkedlist linker loop looping loops map math matrix memory microsoft newbie news number output pointer problem program programming project python random read recursion recursive reference return sort string strings struct studio system temperature template templates test text text-file tree unix url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






