|
Andy Moore wrote: I would disagree with you that learning Win32 is harder C#/Winforms
Wow - I'd say that's a pretty strong allegation. I doubt many people would agree.
Andy Moore wrote: In fact, learning the Win32 API is vital to the fundamentals in Windows UI programming and getting one's head around this ensures successful use of MFC, C#/Winforms, or whatever framework that Microsoft may come up with next.
This is absolutely true. And, as you said, MFC really is just Win32 wrappers, and that's half my point. MFC is easier in a lot of ways, and if you do MFC for a while, Win32 is easy to learn, you learned half of it without ever realising it.
Andy Moore wrote: These frameworks wrap the Win32 API anyway
Yes, this is still true today, until WPF takes over
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Hi,
I was wondering if anybody knows if there is some gui library that allows you to create freshly looking menus and controls which resemble windows vista (looking fresh and clean) and that would run on XP and Windows 2000?
I also like the GUI of real player 10 - this would also be good.
The normal standard issue MFC menus and controls are kind of outdated for the app that I'm working on.
Any idea would be greatly appreciated.
Thanks.
|
|
|
|
|
Im not sure but i think i see an article in codeproject about vista style menu
|
|
|
|
|
Hi.
Right, I have a WIN32 console application. I would like to know how to change the background from black to white. So that I can have black text on a white background.
I know how to alter individual pieces if text foreground and background colour, but I would like to be able to alter the entire console window foreground and background colour.
Many regards.
James.
|
|
|
|
|
just run your console app, right click the title bar to open the proerties dialog and set it from there. Remember to click yes when it prompts you to save for all future windows.
|
|
|
|
|
Sorry, I was not clear, I meant programmatically, at the console initialisation stage.
James.
|
|
|
|
|
FillConsoleOutputAttribute
|
|
|
|
|
Thank you very much for the response.
The function is indeed useful, however, I would like to know if there is a way to define the console output attributes at creation time, as my application writes an indeterminate number of lines to its output console. I would like to avoid the overhead of having to determine if the next write will be ‘outside’ the currently defined range of cells covered by the last call to function.
Is there a way to specify at console initialisation, for example, the background colour of all console line output ?
James.
|
|
|
|
|
Use FillConsoleOutputAttribute when your program starts to fill the entire console with one colour.
Use SetConsoleTextAttribute to set the current colour used for text-output
these are fully documented in MSDN, I really don't know why people don't read the documentation before asking questions - it would save you a lot of time.
|
|
|
|
|
Thanks again for the response.
I really do not understand your need to be critical of my question whilst at the same time attempting to answer it. Why did you bother if the question is so trivial?. Your answer is not even directed at me, it is a cheap arogant point scroring excercise and very childish. There are people of differing levels of experience and competence that post questions on this forum and it is people like you that most of us in the industry despise. Please feel free to ignore any further questions that I might post, I would rather not have your help.
And, your response does not answer my question - try re-reading it.
James.
|
|
|
|
|
Excuse me, but being overly sensitive and calling people arrogant and childish is what the 'industry' despise. I am suggesting you read the documentation as this is surely the starting point of any programming question. Going by the limited description of your problem I provided an accurate solution which you would also be advised to investigate by reading the relevant MSDN pages. If you still insist that this is 'wrong' then try articulting your question a little more clearly.
|
|
|
|
|
Prior to posting my original question, I had read all the MSDN documentation regarding console functionality. I could not find what I wanted, so I posted the question. If there is anyone that knows if there is a way to set console output to display in a particular colour without having to specify the number of output bytes, ie) to be able to avoid the overhead of having to keep track of the number of bytes written so far? If there is not, then so be it, but if there is, then I would very much like some pointers.
James.
|
|
|
|
|
James,
I really do believe the FillConsoleOutputAttribute will solve your problem - and do shouldn't need to know how many characters/bytes have been written. I had assumed you just wanted to fill the entire console buffer with the same colour? You can use FillConsoleOutputAttribute to colour all cell-positions within the console, not just those characters already written (think about how the 'CLS' command might work). So the number of characters to fill = width_of_console * height_of_console. Filling the entire console does not alter the 'cursor position' it just sets the cell-colours.
GetConsoleScreenBufferInfo API will return you information regarding the size of the output-window (in the CONSOLE_SCREEN_BUFFER_INFO::dwSize field). So your number of characters. This is untested code:
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO csbi;
GetConsoleScreenBufferInfo(hConsole, &csbi);
COORD top = { 0, 0 };
DWORD written;
WORD attr = << colour value here >>
FillConsoleOutputAttribute(hConsole, attr, csbi.dwSize.x * csbi.dwSize.y, top,
&written);
Documentation for FillConsoleOutputAttribute states: "If the number of character cells whose attributes are to be set extends beyond the end of the specified row in the screen buffer, the cells are written up to the end of the screen buffer". So you could in fact omit the GetConsoleScreenBufferInfo and just specify a "big" number for the number-of-characters. (i.e. 2^31).
Hope this was of some help, and sorry that we got off on the wrong foot.
regards,
James
|
|
|
|
|
James
Thank you for the reply.
I do not want an argument and I do appreciate the response, dealing with WIN32 is a nightmare and I really do value your help. I do applogise for calling you arrogant and childish, I just sometimes find it frustrating on this web-site because there are so many people that post questions that are clearly homework and I can understand experienced members like yourself that get tired of the endless ill thought through quick fix demands from those that do want to exhaust other channels before posting a help me help question.
I will look into what you have advised and I appreciate the help.
Best regards.
James.
As a point of interest, I cannot believe that you cannot create a console with a default foreground/background output attribute.
|
|
|
|
|
Sorry..that should have been "...from those that do NOT want to exhaust..."
Bit of a typo problem there!
|
|
|
|
|
Why does it have to be so complex? I'm still trying to convert my code but I have ran into a brick wall. I'm reading UTF16 encoded strings from a byte array, most of these strings are Chinese simplified. So for a MBCS I use this
WideCharToMultiByte(936/* GB_2312 */,0,(unsigned short *)data,length/2,text,length+1,NULL,NULL);
The data member there is a pointer within this array. This works, it gives me a string of Multibyte characters. Here is the first character: 0xB0 0xB6. Now, for a unicode build, I should be able to read directly from the array: 0x73ED. According to my charmap utility, this is the correct value for this character. But all I see is "?". Ok, try converting the first multibyte result back to wide:
MultiByteToWideChar(CP_ACP,0,text,length,lpW,length+1);
Exactly the same result: 0x73ED. But I am still not seeing it. Lets try the other, simpler, multi to wide function:
mbstowcs(lpW,text,length);
This time the output is a little different: 0x00B0 0x00E0, and I can see it.
Can anybody explain what is going on here?
|
|
|
|
|
Read the WideCharToMultiByte() docs closer, you'll see that there's a fall back character, which defaults to ' ?' . This character is inserted in the MBCS string when there is no character in the given codepage that matches the Unicode code point.
I can't tell from your post if WideCharToMultiByte() is doing the conversion right. What could be happening is the program you're using to inspect the strings is doing its own WideCharToMultiByte() and the fallback behavior is happening there, which leads to '?' in the display.
--Mike--
Visual C++ MVP
LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
|
|
|
|
|
I figured out that MultiByteToWideChar() was infact doing the correct convertion. I was seeing the '?' in the debugger aswell as the console. The strange thing is that when I added <tchar.h> to the file, I could see the correct character in the debugger (tchar was already included in the stdafx). The thing that was throwing me off was the inability to see the unicode in the console. I tried variations of wcout and wprintf yet they showed nothing.
I have just stripped out all the tchar routines I added to the code, I am instead going to create overide functions similar to the A's and W's in the stl.
-- modified at 4:09 Sunday 27th August, 2006
|
|
|
|
|
If you want use wcout or wprintf in your program to print non-ASCII characters, you must correctly set you program's locale.
Call setlocale(LC_CTYPE, ".936"); at the beginning of your program and try wprintf again.
If you want to use wcout , locale::global must be called instead of setlocale .
Have a look at setlocale[^] and locale::global[^]
-- modified at 4:26 Sunday 27th August, 2006
|
|
|
|
|
When usiong unicode the locale goes out of the window, 936 (for Chinese simplified) does the job when displaying multibyte characters but I am trying to display Unicode. For example:
wchar_t *tmp = L"你好";
wcout << tmp << endl;
This displays correctly, but it is not unicode (sorry if you can't see the characters). tmp maps to 0x00C4 0x00E3 0x00Ba 0x00E3 (which is the Chinese NiHao. But this is not unicode, it's multibyte. The correct unicode value should be:
wchar_t *tmp = L"\x4f60\x597d";
wcout << tmp << endl;
This does not display anything to the console, and in the debugger all I see is "??", even though the characters have been assigned the correct value.
|
|
|
|
|
That is a strange behavior.
I've heard that in some English version of Windows and with some English version of VC, the compiler would convert L"你好" (The Chinese Nihao) to the character squence of 0x00C4 0x00E3 0x00Ba 0x00E3 , but I've NEVER met that situation. Chinese characters can be treated very well in wide string constants in all my programs.
In unicode programs, locale MUST be set to display non-ASCII characters in console, while MBCS programs do not need locale.
I just checked one of my programs, and found that locale::global has no effect on wcout , while it works well on all file streams. One must call wcout.imbue explicitly. Try this. By the way, I'm using MS VC2005.
|
|
|
|
|
Thanks for that.
wchar_t *tmp = L"\x4f60\x597d";
wcout.imbue( locale("Chinese_china") );
wcout << tmp << endl << endl;
This now works displaying the correct output.
|
|
|
|
|
Hey,
I wrote a program that takes input from a user from a text input and then saves it to the registry.
Now I tried converting it to Unicode but it just doesnt save the values as unicode, e.g. doesnt convert the german öüä to its unicode equivalent. Im pretty new to unicode and so on so i would greatly appreciate any help.
In visual studio i selected as character set unicode.
Thanks,
lucki_luke
|
|
|
|
|
If you have 'Use Unicode Character Set' selected in Project Properties, the registry APIs will be in Unicode mode (technically, RegSetValueEx is a macro which maps to RegSetValueExW ) and expect to be passed a UTF-16 string (an array of WCHAR , an LPWSTR ).
If this is defined, however, all GUI controls should be giving you text in Unicode format anyway (again, strictly it's that the GetWindowText macro maps to GetWindowsTextW ), so no conversions should be required. A window can be in 'ANSI' (byte-oriented character set) mode or in 'Unicode' mode; which it is depends on the variant of RegisterClassEx called. If this mismatches the rest of your program, some unexpected conversions can occur. I'm not quite sure how the standard predefined controls get set up.
Advanced: this setting in VS determines whether UNICODE (and _UNICODE), MBCS (and _MBCS), or neither, are defined on the compiler's command line. The TCHAR.H header handles the underscore-prefixed variants for the C runtime string functions which include a 't' in their names (which are Microsoft extensions), while the Windows headers handle the non-prefixed variants for Windows APIs.
|
|
|
|
|
I am trying to retrieve values from within a list of strings
SentenceList.h
----------------------------------
#pragma once
..
#include <list>
...
using std::list;
...
class CSentenceList
{
....
string display(unsigned int iLineNumber = 1);
list<string> Sentences; //list of sentences
// Note: MOVE TO PRIVATE AFTER IMPLEMENTING display
....
};
The list is being created and I would like to create a method 'display' that returns a string according to the line number. The method should loop through the list and return a string according to the value of iLineNumber.
I have tried using Sentences.front, but I could not picture the correct return value to be read to return the string value.
How do I read values from Sentences?
Jon
|
|
|
|
|