|
Hi
I just wanted to replace a '%' character in CComBSTR with "%%". But the code does not support CString. The solution should be UNICODE support.
Any methods to perform this operation ?
Thanks In Advance.
Babu
Today is a gift, that's why it is called the present.
|
|
|
|
|
CComBstr class doesn't have a method to replace a sub-string with another or to insert another string in specified position. All you can do is, get BSTR which is wrapped in CComBSTR class ( either by m_str member or by operator BSTR). You need to copy this to another CComBSTR. You may use its Append() method or overloaded += operators for ease.
CComBSTR str("here%are%percentages%");
CComBSTR newstr;
WCHAR split[] = L"%";
WCHAR* pos = wcstok(str.m_str, split);
while(0 != pos) {
newstr.Append(pos);
newstr.Append(L"%%");
pos = wcstok(NULL, split);
}
NOTE:
I would like to remind that BSTR data type has preceding header components, and the final string is terminated with double null characters. This is how system allocates memory for BSTR. There can be embedded single null characters in BSTR string data. In that case, wcslen() and wcstok() functions won't work as expected. Use CComBSTR::Length() or SysStringLen() to get length of string. You may need to examine each character in string till you find two continuous '\0' characters. During this, whenever you find a '%' add an additional '%' more tho the new string.
Unicode support is completely ensured.
modified on Thursday, March 24, 2011 9:09 AM
|
|
|
|
|
or ...
CComBSTR str("here%are%percentages%");
CString workingString(str);
workingString.Replace(_T("%"),_T("%%"));
str=workingString;
|
|
|
|
|
Its ok. But I guess you didn't notice "But the code does not support CString" in the actual question
|
|
|
|
|
sorry - rookie error - I'll pay more attention
you nailed it then
|
|
|
|
|
Hi
I have an MFC Dialog which contains an ActiveX control ( a small grid control developped en C# with DevExpress )
The problem appears when switch to an other application or screen until editing a row in this grid ( the cursor is inside the zone edit ).
i.e : when cursor in the edited row and switching screen -----> problem of crash ( i can't get the dialog again ; i click on the try icon but no result).
I tried to impliment the Onkillfocus()
void CApp_ToolDlg::OnKillFocus(CWnd* pNewWnd)
{
CWnd *pWnd = GetDlgItem(IDC_AXSEE_PLMPC1); // GET THE CWND OF ACTIVEX CONTROL
if( pWnd != NULL)
pWnd->SetFocus(); // TRY TO SET FOCUS ON IT
CDialog::OnKillFocus(pNewWnd);
}
|
|
|
|
|
I've used VS2010 to create C++ MFC app and MFC ActiveX component. The ActiveX accumulates data and I need to design a method that allows the MFC app to access it.
The data is stored in std::vector using struct.
I'm told there is no direct way to do this so should I store the data differently and/or how can I access it using an ActiceX method?
|
|
|
|
|
If the ActiveX control is running in the same process as the app, then there's nothing stopping you from making an interface method that returns a vector<your_struct>* . If they're in different processes, then you can't return a pointer directly to the vector. If you are using the built-in marshaler, you'll need to convert the data to OLE Automation-compatible types. That means making a SAFEARRAY that contains... well, I'm not sure. I've never had to make the OLE equivalent of a struct, so I don't know how you do that off the top of my head. Hopefully this is enough info to get started.
--Mike--
Dunder-Mifflin, this is Pam.
|
|
|
|
|
Uhu, I have not been working with C++ in a few years, only C#, ouch I have forgotten a lot...
Right now I'm working on a COM Object and I need to sign it so it will work with no warnings at my clients.
I do have a code signing cert, but I have totally forgotten how to do it.
Is there a new and easy way using VS? I'm running VS 2010.
- Anders
|
|
|
|
|
The two SDKs I have on this machine both have a signing app called signtool.exe . I also remember seeing some other signing app in an older SDK that had a wizard to lead you thru the process.
--Mike--
Dunder-Mifflin, this is Pam.
|
|
|
|
|
Of course, thanks
- Anders
|
|
|
|
|
I'm making an COM object (ATL Simple Object) and it works fine from a C# Project, and from ASP Server Side.
But when I try to create it from JSCript in a browser, with new ActiveXObject(), I get an error saying "Microsoft JScript runtime error: Automation server can't create object"
Any idea what to do?
- Anders
|
|
|
|
|
Hi all!
Now I am developing an add-in application. I had instantiated a sub-class of COM to expose the interface to Word. Then I add some commandbar buttons on the command bar. When user click a specified button, a data will be inserted into word document. The data inserted is created by an object of another class of mine, which is derived some interfaces of Word. This class can handle the event come from Word application.
When the data was inserted, user can right-click on it. Then a pop-up menu will be displayed. When an item was chosen, I need to disable the button on command bar.
Problem: I don't know how to control the button within data class. I had tried to transport the pointer of button into data class. But no appropriate way to implement it. I want to write a method and expose it as a member of interface. But I can't find a appropriate type to transport Office::CommandBarButton. I try to use IDispatch* to do it. But the code to convert and save the pointer can't through compilation. I don't know what I can do now. Is there some one can help me? Thank you!
Sincerely.
There is some white cloud floating on the blue sky. That's the landscape I like.
|
|
|
|
|
Hello!
I have a CTabViewImpl set as the client in a CFrameWindowImpl. I wonder how its possible to get WM_COMMAND messages from the active tab page's dialog.
When I have the same dialog template used in a modal dialog, the IDOK and IDCANCEL buttons placed in the template generate the appropriate WM_COMMAND messages.
However, when I use the dialog template as a page in the CTabViewImpl the WM_COMMAND messages are no longer generated. Usually a press on ESC oder RETURN generate the WM_COMMAND messages. Any way to have this mechanism work in embedded, non-modal dialogs too?
Happy coding,
Philipp Kursawe
|
|
|
|
|
Then possibly you won't be getting WM_KEYDOWN messages in page. Are you getting it?
modified on Friday, March 11, 2011 10:36 AM
|
|
|
|
|
Hi Philipp,
In your dialog message map add FORWARD_NOTIFICATIONS() to forward the WM_COMMAND (and some other) messages to the dialog's parent, ie your CTabViewImpl based window. CTabViewImpl in turn will forward (if not handled) the same messages to it's parent, see CTabViewImpl message map.
cheers,
AR
When the wise (person) points at the moon the fool looks at the finger (Chinese proverb)
|
|
|
|
|
What I want to achieve is that my tabbed windows use the IsDialogMessage to behave as if they were dialogs.
So I have implemented a handler for WM_FORWARDMSG in each of my tabviews windows.
In my MainFrame I call tabview.PreTranslateMessage() which correctly forwards the message to the current active tab window.
My CWindowImpl of each tab window has this:
MESSAGE_HANDLER_EX(WM_FORWARDMSG, OnForwardMsg)
LRESULT OnForwardMsg(UINT uMsg, WPARAM wParam, LPARAM lParam)
return IsDialogMessage((LPMSG)lParam);
}
However, pressing the VK_RETURN or VK_ESCAPE key does not result in a WM_COMMAND message being sent to the tabviews window.
Happy coding,
Philipp Kursawe
|
|
|
|
|
Sorry, I don't understand the relationship with your OP
When the wise (person) points at the moon the fool looks at the finger (Chinese proverb)
|
|
|
|
|
I have a base template class
template<class T, UINT titleId, int SortIndex, class WindowClass = ATL::CWindowImpl<T>>
class ATL_NO_VTABLE ITabPageImpl : public WindowClass {
BEGIN_MSG_MAP_EX(ITabPageImpl)
MSG_WM_CREATE(onCreate)
MSG_WM_DESTROY(onDestroy)
REFLECT_NOTIFICATIONS_EX()
ALT_MSG_MAP(1)
NOTIFY_CODE_HANDLER_EX(LVN_DELETEITEM, onModifyTable)
END_MSG_MAP()
ITabPageImpl() : _table(this, 1) {}
private:
ATL::CContainedWindowT<WTL::CListViewCtrl> _table;
In the onCreate method I subclass a control, if the implementation provides a specific method:
__if_exists(T::getTableControl) {
_table.SubclassWindow(static_cast<T*>(this)->getTableControl());
}
However, after subclassing the message loop of T produces an assertion when the subclassed control is supposed to process its first message.
The basic Idea is, that I want to put handling of certain messages in the base class and lift the burden on implementation classes.
Thanks for any help!
Happy coding,
Philipp Kursawe
|
|
|
|
|
Hi Philipp,
You are misunderstanding ATL::CContainedWindow operation. Post on the WTL support list[^] for help.
cheers,
AR
When the wise (person) points at the moon the fool looks at the finger (Chinese proverb)
|
|
|
|
|
Thanks Alain for your reply!
Maybe I should describe what I want to achieve: I want to subclass a child window and pre-handle certain messages in my class before the child window can process them itself.
I thought CContainedWindow was the way to go then?
In the particular case I want to set the background colour of the window.
Happy coding,
Philipp Kursawe
|
|
|
|
|
Hello,
I am struggling to fit CListBoxCtrl and CDoubleBufferWindowImpl together.
I have a owner drawn listbox ready, whose MSG_WM_DRAWITEM I handle in the parent control for now.
I guess the first step would be to move the MSG_WM_DRAWITEM message handling to my custom listbox control.
How would I then also fit in the double buffer technique?
My solution was something like in the DoPaint method to call the original controls DefWndProc but that does not work.
Any ideas?
Happy coding,
Philipp Kursawe
|
|
|
|
|
Hi Philipp,
Philipp Kursawe wrote: I guess the first step would be to move the MSG_WM_DRAWITEM message handling to
my custom listbox control
It may be your choice but it's not the first step.
You need to use a double buffered CListBox , for instance:
class CMyListBox : public CDoubleBufferWindowImpl<CMyListBox, CListBox, ATL::CControlWinTraits>
{
BEGIN_MSG_MAP(CMyListBox)
CHAIN_MSG_MAP(CDoubleBufferWindowImpl)
END_MSG_MAP()
void DoPaint(HDC hdc)
{
DefWindowProc(WM_PAINT, (WPARAM)hdc, 0);
}
};
If you subclass the listbox in your parent dialog OnInit() , you can check with breakpoints that the dc referenced in your DrawItem() member is the MemoryDC set in CMyListBox::DoPaint() .
My test code:
class CTest0View :
public CDialogImpl<CTest0View>,
public COwnerDraw<CTest0View>
{
public:
enum { IDD = IDD_TEST0_FORM };
CMyListBox m_lb;
void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
return;
}
BEGIN_MSG_MAP(CTest0View)
MESSAGE_HANDLER(WM_INITDIALOG, OnInit)
CHAIN_MSG_MAP(COwnerDraw<CTest0View>)
FORWARD_NOTIFICATIONS()
END_MSG_MAP()
LRESULT OnInit(UINT , WPARAM , LPARAM , BOOL& bHandled)
{
m_lb.SubclassWindow(GetDlgItem(IDC_LIST1));
m_lb.AddString(L"Titi");
m_lb.AddString(L"Tata");
m_lb.AddString(L"Toto");
return bHandled = FALSE;
}
};
cheers,
AR
When the wise (person) points at the moon the fool looks at the finger (Chinese proverb)
|
|
|
|
|
Thanks Alain, this works (almost)!
I am using your WTL::CControlDialogImpl to show the listbox in a modal dialog. The drawing is a little off now.
void OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT item)
if (item->itemID == -1) return;
WTL::CDCHandle dc(item->hDC);
dc.GradientFillRect(item->rcItem, RGB(200,200,200), RGB(10,10,10), false);
if (item->itemState == ODS_FOCUS) {
dc.SetTextColor(RGB(255,255,255));
} else {
dc.SetTextColor(RGB(255,255,255));
}
WCHAR text[1024];
int chars = m_Ctrl.GetText(item->itemID, text);
dc.SetBkMode(TRANSPARENT);
dc.SelectFont(font);
dc.DrawText(text, chars, &item->rcItem, DT_NOPREFIX | DT_SINGLELINE | DT_CENTER | DT_VCENTER | DT_END_ELLIPSIS);
}
After some rows the gradients stop to show up and the background is just the standard window color.
Happy coding,
Philipp Kursawe
|
|
|
|
|
Hi, everyone!
I had encounter a problem while I am developing a add-in for Word. I make a class derived from IViewObject and implement my own OnDraw. In OnDraw, I create a compatible DC from the parameter with OnDraw whose type is ATL_DRAWINFO. But the compatible DC can't be created correctly in most time. The error code I get is 183 (The file is existed and it can't be created). I don't know the reason. I guess maybe Microsoft don't allow others to do that, isn't it?
After then, I try to get a DC by GetDC or GetWindowDC. But the object I draw through them isn't in the client area of Word. Maybe I need to get the DC of Client-area of Word. But I don't know how to get it. Even I doubt whether the DC of Client-area is exist. I hope someone could be kind to tell me how to resolve this problem. Thx!
Whiteclouds.
There is some white cloud floating on the blue sky. That's the landscape I like.
|
|
|
|