Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Outputting the infinity symbol to an Edit Box in MSVC++ 1.52

Posted on 1998-02-24
12
Medium Priority
?
746 Views
Last Modified: 2008-02-01
I am doing an application using MSVC++1.52 because it needs to run on Win3.1.

I want to output the infinity symbol to an edit box so the user sees this symbol as the default value (the user can change this to any number) when the screen comes up.

I need 'code' to do it.  

The edit box (m_LoopCount) is initialized as follows:

      m_LoopCount.LimitText(5);
      memset(Line, '\0', 5);      

                     // INSERT THE INFINITY SYMBOL INTO THE BOX HERE

      m_LoopCount.SetSel(0, 5, FALSE);
      m_LoopCount.ReplaceSel(Line);                              
      free(Line);


I assume I need to get the device context and then insert the infinity symbol using the Symbol character set, but I can't remember how.

Again, I would like the code segment to do this (the code that would be inserted in the space indicated in the code snippet above)

Thanks!  (I only have 50 points to give, sooo.......)
0
Comment
Question by:kovach
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
12 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 1182767
If you want the infinity symbol to be in the edit box, that is as part of the text, in the edit box, then you don't want to use a device context to paint in an infinity symbol.  You want to use SetWindowText() to set the text to a string that contains the infinity synbol.  The probablem is knowing what character to use to get the infinity symbol.

If you use an RTF edit box, you can set the font to the symbol font and that should make it easier.
0
 

Author Comment

by:kovach
ID: 1182768
I know you can use SetWindowText, but TextOut, as I show below works fine also.

The question is 'how' do I insert the actual 'infinity' symbol into the edit box - e.g., how to I specify that character and get it to show up since it is not a standard character, and even though I can set the font to 'symbol' as I did,  I do not know how to specify that character to go to the screen


      // Put the infinity symbol in the loop count slot
      // First change the font
      HFONT hfont, hfontOld;
      int MapModePrevious, iPtSize = 12;
      PSTR pszFace = "Symbol";

      hfont = CreateFont(-iPtSize * 20, 0, 0, 0, 0, /* specify pt size    */
          0, 0, 0, SYMBOL_CHARSET, 0, 0, 0, 0, pszFace);         /* and face name only */
      
      hfontOld = SelectObject(hdc, hfont);        
      
CWnd *pWnd ;
pWnd = GetDlgItem(IDC_LOOP_COUNT); // my edit control
pWnd->SetFont(hfont);
      
      TextOut(hdc, 100, -500, "TEST", strlen("TEST"));

      DeleteObject(hfont);
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1182769
Keystroke to enter the infinity symbol is ALT+0165 (with symbol font selected) (ie hold the alt key in and type 0165 on the numeric keypad).  You should be able to use SetFont on the ewdit box to select the symbol font, and then place the character in the text box as text (with SetWindowText or whatever).

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:kovach
ID: 1182770
I know the Keystroke to enter the infinity symbol is ALT+0165.  It states that in the Help file in Windows95

I also showed in my example code that I already had used SetFont on the edit box to select the symbol font

The question I am asking is HOW to put that character into the box

Again, the code I used is:

// Put the infinity symbol in the loop count slot
// First change the font
CFont *font = NULL, *fontOld = NULL;
int MapModePrevious, iPtSize = 12;
PSTR pszFace = "Symbol";

font = new CFont();
font->CreateFont(-iPtSize * 20, 0, 0, 0, 0, /* specify pt size */
0, 0, 0, SYMBOL_CHARSET, 0, 0, 0, 0, pszFace); /* and face name only */


CWnd *pWnd = GetDlgItem(IDC_LOOP_COUNT); // my edit control
fontOld = pWnd->GetFont();
pWnd->SetFont(font);

pWnd->SetWindowText(LPSTR((char)0165));

delete(font);


What this puts in the box is a huge flashing cursor bar and no character


0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1182771
Don't do this...

pWnd->SetWindowText(LPSTR((char)0165));

you are trying to interpret a char as a string pointer

Do this...

pWnd->SetWindowText("¥"); where ¥ is where you type ALT+0165.
 


0
 

Author Comment

by:kovach
ID: 1182772
But how do I get that character (e ALT+0165) in?  You can't just type that sequence into the code line -

I can  (which doesn't work) -

pWnd->SetWindowText(LPSTR((char)0165));

But, I cannot just type "ALT0165" as in the editor, as soon as you hit alt something, it changes the MSVC++ editor window focus

What are you trying to say with your comment?  Can you elaborate and specify 'exactly' how to type the line of code to place this character into the  edit box?  (e.g., edir the pWnd... line above and insert the text to set the window text to that character

Sorry I'm being dense, but I can't get this to work

Thanks
Peter
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1182773
Yes you can just type it in ... you just type it in by typing ALT+0165 between the quotes.
ie you move the cursor between the two double-quotes and press ALT+0165 and then an arrow key (or any other key).  It will probably appear in your code as a 'Yen' sign, but will be the correct character when displayed with the symbol font.

Alternatively you can write

#define INFINITY "\245"  // 245 is octal for 165
pWnd->SetWindowText(INFINITY);

or even

CString Infinity ((char)165);
pWnd->SetWindowText(Infinity);

There are numerous ways...

However, "pWnd->SetWindowText(LPSTR((char)0165));" is not one of them .. and is just plain wrong (you cannot just cast a char to a string).


0
 

Author Comment

by:kovach
ID: 1182774
None of the suggestions work.

1)

#define INFINITY "\245"  // 245 is octal for 165
pWnd->SetWindowText(INFINITY);

gives:

Command line warning D4004 :/G3 only available in optimizing compiler; assuming /G2
d:\newdemo2\newtype.cpp(2742) : error C2018: unknown character '0xa0'
d:\newdemo2\newtype.cpp(2742) : error C2018: unknown character '0xa0'


because of course the system can't interpret the character since that set isn't loaded nor does it know about the extended character set

//CString Infinity ((char)165);
//pWnd->SetWindowText(Infinity);
pWnd->SetWindowText("ALT+0165");


2)
CString Infinity ((char)165);
pWnd->SetWindowText(Infinity);

puts the yen sign in, so I assume the source 'would' work if it was properly setting the font.  The font seems to 'not' be correct though, sooo...

Please look at this again when you have time and see what is wrong and why the font is not correct.  The code is:

-----
                                           
// Put the infinity symbol in the loop count slot
// First change the font
CFont *font = NULL, *fontOld = NULL;
int MapModePrevious, iPtSize = 12;
PSTR pszFace = "Symbol";

font = new CFont();
font->CreateFont(-iPtSize * 20, 0, 0, 0, 0, /* specify pt size */
0, 0, 0, SYMBOL_CHARSET, 0, 0, 0, 0, pszFace); /* and face name only */


CWnd *pWnd = GetDlgItem(IDC_LOOP_COUNT); // my edit control
fontOld = pWnd->GetFont();
pWnd->SetFont(font);

CString Infinity ((char)165);
pWnd->SetWindowText(Infinity);

delete(font);                              
-----

3) pWnd->SetWindowText("ALT+0165");

just sticks the characters 0165 into the text box


Thanks again.
0
 
LVL 10

Accepted Solution

by:
RONSLOW earned 150 total points
ID: 1182775
Dear oh dear ...

1) You must have typed SOMETHING wrong or included a non-printable character.  Don't cut and paste from the web page as you often end up with garbage characters.

I just tried the lines

#define INFINITY "\245"  // 245 is octal for 165
pWnd->SetWindowText(INFINITY);

with VC and it compiles fine.

3) must I spell it out...
press '"' key
press and hold the 'ALT' key
on the numeric keypad, type '0' '1' '6' '5'
release the 'Alt' key
press the '"' key

2) try putting some other string in the SetWindowText - does it come out in the symbol font?  If not, then we need to work on the setting font problem.

The problem could be that you are deleting the font after setting it into the window.  Try making it stay around by making it static (or you could make it a member of your class)

Try this...

// Put the infinity symbol in the loop count slot
// First change the font
static CFont font;
static BOOL bNeedToCreateFont = true;
int MapModePrevious, iPtSize = 12;
PSTR pszFace = "Symbol";

if (bNeedToCreateFont) {
    font.CreateFont(-iPtSize * 20, 0, 0, 0, 0, /* specify pt size */
    0, 0, 0, SYMBOL_CHARSET, 0, 0, 0, 0, pszFace); /* and face name only */
    bNeedToCreateFont = false;
}

CWnd *pWnd = GetDlgItem(IDC_LOOP_COUNT); // my edit control
pWnd->SetFont(&font);

CString Infinity ((char)165);
pWnd->SetWindowText(Infinity);


0
 

Author Comment

by:kovach
ID: 1182776
Not sarcasm .. more like frustration .. I have answered athe question a number of times but you did not appear to be doing what I suggested so it DID appear that I had to spell it out.

Have you tried what I spelled out ?  Are you SURE you typed on the numeric keypad?  Did you HOLD IN the alt key while you pressed the 0165?  What about the num-lock key - is it on?

If it doesn't work, then there is something wrong with your computer system and you should get it looked at - maybe your keyboard is malfunctioning.  If you are doing it right it should work.

BTW: You can always use the character map accessory to select the character and paste it into your program.

Of course, it is your perogative to award points - at least we've solved your problem now.


0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1182777
You may not yet understand, but 'of course' you can use the character map accessory and paste the character in.  The PROBLEM, as I tried to state over and over, was that that is NOT the problem - the key was getting the font to 'stay' so the character would show up as the SYMBOL font character and NOT the Arial font character in that 'slot' - e.g., a COMPLETELY WRONG symbol

As I assume you determined if you re-read the message, I did give you the points as soon as the CORRECT answer was given.

Ego is bad - not all answers are correct


0
 

Author Comment

by:kovach
ID: 1182778
GRRR!!!!

You did NOT state "over and over" that "the key was getting the font to 'stay' so the character would show up as the SYMBOL font character" - you changed your mind about being able to set the font and said it ONCE - and I immediately told you how to fix it.

Yes - I know you allocated points - but made a point of saying you only rated a 'good' because of sarcasm.  Now you are implying that I was ignoring you and addressing the wrong problem?  Really !!!

I HAVE re-read (perhaps you should also) what went on and I addressed your problem several times and got rejected several times for correct answers.  To refresh your memory, here is a summary...

You asked "even though I can set the font to 'symbol' as I did,  I do not know how to specify that character to go to the screen"

In my answer, I tell you how to type it in

You reject and say "I know the Keystroke to enter the infinity symbol is ALT+0165.  It states that in the Help file in Windows95" and then you show source where you try to do it with 'LPSTR((char)0165)' - which is wrong in a number of ways

So I tell you again how to type it in and explain how your code is wrong.

You reject again and reply "But how do I get that character (e ALT+0165) in?  You can't just type that sequence into the code line" and then ask "Can you elaborate and specify 'exactly' how to type the line of code to place this character into the edit box?"

I tell you (again) that you CAN just type it in and elaborate on how to do so, and also give you alternatives to typing it in literally.

You reject yet again (I'm getting a bit frustrated now) and tell me that:
1) the code doesn't compile [it does - it was either a typo or copy/paste error on your part]
2) the wrong character appears [because you haven't set the font correctly - you earlier said you were able to]
3) that "pWnd->SetWindowText("ALT+0165"); just sticks the characters 0165 into the text box" - which seem to imply that you are typing in the keys 'A''L''T''+''0''1''6''5' or something similar which is not what I advised you to do.

So I address those issues and spell out in even more detail how to type it in and you complain !!

Now you are saying that you never wanted to know how to type in the character, just how to set the font?  Please - don't try to change the history .. its all there in the log.

Yes, ego is bad - but my answers WERE and still ARE correct.  ALL of them - even the ones you rejected.

And, as I said before, if you are still unable to get the inifinity symbol then either you are not doing as I advised, or your hardware is faulty.  But please don't tell me that any part of my answers were incorrect or not relevant !!

0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question