Archive for June, 2004

When you have a dialog based app, and you don’t want it to close, what most people do is to override the handler for the IDCANCEL button and comment out the call to CDialog::OnCancel() which calls CDialog::EndDialog(...) which then calls the EndDialog API call. Now this is all fine except that the dialog won’t close if you click the top-right [x] button or if you press Alt-F4, and this can be confusing to the end-user since all windows are expected to close if you attempt one of the above. The solution is to also handle the WM_CLOSE handler and to call CDialog::OnCancel() from it as shown below :-

void CDelMe03Dlg::OnBnClickedCancel()

void CDelMe03Dlg::OnClose()

If you are wondering about this behavior, what happens is that when the default dialog box procedure gets a WM_CLOSE message, it posts a BN_CLICKED (through WM_COMMAND) message to the dialog box passing IDCANCEL as the control id. Now this means that OnBnClickedCancel (or whatever you called it) gets called and since this does not call CDialog::OnCancel, the dialog just stays there like nothing ever happened.

Read Full Post »

I still remember fighting to hold back the tears when Goran lost the 5th set to Agassi in the ‘92 Wimbledon; also remember the straight sets loss to Sampras in ‘94 and then that 5-setter in ‘98 again to Sampras. It was really awful for Goran fans, the man who possessed the most destructive and unreturnable serve in the history of tennis might finish his career as the greatest player never to win a Grand Slam. Then, in 2001 when he beat Pat Rafter of Australia, the whole world heaved a sigh – Goran had finally overcome his greatest enemy – his temperament – and managed to win 7 straight games on the grass of Wimbledon. At the end of the match he said he didn’t care if he never won another match in his life – he was happy, happy like a child who had got his candy, and so were we all, exultant fans rejoicing for Goran.

Goran was never a perfect player, but everyone feared him, from the returning greats like Agassi and Chang to the scud-servers like Becker and Sampras. In fact Sampras has often stated how Goran was one of the toughest opponents he faced due to his astonishing unpredictability. You never know if he was going to play the worst tennis he can play, or win all service games love with that unplayable serve of his. I vaguely remember the 1990 Wimbledon, or it might have been some other grass court tournament, when Goran was down love-40 and on a second serve hit an ace and then 4 more to win the game, and continued on in that vein till he had the match.

Mom always wondered why I should almost break into tears and be totally depressed for a few days whenever he lost. She used to tell me that she couldn’t even pronounce his country – Croatia. I used to tell her that I don’t know why and to be honest I didn’t. Maybe it was because I empathized fully well with Goran’s moods, maybe because I myself am a very temperamental person or so they all tell me, those who know me. 2 days ago I watched with a choking feeling in my throat, as Goran played his last match on Wimbledon and lost to Leyton Hewitt in the third round, on centre court. Everyone bid him an emotional farewell, the crowds, his opponents and the press – including the British press who adored Goran. The press loved Goran, not because of his brilliant sarcasm and humor, not because on his day he could blast off the world’s best, but because he was Goran Ivanisevic. There will never ever be another like Goran in tennis, never ever, because some people are born unique, and it was so with Goran Ivanisevic, the volatile tennis great from Split, Croatia.

Read Full Post »

I was reading Brian Johnson’s Weblog and there was a comment by Ramon de Klein where he expressed unhappiness with the addition of so many new keywords in C++/CLI. I replied to Ramon saying that there were essentially just three new keywords that might clash with existing code – nullptr, gcnew and generic.

And just to prove my point I typed in a simple for loop into a test program and used some of the contextual identifiers as variable names. It compiled of course, but what made the whole thing funny was that the VC++ syntax colorizer was not able to identify their context and showed them in blue (as keywords) and this obviously produced some curious looking color-formatted code.

My blog’s syntax colorizer (developed by Jambo Johnson) also results in the same funny looking code and I thought I’d include it here for you all to see :-)

int finally = 0;
int delegate = 6;
for(int abstract=0; abstract<10; abstract++)
    finally += abstract * delegate;

You will indentify the humor only if you’ve used VC++ for a while now and are used to the syntax colorizer, because only then will the fact that everything is in blue (keyword color) will strike you flat on your face :-D

Read Full Post »

I’ve finally got around to writing another C++/CLI article for CodeProject.

Function overriding in C++/CLI

The article covers the new function overriding features available in C++/CLI like explicit overriding, renamed overriding and multiple overriding. It also shows you how to use the sealed and abstract function-modifiers.

Read Full Post »

Recently this question came up in the Microsoft MFC Newsgroup, where someone was porting an MFC app to pure-API, and wanted to know what the PreTranslateMessage equivalent was for the pure-API application. Essentially all you need to do is to put your code just before the TranslateMessage call, as shown in the code snippet below :-

// Main message loop
while (GetMessage(&msg, NULL, 0, 0))
    if (!TranslateAccelerator(
        msg.hwnd, hAccelTable, &msg))
        //Put your PreTranslateMessage stuff here

Or if you don’t want to do that, you could do this as well, though it seems less elegant :-

    UINT message, WPARAM wParam, LPARAM lParam)
    //Put your PreTranslateMessage stuff here

    switch (message)
    case WM_COMMAND:
    case WM_PAINT:
        //... etc.

        return DefWindowProc(hWnd,
            message, wParam, lParam);
    return 0;

The basic thing to remember is that, there is no message called PreTranslateMessage in Win32. PreTranslateMessage is something the MFC developers added so that we have an option to do something before a call is made to TranslateMessage/DispatchMessage; and incidentally, some Win32 Gurus like Joe Newcomer for instance, are quite vocal about their opinion that using PreTranslateMessage is bad style.

Read Full Post »

I admit to having a gmail account of my own, just like most of you guys do. And I also admit to experiencing a substantially pleasurable mood when I did get my own gmail account. But now that I have it, I don’t really use it. At my bandwidth (or rather the lack of bandwidth), web mail is not usable for any professional or meaningful purpose. And considering that gmail does not offer an IMAP/POP interface for fetching mail, the only purpose I seem to have for my gmail account is to use it as a sort of online brief-case folder (like the one we had in Win95 before MS scrapped it).

I am also sure that most people have their own domain names and therefore their custom mail IDs, often having 200 MB to 2 GB of POP space, and for people who have their own servers on an ISP’s shared or unshared server rack, the POP limit is the free space on the hard disk partition containing the mail spool folder. So, why is it that people make such a big deal out of a gmail account? Yahoo upped their free mail space to 100 MB, and their paid Plus users have 2 GB of POP mail space now. Redif-India upped their free mailbox to 1 GB and paid users get 2 GB. But those sites don’t get the same kind of buzz that gmail does.

Here is what my friend and fellow-MVP Doctor Pavanaja had to say on gmail :-

What is so great about a gmail account? Is it the promised 1 GB mail box? Why should people be fascinated by some xyz@gmail.com account when they can have their own domain mails with POP access? I have my own domain, I can download the mails and keep them in my laptop, carry them around; read them in airports, while traveling in a flight etc. These are not possible with gmail. Every time, I have to be online to do anything with the mail.

So am I right in concluding that gmail is just a fashion statement? And a very strong one at that? Your thoughts on this are appreciated.

Read Full Post »

It was a little past 9:30 PM, and I was driving back home from the restaurant from where I had my supper, which incidentally consisted of curd-rice, two cups of coffee and a glass of pomegranate juice – yeah, yeah I know it’s a weird sort of supper to have. It was drizzling heavily enough for people to take shelter under bus-stops but not heavily enough to make driving difficult in the slightest way. For some reason, I felt like taking a longer drive home and so I just drove around the Trivandrum city main roads, and also played my Roxette CD just to bring in a bit of music. The same roads which were so clogged with traffic during day-time, that even a 1 KM stretch took about 10 minutes, 3 stops and 2 traffic lights, were mostly devoid of traffic of any kind. The darkness and the rain helped hide the dirty footpaths and open drainage gutters on the sides of the roads and all of a sudden, the typically dirty and uninspiring Trivandrum city roads became a sort of charming sensation of beauty for me.

I must have drove all over the main part of the city and covered about 20-25 KM, since I did manage to listen to 4-5 Roxette tracks in the mean time. Once in an odd while, some nasty driver’s rude high beam blinded me temporarily and left me seeing blurred light blots on my wind shield, but I only smiled sweetly back at them rather than swear at them with all my vocal might as I am usually prone to do. I really wish I had my camera with me though I am not really sure if any camera would have captured tonight’s beauty, for I feel tonight was something very special, and I am very much scared that tomorrow – I might not see things in the same lovely manner as I did tonight. I felt very warm and comfortable as I reached home finally – I am not sure how I reached home, but abruptly I found myself very near my apartment and must have subconsciously turned the right way. I’ve always been in love with my home-town, but tonight was the first time she kissed me goodnight.

Read Full Post »

C++/CLI supports managed arrays using a far more intuitive syntax than which existed in the older syntax. Here are some of the basic features of managed arrays in C++/CLI :-

  • Syntax resembles that of C++ templates
  • System::Array is abstract base type for all managed arrays
  • Allocated on the CLR heap (means they get GC’d)
  • Rank of the array need not be 1
  • Implicit conversion to and explicit conversion from System::Array
  • The rank and dimensions of an array object cannot be changed

Pseudo-template of an array type

The declaration and usage of array types in C++/CLI seems to use an imaginary template type (there is no such template of course, it’s all VC++ compiler magic)

namespace stdcli::language
    template<typename T, int rank = 1>
        ref class array : System::Array {};

Sample array usage

These samples show some code snippets that demo how to use single-dimensional and multi-dimensional arrays with C++/CLI

ref class R
    // Single dim array of ref type
    void funcsdref()
        array<String^>^ strarray =
            gcnew array<String^>(5);
        for(int i=0; i<5; i++)
            strarray[i] = String::Concat("Str ",i.ToString());
        for(int i=0; i<5; i++)

    //Single dim array of value type
    void funcsdval()
        array<int>^ strarray = gcnew array<int>(5);
        for(int i=0; i<5; i++)
            strarray[i] = i * 10;
        for(int i=0; i<5; i++)

    //Multi dim array of ref type
    void funcmdref()
        array<String^,2>^ cricketerarray =
            gcnew array<String^,2>(3,2);

        cricketerarray[0,0] = "Sachin Tendulkar";
        cricketerarray[0,1] = "India";
        cricketerarray[1,0] = "Shane Warne";
        cricketerarray[1,1] = "Australia";
        cricketerarray[2,0] = "Shoaib Akhthar";
        cricketerarray[2,1] = "Pakistan";


        for(int i=0; i<3; i++)
            for(int j=0; j<2; j++)
                Console::Write("{0} \t",cricketerarray[i,j]);

Jagged arrays

C++/CLI makes it really easy to declare and use jagged arrays. See my earlier blog entry for the syntax :-

Read Full Post »

Very often, you hear people barking at someone because the poor fellow happened to send an HTML-mail to a mailing list. Now I personally do not understand this at all. Just about every email client out there, supports viewing HTML mails, and so do all the web based mail sites. And HTML mails are specially useful when you want to put certain text in bold, some text in italics, a couple of words in red or you need a bulleted list of items. They do add a few extra KB to every mail, but even a low-bandwidth guy like me has no problems with handling an extra 5-6 KB per email I receive.

It is true that HTML mails are abused quite often these days, where people embed silly smiley images, put JavaScript and do all sorts of other really dumb things. But using that as an argument against HTML mails is like saying that no one should be allowed to drive on the roads just because some drivers happen to be dangerous. HTML mails are a lot more handy than text mails, and the formatting capability is very useful when used with responsibility and maturity. Of course, when posting to newsgroups, it’s polite to use text mails, because there are still many newsreaders that do not handle HTML mails very well. But for regular emailing, I see no reason to avoid HTML mails. In fact I absolutely use HTML mails for all my emails, and even when I reply to a text mail. If someone thinks I am a silly idiot because I use HTML mails, then they are welcome to continue thinking so. It doesn’t concern me in the least.

Read Full Post »

My new car

I got my new car yesterday – went to Cochin, a city 220 KM away from Trivandrum, took it from the showroom and drove it all the way back to Trivandrum. It’s a Toyota Corolla H2 model – Black Mica body color.

I had to pay 88% more than what the same car costs in the US :-o (I checked US prices on the web), but I am now used to paying more for everything, having lived in India for more than two decades. What tickles me no end is when people say that cost of living is lesser in India. Lesser, my foot! Everything costs 50% to 80% more than what it costs in the US/Canada. Oh well!

Anyway, I think I am gonna have fun driving around in my new car :-)

Read Full Post »

Older Posts »


Get every new post delivered to your Inbox.