Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Keyboard Input: More Evil Than Britney Spears

Status
Not open for further replies.

rmullen3

Programmer
Oct 21, 2001
5
0
0
DE
ACK! ARGH!
I was learning VC++ smoothly, quickly, and I was doing great... Then, I get to keyboard input and BAM! I'm stuck.

Here's what I do:
ClassWizard. Add Function, WM_KEYDOWN.
Edit WM_KEYDOWN's code. After the TODO,


char lsChar;
HCURSOR lhCursor;

lsChar = char(nChar);

if (lsChar == ‘A’)
{
lhCursor = AfxGetApp()->LoadStandardCursor(IDC_ARROW);
SetCursor(lhCursor);
}

Now, according to my nifty book, that SHOULD work, and to me, it looks like it should, BUT... I always get the danged "'A' : undeclared identifier" compilation error. =(

Or is this code just horribly wrong?
Everything works fine until I enter that into the KEYDOWN function.

Perhaps one of you can help, I'd greatly appreciate it!
:D



 
lsChar == ‘A’

Did you copy and paste that code? I think you're using the wrong character for your quotes. Mine looks like this:

lsChar = 'A'

I imagine you get messages like "character '0x91' unknown" as well. That's maybe French accent or something.



:) Hope that this helped! ;-)
 
What do you mean with the line:

lsChar = char(nChar);

if you want to cast to char do it like this:
lsChar = (char)nChar;

I am wondering how your code compiled at all.
(N.B. casting is a right-to-left operation for the compiler)

HTH,
s-)

Blessed is he who in the name of justice and goodwill, sheperds the weak through the valley of darkness...
 
What's wrong with lsChar = char(d);?
This is a normal C++ type conversion operator and compiles without problem.

Explicit Type Conversion Operator
C++ allows explicit type conversion using a syntax similar to the function-call syntax. A simple-type-name followed by an expression-list enclosed in parentheses constructs an object of the specified type using the specified expressions. The following example shows an explicit type conversion to type int:

int i = int( d );



:) Hope that this helped! ;-)
 
I changed it to a single equation mark (although I thought in C++ = is used to assign value while == is used in comparison), and I changed the other part to lsChar = (char)nChar;

Yet, I still receive:

C:\My Documents\Cppsp\Keyboard\KeyboardDlg.cpp(183) : error C2018: unknown character '0x91'
C:\My Documents\Cppsp\Keyboard\KeyboardDlg.cpp(183) : error C2018: unknown character '0x92'
C:\My Documents\Cppsp\Keyboard\KeyboardDlg.cpp(183) : error C2065: 'A' : undeclared identifier
Error executing cl.exe.

Keyboard.exe - 3 error(s), 0 warning(s)


:|
 
Here's my updated code:

{
// TODO: Add your message handler code here and/or call default


char lsChar;
HCURSOR lhCursor;

lsChar = (char)nChar;

if (lsChar = ‘A’)
{
lhCursor = AfxGetApp()->LoadStandardCursor(IDC_ARROW);
SetCursor(lhCursor);
}
CDialog::OnKeyDown(nChar, nRepCnt, nFlags);
}

Sorry for bein' a n00b :)
 
Not about the =
It's about the 'A'
instead of
if (lsChar = ‘A’)
it should be
if (lsChar == 'A')

Look carefully at the two quotes besides the A

---
regarding char(nChar) and (char) nChar
the former look like a constructor to me, especially when the type is a class... Anyway, the effect is the same right, a new object is created that has equivalent values as the original object.
 
Sorry, the single "=" was my typo...it's the quotes! :) Hope that this helped! ;-)
 
Yes, it works now. Thank ye's for everybody :D
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top