• Advertisement
Sign in to follow this  

HEX in Win32

This topic is 4475 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

To display numbers in DOS console in HEX mode I use ios::hex flag. What if I need to display HEX numbers in Win32 or MFC ? For Win32 I display text with TextOut function (and HDC) and for MFC I use CEdit::ReplaceSel Member.

Share this post


Link to post
Share on other sites
Advertisement
It doesn't matter weither it's win32 or with the help of MFC....
See if you can grab any ( old) book from Charles Petzold at Ms Press; he has written many win32 programming books.
Using MFC you can place a CRichEditCtrl on a CDialog or using a CView display infos with CDC::TextOut

Share this post


Link to post
Share on other sites
Just use a std::ostringstream to format the number into a string, and then pass that string to your display code:

std::string FormatAsHex(int number)
{
std::ostringstream format;
format << std::hex;
format << number;
return format.str();
}

// Someplace else
pSomeControl->SetWindowText(FormatAsHex(2348).c_str());


If you use MFC heavily in your code you can use CString::Format() as well.

Share this post


Link to post
Share on other sites
Or you could use sprintf...


char szBuffer[128];
const int iInteger = 15;

sprintf(szBuffer, "Base 10: %i\nBase 16: %x", iInteger, iInteger);



Of course I'd prefer to use the stringstream way as ApochPiQ mentioned, but this is still an alternative.

[Edited by - pizdayob on January 19, 2006 2:00:32 PM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement