Click here to Skip to main content
15,901,122 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Important Points for KT Pin
LittleYellowBird10-Jun-10 5:22
LittleYellowBird10-Jun-10 5:22 
GeneralRe: Important Points for KT Pin
Cedric Moonen10-Jun-10 8:11
Cedric Moonen10-Jun-10 8:11 
GeneralRe: Important Points for KT Pin
Richard MacCutchan10-Jun-10 5:43
mveRichard MacCutchan10-Jun-10 5:43 
GeneralRe: Important Points for KT Pin
Niklas L11-Jun-10 2:09
Niklas L11-Jun-10 2:09 
GeneralRe: Important Points for KT Pin
Richard MacCutchan11-Jun-10 2:44
mveRichard MacCutchan11-Jun-10 2:44 
GeneralRe: Important Points for KT Pin
Tim Craig10-Jun-10 13:48
Tim Craig10-Jun-10 13:48 
GeneralRe: Important Points for KT Pin
CPallini10-Jun-10 3:00
mveCPallini10-Jun-10 3:00 
QuestionProblem in redrawing Rectangle on "Up Arrow Key Down" in MFC Dialog Based application Pin
Arindam Tewary9-Jun-10 23:55
professionalArindam Tewary9-Jun-10 23:55 
Hi,

I am writing a small program in MFC using Dialog based project.
What I want to achive is : On pressing "Up Arrow Key" I want to redraw a rectangle which was already drawn.( want to draw the rectangle in other point).

Can you please help me what I am doing wrong here.

I am setting a variable "iKeyPressed" to "1" "PreTranslateMessage" method when Up Key is pressed.

BOOL CKeyDownTestDlg::PreTranslateMessage(MSG* pMsg)
{
	// TODO: Add your specialized code here and/or call the base class
    iKeyPressed = 0;
	if (pMsg->message == WM_KEYDOWN)
	{
		if(pMsg->wParam==VK_UP)
		{
			iKeyPressed = 1;
			CKeyDownTestDlg::OnPaint();
		 //::AfxMessageBox(_T("Inside"));              
		}
	}
	return CDialog::PreTranslateMessage(pMsg);
}


Then in OnPaint() method I am checking the value of "iKeyPressed". If that is "1", then I intend to "Redraw" (erasing out the previously drawn rectangle)rectangle which was drawn earlier.

void CKeyDownTestDlg::OnPaint()
{
	if (IsIconic())
	{
		//These code is not executed.
	}
	else
	{
		char c[10];
		
		CPaintDC dc(this); // device context for painting
		CString MFCString; 
		MFCString = c;
		if(iKeyPressed==0)
		{
			dc.Rectangle(5,5,100,20);
			AfxMessageBox(_T("iKeyPressed = 0"));     
			/*dc.SelectObject(old_brush);*/
		}

		if(iKeyPressed==1)
		{
			CPaintDC dc(this); // device context for painting
			AfxMessageBox(_T("iKeyPressed = 1"));      
			dc.Rectangle(5,5,20,100);			
		}
		CDialog::OnPaint();
	}
}

Interestingly, while executing I could see Message "iKeyPressed = 1".

Any help is appreciated.
Thanks,
Arindam D Tewary

AnswerRe: Problem in redrawing Rectangle on "Up Arrow Key Down" in MFC Dialog Based application Pin
Aescleal10-Jun-10 0:14
Aescleal10-Jun-10 0:14 
AnswerRe: Problem in redrawing Rectangle on "Up Arrow Key Down" in MFC Dialog Based application Pin
CPallini10-Jun-10 0:26
mveCPallini10-Jun-10 0:26 
GeneralRe: Problem in redrawing Rectangle on "Up Arrow Key Down" in MFC Dialog Based application Pin
Arindam Tewary10-Jun-10 0:38
professionalArindam Tewary10-Jun-10 0:38 
GeneralRe: Problem in redrawing Rectangle on "Up Arrow Key Down" in MFC Dialog Based application Pin
CPallini10-Jun-10 1:02
mveCPallini10-Jun-10 1:02 
Questioncatching new Pin
Sakhalean9-Jun-10 22:56
Sakhalean9-Jun-10 22:56 
AnswerRe: catching new Pin
rp_suman9-Jun-10 23:19
rp_suman9-Jun-10 23:19 
GeneralRe: catching new Pin
Sakhalean9-Jun-10 23:27
Sakhalean9-Jun-10 23:27 
GeneralRe: catching new Pin
rp_suman10-Jun-10 6:00
rp_suman10-Jun-10 6:00 
AnswerRe: catching new Pin
Aescleal9-Jun-10 23:25
Aescleal9-Jun-10 23:25 
GeneralRe: catching new Pin
Sakhalean9-Jun-10 23:28
Sakhalean9-Jun-10 23:28 
GeneralRe: catching new Pin
Aescleal9-Jun-10 23:43
Aescleal9-Jun-10 23:43 
GeneralRe: catching new Pin
Sakhalean10-Jun-10 0:22
Sakhalean10-Jun-10 0:22 
GeneralRe: catching new Pin
Stephen Hewitt10-Jun-10 14:07
Stephen Hewitt10-Jun-10 14:07 
QuestionPopup Menu Pin
VVVimal9-Jun-10 22:37
VVVimal9-Jun-10 22:37 
AnswerRe: Popup Menu Pin
Niklas L9-Jun-10 22:54
Niklas L9-Jun-10 22:54 
AnswerRe: Popup Menu Pin
rp_suman9-Jun-10 22:59
rp_suman9-Jun-10 22:59 
QuestionRe: Popup Menu Pin
David Crow10-Jun-10 3:04
David Crow10-Jun-10 3:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.