Wednesday, September 28, 2011

Correct handling of WM_NCPAINT message in C/C++

Handling WM_NCPAINT ourselves than passing it to the default window message handler (Default() in MFC and DefWindowProc() in non-MFC application) is to enable us to paint the non-client areas of our window ourselves.

I have done a lot of googling on this matter but the results hadn’t been very helpful to me. But with a series of experimentation and trial-and-errors, I finally got this problem solved by myself.

Handling the message in MFC way

BEGIN_MESSAGE_MAP(YourClass, BaseClass)
    ON_WM_NCACTIVATE()
    ON_WM_ACTIVATE()
END_MESSAGE_MAP(YourClass)

static BOOL bActive;

BOOL YourClass::OnNcActivate(BOOL bActive)
{
    return FALSE; // always return false to enable us to paint
                  // the non-client areas of our window
}

void YourClass::OnActivate(UINT nState, CWnd* pWndOwner, BOOL bMinimized)
{
    bActive = !bMinimized;
    PaintNonClientArea();
}

void YourClass::PaintNonClientArea()
{
    if( bActive )
    {
       // do the active painting code here
       ...
       ...
    }
    else
    {
       // do the inactive painting code here
       ...
       ...
    }   
}

Handling the message in non-MFC way

LRESULT CALLBACK MyWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch( uMsg )
    {
        case WM_NCACTIVATE:
            break;
        case WM_ACTIVATE:
            bActive = wParam!=WA_INACTIVE;
            PaintNonClientArea();
            break;
        default:
            return DefWindowProc(hWnd, uMsg, wParam, lParam);
    }   
    return 0;
}

Be responsible in our FB status updating

Facebook is the social network of these days. It has a lot of fun to offer. One of the most used is status updating.

Updating our status let’s other people know what is in our mind. And, together with other features like uploading photos/videos, tells the world how active we are in facebook.

In our status update, we can say just anything we want to say—and no one has the authority to tell us what shouldn’t we (except, of course, to the kind of language, e. g. foul language, which is automatically filtered by FB). Just remember, we are accountable to whatever we say.

Posting a status update, as we all know it, goes to your wall, to your friends’ wall and to your friends’ friends’ walls—the world eventually sees what you post. So if you wanna say something, you have to consider some things. Well, if you post a status that only you can see, considerations do not matter at all.

If you post a status just about what happened in your morning, or if your dog had a hard time peeing, you have only to think why are you posting it. For some reference, look here.

However, if giving information is what you are after in updating your status, there is only one rule you have to adhere to: verify your source!

Being informative in our status updates is good. But the question is: where did you get that information? If you get it first hand (either by yourself or from any reliable source), it’s safe to post it. But if you just saw it from a page in the net, from your e-mail from anonymous senders or senders you haven’t seen before, or just from any source, you should have a second thought.

Information can draw varied reactions: curiosity, excitement, delight, etc. Not least of ’em all is—panic.

I have personally seen lots of information appearing in my wall from other FB friend’s status update: about hackers sneaking into facebook, about a link which is a virus, and the most recent is about this 15 year old girl whose name is Amy Bruke.




It does not really matter to me that they posted it. But what annoys me is that they posted it obviously without checking the veracity of their information. Aggravating my annoyance is the post when it says at the end to make it your status. And someone clicking the like button on that post really makes me sick.

One last word, again, it is our right to post what’s that in our mind. But be responsible in posting.

This site might be an insight.