|
CWnd has a static member function FromHandle which will give you a (possibly) temporary object. If an object is already attached to a window handle, you'll get a base class pointer to that object, and you can safely upcast it. If not, then you'll get a pointer to a temporary object, which may well only exist while the current message is being processed.
Steve S
|
|
|
|
|
Abhay-
I'm trying to do much the same thing myself, if I understand your message correctly. I need to access the methods/properties of COM objects that already exist within another application.
The approach I am taking (though I've not yet succeeded) is to create a CAxWindow instance using the HWND of the target window, then call the method CAxWindow::QueryControl(). (An alternative is use of the AtlAxGetControl() function.) In theory, this would provide a pointer to the object's IUnknown interface, or any other interface if the appropriate interface ID were passed in. From that, it should be possible to invoke methods of the interface that is returned.
As I said, I have not yet succeeded in this task, which is why I was scanning this message board. I'll keep trying the above approach and searching other resources, but if anyone has any insight on this topic, I would appreciate it- and I'm sure Abhay would as well!
Bob
|
|
|
|
|
Hi
I´m trying to create an instance of:
CComQIPtr<IInputObjectSite>pInputObjectSite;
but i´m getting error 2787 (No guid has been associated with this object).
The guid is declared in shlguid.h, and this file is included in the project. Why it doesn´t recognize it?
Thanks
Gabriel
Old C programmers never die. They just cast into void
|
|
|
|
|
try IID_IInputObjectSite as the template parameter
|
|
|
|
|
Thanks for your suggestion. It worked. I formerly posted that it didn´t work but i was really tired and i was forgetting the & before the GUID.
Gabriel
Old C programmers never die. They just cast into void
|
|
|
|
|
Is there a way I could get to see the value of an iterator?
IOW, if I am doing something at the 525th place in a vector, is there a way I could get the iterator to show me its position?
Thanks for any insight.
William
Fortes in fide et opere!
|
|
|
|
|
You can subtract iterators just like you can subtract pointers:
vector<int> v(600);
vector<int>::iterator it = v.begin() + 525;
cout << it - v.begin() << endl; Prints 525.
--Mike--
Ericahist [updated Oct 26] | CP SearchBar v2.0.2 | Homepage | RightClick-Encrypt | 1ClickPicGrabber
"Linux is good. It can do no wrong. It is open source so must be right. It has penguins. I want to eat your brain."
-- Paul Watson, Linux Zombie
|
|
|
|
|
Clever!!
But you still didn't answer the question, because (let's suppose) 'v.begin' has the internal value of 306759. By assigning its internal value plus 525 (as follows)
vector<int>::iterator it = v.begin() + 525; you are essentially adding 306795 to 525 giving 'it' the value of (525 + 306795) = 307320. Then you turned right around and did (307320 - 306795) which very logically gives you the difference of 525 (the same number you just added to 'v.begin()', the subtrahend).
IOW, you didn't give me the value of either the minuend nor the subtrahend. You simply gave me the numerical difference between them, which is the same number you added to one of them in the first place.
What I want to know is whether I am able to see the value of 'v.begin()' or 'it' after (let's say) 525 has been added to it.
William
Fortes in fide et opere!
|
|
|
|
|
No - an iterator may not have a simple value - i.e. an iterator is NOT neccesarily a pointer. For example, in VC++ 7.0, std::string::iterator is a struct , not a char* .
Now, it sounds to me like you're looking for a pointer to the element the iterator references, which you can get hold of using &*it , where it is an iterator.
Stuart Dootson
'Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p'
|
|
|
|
|
Michael Dunn has the right idea. The key concept of iterators is that they are an abstraction for accessing containers and don't necessarily know their own position. For example, take the iterator for the std::list template. This iterator implements the bidirectional iterator model meaning that it merely needs to know the previous node and the next node in a container. For std::list , that means that it just needs a reference to a single node in the doubly-linked list -- it has no concept of where that node is in the list.
Here's an example as to why this is important: Let's say that you have a list and you start iterating through it. Somewhere in the middle, you insert a node somewhere in the list. This does not invalidate the iterator, so you can still happily keep moving around the list. If the iterators kept track of the position, the list would have to keep track of every single iterator and notify them that their position has been changed. Or they could just get invalidated, which is worse.
Even a std::vector iterator (which implements the random access iterator model) probably doesn't know what position in the vector it points to -- most implementations just store a pointer to the item, not an index, and some older implementations typedef the iterator type to a pointer directly! However, it means that it can find out the relative distance to another iterator, so subtracting iterators produces a useful result.
As far as I can tell, only a random access iterator needs to implement subtraction. Other iterator types probably won't compile when you try to subtract them.
- Mike
|
|
|
|
|
Michael Imamura wrote:
random access iterator needs to implement subtraction
Really, you should use std::distance - that's guaranteed to work on anything more complex than an InputIterator (see this page[^].
<edit>Whoops - wrote this before looking at your next response</edit>
Stuart Dootson
'Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p'
|
|
|
|
|
Stuart Dootson wrote:
Really, you should use std::distance
Isn't operator- overloaded for such iterators?? They must be, because they all are supposed to mimic pointers. My STL book is at work. :grumble:
Argh. No. Random iterators only. I'll get some sleep now.
--
The moment of terror is the beginning of life.
|
|
|
|
|
Heh - saved me looking it up
I think they did it that way to make it more difficult to determine the distance between iterators where it implies an inefficient implementation. For example, with linked list iterators (bidirectiuonal iterators?), it's an O(n) operation, whereas for random-access iterators, it's O(1).
Stuart Dootson
'Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p'
|
|
|
|
|
Yikes -- sorry for the long-winded response. I forgot to mention how to find the relative position between two non-random-access iterators. The trick is to use the std::distance function:
using namespace std;
typedef list<int> intlist;
int _tmain(int argc, _TCHAR* argv[]) {
intlist lst;
lst.push_back(1);
lst.push_back(2);
lst.push_back(3);
lst.push_back(4);
lst.push_back(5);
intlist::iterator iter = lst.begin();
++iter;
++iter;
cout << static_cast<int>(distance(lst.begin(),iter)) << endl;
return 0;
} Outputs 2 as expected.
A warning: For bidirectional iterators, distance is a linear-time operation.
- Mike
|
|
|
|
|
Thank you for replying.
Your response was neither long-winded, nor off-beat; to the contrary, I found it to be eloquent and informative.
Since I'm dealing with iterators of vectors, maps and multimaps, I'll restrict myself to the way iterators pertain to them.
There is this huge vector of strings I'm dealing with that acts as the repository of data. The data are classified (meaning, categorized and differentiated) according to certain criteria. For example, when the program is handling blue data, they are deposited to the vector, but their place in the vector is being recorded in the multimap relative to where (in the vector) they are located. This means there is a beginning and an ending point the multimap record for each set of color data. The same is done for red data, green data, yellow data (etc.).
The idea is that someone can go to the multimap and find where all the red data reside in the vector. (The same for blue data, and green data, etc.) This is because each entry in the multimap records a beginning and an ending point for each different set of data. Those beginning and ending points relate to positions in the vector, and herein is where I'm experiencing iterator nightmares.
While the entry of data to the vector is done sequentially through a series of "push_back()'s", the simple idea of using "v.begin()" and "v.end()" to register boundaries for the various colors, isn't turning out to be a walk in the park. For example, "v.end()" of one color does not always lend itself valid as far as where the next color should begin. IOW, "v,end()" is NOT necessarily "v.begin()" for the next color, which has caused me to look at everything pertaining to iterators.
This is why I was thinking of checking the value of "v.end()" iterator to determine if there might be some break, or incorrect value being passed to "v.begin()" for the next set of color data.
BTW, I'm just using colors figuratively to distinguish one set of data from another.
William
Fortes in fide et opere!
|
|
|
|
|
How come this code fails with the ATLASSERT( ::IsWindow(m_hWnd) );?
This code is in my CMainFrame and I'm tring to show a dialog.
CPrintDialog dlg(FALSE);
...
TCHAR sTitle[_MAX_FNAME] = {0};
AtlLoadString( IDR_MAINFRAME, sTitle, _MAX_FNAME );
dlg.SetWindowText( sTitle );error here
// Show it
Thank You
Bo Hunter
|
|
|
|
|
|
i didn't find any metohod in CListViewCtrl that can set the height of the item, can someone tell me how to do it? thanks in advance
|
|
|
|
|
The simpliest way is to use image list, like the following:
m_ImageList.Create(1,20,ILC_COLOR,1,1); // set height to 20 pixels
m_List.SetImageList(&m_ImageList,LVSIL_SMALL);
|
|
|
|
|
If ur ok 2 handle Ownerdraw then just override MeasurItem and set the item hight as u like by using the struct parameter in MesureItem.
|
|
|
|
|
Here in the (un)real world, I've just come across a problem. We have some COM+ components, including a database layer which uses OLE DB, via ATLDBCLI.H
There is a template class wrapping CCommand, which depending on parameters will set required properties. One of these is DBPROP_SERVERDATAONINSERT, which is useful when using server-generated data, like IDENTITY columns.
However, I now find that in cases where this is erroneously added (ie no insert is allowed), this causes the Open to fail with a multiple-step error, and by the time I find out, I can't get any more detailed information.
With MDAC 2.7, this wasn't an issue, but it seems to be so now with 2.8.
Is anyone else aware of this? I haven't looked in the MS newsgroups for a little while (although I use CP every day..), but I thought I'd raise it here in case anyone else is having similar issues.
I'm slowly going through the affected code, which, thankfully, is only in one component, albeit spread over 20+ files.
Steve S
|
|
|
|
|
i compiled a atl project to implement dhtm binary behavior by vc6.0.
but, the error, 'IElementBehavior' : base class undefined, had appeared.
i included mshtml.h in my project.but i find that the interface 'IElementBehavior' is not in it. why?help me.thanks.
vc++6.0 winxp pro
|
|
|
|
|
Hi,
How can i get the reference to an activex control using handle.
Regards
Abhay
eeeshwar
|
|
|
|
|
Hi.
I have some ATL dialog which hosts web browser on it and I would wish to disable the context menu opened on the web page running in it. I have no
option to do it with script built in on the web page itself - cause this
would get changed dynamically and I have no control on its content. Is
there any technique to do this from ATL dialog itself?
Thanks
|
|
|
|
|
I have made a dialog-based WTL application in VS.NET.
I'm trying to make one edit window act as a command prompt. I would therefore like to receive a notification in the parent dialog when the user presses carriage return in the edit control.
I have tried to use the example by Kristian Lippert in his article Subclassing controls in ATL dialogs using WTL[^] but with no luck. It seems that the sub-class does not receive the WM_KEYDOWN or WM_CHAR at all (does receive WM_CHAR when typing some text).
First I thought that I could just use the IDOK-notification and use the control ID or the control hWnd parameters of the notification. But they are "empty" no matter which control has the focus when CR is pressed.
Any help appreciated.
Below is my control-template:
#define EN_GOT_RETURN 0x1000<br />
<br />
template <class T><br />
class CEditEnterNotificationT : public CWindowImpl<CEditEnterNotificationT<T> , CEdit><br />
{<br />
public:<br />
BEGIN_MSG_MAP(CEditEnterNotificationT< T >)<br />
TRACEMSG("CEditEnterNotification");<br />
MESSAGE_HANDLER(WM_CHAR, OnChar)<br />
MESSAGE_HANDLER(WM_KEYDOWN, OnKeyDown)<br />
END_MSG_MAP()<br />
<br />
CEditEnterNotificationT(HWND hWnd = NULL){ }<br />
<br />
CEditEnterNotificationT< T >& operator=(HWND hWnd)<br />
{<br />
m_hWnd = hWnd;<br />
return *this;<br />
}<br />
<br />
LRESULT OnChar(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)<br />
{<br />
switch (wParam)<br />
{<br />
case '\r':
ATLTRACE("WM_CHAR - CR\n");<br />
return 0;<br />
break;<br />
}<br />
return DefWindowProc(uMsg, wParam, lParam);<br />
}<br />
<br />
LRESULT OnKeyDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)<br />
{<br />
switch (wParam)<br />
{<br />
case VK_RETURN:<br />
ATLTRACE("WM_KEYDOWN - CR\n");<br />
::PostMessage (m_parent, WM_COMMAND, MAKELONG(EN_GOT_RETURN, this->m_dlgItem), LPARAM(this->m_hWnd));<br />
bHandled = TRUE;<br />
return FALSE;<br />
}<br />
return DefWindowProc(uMsg, wParam, lParam);<br />
}<br />
<br />
BOOL AttachToDlgItem(HWND parent, UINT dlgID)<br />
{<br />
m_dlgItem = dlgID;<br />
m_parent = parent;<br />
HWND hWnd = ::GetDlgItem(parent,dlgID);<br />
return SubclassWindow(hWnd);<br />
}<br />
private:<br />
UINT m_dlgItem;<br />
HWND m_parent;<br />
};<br />
<br />
typedef CEditEnterNotificationT<CWindow> CEditEnterNotification;<br />
|
|
|
|
|