|
Use GetWindowText and your OnDone code in CMyDialog::OnOk() asuming it's a Dialog your using.
Or read Mike Dunn's FAQ thers's a link on top of the page!
van Padoea.
|
|
|
|
|
One way would be to override PreTranslateMessage in your dialog and catching the enter key:
BOOL CMyDialog::PreTranslateMessage( MSG* pMSG )
{
if ( pMSG->message == VM_KEYDOWN && pMSG->wParam == VK_RETURN )
{
if ( GetFocus( ) == &m_wndMyEditBoxThatIWantToCatchTheEnterKeyIn )
{
}
}
}
Of course there are many other ways also.
Hope this helps,
- d a b s -
Wenn ist das Nunstück git und Slotermeyer? Ja! Beierhund das oder die Flipperwaldt gersput!
|
|
|
|
|
Okay. I already have in my prestranslate message:
if ((pMsg->message == WM_KEYDOWN))
{
if (pMsg->wParam == VK_RETURN)
{
return TRUE;
}
}
and dont know why or how (can you explain?), but it prevents the Cdialog from getting dismiised with an Enter. If I do your code idea, will the dialog vanish after pressing Enter? Thats what I want to happen, but if the user presses enter any other place other than the editbox , i dont want the dialog to vanish. Also a blank Cedit should not be able to be dismissed with Enter. Will your code if I replace mine with yours, so that? Or do I have to do (modified your code in red):
if ( pMSG->message == VM_KEYDOWN && pMSG->wParam == VK_RETURN )
{ //It's the enter key - check if your editbox has the focus:
if ( GetFocus( ) == &m_wndMyEditBoxThatIWantToCatchTheEnterKeyIn )
{ //Do stuff here... }
return TRUE
}
Thanks,
ns
Thanks,
ns
|
|
|
|
|
Yes this should work - only return TRUE if your editbox has the focus when the enter key is pressed.
Wenn ist das Nunstück git und Slotermeyer? Ja! Beierhund das oder die Flipperwaldt gersput!
|
|
|
|
|
Wait , wait.....I'm not there yet (sorry).
The way it originally was, what exactly did trapping those messages do? The dialog only vanished when I pressed DONE ( with EndDialog). SO the return TRUE seems to make my dialog unresponsive to any ENTERs....
Sorry to bother you but can you please explain what exactly is happening when TRUE is returned? MSDN says:
Return value : Nonzero if the message was translated and should not be dispatched; zero if the message was not translated and should be dispatched.
so when TRUE is returned, this means ignore these keystrokes. SO if I do a return TRUE within your focus checking if condition, this means my enter will be ignored? .....confused. I thought it would be:
if (focusonedit)
{do stuff}
else
return TRUE
What I understand you are saying is
if (focusonedit)
{
do stuff
return TRUE
}
Want the dialog to respond to Enter only when focus is on edit, and I am confused as to which one to use (the fisrt or second
of the two above.
Appreciate your help greatly.
ns
Thanks,
ns
|
|
|
|
|
Try them both and see what happens! (hint: RETURN TRUE discards the keypress)
You'll learn more by trying yourself!
Good luck!
van Padoea!
|
|
|
|
|
hello,
first of all let me thank you in advance, excuse me for my english, it's not my best.
I have some property pages that have ListCtrls (in report mode), and I'm editing the ListCtrl subitems, in order to begin the edition I want to allow the user to double click them (what is easy) and to hit the "enter" key in order to begin or finish the edition.
I've seen that there's a function that meets my needs:
OnReturnLctrl(NMHDR* pNMHDR, LRESULT* pResult)
this function works as the double click function (it use the same parameters).
The problem arises when I press the enter key, because I get the property sheet closed.
Could you give me an advice in order to be able to use the OnReturnLctrl(NMHDR* pNMHDR, LRESULT* pResult) and not to get out of the property page when I press the enter key?
NOTE
I would not like to remove the default buttons.
|
|
|
|
|
Return FALSE in CMyPropertyPage::OnApply()
thus
<br />
BOOL CMyPropertyPage::OnApply() <br />
{<br />
return FALSE;<br />
}<br />
van Padoea
|
|
|
|
|
This is also a general issue with dialogs that have controls on which support in-place edit. The real trick is not to override OnApply or OnOK (in the dialog case), but to use PreTranslateMessage at the control's parent window level, the dialog or property page.
There's an article on this in the controls/List Control or Tree Control section of CodeProject that describes how to do this, but I don't have the reference to hand.
Steve S
[This signature space available for rent]
|
|
|
|
|
Yes, but if I use PreTranslateMessage I canot call the event that I need to handle, at least I don't know how to do it...
In the PreTranslateMessage I have tried:
<br />
if ((pMsg->message == WM_KEYDOWN) && ((int)pMsg->wParam == VK_RETURN))<br />
{<br />
if (pMsg->hwnd != this->m_cLCtrlIntroduccio.GetSafeHwnd())<br />
{<br />
return TRUE;<br />
}<br />
}<br />
in order not to be able to process the enter key in any other control.
but then I also cannot reach:
<br />
MyClass::OnReturnLctrlIntroduccio(NMHDR* pNMHDR, LRESULT* pResult) <br />
{<br />
AfxMessageBox("return detected in the ListCtrl");<br />
*pResult = 0;<br />
}<br />
because the property sheet disappears in the same way...
|
|
|
|
|
Ah. What I meant was that you detect that the input message is aimed at your edit window, and send the message normally (there are different ways to do this) before returning TRUE.
if (pMsg->message == WM_KEYDOWN &&
pMsg->wParam == VK_RETURN || pMsg->wParam == VK_ESCAPE)
{
CEdit* edit = m_TreeCtrl.GetEditControl();
if (edit)
{
edit->SendMessage(WM_KEYDOWN, pMsg->wParam, pMsg->lParam);
return TRUE;
}
}
You can also replace the SendMessage with
::TranslateMessage(pMsg);
::DispatchMessage(pMsg);
if you want to.
This should work as you require.
Sorry for any confusion.
Steve S
[This signature space available for rent]
|
|
|
|
|
Great!
sorry, this was really clear, it's my fault, tonight I haven't sleeped and I'm very tired
thank you very much!
|
|
|
|
|
How do I convert a CString to a _bstr_t?
Thanks,
ns
|
|
|
|
|
_bstr_t bstrText = L"text";
CString strText = (LPCWSTR)bstrText;
CString strText2 = (LPCSTR)bstrText;
Wenn ist das Nunstück git und Slotermeyer? Ja! Beierhund das oder die Flipperwaldt gersput!
|
|
|
|
|
The other way round:
I have CString a ="abc";
I want to make this a _bstr_t, so that I have:
_bstr_t ab = SOmethingDoneTo (a)
Thanks,
ns
|
|
|
|
|
Incidentally, whats the L mean here from your snippet?
L"text";
Thanks,
ns
|
|
|
|
|
To answer both of your questions:
ns wrote:
Incidentally, whats the L mean here from your snippet?
It means that the hardcoded text shall be interpreted as a string of wchar - not char. In other words:
char* pszText = "this is a text";
wchar_t* pszwText = L"so is this";
char* pszText2 = L"doesn't work";
wchar* pszwText2 = "doesn't work either"
To answer your other question - to convert from CString to _bstr_t you can use:
CString strText = _T("This is a text");
_bstr_t bstrText = (LPCTSTR)strText;
Wenn ist das Nunstück git und Slotermeyer? Ja! Beierhund das oder die Flipperwaldt gersput!
|
|
|
|
|
Here is a code fragment:
void CShelf2Dlg::OutStr(CString Str, int Port)
{
VARIANT va;
va.vt = VT_BSTR; // The variant is storing a string
va.bstrVal = Str.AllocSysString(); // Convert the CString to the VARIANT
Comport[Port]->SetOutput(va); // and output it
}
Elaine (fluffy tigress emoticon)
Would you like to meet my teddy bear ?
|
|
|
|
|
Well, I did
_bstr_t b_dataBaseName = SysAllocString (dataBaseName);
where dataBaseName is a char* and get the error:
error C2664: 'SysAllocString' : cannot convert parameter 1 from 'char *' to 'const unsigned short *'
Thanks,
ns
|
|
|
|
|
This will work but your program will leak memory. ::SysAllocString allocates a BSTR and you are assigning it to a _bstr_t. _bstr_t does not take ownership of the BSTR however so you would have to release it using ::SysFreeString( ).
Yet another way would be to use the USES_CONVERSION macros defined in atlconv.h - your code would then look like:
USES_CONVERSION;
_bstr_t b_databaseName = T2W( dataBaseName );
Hope this helps,
- d a b s -
Wenn ist das Nunstück git und Slotermeyer? Ja! Beierhund das oder die Flipperwaldt gersput!
|
|
|
|
|
I tried both your ideas, (freeing the bstr also), but I got from the atlconv idea:
error C2664: 'MakeDB' : cannot convert parameter 1 from 'class _bstr_t' to 'unsigned short ** '
I must be doing something incredibly dumb....
char* dataBaseName = new char[dataBaseName0.GetLength() +1];
strcpy(dataBaseName, dataBaseName0);
USES_CONVERSION;
_bstr_t b_dataBaseName = T2W( dataBaseName );
char* strFile = new char[strFile0.GetLength() +1];
strcpy(strFile, strFile0);
_bstr_t b_strFile = T2W(strFile);
_Class1Ptr ptr;
ptr.CreateInstance(__uuidof(Class1));
ptr->MakeDB( b_strFile, b_dataBaseName);
delete[] etc
Thanks for all the help so far....
Thanks,
ns
|
|
|
|
|
This is probably the easiest way to do it:
USES_CONVERSION;
LPCWSTR pszwDatabaseName = T2W( (LPCTSTR)dataBaseName0 );
LPCWSTR pszwFileName = T2W( (LPCTSTR)strFile0 );
_Class1Ptr ptr;
ptr.CreateInstance(__uuidof(Class1));
ptr->MakeDB( pszwFileName, pszwDatabaseName );
Wenn ist das Nunstück git und Slotermeyer? Ja! Beierhund das oder die Flipperwaldt gersput!
|
|
|
|
|
Did your latest idea:
error C2664: 'MakeDB' : cannot convert parameter 1 from 'const unsigned short *' to 'unsigned short **
for my VB function:
Public Function MakeDB(txtPMAFilename As String, dataBaseName As String)
why does it think vb String is 'unsigned short **' ?
I've tried so many different ideas from all the supportive replies, but seem to be stumped!
Thanks,
ns
|
|
|
|
|
I had to change the vb parameters to byval....now it compiles. May or may not run but at least it compiled! Sorry for all the bother and thanks for all the help!!!
ns
Thanks,
ns
|
|
|
|
|
SInce the resolution was to code the VB function parameter as ByVal, does this mean that _bstr_t variables can only be passed in by value? What if we wanted to change a _bstr_t variable in the VB dll so that the changes would be reflected in the VC side?
Puzzled,
Thanks,
ns
Thanks,
ns
|
|
|
|