Normally from the taskbar close menus you should send only WM_CLOSE to the main window and you should handle the program exit and "exit possible" flag from the WM_CLOSE handler of your main window. I would extend Superman's solution by using a counter instead of a bool, everytime a modal dialog opens increase the counter and everytime a modal dialog closes decrease the counter. If you have a lot of modal dialogs then you could automatize this by inheriting your dialog classes from a common class and you could implement this feature only once for all dialogs in the base class. So it is OK to close the main window only if your dialog counter is zero. Optionally you can grey out the close buttons/menuitems when the counter is nozero.
EDIT: Here is an alternative solution that MAY WORK, I haven't tried it: Usually when at least one modal dialog is active all other windows/dialogs in the background are disabled (with EnableWindow()[^]). So if the main window is disabled we can suspect that it is disabled because of a modal window (unless you are disabling it manually that I doubt). In this case you could use the IsWindowEnabled()[^] function on the main window to detect whether it is enabled or disabled. So all you have to do is cancelling the main window close (from your WM_CLOSE handler) if the main window is disabled (plus all you should do from your context menu close command is sending a WM_CLOSE to the main window so your WM_CLOSE handler will handle the main window close command regardless of the source of the command). CWnd also has an IsWindowEnabled()[^] method besides the winapi IsWindowEnabled().
I created a MFC dialog using CDHtmlDialog and added a HTML page with many controls and one of them is a IMAGE tag. I got a default image loaded from the hard drive displayed in the HTML page. Up to this part, everything works fine.
Now what i want to do is, dynamically change the image based on the user click on one of the HTML buttons. I don't want this image source to be hard coded in the HTML nor the image source send from the MFC app.
What i want is for the MFC app to send the image data to the HTML in some (binary) format and then the page to display the image.
I am not even sure whether this is possible. So basically what i want is for the HTML page to display a image from the memory.
Can anyone guide me on how to do this? What approach needs to be taken?
What you're supposed to do is respond to the button click by generating new HTML on the fly, and telling the HtmlDialog to load it. I don't recall the exact function names, but you'll find it all in the documentation.
The difficult we do right away...
...the impossible takes slightly longer.
So the 1st question is,
1. How to read a Image file as memory buffer (unsigned char *) in MFC? i.e, making sure it doesn't loose any NULL terminators or any binary contents.
And 2nd question is,
And 3rd question is,
The reason why i want to do it this way is because the HTML should never be able to display the Image file from a file path or URL. That is a requirement for the project i am doing.
HTML page should only use a memory buffer containing the Image file info. Hope this information helps.
Thanks in advance. I appreciate the 2 earlier responses i got.
I am going to assume you will follow what Richard said and reload the HTML in the dialog. I am also going to assume that you are able to modify the HTML from within your code.
In this case, you should be able to achieve what you want by embedding the image as Base64 encoded data, but note that this process increases the size of your data. This is also know as The Data URI Scheme: http://en.wikipedia.org/wiki/Data_URI_scheme[^]
Here is the description:
Consider lists of numbers from real-life data
sources, for example, a list containing the number of students enrolled in different
course sections, the number of comments posted for different Facebook status
updates, the number of books in different library holdings, the number of votes per
precinct, etc. It might seem like the leading digit of each number in the list should
be 1–9 with an equally likely probability. However, Benford’s Law states that the
leading digit is 1 about 30% of the time and drops with larger digits. The leading
digit is 9 only about 5% of the time. Write a program that tests Benford’s Law. Collect a list of at least one hundred numbers from some real-life data source and enter them into a text file.
Your program should loop through the list of numbers and count how many times 1 is the
first digit, 2 is the first digit, etc. For each digit, output the percentage it appears
as the first digit. If you read a number into the string variable named strNum then you can access
the first digit as a char by using strNum .
And Here is how I got so far:
Programming Language C++ (I just take this class this F2013)
I suppose that you didn't expect the result you've got.
Your program doesn't check the frequency of the first digit of the number but all the digits in the stream.
You have to split your data set into numbers first and then take only the first digit of that number.
Now there are several ways to split a number but the easiest is probably to use the getline function of a stream. The get line default uses the endline to seperate the lines but you can provide your own delimiter.
This reduces the complexity of your program, which is good in industrial code but isn't when someone still needs to learn coding algorithms.
I think your aim should be to write your own string split function/algorithm.
Learn from the mistakes of others, you may not live long enough to make them all yourself.
Create a "number box" that has 10 compartments, one for each digit 0-9.
For each number in your list
Check the first digit.
If it is a 0, increment the "0" compartment in the above-mentioned box.
If it is a 1, increment the "1" compartment in the above-mentioned box.
If it is a 2, increment the "2" compartment in the above-mentioned box.
// output statistics here
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
I'm using opensource library (exprtk http://partow.net/programming/exprtk/[^]) on qt 5.1.0 64 bit with visual studio 2012. But I'm taking c1128 error. Full output of error: C1128: number of sections exceeded object file format limit : compile with /bigobj