|
DISPID_BEFORENAVIGATE2 event is fired before navigating to a URL, It will be called several time before the final page due to redirect. The first event should be that of the url set in the Navigate() and then events for redirected urls. The advantage of DISPID_BEFORENAVIGATE2 is that you can cancel the redirection. please check whether the first event of DISPID_BEFORENAVIGATE2 has the original url.
|
|
|
|
|
Hi, Rajkumar.
Thanks for the idea. I'd actually checked this one, and the results are inconsistent. If I launch a new tab by calling Navigate(), this event is only fired once and a call to m_pBrowser->get_LocationURL(&bstrUrl); yields an empty string.
On the other hand, if I set the breakpoint and click on the link to CP from your email, it's called numerous times as you predicted.
In a third scenario, if I click the empty tab to create a new one, it's called with an empty string (not "about:Tabs"); When next navigating to a new page via the address bar UI, e.g. practicalusa.com, it is again only called once and yields not the practicalusa.com site, but rather the previously expected "about:Tabs."
And of course, this is all without even getting into the issue of domain level redirects. Consequently, I've not found a dependable way of determining what the original url was that I passed into Navigate().
Heaven forbid this should be easy.
|
|
|
|
|
Hi,
m_pBrowser->get_LocationURL(&bstrUrl); return the url the Webbrowser control is currently displaying, BeforeNavigate is the stage at which no url is Completed its Navigation or displayed (I think it updated after Navigate complete or Document complete). And that is the reason you got "about:Tabs." when you expected "practicalusa.com" since "about:Tabs." is the previous navigated url.
you need to check the parameter of the event, (second parameter url of BeforeNavigate2)
void DWebBrowserEvents2::BeforeNavigate2(
IDispatch *pDisp,
VARIANT *&url,
VARIANT *&Flags,
VARIANT *&TargetFrameName,
VARIANT *&PostData,
VARIANT *&Headers,
VARIANT_BOOL *&Cancel
);
I checked it in MFC classes, that get_LocationURL() returns empty string as you said.
the number of time event fired is inconsistent depends upon the number of redirects.
modified on Friday, May 9, 2008 12:55 AM
|
|
|
|
|
That was the silver bullet. Thanks, man - you rock!
|
|
|
|
|
how can I programmatically enable "File & Printer sharing for Microsoft Networks" ?
Are here any solution which works under XP and Vista ?
|
|
|
|
|
I have similiar question/problem about chars and LPTSTR.
I have some C++ code that copiles in Studio 6.0:
CWinApp *app = AfxGetApp();<br />
<br />
char m_commandLine[40];<br />
strcpy(m_commandLine, app->m_lpCmdLine);
but doesn't do so in Studio 2005:
error C2664: 'strcpy' : cannot convert parameter 2 from 'LPTSTR' to 'const char *'<br />
<br />
1> Types pointed to are unrelated;<br />
conversion requires reinterpret_cast, C-style cast or function-style cast
Rather than doing the "reinterpret_cast", is there some setting in compiler that I need regarding the workings with char *s, CStrings?
(I am running into char/CString problems porting to Studio 2005.)
Thanks in advance,
Johnny
|
|
|
|
|
How a LPTSTR maps to a character type is dependent on the definition of the macro _UNICODE.
With _UNICODE defined, the character type is wchar_t.
With _UNICODE not defined, the character type is char.
Your project has _UNICODE defined, so you're trying to copy a wchar_t array to
a char array. Not good (and a cast would mask the problem!).
See Generic-Text Mappings[^]
You could do something like this:
TCHAR commandLine[40];
strcpy(commandLine, app->m_lpCmdLine); // 2nd is LPTSTR and 1st is char [max]
or better yet:
CString commandLine(app->m_lpCmdLine);
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks! I will look through my settings (.vcproj and .sln) to see what is going on.
Best regards,
John
|
|
|
|
|
App which would work on every Windows system.
Will setting "include MFC as a static library" do the trick?
I had programs compiled with Debug and not Release and they didn't work on certain machines (without vs08 of course). I realize that they should be compiled in Release configuration, however now i want to be SURE, before I go and check it out (if won't work, it will be to late...).
Greetings - Gajatko
Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.
|
|
|
|
|
gajatko wrote: I had programs compiled with Debug and not Release
Don't tell it toxcct or you'll be flamed.
Anyway you should never deploy debug builds of your applications.
Have a look at http://msdn.microsoft.com/en-us/library/ms235299.aspx[^]
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.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
gajatko wrote: App which would work on every Windows system.
Will setting "include MFC as a static library" do the trick?
Not necessarily. What if you are using an API or a function that is not supported on a particular platform? It wouldn't matter how you linked to the MFC libraries at that point.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I am looking for a way to override the maximize button for the main window in an MDI application. I have found several articles telling me how to override the maximize button for the child window, but not the main window. What I need is when the User clicks on the maximize button the application maximizes itself to two monitors instead of just one monitor. I hope that somebody can help me.
|
|
|
|
|
You need to handle the WM_SYSCOMMAND message.
void CMainFrame::OnSysCommand(UINT nID, LPARAM lParam)
{
switch(nID)
{
case SC_MAXIMIZE:
break;
case SC_MINIMIZE:
break;
case SC_CLOSE:
break;
}
CFrameWnd::OnSysCommand(nID, lParam);
}
Best Wishes,
-David Delaune
|
|
|
|
|
Thank you that was extremely helpful
|
|
|
|
|
I need someone to please help me figure out how to get a TCHAR into a CString; when I will NOT know in advance what the TCHAR will be. Here's my code:
// SysData.h : header file
//
#pragma once
// CSysData
// Class that contains the System File Data
class CSysData
{
public:
// Functions:
CSysData(); // Default Constructor
~CSysData(); // Default Destructor
void CreateDirectoryName(CSysData cData);
void CleanUp(void);
// Copy Constructor:
CSysData(const CSysData& cSource);
// Assignment operator:
CSysData& operator= (const CSysData& cSource);
CString SetPathName(CString str);
//Varables:
CString m_csOperatorName;
CString m_csWellName;
CString m_csPath;
CString m_IsFileName;
CString m_csDirections;
CString m_csTanks;
};
Here's how I obtain the path:
CString CSystemDB::SetPath(CSysData cSysData)
{
CString str, str1, str2, str3;
str1 = _T("c:\\Wells\\Program\\DataBases\\Operators\\");
// Make path for SystemDB.bku file for each Operator:
str3 = "c:\\Wells\\Program\\DataBases\\SystemDB\\SystemDB.bku";
m_csSystemDB_BKU = str3;
// Make path for SystemDB.sdb file for each Operator:
str2 = "c:\\Wells\\Program\\DataBases\\Operator\\";
str2 += cSysData.m_csOperatorName;
str2 += _T("\\");
str2 += "SystemDB.sdb";
m_csSysNameTMP = str2;
str = str1;
str += cSysData.m_csOperatorName + _T("\\");
str += cSysData.m_csWellName;
str += _T("\\");
m_vSys.m_cSysData.m_csPath = str;
DoDirectory(m_vSys.m_cSysData);
// Now get the file filename:
cSysData.m_IsFileName = cSysData.m_csWellName;
cSysData.m_IsFileName += ".wdb";
m_csFileName = str;
}
The cSysData data was collected from dialog editbox input from the User.
now I must open a CStdioFile using a TCHAR filename. m_csFileName has that filename at this point, BUT it is not a TCHAR. How do I make it into a TCHAR? I simply don't know how. Mark showed me how to do it using the CString Constructor, but this is not possible after the CString has already been constructed.
Can someone please help me?
A C++ programming language novice, but striving to learn
|
|
|
|
|
sorry, i don't really get your question.
if you want to get a char (TCHAR) at a certain position, use CString::operator[]() or CString::GetAt()
if you want to retrieve a certain character (TCHAR), use CString::Find()
and please, please, PLEASE, format your code samples using <pre></pre> tags
|
|
|
|
|
Probably you need a const TCHAR * : just pass the CString itself.
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.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Larry Mills Sr wrote: now I must open a CStdioFile using a TCHAR filename.
Why? What's wrong with:
CStdioFile file(m_csFileName, CFile::modeRead);
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Larry Mills Sr wrote: BUT it is not a TCHAR. How do I make it into a TCHAR?
Hello Larry,
You seem to reiterate the same questions regarding TCHAR which implies that you may be confused about the subject. First thing you should know is that technically there is no such thing as a TCHAR. TCHAR simply means "Template Character" and is simply a wrapper definition for both wchar_t and char based on whether or not UNICODE is defined. In other words if UNICODE is defined then TCHAR=wchar_t otherwise its a char.
All you need to do is enable unicode support in your project and CString will default to CStringW and TCHAR will default to wchar_t. Thats all you need to do. There are some functions which may require you to convert the wchar_t to multi-byte and if you run into these types of functions you can use my previous answer to convert the wchar_t to char[^].
Best Wishes,
-David Delaune
|
|
|
|
|
More here...[^]
Larry Mills Sr wrote: m_csFileName has that filename at this point, BUT it is not a TCHAR. How do I make it into a TCHAR?
Actually the character type of the string IS the same as TCHAR.
As David mentioned, a TCHAR is just a conditional macro whose resulting type is based
on whether the _UNICODE macro is defined or not. CString is the same - its
internal string character type is determined by the same Unicode macro being defined
or not defined.
I'm still not sure where in your code you think you need this "TCHAR"...
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark,
You showed me yesturday to get a CString set for TChar you have to do so in it's constructor. Naturally all members of a class(ie, CSysData cSysData in my case) are iniatized upon insanitation therefore I would not be able to do as you did in your example using my class. So naturally I am confused and have no way of knowing what to do next, which is why I included the class header and the function(SetPath(....)) to show you and everyone else what I was doing.
This operation has to be done correctly because throughout the program I'm writing most functions will need some data from the file this class (CSysData) establishes.(ie, SystemDB.sdb).
I'm not sure what David means by setting CString to UNICODE. How, exactly? and How will that setting effect SetWindowTextW(IDC_NAME,str);(where str is CString str) or GetWindowText(str); Do you use a CString or do you have to use something else? to get the data?
A C++ programming language novice, but striving to learn
|
|
|
|
|
Larry Mills Sr wrote: are iniatized upon insanitation
Yes sometimes it happens that way.
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.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Larry Mills Sr wrote: You showed me yesturday to get a CString set for TChar you have to do so in it's constructor.
That was yesterday, and only to specifically get the file to open,
which I thought was the problem. That was a code example which hard-coded
a valid pathname so you could check your file handling code.
This string issue is entirely separate, and I'm not sure what problem you're
having at this point Compiler errors? Runtime errors? Step through with
the debugger (it's only a handful of lines of code) and watch the value of your
strings. If they're not doing what you want, then fix the code.
Larry Mills Sr wrote: I'm not sure what David means by setting CString to UNICODE. How, exactly?
With visual studio projects, typically you just use the project/general/character set setting.
If you set this to use Unicode character set, then VS adds "/D "_UNICODE" /D "UNICODE"" to the compiler
command line. This defines two macros: _UNICODE and UNICODE. Now if you look at the header files
for CString(T) and TCHAR, you'll see that the definition of _UNICODE affects the character type
of those generic string types.
Larry Mills Sr wrote: How will that setting effect SetWindowTextW(IDC_NAME,str);(where str is CString str) or GetWindowText(str);
You use a CString and that's it. Any method that takes a CString is already coded
to take generic strings into consideration. All you have to be concerned with is passing
the appropriate type. If a method expects a CString, then pass it a CString.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote:
With visual studio projects, typically you just use the project/general/character set setting.
If you set this to use Unicode character set, then VS adds "/D "_UNICODE" /D "UNICODE"" to the compiler
command line. This defines two macros: _UNICODE and UNICODE. Now if you look at the header files
for CString(T) and TCHAR, you'll see that the definition of _UNICODE affects the character type
of those generic string types.
Please be patient; I don't want to mess anything up in the compiler. Are you saying I need to go into the compiler settings and ADD a "/D" to it's settings in order for my CStrings to work as correct filenames? for "CStdioFile". Or did I missunderstand you?
A C++ programming language novice, but striving to learn
|
|
|
|
|
Larry Mills Sr wrote: Are you saying I need to go into the compiler settings and ADD a "/D"
No. That's what the Visual Studio does for you when you change the character set setting.
I still don't know what problem(s) you're having...
Compiler errors? Linker errors? Runtime errors? Not doing what you expect it too when it runs?
Larry Mills Sr wrote: in order for my CStrings to work as correct filenames? for "CStdioFile".
You don't have to do anything.
CStdioFile::Open(), for example, takes a LPCTSTR as an argument.
Since CString has a LPCTSTR casting operator, you can use a CString anywhere a LPCTSTR
is expected:
CStdioFile file;
file.Open(SomeCString, ...
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|