|
Yes, I want to show a dialog *after* showing the application window. All solutions I have tried will show the dialog before painting the application window.
Err.. I am not sure what you mean with "what kind of pointer do you have in CView derived class".
The only flaw in my application (that I know of ) is that the dialog should be iniated automatically instead of having to iniate it from menu. The menu item is handled in CView derived class (CMyView), in OnFileSelectserver() function. That function has calls to CDocument derived class (CMyDocument).
So I need to be able to call CMyView::OnFileSelectserver() from inside CWinApp based class (CMyApp), in InitInstance(). How to do that?
Putting the CMyView::OnFileSelectserver() in CMyView::OnInitialUpdate() causes the dialog to be shown first, then a pause as the program gathers data and only after that the application is shown. Doing that skips the progress bar and gives the impression that nothing is happening. That's the problem. First application window, THEN dialog.
|
|
|
|
|
Add the following code lines in your InitInstance function of your application:
...
m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow();
CYourView* pView = (CYourView*) ((CFrameWnd*) m_pMainWnd)->GetActiveView();
pView->SendMessage(WM_COMMAND, ID_for_your_OnFileSelectserver_menu_item, 0);
return TRUE;
Insert the right ID for the ID_for_your_OnFileSelectserver_menu_item in the SendMessage function.
I hope this helps you!
Daniel
---------------------------
Never change a running system!
|
|
|
|
|
This looks like exactly what I need! Thanks!
(I can't test it in action until Monday, but I am sure it will work.)
|
|
|
|
|
...aaand perfectly it did the job!
|
|
|
|
|
Fine!
Nice greets from Tyrol / Austria, Daniel.
Daniel
---------------------------
Never change a running system!
|
|
|
|
|
If you want to fire you dialog right after the application starts, that is before a document has been opened, you will have to do it as was posted. But if you want your dialog to open after a document had been loaded and its view had been created, you could use your views OnInitialUpdate() message handler.
A pointer to the active (SDI-)view can be obtained using CFrameWnd::GetActiveView() .
(For MDI, there is a possibility shown in that MSDN entry).
--
"My opinions may have changed, but not the fact that I am right."
Found in the sig of Herbert Kaminski
|
|
|
|
|
Hello,
I'm using this code but I'm novice with all the vars involved (it's the first time I use them) and I don't know how to free them...
This code is very used in my app and I can see that the memory resources are getting smaller and smaller every cycle...
//---------------------------------------------
// VARIABLES INVOLVED...
//---------------------------------------------
IHTMLDocument2* pHTMLDocument2;
LPDISPATCH lpDispatch;
IHTMLElement* pBody;
BSTR bstr;
HRESULT hr;
//---------------------------------------------
// CODE USED
//---------------------------------------------
lpDispatch = this->m_HTMLCtrl.GetHtmlDocument();
if (lpDispatch)
{
hr = lpDispatch->QueryInterface(IID_IHTMLDocument2, (LPVOID*)&pHTMLDocument2);
lpDispatch->Release();
hr = pHTMLDocument2->get_body(&pBody);
bstr = csCodiHTML.AllocSysString();
if (pBody)
{
pBody->put_innerHTML(bstr);
pBody->Release();
}
SysFreeString(bstr);
}
|
|
|
|
|
Well you never seem to release the pHTMLDocument2 interface. Thats probably your problem. Then you would probably be better off using smart pointers. If you are using ATL (which you should be ) you can use the CComPtr<> template class. There are even some predefined smart pointers that have already beed defined, IHTMLDocument2Ptr and IDispatchPtr to name few. Then you should be using CComBSTR to manage all BSTR's you are allocating. You can use it directly with CString:
<br />
CString strHTML( _T("some html code") );<br />
CComBSTR bstrHTML = strHTML;<br />
But of course you still need to learn the refcounting rules of COM if you want to know what you are doing
Wenn ist das Nunstück git und Slotermeyer? Ja! Beierhund das oder die Flipperwaldt gersput!
|
|
|
|
|
OK, I've placed the release that you've mentioned...
but is still behaving equal...
I'm thinking on try the other mentioned method:
dabs wrote:
CComPtr<> template class.
Could you give me a little example on how to do it?
Only the guidelines on how to use those pointers:
CComPtr<IHTMLDocument2Ptr> pHTMLDocPtr;
CComPtr<IDispatchPtr> pIDispatchPtr;
pIDispatchPtr = this->m_HTMLCtrl.GetHtmlDocument(); <code>this is not working</code>
I've tried something and it has not worked, and MSDN texts are so... "esoteric" for me...
Thank you in advance...
|
|
|
|
|
CComPtr is a template, so you have to specify the template parameter, this is a first. But it might be a mistake when inserting the text here. It consider it as unknown html tag, but for any case:
<br />
CComPtr<IHTMLDocument> spHTMLDocPtr;<br />
CComPtr<IDispatch> spIDispatchPtr;<br />
the second part I am not sure how it works in your case, but the most usual use of the interface pointers is:
m_htmlCtrl.GetHtmlDocument( &spIDispatchPtr );
this is because if the method is designed as you wrote
spPtr = GetMethod();
the method probably adds one reference (AddRef) to the returned pointer, but if you attach it to the smart pointer (ccomptr) he is not smart enough here and add another more addref. So you have 2 addrefs, and only one will be released in the ccomptr destructor. Hence here you should use something like spIDispatchPtr.Attach( this->...GetHtmlDocumet() );
Hope that I am not wrong
|
|
|
|
|
Hello,
first of all thank you for your interest.
I have tried it... but the compiler has told me:
C:\sdsgfasjk.cpp(977) : error C2664: 'Attach' : cannot convert parameter 1 from 'struct IDispatch *' to 'class _com_ptr_t<class _com_IIID<struct IDispatch,&struc
t __s_GUID _GUID_00020400_0000_0000_c000_000000000046> > *'
after writting this:
spIDispatchPtr.Attach(this->m_HTMLCtrl.GetHtmlDocument());
Could you explain me what's happening (I'm getting lost...) and I should get it finished in 4 hours!
Thank you in advance...
NOTE:
seems that I'll be continue needing the CComPtr<idispatchptr> spIDispatchPtr;, how will I pass to the CComPtr<ihtmldocument2ptr> spHTMLDocPtr; (I mean how I will use them altogheter?
|
|
|
|
|
Well, the second part is easier, just change the CComPtr<IHTMLDocument> to CComQIPtr<IHTMLDocument> . Then when you do an assignment from spDispPtr, the spHtmlDoc will do the things necessary for it automatically (QI stays for QueryInterface).
Hmm, the first part, it is so, that the GetHtmlDocument doesn't add the reference (if my thinking was correct and it is GetHtmlDocument from MFC's CHTMLView). Then you have to do it as it was before spDispPointer = GetHtmlDocument() and you will be on the safe side (sorry that I didn't check the MFC sources for this, but somehow this is not correct behavior in COM, you have allways add reference to pointer you are returning). So try it and write me, what is the result then.
And please for < and > characters, use the buttons under the edit area, it might be important to see the template parameters
|
|
|
|
|
First of all thank you very much...
I've done what you've told me (at least what I've understood ):
CComQIPtr<IHTMLDocument2Ptr> spHTMLDocPtr;
CComPtr<IDispatchPtr> spIDispatchPtr;
Now seems that I won't need spIDispatchPt, but I'm getting lost again...
when I use this:
spHTMLDocPtr = this->m_HTMLCtrl.GetHtmlDocument();
spHTMLDocPtr gets an adress, but when I leave the function (just after calling the previous line) it gives me an error:
First-chance exception in TCC.exe: 0xC0000005: Access Violation.
and moreover...
it seems that in order to get acces to the HTML body I'll need again to use this:
spHTMLDocPtr->GetInterfacePtr()->get_body() and I'll be again at the beggining: having a pointer that is not being freed...
NOTE:
How will I get access to the HTML body using smart pointers?
Is there somewhere a list of those smartpointers?
Thank you very much again...
|
|
|
|
|
Hi,
one very quick issue - you should not use CComPtr<IDispatchPtr> spIDispatchPtr but
CComPtr<IDispatch> spIDispatchPtr !
Normally the workflow is something like that:
<br />
CComPtr<IHTMLDocument2> spPointer1 = GetHtmlDocument();<br />
if( spPointer1 )<br />
{<br />
CComPtr<IHtmlBody> spBody = spPointer1->get_body();<br />
...etc...<br />
}<br />
then every pointer you received have correct addref/release handling - when spBody goes out of scope, the reference is released, the same for spDispatchPtr
|
|
|
|
|
OK... understood, but I'm getting a lot of errors:
using this code:
CComPtr<IHTMLDocument2> spPointer1 = this->m_HTMLCtrl.GetHtmlDocument();
if( spPointer1 )
{
CComPtr<IHtmlBody> spBody = spPointer1->get_body();
if (spBody)
{
spBody->put_innerHTML("");
}
}
I get those error messages:
Compiling...
error C2440: 'initializing' : cannot convert from 'struct IDispatch *' to 'class ATL::CComPtr<struct ihtmldocument2="">'
No constructor could take the source type, or constructor overload resolution was ambiguous
error C2065: 'IHtmlBody' : undeclared identifier
error C2955: 'CComPtr' : use of class template requires template argument list
c:\archivos de programa\microsoft visual studio\vc98\atl\include\atlbase.h(563) : see declaration of 'CComPtr'
error C2660: 'get_body' : function does not take 0 parameters
error C2512: 'CComPtr' : no appropriate default constructor available
error C2262: 'spBody' : cannot be destroyed
error C2451: conditional expression of type 'class ATL::CComPtr' is illegal
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
error C2678: binary '->' : no operator defined which takes a left-hand operand of type 'class ATL::CComPtr' (or there is no acceptab
le conversion)
error C2039: 'put_innerHTML' : is not a member of 'CComPtr'
c:\archivos de programa\microsoft visual studio\vc98\atl\include\atlbase.h(563) : see declaration of 'CComPtr'
Error executing cl.exe.
|
|
|
|
|
I see. These errors are cased by the fact, that the IHtmlBody interface doesn't exists. I just wrote something in a sample. sorry for that I suppose it to be a sample of generic usage of smart pointers, not exact webbrowser reference
I'll have look what it is exactly... So the IHtmlBody is in fact IHTMLElement.
|
|
|
|
|
OK!
Now it works and the memory is getting freed and so on!
Thank you very much for your help!!!
More or less I've finished in the established time... (more or less)
Only one more question:
Qhere could I find a list of com smart pointers? I don't know where to get it and without you I wouldn't be able to do it because I wouldn't know where to find them...
Thank you again!
|
|
|
|
|
congratulation
well, there is nothing like list of smart pointers. CComPtr is a template - this means the actual code is 'created' during the compilation. Therefore you can create CComPtr or CComQIPtr with any interface (for being precise, must be derived from IUnknown, but for your usage it is vith every interface you can get from any of microsoft libraries), so for IHTMLElement it is CComPtr<IHTMLElement> for IDispatch it is CComPtr<IDispatch> for IHTMLForm it is CComPtr<IHTMLForm> for IAnyInterface it is CComPtr<IAnyInterface> etc. (the same is valid for CComQIPtr). Compiler then takes the parameter (what is written between <> ) and makes some specific CComPtr pointer pointing to some specific interface.
Hope it is clean for you now
|
|
|
|
|
Yes!
great...
Thank you again!
can I ask you the last question? (I promise this is the last )
If not don't continue reading!
I'll try it:
The first time I try to get the document it's an empty pointer and I cannot get access to it, but the second and the other times I can do it...
Is there any way to create a document for an HTMLView?
Let me promise that I will not bother you again...
Thank you in advance!
|
|
|
|
|
Hmm this is probably some IE specific issue I never heard about, so I am afraid I can't help you in this topic
|
|
|
|
|
Hello again...
I'll post that last question to the general forum... (I don't want to abuse...)
Thank you again! You've helped me a lot
|
|
|
|
|
btw if you look directly to mfc code, that guys does it exactly as we supposed to you:
CComPtr<IDispatch> spDisp = GetHtmlDocument();
mfc, viewhtml.cpp, line 108
|
|
|
|
|
Does anybody has experience in using CRichEditView in a Splitter window?
The scroller of the rich edit view and the scroller of the splitter window are both visible. I can hide the scroller of the rich edit view (only the scroller of the splitter window is visible).
If the rich edit view scrolls (by key up/down) I do not get the scrolling message from the rich edit to update the scroller of the splitter.
Who has ever implemented a rich edit view in a dynamic splitter window?
Does anybody know a sample application?
Berlenz
|
|
|
|
|
But why to not make it vice versa? Hide the scroll bar of slitter window, align your richedit control in all client area of splitter window and all will be pleased.
|
|
|
|
|
I use a "dynamic splitter" window. For that reason I have to show the scroller of the splitter window because it shows the splitter boxes.
Splitter Box:
A small control at the top of the vertical scroll bars or to the left of the horizontal scroll bars in a dynamic CSplitterWnd. Used to create new rows or columns of panes.
Berlenz
|
|
|
|