Tuesday, March 14, 2006

Small problem with a MFC application..

While I was coding with MFC with my C++ team mates Sally & Shimaa.. (we were doing the hacking task which was quite an easy one).. we faced a tiny silly problem... The problem was that when displaying an int value in a messagebox, the value appears as strange characters..

For example, if u wrote:
int x = 2;
CString str = x;

then u willl get strange characters in the Message box..
mmm.. I tried type casting.. (static_cast string str = <>(x); ) but.. the same thing happened again... I tried _itoa(x,str,size); ...but again & again.. it doesn't work well in all cases....actually I didn't knew how to fix it till I went home & googled for the solution... & here we go... just made good use of the "CString" class & everything went just fine... (Thanks Google)

I tried this Code as a sample:
int value = 1000;
CString string ;

IT WORKS.. :D ..

Here are some more additional information about the CString::Format method (got it from msdn )
nFormatID : The string resource identifier that contains the format-control string.
pszFormat :A format-control string.
argument :Optional arguments.

This function formats and stores a series of characters and values in the CStringT. Each optional argument (if any) is converted and output according to the corresponding format specification in pszFormat or from the string resource identified by nFormatID.

Just wanted to write this here in case anyone faced the same problem..
Still enjoying the MFC till now..
Meet u in another problem I face with programming ;)

Sunday, March 12, 2006

Print preview in C#

while I was playing a while with the print preview function that we took in the programming.. I faced a problem in making it "Multi" page... I tried everything... but I failed... so... I googled for a solution for that... & here is what I got from www.codeproject.com

The person who wrote that article made a class called "MultipadPrintDocument " (as his application was called Multipad)

Here is some explanation as mentioned by him for how the print preview works...

MultipadPrintDocument implements the virtual methods OnBeginPrint() and OnPrintPage(). OnBeginPrint() sets the pointer to the current character (_offset) to 0 and the current page number to 1.
OnPrintPage() has one parameter of type PrintPageEventArgs. When the system calls OnPrintPage(), we have to typeset the page using the Graphics object in the PrintPageEventArgs parameter. We typeset the page by printing lines of text until the page is full or until we reach the end of the text. The PrintPageEventArgs parameter has a property MarginBounds which contains the page size. Unfortunately, the dimensions are expressed in hundredths of an inch.
In .NET, there is no GraphicsUnit which represents a hundredth of an inch. Because we're going to measure strings in GraphicsUnit.Document (1/300th of an inch), we convert the page dimensions by multiplying them with 3. Now we're ready to start printing the lines of the text.

First, we create a StringBuilder which will hold the text of a single line. We also create a GenericTypographic StringFormat object. It's very important to use GenericTypographic because otherwise, MeasureString() and DrawString() wouldn't behave as expected. We also set the tab stops: if a line of text contains tabs, the text will be formatted correctly (the tabs will not be replaced with spaces, they will act as real tabs). Finally, we set the PageUnit property of the Graphics object to GraphicsUnit.Document.

Before we start filling the page with lines, we check to see if there is enough space to print at least four lines: one line of text and three lines for the page number (two empty lines above the page number). If there isn't enough room, we simply leave the page blank. This situation should rarely occur.

Now we're ready to break up the text in lines. We read the text string one character at a time. We add the character to the line buffer (the StringBuilder object), except if the character is a NewLine or Eos (end of string). Note that NewLine is "\r\n" in Windows or "\n" in Unix, so we have to keep in mind that we don't simply skip one character but Environment.NewLine.Length characters (yes, we strive to perfection). If the character is a space or a tab, we save this position because when the line is full, we don't want to break the line in the middle of a word, no, we will print the line up to the last tab or space. For example, if we have the line "The quick brown ... lazy dog." and the line overflows at the 'd' of "dog", we will begin the next line with "dog" instead of "og". If the last character is a space or tab, we continue to add these characters. This way, the next line will never start with white space. If the line overflows or we encounter a NewLine or Eos, we print the text in the line buffer. Then we increment the y position of the next line and empty the line buffer. If there's still room for a new line of text and we still have text to print, we continue the loop; if not, we exit the loop, print the page number at the bottom of the page, increment the page number and set the property HasMorePages of the PrintPageEventArgs parameter to true if there's still text to print, otherwise we set it to false.

Here I am... modifying my code.. still I have some mistakes in the final view, but really my eyes are in their worst state now.. :S (Note: I lost my glasses which makes everything worse)
so.. I will go take a rest now & complete my code later..
sure I will tell u in case i discovered sth new...

Thursday, March 09, 2006

Way to Game Programming...

- A team in my college is starting a game programming project... I'm one of the members in that team.. we are starting ISA in the coming period.. that's y I'm reading about OpenGL..

What is OpenGL? (for those who don't know)
OpenGL (Open Graphics Library) is a specification defining a cross-language cross-platform API for writing applications that produce 3D computer graphics (and 2D computer graphics as well). The interface consists of about 250 different function calls which can be used to draw complex three-dimensional scenes from simple primitives. It is very popular in the video games industry where it competes with Direct3D (on Microsoft Windows)

OpenGL is a method for rendering 3d images. GL stands for Graphics Language. OpenGL is the "open source" version of GL. id software is a huge proponent of OpenGL because it is platform-independant, unlike DirectX which is Windows-specific.

Why OpenGL?
-Device independence
-Simple, easy to learn
-Powerful, flexible feature set
-Cross-platform portability
-Established: many tools and resources already available
-Performance(varies with hardware...)

To be Continued...

Saturday, March 04, 2006

Some nice statistics..

In conclusion, if we look at the data available to us, especially as presented in the final, normalized chart above, we can see that there are broad patterns in language usage. Beyond the overall ranking, it is also possible to see whether a language is more used (jobs) or promoted (ads), and also whether it is used for open source projects, where presumably the participants have chosen a language because they feel it is truly the best choice, rather than dictated by management or commercial needs. We feel this is an important sector to keep an eye on, because it's where a lot of interesting things are happening, and because software really is a field in constant evolution, where today's niche player may become tomorrow's giant. These results should also be taken with a grain of salt, because it's obvious that our calculations are based on data that is not extremely accurate, nor detailed. That said, I stand by them, because I think they do correspond to what I see and read in my field.