|
You're right - it does work - I was having a blonde moment!
The STL rocks. I feel I have hardly scratched the surface yet already I am in awe of its capabilities...
|
|
|
|
|
Don't forget to make operator() of your functors a const method. Otherwise it may not work, if your STL implementation passes the functor objects by const reference.
Good music: In my rosary[^]
|
|
|
|
|
Top tip - cheers. It does actually mention this in the excellent C++ Standard Library book I have (Nicolai Josuttis) so there's no excuse...
|
|
|
|
|
Greetings...
I have been working on some ATL controls which have MFC support. I can view the property page of the ATL classes and see the events they can handle, which are a partial list of those available to pure MFC classes. However I need to handle the event WM_SETTINGCHANGE and that is not listed as a possible event. I can manually type it under:
<br />
BEGIN_MSG_MAP(CSomeClass)<br />
...<br />
MESSAGE_HANDLER(WM_SETTINGCHANGE, OnSettingChange)<br />
...<br />
END_MSG_MAP()<br />
but this doesn't work..the debugger never stops in the OnSettingChange function.
However, if I make a new purely MFC project, WM_SETTINGCHANGE is listed under the events tap of the classe's property page, and it all works just fine.
The question I guess is, how can it be that ATL "with MFC support" has only some of the events? also what is the work arround, especially as in pure MFC the event handling function is in the form of
<br />
OnSettingChange(UINT uFlags, LPCTSTR lpszSection)<br />
and in ATL control project with MFC support it is in the form of:
<br />
OnSettingChange(UINT , WPARAM , LPARAM , BOOL& )<br />
Thanks,
Aristotel
|
|
|
|
|
Hi,
In my main frame I have a splitter pane with two views. I want to scroll the appropriate window when the mouse hovers over it. What is the best way to do this?
I was thinking of handling the WM_MOUSEWHEEL message and checking if the cursor is within the bounds of the view's rectangle (using GetCursorPos() and GetWindowRect()) but I think it would waste too many CPU cycles
Is there a better way?
Thanks in advance.
|
|
|
|
|
First, this is not the appropriate forum: you'll get more response in the Visual C++ forum as it is purely related to visual C++ and MFC.
For your question, do you know that if you make your views inherits from CScrollView instead of CView, this is automatically managed ? You'll have also scroll bars at the bottom and at the right of your views.
Hope this helps
|
|
|
|
|
cedric moonen wrote:
as it is purely related to visual C++ and MFC
How do you figure? He never mentions MFC, so I think we should assume that he's using WTL.
--
An eye for an eye will only make the world blind.
|
|
|
|
|
Sorry, I don't know WTL and the words mainframe and splitter made me believe he was using the MFC.
Next time, I'll ask before saying something wrong
|
|
|
|
|
The MSDN docs says:
The WM_MOUSEWHEEL message is sent to the focus window when the mouse wheel is rotated. The DefWindowProc function propagates the message to the window's parent. There should be no internal forwarding of the message, since DefWindowProc propagates it up the parent chain until it finds a window that processes it.
After having read that, my first stab at the problem would be to process the WM_MOUSEWHEEL message at the splitter level. There I'd use WindowFromPoint() and GetCursorPos() to figure out which window it's over. Then I'd use GetParent() until I get either left or right pane window. Then I'd send the appropriate WM_xSCROLL messages to the correct pane.
--
An eye for an eye will only make the world blind.
|
|
|
|
|
Hi, All!
When i trying to add a new ATL object to my project i see this error! May be smbd solve it?
Thanx!
|
|
|
|
|
AdyOS wrote:
When i trying to add a new ATL object to my project i see this error
which error ?
AdyOS wrote:
May be smbd solve it?
certainly not, how could we ? we don't have neither the code nor any explanation of what you do nor the error message...
please understand us too if you want us to give some help...
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
OK! I have an ATL project with support MFC. The project already have some ATL objects (there are Dilaogs). And now i try to add a new Dialog to my project, but when i click Insert->New ATL object i see this error. Before all was ok.
|
|
|
|
|
|
toxcct wrote:
which error ?
The one contained in the title of the message
|
|
|
|
|
I'm receiving an unknown software exception when trying to use COM (ATL) to interoperate with the .NET CLR. I AM using VS2005 Beta 2 but I think the problem occurs in VS2003 also (from what I've seen when googling).
To reproduce this behaviour, create a simple ATL object (I used non-attributed, dunno if it matters), add a single method with no params that just returns S_OK. Compile with the /clr switch. (Note there's no need to go to the trouble of creating or instantiate any managed objects - compiling with the /clr switch is enough).
Now write a console app that creates this object, calls the method and exits. Upon exit, Kaboom!. As there is virtually zero code, it's quite tricky to fix. Has anyone seen this and, more importantly, fixed or worked around it?
Many thanks
swg
|
|
|
|
|
Hi, I have the same problem,
please help me...
|
|
|
|
|
Hi Friends,
I am using some open source code which is in C++ language.
But i have to convert it to C code.
In the C++ source, there are many class templates.
I want to convert to the templates to C code.
I don't know how to do it.
Please guide me.
With Thanks and Regards,
Arun AC
|
|
|
|
|
Arun Chakaravarthy wrote:
I am using some open source code which is in C++ language.
But i have to convert it to C code.
In the C++ source, there are many class templates.
I want to convert to the templates to C code.
I don't know how to do it.
Convert the templates to macros (templates and macros are very similar in C++).
|
|
|
|
|
CP Visitor wrote:
Convert the templates to macros (templates and macros are very similar in C++).
That may not always be possible. Especially if the existing code is using type expressions.
Good music: In my rosary[^]
|
|
|
|
|
it won't be possible directly, since templates are pure C++.
but you could write the specialized classes with the types you'll have to use in...
let's take an easy example...
in C++, we have a class called map<Key, Value>
well, if you use it only for (key, Value) of types (char, int), you can rewrite the part of the map<char, int> which will work only on those types... (i conceed, it's a lot of work)
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
In my application I want to access files, where the underlying character type (ASCII or Unicode) is transparent for the application.
Suppose that in a reporting module a report is written to file, like this:
myfile << reportHeader << std::endl;<br />
for (all columns) myfile << columnname;<br />
myfile << std::endl;<br />
for (all records)<br />
{<br />
for (all columns) myfile << data;<br />
myfile << std::endl;<br />
}<br />
Now, I want my application to transparently write the report to ASCII or Unicode files, depending on the user specification.
Currently, you have to do it like this:
std::ofstream asciiFile;<br />
std::wofstream unicodeFile;<br />
if (user wants Unicode)<br />
{<br />
unicodeFile.open ("output.txt");<br />
unicodeFile << reportHeader << std::endl;<br />
}<br />
else<br />
{<br />
asciiFile.open ("output.txt");<br />
asciiFile << reportHeader << std::endl;<br />
}<br />
for (all columns) <br />
{<br />
if (user wants Unicode) unicodeFile << columnname;<br />
else asciiFile << columnName;<br />
}<br />
... and so on<br />
The disadvantages seem obvious:
- clumsy, unreadable code (especially if the write-to-file logic is spread over several methods)
- writing Unicode strings (std::wstring) to an Ascii stream doesn't even work; it produced garbage
Therefore, I need a kind of transparent stream, so that I can write the following:
transparentstream myfile;<br />
myfile.setMode (ascii or unicode);<br />
myfile.open ("output.txt");<br />
myfile << reportHeader << std::endl;<br />
for (all columns) myfile << columnname;<br />
myfile << std::endl;<br />
for (all records)<br />
{<br />
for (all columns) myfile << data;<br />
myfile << std::endl;<br />
}<br />
Problems are:
- from which stream do I inherit the transparentstream?
- how do I define the transparentstream so all defined output operators keep on working?
- where do I put the conversion logic? (basic_buf? basic_filebuf?)
Of course I want something similar for input, where the stream can find out itself whether the file is Unicode (starts with 0xfffe or 0xfeff) or plain Ascii.
And as an additional challenge: is it possible to have such a transparent stream that can do something like this?
transparentstream mystream;<br />
mystream.open("http://www.mywebsite.com/mypage.html");<br />
mystream >> ...;<br />
And if this is possible, how do I implement such a stream of buf class?
Did some of you already encounter problems trying to mix the STL and Unicode files?
How did you solve it?
Thanks for you suggestions.
Enjoy life, this is not a rehearsal !!!
|
|
|
|
|
Are you referring to overloaded << and >> operators?
ofstream &operator<<(ofstream &of, const CData const &data)
ifstream &operator>>(ifstream &if, const CData const &data)
Kuphryn
|
|
|
|
|
Not exactly.
I want to write to (or read from) a stream without having to worry about whether the file is Ascii or Unicode.
Afaik, STL forces me to know beforehand what the file is and use either an ofstream (for Ascii) or a wofstream (for Unicode), which means that all output statements should be doubled in my application.
In my original post I gave a simple example for a reporting module.
The first code examples shows how to do it in Ascii only.
The second example shows how STL currently forces me to write this module if I want to support both Ascii and Unicode in my application.
The third example shows how I would hope to write it, at least if somebody has a brilliant idea.
Enjoy life, this is not a rehearsal !!!
|
|
|
|
|
You determine the file type via input?
One solution is to overload the operators as mentioned. There could be multiple objects (CObject and CObjectUnicode).
Kuphryn
|
|
|
|
|
Streams are transparent, you should use locale codecvt facet so that the buffer will be converted before saving and after loading.
Your code should look like this:
<br />
std::wofstream myfile;<br />
std::locale loc(std::locale(),new std::codecvt<wchar_t,ascii ? char : wchar_t,std::mbstate_t>());<br />
myfile.imbue(loc);<br />
<br />
<br />
myfile.open ("output.txt");<br />
myfile << reportHeader << std::endl;<br />
for (all columns) myfile << columnname;<br />
myfile << std::endl;<br />
for (all records)<br />
{<br />
for (all columns) myfile << data;<br />
myfile << std::endl;<br />
}<br />
Note that myfile is always wchar_t and codecvt converts the caracters to char.
If your internal data is char based you should use a char based stream and imbue it with a codecvt that converts from char to wchar_t is you need to save Unicode.
Also when saving to Unicode you should write 0xEF 0xBB 0xBF first to indicate the file is Unicode (is what you will find at the beginning of utf-16 xml files) and when reading the file read the first 3 bytes, test them and then use the right codecvt facet to convert to your internal data.
|
|
|
|