|
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
|
|
|
|
|
How to get the handle of a previous appln window
|
|
|
|
|
Can u be more precise..
I didnt get u......
cheers,
Super
------------------------------------------
Too much of good is bad,mix some evil in it
|
|
|
|
|
If you are trying to create a singleton application then this is not the best way to do it. There are articles here about this - the best one is probably by Joseph Newcomer - can't remember the URL.
If however you want to find out the handle to a previous instance of your app window you can always use ::FindWindow( ). You must know the WNDCLASS of your main window to do this and to complicate matters even more you will probably have to think about the case when there are more than one previous windows around.
Example: to find a running instance of Excel you can use:
HWND hWndExcel = ::FindWindow( _T("XLMAIN"), NULL );
Then if you want to find a window with a special window caption - say you know the Excel instance you want to find has the file "secrets.xls" open you could use this:
HWND hWndExcel = ::FindWindow( _T("XLMAIN"), _T("Microsoft Excel - secrets.xls") );
Hope this helps somewhat,
- d a b s -
Wenn ist das Nunstück git und Slotermeyer? Ja! Beierhund das oder die Flipperwaldt gersput!
|
|
|
|
|
I have a large client area, and scroll bars are needed to view it all. Using the normal code puts only the visible area in the clipboars. I need to dump the visible as well as the non-visible part of the client area on to the clipboard. Please help!!!
|
|
|
|
|
I made an app that can run on Win9x/Win2k.
I want that on Win2k my dialog become transparent, so I used the fonction SetLayeredWindowAttributes(...). It won't compile, I've added /D "_WIN32_WINNT=0x0500" to the compiler additional Options, now it compils but don't work on Win9x...
Is it a way to make my app work on all Windows ?
|
|
|
|
|
Unfortunately not... Transpareny was introduced in W2K (WinNT 5.0)
|
|
|
|
|
Yes I know, but I thought that the app can run on Win9x and the fonction simply ignored....
And I know I can load SetLayeredWindowAttributes directly from "User32.dll" with LoadLibrary blabla, but I was asking if there is a solution to simply use SetLayeredWindowAttributes (I don't need to load it from User32.dll because I have the last Platform SDK) and make my app run on all Windows (and the fonction does nothing on Win9x).
Ouch sorry for my english I hope someone will understand what I want to say ;o)
Anyway, Lakitu thanks for your answer.
|
|
|
|
|
OSVERSIONINFO os;
::GetVersionEx(&os);
if ( os.dwMajorVersion>=5 )
SetLayeredWindowAttributes(...).
MS quote (http://www.microsoft.com/ddk) : As of September 30, 2002, the Microsoft® Windows® 2000 DDK, the Microsoft Windows 98 DDK, and the Microsoft Windows NT® 4.0 DDK will no longer be available for purchase or download on this site.
|
|
|
|