Doing math with DisplayWindowText in MFC

This is a discussion on Doing math with DisplayWindowText in MFC within the C++ Programming forums, part of the General Programming Boards category; Ive been trying to figure this out for quite a while. What i am doing is using the GetWindowText to ...

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    7

    Doing math with DisplayWindowText in MFC

    Ive been trying to figure this out for quite a while. What i am doing is using the GetWindowText to get a value take it out do a math function and put it back in the problem I see is that when i take it out and convert it into a Int so i can do math functions on it i cant convert it into what DisplayWindowText uses because the int sizes of them are different.
    Any ideas are appericiated.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,546
    Well if it were done with C strings, it would look like

    Code:
    char numstr[10] = "10";
    int num;
    sscanf( numstr, "%d", &num );
    num *= 2;
    sprintf( numstr, "%d", num );
    Pass the result to SetWindowText perhaps?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    7,318
    What is DisplayWindowText? Do you mean SetWindowText ?

  4. #4
    Registered User
    Join Date
    Nov 2006
    Posts
    7
    Quote Originally Posted by Daved
    What is DisplayWindowText? Do you mean SetWindowText ?
    ...yea....i havent coded in a month or so now because of this

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    7,318
    >> I see is that when i take it out and convert it into a Int so i can do math functions on it i cant convert it into what DisplayWindowText uses because the int sizes of them are different.

    Can you show what you tried? Are you just referring to converting the int to a string to pass to SetWindowText?

  6. #6
    Registered User
    Join Date
    Nov 2006
    Posts
    7
    Quote Originally Posted by Daved
    >> I see is that when i take it out and convert it into a Int so i can do math functions on it i cant convert it into what DisplayWindowText uses because the int sizes of them are different.

    Can you show what you tried? Are you just referring to converting the int to a string to pass to SetWindowText?
    yea pretty much i just need the int to go back into a string form and be displayed in SetWindowText.

  7. #7
    Registered User
    Join Date
    Jan 2005
    Posts
    7,318
    Can you show what you tried that is not working? Did you try Salem's suggestion?

  8. #8
    Registered User
    Join Date
    Nov 2006
    Posts
    7
    When I tryed Salem's method I got the following error,

    error C2664: 'sprintf' : cannot convert parameter 1 from 'CString' to 'char *'

  9. #9
    Registered User
    Join Date
    Jan 2005
    Posts
    7,318
    That means you are using CStrings. To convert an int to a CString, use the CString's Format method. For example:
    Code:
    int i = 19;
    CString str;
    str.Format("%d", i);
    SetWindowText(str);

  10. #10
    Registered User
    Join Date
    Nov 2006
    Posts
    7
    It finally works! Thanks for all your help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to use operator+() in this code?
    By barlas in forum C++ Programming
    Replies: 10
    Last Post: 07-09-2005, 07:22 PM
  2. WIndows programming?
    By hostensteffa in forum Windows Programming
    Replies: 7
    Last Post: 06-07-2002, 08:52 PM
  3. Release MFC Programs & Dynamic MFC DLL :: MFC
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 05-18-2002, 06:42 PM
  4. Beginning MFC (Prosise) Part III - Now What? :: C++
    By kuphryn in forum C++ Programming
    Replies: 5
    Last Post: 03-03-2002, 05:58 PM
  5. MFC is Challenging :: C++
    By kuphryn in forum C++ Programming
    Replies: 8
    Last Post: 02-05-2002, 12:33 AM

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