Hello guys. First of all i have to say i've been learning a lot on daniweb and appreciate all your effors.
Secondly, i'm currently learning MFC with c++ and atm I am making a program called "fast fingers", where you have to press those chars on keyboard that are dynamically shown in the static text.

I already made static text which shows random chars and it is based on progress control.
The thing i'm stuck is that I don't know how I can compare the chars that i click on keyboard and the ones that are shown on static text.
I already searched whole web and can't find it. :(
I am trying with mfc message WM_CHAR, but i'm stuck because I don't know how.
So if anyone knows how to, i'd be so happy.
Thanx guys.

In win32 it is in either LPARAM or WPARAM, I've forgotten (don't use it)--so, I'll happily google that for you so that we both learn. I'm hoping you can apply this to your MFC application.

Ok, MSDN (which you should be using as a reference) says: http://msdn.microsoft.com/en-us/library/ms646276%28v=vs.85%29.aspx

WPARAM is the character code of the key. I think it means the virtual key code for the key, not the hardware scan code (it should have specified if it was).

Does that help?

I've already tried smt like that:

void CNaloga3Dlg::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
	// TODO: Add your message handler code here and/or call default
	
	char m_check;
	m_check = getSymbols();
	if (nChar == m_check)
	{
		MessageBox(_T("Bingo"));
	}

	CDialog::OnChar(nChar, nRepCnt, nFlags);
}

getSymbols() is a function where i get random char and show it on static text.
But i just don't know how to compare that char to the one that i input on the keyboard.
Like i said i'm very noobish, so sorry if something sounds so stupid.
Thanx.

Don't be so hard on yourself.

http://msdn.microsoft.com/en-us/library/ms646307%28v=vs.85%29.aspx

if(nChar == static_cast<char>(MapVirtualKeyEx(wParam,MAPVK_VK_TO_CHAR,0)) )
{
//...
}

I don't have a solution if that isn't the problem, unfortunately. I'm sure someone can help, however.

Have you tried stepping through it with the debugger to see what "nChar" or "m_check" actually contain?

Hello. I don't quite understand what you are implying though, when i debug, it shows nothing, like i don't press any keys or whatsoever.
However, i'm pretty sure m_check contains the symbol that is generated through my function and is shown in the static text.
Thanx, I really hope someone can help.

Hello, thanx for your help.
However, i added PreTranslateMessage and deleted OnChar, but it doesnt do much though.

This my function that creates random characters and add them dynamically to static text.

char CNaloga3Dlg::getSymbols(void)
{
	char c;
	srand( (unsigned int) time(NULL));
	c = (rand() % 26) + 'a';
	return c;
}

BOOL CNaloga3Dlg::PreTranslateMessage(MSG* pMsg)
{
	char m_check = getSymbols();
	if (pMsg->message == WM_CHAR)
	{
 		if (pMsg->wParam == m_check)
			MessageBox(_T("Bingo"));
	}

	return CDialog::PreTranslateMessage(pMsg);
}

But when i try clicking it doesnt show any MessageBox on window. Even when I debug,
I get some weird chars @ m_check.

This is in WM_OnTimer, where i put my chars into static text.

void CNaloga3Dlg::OnTimer(UINT_PTR nIDEvent)
{
	// TODO: Add your message handler code here and/or call default

	CStatic* pStaticTest1 = (CStatic*) GetDlgItem(IDC_ZNAKI);
	CString stevilo;
	stevilo.Format(_T("%c"), getSymbols());

	if (check1 == 1)
	{
		if (m_progress.GetPos() != 100)
		{
			m_progress.StepIt();
		}
		else
		{	
			pStaticTest1->SetWindowText(stevilo);
			m_progress.SetPos(0);
		}
	}

	CDialog::OnTimer(nIDEvent);
}

So if any of you knows how to help me, i'd very much appreciate it.
Thanx, annnDi.

[IMG=http://img69.imageshack.us/img69/2964/naloga3.jpg][/IMG]

Uploaded with ImageShack.us
In the picture above is the dialog.

Gahhh....I'm sorry, I don't have any idea, but I still want to lend you some advice though: Don't stick with Visual Basic/Studio from Microsoft for too long....That is NOT the best thing to officially and respectively teach programmers how to be good programmers. The whole interface of that program is essentially made easier/different than more of a raw-style programming mechanism, such as C++ with Windows API.

Hope I wasn't too harsh.....

> Hope I wasn't too harsh.....
Harsh? No, not really - just clueless.

Please stop interjecting useless comments into other people's threads. This "advice" you seem compelled to give on a topic that you don't understand is not helpful.

commented: Youda man +6

> Hope I wasn't too harsh.....
Harsh? No, not really - just clueless.

Please stop interjecting useless comments into other people's threads. This "advice" you seem compelled to give on a topic that you don't understand is not helpful.

You're being too strict....

It's no problem, I was just asking for help.

It's no problem, I was just asking for help.

No, I meant the other poster before me was, not you.

@AnnnDi: there are a few small problems with your program:
First, the srand() function only needs to be called once. So put one call to this function somewhere at the start of the program (either at the start of WinMain or at the OnCreate of your main form or something like that), and don't put another call to it anywhere else, it is not necessary.

Second, each time you call getSymbols(), it will generate a new random character. So you cannot call it once to print a random character to the Dialog and then call it again to do the comparison with the keystroke. You need to call it once, store the character that it gives, then put that character in your Dialog, and then reuse that same character in the comparison of the keystroke (you would probably have to make it a "global" variable... well maybe not global, but somewhere it can be reached by both the print function and the comparison function).

I think that should fix it, because I think you are doing everything correctly.

PS. Please ignore spoonlicker, _it_ is a troll.

Hello thanx for help.
By srand function you mean my getSymbols() function or just srand line, because I did put my srand((unsigned int) time(NULL)) line in OnInitDialog.
Secondly, do you have any idea how I store make getSymbols so when i call it in OnTimer and PreTranslateMessage it produces the same char?
My PreTranslateMessage function only works on the start of the program, when I don't "start" the game by pushing start button to launch static text to dynamically show random chars.

BOOL CNaloga3Dlg::PreTranslateMessage(MSG* pMsg)
{
	if (pMsg->message == WM_CHAR)
	{
		CWnd* pWnd3 = GetDlgItem(IDC_ZNAKI);
		CString str3;
		pWnd3->GetWindowText(str3);  // Here is where I get caption(random char that is shown in the caption) of the static text and compare it to the pressed key, but it doesnt do anything when i launch the game.

		if (pMsg->wParam == str3)
		MessageBox(_T("Bingo"));
	}

	return CDialog::PreTranslateMessage(pMsg);
}

I hope you understand my problem, thanx a lot for your effort.
Thanx for help.

Update: I fixed my problem, i had to put in my OnBnClickedButton2 function this->SetFocus and fix if (pMsg->wParam == str3) into if (pMsg->wParam == str3[0]).
If i'll have any question i hope I can ask.
Thank you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.