Thread: Display Int as Hex in an Edit box

  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.

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    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,210
    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をこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    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,895
    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をこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    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,895
    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をこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    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 11: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,895
    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をこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    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, 12:36 PM
  5. New Theme
    By XSquared in forum A Brief History of Cprogramming.com
    Replies: 160
    Last Post: 04-01-2004, 08:00 PM