Thread: Doing math with DisplayWindowText in MFC

  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 int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    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.

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    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,366
    >> 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,366
    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,366
    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, 06:58 PM
  5. MFC is Challenging :: C++
    By kuphryn in forum C++ Programming
    Replies: 8
    Last Post: 02-05-2002, 01:33 AM