Get one CHeaderCtrl object once and use that during the loop (performance),
and also check that the object is valid before using it

Based on TortoiseSVN revision 24438

Signed-off-by: Sup Yut Sum <ch3cooli@gmail.com>
Should use _countof() instead of sizeof()

Signed-off-by: Sup Yut Sum <ch3cooli@gmail.com>