was wonder how to print a string with a int variable in WinAPI

can't make it work with drawtext or textout :(

Page 1 of 1

6 Replies - 1652 Views - Last Post: 04 November 2008 - 01:22 PM Rate Topic: -----

#1 Pat234  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 18
  • Joined: 02-November 08

was wonder how to print a string with a int variable in WinAPI

Posted 03 November 2008 - 10:06 AM

whats the equivilance of:
cout << "the screen size is: " << x;
or
printf("the screen size is: %d", x);
in winapi

is there a way to print the ints like that in winapi?
i can't find a way to do that with textout or drawtext.
Is This A Good Question/Topic? 0
  • +

Replies To: was wonder how to print a string with a int variable in WinAPI

#2 Hyper  Icon User is offline

  • Banned

Reputation: 108
  • View blog
  • Posts: 2,129
  • Joined: 15-October 08

Re: was wonder how to print a string with a int variable in WinAPI

Posted 03 November 2008 - 04:57 PM

http://msdn.microsof...019(VS.85).aspx

From the looks of it, you should be able to put an integer value in the string itself and have TextOut just output it all.
Was This Post Helpful? 1
  • +
  • -

#3 Pat234  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 18
  • Joined: 02-November 08

Re: was wonder how to print a string with a int variable in WinAPI

Posted 03 November 2008 - 07:42 PM

after reading a few chapters in Charles Petzold Book
i found:
int iA =12, iB = 7;
int iLength;
TCHAR szBuffer[40];

iLength = wsprintf(szBuffer, "The sum of %i and %i is %i", iA, iB, iA + iB);
TextOut(hdc,x, y, szBuffer, iLength);


and thanks Hyper, i didn't understand how wsprintf works at first but your explanation of wsprintf helped me understand it

This post has been edited by Pat234: 03 November 2008 - 07:43 PM

Was This Post Helpful? 0
  • +
  • -

#4 Hyper  Icon User is offline

  • Banned

Reputation: 108
  • View blog
  • Posts: 2,129
  • Joined: 15-October 08

Re: was wonder how to print a string with a int variable in WinAPI

Posted 03 November 2008 - 07:54 PM

You're welcome, very much!

Thank you for using the "Thanks this post helped!" button.

Charles Petzold Book? The "Programming Windows 5th Edition?"
Was This Post Helpful? 0
  • +
  • -

#5 Pat234  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 18
  • Joined: 02-November 08

Re: was wonder how to print a string with a int variable in WinAPI

Posted 03 November 2008 - 08:39 PM

View PostHyper, on 3 Nov, 2008 - 06:54 PM, said:

Charles Petzold Book? The "Programming Windows 5th Edition?"

Yeah, that same exact book. Glad i bought it with its 1,500 pages worth of info lol
(link: http://www.amazon.co...5...F8&s=books)
Was This Post Helpful? 0
  • +
  • -

#6 codesrock  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 22
  • Joined: 03-November 08

Re: was wonder how to print a string with a int variable in WinAPI

Posted 04 November 2008 - 07:31 AM

is there any more WinAPI to print like this..??
Was This Post Helpful? 0
  • +
  • -

#7 Hyper  Icon User is offline

  • Banned

Reputation: 108
  • View blog
  • Posts: 2,129
  • Joined: 15-October 08

Re: was wonder how to print a string with a int variable in WinAPI

Posted 04 November 2008 - 01:22 PM

View Postcodesrock, on 4 Nov, 2008 - 06:31 AM, said:

is there any more WinAPI to print like this..??


Yes, there is:
- TextOut: http://msdn.microsof...019(VS.85).aspx
and
- DrawText: http://msdn.microsof...909(VS.85).aspx

Welcome, hope it helps.

EDIT: I'm glad that *exact book* has helped you, Pat234, that's quite good to know. :)

This post has been edited by Hyper: 04 November 2008 - 01:23 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1