|
|
My friend, this time I had to balance the troll's vote to your reply.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Thanks my friend but it seems my answer was important because I got 4 votes!?
|
|
|
|
|
I got an answer from Mukesh Kumar
Thanks anyway
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
I am having a dialog control with edit boxes in it and when I type in those boxes and hit 'Enter' key the dialog closes. I am not having any OK or Cancel buttons (I deleted them as soon as I created the dialog). I want to replicate tab behavior when I hit 'Enter' key and also for a couple of edit boxes in the same dialog I have declared handlers to do some processing as below-
ON_NOTIFY(EN_MSGFILTER, IDE_CONTROL, UpdateControl)<br />
CWnd* wnd;<br />
wnd = GetDlgItem(IDE_CONTROL);<br />
wnd->SendMessage(EM_SETEVENTMASK, 0, ENM_KEYEVENTS);<br />
void CControlDlg::UpdateControl(WPARAM wParam, LPARAM lParam) <br />
{<br />
}
How can I perform both of these functions at the same time (disabling enter key/escape key from closing the dialog, while processing the above function when you hit 'Enter' key in some single line edit boxes)??
thanks for any help.
PKNT
|
|
|
|
|
Set your edit box to 'want enter' key...
God bless,
Ernest Laurentin
|
|
|
|
|
Thanks or the reply, I did that too, but it still closes the dialog box . I would like to have them do some function if I want to and/or just go to next control in tab order.
PKNT
|
|
|
|
|
Usually when you press enter in a dialog the default button gets pressed... in order to avoid that you should:
A) Remove that button. (Not the best solution)
B) Handle that in the pretranslatemessage. (Not the best solution)
C) Handle the event of pressing that button.
D) Possibly other solutions that I don't remember now...
Hope this helps.
OOps! I've not read your message correctly... I would make a special class that would handle this kind of event, then it is very easy to make it work:
void CTAMEdit::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)<br />
{<br />
switch (nChar)<br />
{<br />
case VK_UP:<br />
{<br />
GetParent()->;PostMessage(WM_NEXTDLGCTL,TRUE,0);<br />
return;<br />
}<br />
case VK_DOWN:<br />
{<br />
GetParent()->;PostMessage(WM_NEXTDLGCTL,FALSE,0);<br />
return;<br />
}<br />
case VK_RETURN:<br />
{<br />
FinishEditing();<br />
return;<br />
}<br />
}<br />
CEdit::OnKeyDown(nChar, nRepCnt, nFlags);<br />
}
I've used that code to handle the up and down keys in order to go to the next control in the dialog...
Now I hope this helps you...
|
|
|
|
|
Thanks for the reply, I tried this by adding WM_KEYDOWN function to the dialog and editing it in the way you did, but it never went into that function and closes the dialog. Since you are saying that it worked for you, I think I may be doing something wrong .
PKNT
|
|
|
|
|
I handled the WM_KEYDOWN message yes, but not in the dialog, I made a special class derived from a CEdit and handled that message in that class (so it is handled before being handled in the dialog itself).
If you want to stop that or process that in the dialog (not recommended and much more easy and portable if you do that special class) you can use the PreTranslateMessage routine.
Hope this helps.
|
|
|
|
|
I tried by defining a new class derived from CEdit class and then defined WM_KEYDOWN message handle in it as you have shown above. Now I created a new edit control box in my dialog which is an object of newly derived class. Even now when I try to hit enter it closes the dialog box.
PKNT
|
|
|
|
|
I got that behaviour in the CEdit derived class, but I handled also the PreTranslateMessage... ( didn't remembered...).
If you do that in the dialog it will work for you.
BOOL CTAM_BODlg::PreTranslateMessage(MSG* pMsg)<br />
{<br />
if (pMsg->message == WM_KEYDOWN)<br />
{<br />
switch (pMsg->wParam)<br />
{<br />
case VK_RETURN:<br />
{<br />
CWnd *pWnd = GetFocus();<br />
if (pWnd == &m_cBtnPasteApplyNow)<br />
{<br />
OnBnClickedBtnPasteApplyNow();<br />
}<br />
else if (pWnd == &m_cBtnPasteCalibrate)<br />
{<br />
OnBnClickedBtnPasteCalibrate();<br />
}<br />
<big> return FALSE;</big><br />
}<br />
}<br />
}<br />
<br />
return CDialog::PreTranslateMessage(pMsg);<br />
}
return FALSE is the key...
|
|
|
|
|
I handled PreTranslateMessage and now it doesnt close the dialog, but it doesnt go to the next control. I think I am gonna try that now. Thanks for your prompt responses.
Update- I got the other issue too working... thanks again
PKNT
|
|
|
|
|
|
You can map the LBUTTONCLICK message of OK and Cancel buttons. and comment the code CDialog::OnOK() and CDialog::OnCancel(). Then when you hit the key 'Enter' and 'Escape' the dialog does not will be colsed.
|
|
|
|
|
Kiran Satish wrote: I want to replicate tab behavior when I hit 'Enter' key
Hope this helps:
BOOL CTrialDlg::PreTranslateMessage(MSG* pMsg)
{
if(pMsg->wParam == VK_RETURN)
pMsg->wParam = VK_TAB;
return CDialog::PreTranslateMessage(pMsg);
}
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
You would need to check 'pMsg->message == WM_KEYDOWN'
God bless,
Ernest Laurentin
modified on Tuesday, May 6, 2008 11:57 AM
|
|
|
|
|
Ernest Laurentin wrote: You would need to check 'pMsg->message == WM_KEYDOWN'
Really? You mean - like, what I provided won't work? Did you even try the code before complaining anything?
A 'C++' question asked in the Visual C++ forum:
Title: please stomuch me
if i have
string s[7];
s[1]="hello"
...
s[7]="how are you"
can i trace s[1] by loop and select specified item as example i, want to select e from s[1]="hello"..... the question is : this process possible or impossible!? I hope help me.......thanks - sofia_111
|
|
|
|
|
Another option but not so "pretty" is to use a "bypass". You can use bools that determine which edit box has the focus by setting TRUE in OnEditBoxSetFocus and FALSE in OnEditBoxKillFocus. Then in your OnOk or OnCancel messages (when you press Enter or Cancel) ask for that bools. If no edit box has focus then close dialog, if one of them has it, then process its content and exit the function with a simple return, not the return from CDialog.
It is not a profi way, I know, but works :P
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
|
|
|
|
|
Sorry, I didn't read your question correctly first time around...
Here...hope that helps, override your pretranslate message
BOOL CDelme1Dlg::PreTranslateMessage(MSG* pMsg)
{
if ( pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_RETURN )
{
CWnd* pWnd = GetFocus();
if ( pWnd )
{
TCHAR szClass[32];
GetClassName(pWnd->m_hWnd, szClass, 32);
if ( _tcsicmp(_T("Edit"), szClass) == 0 )
{
this->NextDlgCtrl();
return FALSE;
}
}
}
return CDialog::PreTranslateMessage(pMsg);
}
God bless,
Ernest Laurentin
|
|
|
|
|
Hi,
I am having this error come up when I am running some software that was written in Visual C++ 6.0. I searched online and everyone says to install MDAC and the problem will dissappear, but I am still experiencing it.
Does anyone know what else I need to do to fix this problem
Thanks
|
|
|
|
|
godspeed123 wrote: I am having this error come up when I am running some software that was written in Visual C++ 6.0.
Did you write it? When did the problem first appear? What have you discovered using the debugger?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I actually didnt write this software, but it happens I think when it is creating a report, so it has something to do with a database, or something along the line of that.
|
|
|
|
|
So start debugging from that point.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Dear Friends,
I m working on an aplication which is using Oracle as a backend. I need to sync the time between Oracle server and my machine using some oracle defined function. Actualy i m not very familiar with how Oracle supports for this time sync.
Can anybody help me out with this?
Thanks in Advance..
If u need any more input to answer please let me know
Megha
|
|
|
|