|
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 --
|
|
|
|
|
Haha...okay, thanks a lot, you are right of course.
Thank you again.
Sarajevo, Bosnia
|
|
|
|
|
Hi
Im creating an application in VC++ 6.0.
This application is ATL/COM service exe. in which i need to write certain inform to the queue as well reading data from different queue and perform some process.
I could able to write the given data to the specified queue but unable to read from the queue..
The code i have given below (only MSMQ receive part), while running below mentioned code im getting HR failure error. (no other error mentioned in msdn is not occuring)
can any could help me to get out of this issue...
//code:
HANDLE header1:pen_Queue(unsigned short *Qname)
{
MQQUEUEPROPS QueueProps;
PROPVARIANT aVariant[10]; // Modify for additional properties.
QUEUEPROPID aPropId[10]; // Modify for additional properties.
DWORD PropIdCount1 = 0;
HRESULT hr=MQ_OK;
HANDLE hQueue = NULL;
ULONG MSG_BODY_LEN;
// Queue handle
DWORD dwFormatNameBufferLength = 100;
WCHAR wszFormatNameBuffer[100];
PSECURITY_DESCRIPTOR pSecurityDescriptor;
// Set the pathname of the queue (PROPID_Q_PATHNAME).
aPropId[PropIdCount1] = PROPID_Q_PATHNAME; // Property identifier
aVariant[PropIdCount1].vt = VT_LPWSTR; // Type indicator
aVariant[PropIdCount1].pwszVal = Qname;
PropIdCount1++;
// Set the label of the queue (PROPID_Q_LABEL).
aPropId[PropIdCount1] = PROPID_Q_LABEL; // Property identifier
aVariant[PropIdCount1].vt = VT_LPWSTR; // Type indicator
aVariant[PropIdCount1].pwszVal = L"Test Queue"; // Queue label
PropIdCount1++;
///Set Queue Size
aPropId[PropIdCount1]=PROPID_Q_QUOTA;
aVariant[PropIdCount1].vt =VT_UI4;
aVariant[PropIdCount1].bVal=5 ;
PropIdCount1++;
////////////////////////////////////////////////////////
// Add additional properties here. When adding properties,
// increment the indexes for the aVariant and aPropId arrays
// in their respective declaration statements above.
////////////////////////////////////////////////////////
////////////////////////////////////
// Set the MQQUEUEPROPS structure.
/////////////////////////////////////
QueueProps.cProp = PropIdCount1; // Number of properties
QueueProps.aPropID = aPropId; // Ids of properties
QueueProps.aPropVar = aVariant; // Values of properties
QueueProps.aStatus = NULL; // No error reports
pSecurityDescriptor = NULL; // Set default security descriptor
////////////////////////////
//Create the queue.
////////////////////////////
dwFormatNameBufferLength = sizeof(wszFormatNameBuffer)/sizeof(wszFormatNameBuffer[0]);
hr = MQPathNameToFormatName((unsigned short*)Qname,wszFormatNameBuffer,&dwFormatNameBufferLength);
if (FAILED(hr))
{
MessageBox(NULL,"hr failed","RECIEVE",MB_OK);
}
if(hr==MQ_OK)
{
hr = MQOpenQueue(
wszFormatNameBuffer, // Format name of the queue
MQ_RECEIVE_ACCESS, // Access mode
MQ_DENY_NONE, // Share mode
&hQueue // OUT: Queue handle
);
//return hQueue;
}
else
{
hr = MQCreateQueue(
pSecurityDescriptor, // Security
&QueueProps, // Queue properties
wszFormatNameBuffer, // Output: Format Name
&dwFormatNameBufferLength // Output: Format Name length
);
}
MQMSGPROPS pmsgprops;
MQPROPVARIANT *paVariant;
MSGPROPID * paPropId;
DWORD dwcPropId = 0;
//
// The output parameters to an asynchronous call to MQReceiveMessage
// should be kept intact until the operation completes, you should
// not free or reuse them until the operation is complete.
//
//pmsgprops = new MQMSGPROPS;
paVariant = new MQPROPVARIANT[ 10];
paPropId = new MSGPROPID[ 10];
//////////////////////////////////////////////////
// Prepare the message properties to be retrieved.
/////////////////////////////////////////////////
// Set the PROPID_M_BODY property.
paPropId[dwcPropId] = PROPID_M_BODY; //PropId
paVariant[dwcPropId].vt = VT_VECTOR|VT_UI1; //Type
paVariant[dwcPropId].caub.cElems = MSG_BODY_LEN ; //Value
paVariant[dwcPropId].caub.pElems = new unsigned char[ MSG_BODY_LEN];
dwcPropId++;
////////////////////////////////
// Initialize the MQMSGPROPS structure
///////////////////////////////
pmsgprops.cProp = dwcPropId; //Number of properties
pmsgprops.aPropID = paPropId; //Ids of properties
pmsgprops.aPropVar = paVariant; //Values of properties
//pmsgProps->aStatus = NULL; //No Error report
///////////////////////////////////////////////
// Receive the message using callback function
// ReceiveCallbackRoutine.
///////////////////////////////////////////////
//hr = MQReceiveMessage(hQueue,100,MQ_ACTION_RECEIVE,pmsgprops,NULL,NULL,NULL,NULL);
hr = MQReceiveMessage(
hQueue, // Handle to the Queue
100, // Max time (msec) to wait
MQ_ACTION_RECEIVE, // Action
&pmsgprops, // Properties to retrieve
NULL, // No OVERLAPPED structure
NULL, // Callback function
NULL,
MQ_NO_TRANSACTION // No Cursor
);
// the following error is occured
if (FAILED(hr))
{
MessageBox(NULL,"Error","RECIEVE",MB_OK);
}
Regards
shakumar
shakumar
|
|
|
|
|
CInternetSession session;
thrown an assertion error in afxwin1.inl Line 27.
what must i do?
|
|
|
|
|
Hi,
I am programming a COM object in C++, to be used in a Visual Basic Apllication.
I want to know if there is a way to separate the interface members with namespaces like this
Study.FramesOfReference.Series.Item()
where Study is a COM Object that contains a CoClass FramesOfReference which Contains a CoClass Series wich has a method Item()
Thank U very Much
Juan
JO
|
|
|
|
|
I need to create a shell extension similar to the already existing "Sent To->Email Recipient"
The only difference is that rather than creating a new mail message with a files as attachments, I want to create a new message with the file paths in the message body. Preferably I'd like to have the files linked so the recipient can just click on the link and have the file open up (everyone in the network has access to common network drive) ...
I've toyed around with just doing registry stuff (not using VC++ or ATL) and I got pretty close. It would work fine for 1 file, but if I selected 10 files, it would create 10 new messages (one for each file path).
... Anyways, I followed the excellent shell extension guide found here: http://www.codeproject.com/KB/shell/shellextguide1.aspx[^] and I have the extension all laid out the way I want it. It registers fine and is displayed perfectly.
I'd like to know what the best approach from here would be as far as actually creating a new email message... I tried using System::Diagnostics::Process::Start, but the .Net & clr stuff didn't seem to work out to well...
Any suggestions?
|
|
|
|
|
When I follow the link to the WTL documentation project:
http://www.codeproject.com/KB/wtl/wtldocs2.aspx[^]
I get an error message that's telling me that an error occurred in the page.
I could access the page a few weeks ago. Anybody else with this problem?
|
|
|
|
|
I encountered strange problem with WTL program I'm trying to make (please bear with me because I'm not a pro, programming is just my hobby). I'm trying to make a program to view any image directly from zip (something like CDisplay, but with FreeImage and ZipUtils).
I reused code of a WTL Bitmap viewer example (from original WTL package).
I'm switching 2 views in SDI application (see http://www.codeproject.com/KB/wtl/switchviews_wtl.aspx), one flicker-free image display (generic view) and a CListViewCtrl thumbnails list (not a control in client, I use whole view#2 window).
I build with VC8ExpressSP1 + Platform SDK2003R2 + WTL latest version.
Essential code:
<br />
class CMainFrame : public CFrameWindowImpl<CMainFrame >, public CUpdateUI<CMainFrame >,public CMessageFilter, public CIdleHandler, public C_ImgArchive<br />
{<br />
public:<br />
DECLARE_FRAME_WND_CLASS(NULL, IDR_MAINFRAME)<br />
<br />
CIAVView m_view;<br />
CThumbView m_thumbview;<br />
<br />
BEGIN_UPDATE_UI_MAP(CMainFrame)<br />
END_UPDATE_UI_MAP()<br />
<br />
BEGIN_MSG_MAP(CMainFrame)<br />
MESSAGE_HANDLER(WM_CREATE, OnCreate)<br />
.....<br />
CHAIN_MSG_MAP(CUpdateUI<cmainframe>)<br />
CHAIN_MSG_MAP(CFrameWindowImpl<cmainframe>)<br />
END_MSG_MAP()<br />
<br />
....}<br />
<br />
LRESULT CMainFrame::OnCreate(UINT , WPARAM , LPARAM , BOOL& )<br />
{<br />
<br />
m_hWndClient=m_thumbview.Create(m_hWnd, rcDefault, NULL,<br />
WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | LVS_ICON | LVS_SINGLESEL | WS_EX_COMPOSITED);<br />
<br />
m_view_hWnd=m_view.Create(m_hWnd, rcDefault, NULL, <br />
WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN);<br />
<br />
....<br />
}<br />
<br />
<br />
<br />
class CIAVView : public CScrollWindowImpl<CIAVView ><br />
{<br />
public: <br />
DECLARE_WND_CLASS_EX(NULL, CS_HREDRAW | CS_VREDRAW, -1)<br />
BEGIN_MSG_MAP(CIAVView)<br />
MESSAGE_HANDLER(WM_ERASEBKGND, OnEraseBackground)<br />
...<br />
CHAIN_MSG_MAP(CScrollWindowImpl<ciavview>)<br />
END_MSG_MAP()<br />
<br />
void DoPaint(CDCHandle dc);
...<br />
}<br />
<br />
class CThumbView: public CDoubleBufferWindowImpl<CThumbView, CListViewCtrl><br />
public:<br />
DECLARE_WND_SUPERCLASS(NULL, CListViewCtrl::GetWndClassName())<br />
<br />
CImageList m_ImageListThumb;<br />
<br />
BEGIN_MSG_MAP(CThumbView)<br />
... <br />
END_MSG_MAP()<br />
...<br />
}<br />
<br />
</ciavview></cmainframe></cmainframe>
The problem is: in debug version all is fine with window redrawing
but in release version my flicker-free window is never updated, even when it is the first-in-order ID view.
If I drag it's contents out of the screen, it gets redrawn at those parts that go out of screen.
When there is just one wiev, there's no problems. There is another issue with thumbnails-list not displaying properly, but I circumvent it with showing/creating thumbview window first. (playing with WS_CLIPSIBLINGS or WS_CLIPCHILDREN doesn't have any effect, except not drawing anything where it should)
I seem to me that my "flicker-free" view window never receives WM_PAINT message in release version.
Is this somehow related to debugger-window-activations -stuff (I vaguely remember reading somewhere something like that)...?
I can provide full source code if neccesary.
modified on Friday, December 14, 2007 9:13:09 PM
|
|
|
|
|
|
I can't find any tutorials on implementing WTL with COM. I have no knowledge of ATL itself. No decent guides around and none on here.
|
|
|
|
|
AFAIK, WTL is just an extension to ATL. Thus, you create COM the same way you would with ATL.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
My friend says I need to have ATL knowledge before tackling WTL with COM. Know any good ATL tutorials. Cause I can't find any decent ones on here from start to finish,
|
|
|
|
|
You won't find many tutorials on the web. However, I can recommend a book:
ATL Internals: Working with ATL
Second Edition
Tavares, Fertitta, Rector and Sells
ISBN: 0-321-15962-4
Geo
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
Kuryn wrote: I have no knowledge of ATL itself
What about COM itself? If not the best book I ever read for COM was Inside COM[^]
No ATL in that book but IMHO knowing COM well is a prerequisite to understanding ATL.
For ATL did you try the MSDN Tutorial[^]?
|
|
|
|
|
WTL is more about GUI programming than COM. ATL itself has COM-related classes like smart pointers and IDispatch implementations.
|
|
|
|
|