|
I found surprisingly few articles that can help me about the subject. I simply want to have my program execute from the Windows Explorer context menu, and to have an icon with it. I found out that I can add an entry to *\\shell\\MyProgram, but I don't know how to associate an icon with it.
Could any one of you direct me to a nice article about this issue? I would like to do this in my own code, not to use some extension dll or something.
Thanks.
|
|
|
|
|
|
I have created an ATL control project which draws a polygon.
sides is the property wich takes input from user.
Inserted this control to MFC dialog.
when i tried to add variable for this control causes error as follows.
"Error: the Extender provider failed to return an extender for this object".
what does it mean?
|
|
|
|
|
Dear All,
Unable to convert CString to BSTR! Am I a stupid?!
I have an interface method which needs to convert CString to BSTR and return BSTR to caller.
AllocSysString of CString is not copying the data to BSTR.
STDMETHODIMP CTP_Interface_ErrorCode_Wrp::GetAdditionalDataFlag(BSTR *AddDataFlag)<br />
{<br />
AFX_MANAGE_STATE(AfxGetStaticModuleState())<br />
<br />
<br />
CString temp = pTP_Interface_ErrorCode->GetAdditionalDataFlag();<br />
*AddDataFlag = temp.AllocSysString();<br />
<br />
return S_OK;<br />
}
Any one please help me.
Thanks very much, Nani
|
|
|
|
|
You code looks correct.
How do you see that value is not copied? I mean have you used debugger or you just saw it on the client side?
BTW try first something simpler such as
CString temp(_T("foo"));
*AddDataFlag = temp.AllocSysString();
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.
[my articles]
|
|
|
|
|
Yeah. I am real crap!!!
I did everything correctly, but the debugger is giving some number instead of string.
I dont know why?!
I converted back from BSTR to CString in my client, and was able to print results properly.
Thank very much
|
|
|
|
|
Hello mandanani,
If I understand your problem correctly, I think the problem you are facing is the formatting of the debugger output.
Were yu looking at the contents of the BSTR from the Watch Window ? If so, simply put a ", su" after the BSTR variable and see the contents of the BSTR transformed into something you can read.
This is known as reformatting the varible. The "su" means "string unicode".
- Bio.
|
|
|
|
|
Hi Nani,
Your code is correct and here CString is converted into BSTR also.
Just add one messagebox and check it out.
MessageBox(0,(LPCTSTR)(CString)*AddDataFlag,"1",0);
Yes U Can ...If U Can ,Dream it , U can do it ...ICAN
|
|
|
|
|
better use _bstr_t(CSTRIBG).Detach() or .copy
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You/codeProject$$>
|
|
|
|
|
Hi, my program uses a WebBrowser Control with the following code:
HRESULT hr = CoCreateInstance(CLSID_WebBrowser,<br />
NULL,<br />
CLSCTX_INPROC,<br />
IID_IWebBrowser,<br />
(void**)&m_spWebBrowser);
Then I navigate the control to a local html file, which contains some type text inputs, the code is like this;
<span contentEditable="true"></span>
Upon the load completion, I attached a render behevior for each element, the definition is list below:
class ATL_NO_VTABLE CIdsUISpanRB : <br />
public CComObjectRootEx<CComSingleThreadModel>,<br />
public CComCoClass<CIdsUISpanRB, &CLSID_IdsUISpanRB>,<br />
public IDispatchImpl<IIdsUISpanRB, &IID_IIdsUISpanRB, &LIBID_IdsViewer>,<br />
public IElementBehavior,<br />
public IElementBehaviorFactory,<br />
public IHTMLPainter
The render behavior above implemented an event sink, I conneted it with the webbrowser control by AtlAdvise:
hr = AtlAdvise(m_spElem, (IDispatch*)this,
DIID_HTMLElementEvents2,<br />
&m_dwCookie);
What I want to do, is to process the input event within the invoke method of IDispatch interface:
STDMETHODIMP CIdsUISpanRB::Invoke( DISPID dispidMember,<br />
REFIID riid,<br />
LCID lcid,<br />
WORD wFlags,<br />
DISPPARAMS* pdispparams,<br />
VARIANT* pvarResult,<br />
EXCEPINFO* pexcepinfo,<br />
UINT* puArgErr)<br />
{<br />
switch (dispidMember)<br />
{<br />
case DISPID_HTMLDOCUMENTEVENTS_ONKEYDOWN:<br />
{<br />
break;<br />
}<br />
}<br />
}
The problem I have, is that I can't get keydown or keyup event, but only keypress message, so any one can tell me why? how to get the keydown event?
Another thing, I attached an edit designer to the whole html docuement mentioned above, in order to handle events within the html doc. Within the edit designer, I can get keydown event, but no keyup.
moreover, as docuemented, the TranslateAccelerator method of IEditDesigner, will be called first if any keyboard event triggered, but acutally this function was never called even I press the keyborad, what's wrong?
|
|
|
|
|
Hello guys,
I have encountered a strange issue with Vista, and if anybody has any clue please let me know.
So okay, I have a normal dialog with a tab control, it has embedded a few tab pages with controls, this all work regularely on Win 2000 and XP and Server 2003. Now with Vista, one control is a password control, and if I hit CAPS and start typing into that control, there will be a big tooltip notifying me that I am typing with my caps on, bla bla. This is a OS level tooltip, because I see it everywhere on Vista whenever I do the same, from logging on to Vista, to any of the system dialogs.
The problem is that when the tooltip disappears, the area below it is blank, I don't see the controls as if they were eraised. This is the problem that the controls does not repaint themselves, I guess, but I don't know why - if I open a Notepad, for example, move it in front of my WTL dialog, and them aside, the dialog and controls are painted regularely.
So if anybody has any thoughts on this please let me know.
Thank you.
Sarajevo, Bosnia
|
|
|
|
|
Hi everybody,
I have a problem with a menu on a regular dialog. I want to change the text of the menu item in run-time, so I do this:
ModifyMenu( GetMenu(), 0, MF_STRING | MF_BYPOSITION, 0, (LPCTSTR) _T( "View" ) );
This works if the menu is submenu and I am changing the items there, but if I want to change the root menu (the one that sits on the menu bar and does not have an ID), then it changes but it does not display any changes until I move the mouse over it, so I guess it does not refreshes immediatelly.
Or maybe there is a whole better way to change the text of the menu items at runtime?
I went through Michael Dunn's articles, but only have seen the examples of toolbar and statusbar, with UISetText, but this does not work in my case.
Thanks for your help in advance.
|
|
|
|
|
You need to call DrawMenuBar() to redraw the menu.
|
|
|
|
|
Exactly! Thanks for your help, I really appreciate it.
|
|
|
|
|
The problem still persists in some way. After I call DrawMenuBar(), it does refreshes the menu but now the code that checks and unchecks the menu item does not work at all. Also, the code that grays out some menu item does not work either, and it doesn't matter how many times I call DrawMenuBar().
I am not sure whether this behavior is specific to DrawMenuBar(), or is caused by the ModifyMenu command, but it sure screws up the app.
Thank you.
|
|
|
|
|
I need to pass user defined COM class through COM interface. I passed its interface as I can not pass its coclass. Please correct me if I am wrong.
The code was compiling. Now the problem is I have some data types in the coclass and can not use them from interface.
Could you please let me know how to solve this.
Here below is the code:
STDMETHODIMP CTP_Interface_Wrp::GetObligorInputData(ITP_CompInputData_Wrp *pVal)<br />
{<br />
AFX_MANAGE_STATE(AfxGetStaticModuleState())<br />
<br />
<br />
pTP_DLL_Interface->GetObligorInputData(pVal->pTP_CompanyInputData);
return S_OK;<br />
}
Actually pTP_CompanyInputData is member vairable of TP_CompInputData coclass. This can not be accessed from its interface class ITP_CompInputData.
|
|
|
|
|
I fixed the problem by type casting interface with its coclass.
((CTP_CompInputData_Wrp*)pVal)->pTP_CompanyInputData
Please let me know if this is the right approach.
|
|
|
|
|
mandanani wrote: I fixed the problem by type casting interface with its coclass.
((CTP_CompInputData_Wrp*)pVal)->pTP_CompanyInputData
Please let me know if this is the right approach.
I don't think that's a good idea, because a client could quite reasonably implement its own version of your interface, and pass it to your method, causing the type cast to fail and provide no useful error message as to why. If it isn't reasonable to add the property to your interface, you can add an interface to your class that does have that property, and then you can query for that interface safely.
Nathan
|
|
|
|
|
I have an MFC based dialog exe (VS2005 just one dialog) it has some global pointers which are initialized when the exe starts up.
I added an ATL COM object to the project (enabled ATL support) now i call methods on this COM object through another process, everything goes on fine but in the called methods the global pointers appear NULL, seems the like the COM object is created in some other context can someone shed more light into this.
[Edit]
OK i just found out that even if the EXE is running windows still runs it one more time with arguments(/Embedded) this completely screws up my design (which is apparently flawed) is there some way out?
[/Edit]
Thanks.
C++ where friends have access to your private members !
modified on Tuesday, January 08, 2008 5:31:20 AM
|
|
|
|
|
Monty2 wrote: is there some way out?
Of what? We don't know what problem you are trying to solve. If you require interprocess communications I would not suggest COM as a solution, it is far to complex for most IPC requirements. But, I really don't know what problem you are trying to solve so that may not help you at all.
|
|
|
|
|
The following code is an ATL OLEDB Consumer Assesor. I need to Add to it the IRowsetIndex::Seek to perform a Seek. How I must to modify my code to permform it?. Thanks a lot.
#ifndef __DBOITEMPROV_H_
#define __DBOITEMPROV_H_
class CdboItemProvAccessor
{
public:
TCHAR m_Articulo[7];
double m_Cantidad;
double m_Gravado;
BEGIN_COLUMN_MAP(CdboItemProvAccessor)
COLUMN_ENTRY(1, m_Articulo)
COLUMN_ENTRY(2, m_Cantidad)
COLUMN_ENTRY(3, m_Gravado)
END_COLUMN_MAP()
void ClearRecord()
{
memset(this, 0, sizeof(*this));
}
};
class CdboItemProv : public CCommand<caccessor><cdboitemprovaccessor> >
{
public:
HRESULT Open( char* mySql )
{
HRESULT hr;
hr = OpenDataSource();
if (FAILED(hr))
return hr;
return OpenRowset( mySql );
}
HRESULT OpenDataSource()
{
HRESULT hr;
CDataSource db;
CDBPropSet dbinit(DBPROPSET_DBINIT);
dbinit.AddProperty(DBPROP_AUTH_CACHE_AUTHINFO, true);
dbinit.AddProperty(DBPROP_AUTH_ENCRYPT_PASSWORD, false);
dbinit.AddProperty(DBPROP_AUTH_MASK_PASSWORD, false);
dbinit.AddProperty(DBPROP_AUTH_PASSWORD, "");
dbinit.AddProperty(DBPROP_AUTH_USERID, "Admin");
dbinit.AddProperty(DBPROP_INIT_DATASOURCE, OLESTR("S:\\NuevoSis\\Principal\\Principal.mdb"));
dbinit.AddProperty(DBPROP_INIT_MODE, (long)16);
dbinit.AddProperty(DBPROP_INIT_PROMPT, (short)4);
dbinit.AddProperty(DBPROP_INIT_PROVIDERSTRING, "");
dbinit.AddProperty(DBPROP_INIT_LCID, (long)1033);
binit.AddProperty(DBPROP_AUTH_PERSIST_SENSITIVE_AUTHINFO, false);
//hr = db.Open(_T("Microsoft.Jet.OLEDB.4.0"), &dbinit);
hr = db.OpenWithServiceComponents("Microsoft.Jet.OLEDB.4.0", &dbinit);
if (FAILED(hr))
return hr;
m_session.Close();
return m_session.Open(db);
}
HRESULT OpenRowset( char* mySql )
{
// Set properties for open
CDBPropSet propset(DBPROPSET_ROWSET);
propset.AddProperty(DBPROP_CANSCROLLBACKWARDS, true);
propset.AddProperty(DBPROP_IRowsetChange, true);
propset.AddProperty(DBPROP_UPDATABILITY, DBPROPVAL_UP_CHANGE | DBPROPVAL_UP_INSERT | DBPROPVAL_UP_DELETE);
propset.AddProperty(DBPROP_IMMOBILEROWS, true);
return CCommand<caccessor><cdboitemprovaccessor> >::Open(m_session, mySql, &propset);
}
CSession m_session;
};
#endif // __DBOITEMPROV_H_
|
|
|
|
|
Hi,
I have a problem with getting a transparent static control to draw correctly on a WTL dialog. Everything I do works, but only if the text color is black.
Message handler is like this:
<small>MESSAGE_HANDLER(WM_CTLCOLORSTATIC, OnCtlColorStatic)</small>
Then I have a method to handle it:
<br />
<small>LRESULT OnCtlColorStatic(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);</small>
and in the code I do like this:
<small>LRESULT MainDialog::OnCtlColorStatic(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)<br />
{<br />
HWND hWnd = (HWND)lParam;<br />
HDC hDc = (HDC)wParam;<br />
<br />
COLORREF m_crTextColorMaroon;<br />
m_crTextColorMaroon = RGB( 128, 0, 0 );<br />
HBRUSH hbr;<br />
hbr = (HBRUSH)m_crTextColorMaroon;<br />
<br />
if( hWnd == (HWND)GetDlgItem(IDC_FILE) ||<br />
hWnd == (HWND)GetDlgItem(IDC_FILESIZE)) <br />
{<br />
::SetTextColor( hDc, m_crTextColorMaroon );<br />
::SetBkMode(hDc, TRANSPARENT);<br />
return (LRESULT) GetStockObject (HOLLOW_BRUSH);<br />
}<br />
<br />
return 0;<br />
}</small>
So far so good, everything works. I am only changing the color of the controls that will represent a label, the other static controls on the dialog should display text in the black color. So this works perfectly when the dialog gets displayed.
Now the user changes the language on the menu, and I do this:
<small>SetDlgItemText( IDC_FILE, (LPCTSTR) SomeNewText);</small>
and the text gets drawn over the previous text, making it indecipherable.
What is wrong with this code? Why doesn't the static controls clear its content before the new text is drawn.
If I use <small>SetDlgItemText(...)</small> with any other static control that is not handled in the <small>OnCtlColorStatic</small> method, it gets drawn correctly.
Thanks for your help.
Sarajevo, Bosnia
|
|
|
|
|
You're returning HOLLOW_BRUSH which paints nothing. When the control asks you what brush to use as the background brush, you give it a brush that doesn't paint, so the old contents of the control aren't erased. I'd do this:
LRESULT MainDialog::OnCtlColorStatic(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
HWND hWnd = (HWND) lParam;
HDC hDc = (HDC) wParam;
if(hWnd == GetDlgItem(IDC_FILE) || hWnd == GetDlgItem(IDC_FILESIZE))
{
SetTextColor(hDc, RGB(128,0,0));
SetBkMode(hDc, TRANSPARENT);
}
bHandled = false;
return 0;
} This code changes the attributes of the DC that you care about, then lets the message go on to the default window proc, which will set the right background color.
|
|
|
|
|
Thanks for your help, Mike, but this does not work for me. Now all static controls display a black colored text. Yes, I can change the text and not to get it write over the previous one, but the text is not redish ( RGB(128, 0, 0)) but black.
Can I send you the app, it's only one dialog, just a few lines of code above the normal code generated for the ATL exe app?
Thanks.
Sarajevo, Bosnia
|
|
|
|
|
OK, this time I actually tested the code that I'm going to post.
LRESULT CMainDlg::OnCtlcolorstatic(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
LRESULT res = ::DefWindowProc(m_hWnd, uMsg, wParam, lParam);
HDC hdc = (HDC) wParam;
HWND hwnd = (HWND) lParam;
if(hwnd == GetDlgItem(IDC_STATIC1) || hwnd == GetDlgItem(IDC_STATIC2))
{
SetTextColor(hdc, RGB(255,0,0));
SetBkMode(hdc, TRANSPARENT);
}
return res;
} The first line gets the default brush so the background looks right.
Last modified: 8hrs 3mins after originally posted --
|
|
|
|
|