Display Int as Hex in an Edit box

This is a discussion on Display Int as Hex in an Edit box within the C++ Programming forums, part of the General Programming Boards category; This screen shot shows both the code and actual application of my program. What I am trying to do is ...

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    1

    Display Int as Hex in an Edit box

    This screen shot shows both the code and actual application of my program.
    What I am trying to do is choose a register type, enter a range, and have the corresponding address displayed in hex, but as shown, the address is displayed in decimal.
    What is the best way to display in hex?
    The code to the upper right of the dialog box - AssembleMessage() is what I am using to write to the Address Edit box.
    Any comments appreciated.
    Thank you.
    Attached Images Attached Images  

  2. #2
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,612
    Ah, well, that's easy.
    Use fprintf or similiar and use %X as argument, then pass an int. It will converted to hex.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    That would be sprintf() I believe. While it was my first thought as well, it's a very C-based approach. I think C++ has a different method to do it, but both should work just as well.

  4. #4
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,612
    Ah yes, typo >_<
    At first, I was thinking of CString, but obviously this isn't MFC...
    There there are string streams... can they do it? I don't know. I don't mess around with them very much. In fact, I haven't used them even once.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    It uses the MFC logo in the dialog.
    CString has a Format function.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  6. #6
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,612
    OK, I must have been blind or something >_<
    This is certainly an old version of MFC. In MFC you don't really use SetDlgItemX very much... you set member variables and use them.
    Anyhow

    Code:
    CString mystr;
    mystr.Format("&#37;X", myint);
    m_mytextbox.SetWindowText(mystr);
    // Or
    m_mytextbox = mystr;
    UpdateData(FALSE);
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #7
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Just because DDX isn't used doesn't mean it's and old MFC version. It's just not a typical MFC app. (DDX is very old.)
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  8. #8
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,612
    I was mentioning that it was on version due to the icon.
    Also, consider using manifests to include Windows XP's look and feel if you use Windows XP (no reason not to).
    Last edited by Elysia; 12-10-2007 at 10:31 AM.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #9
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Oh. Well, the last time I used MFC was in VS.Net 2002, and IIRC it still used the icon there. I know that it used it in VC++6.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  10. #10
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,612
    AFAIK, the new one was introduced in .NET 2002.
    I've been using MFC for a long time... and definitely in .NET 2002 and it was the new one. Or if it wasn't, at least it was in 2003.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can some one please tell me the cause of the error ?
    By broli86 in forum C Programming
    Replies: 8
    Last Post: 06-26-2008, 08:36 PM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. Replies: 3
    Last Post: 05-13-2007, 08:55 AM
  4. Need help understanding info in a header file
    By hicpics in forum C Programming
    Replies: 8
    Last Post: 12-02-2005, 11:36 AM
  5. New Theme
    By XSquared in forum A Brief History of Cprogramming.com
    Replies: 160
    Last Post: 04-01-2004, 07:00 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21