|
I'll try to explain what I see in the debugger.
This piece of code was used in a Browser Helper Object.
1 case DISPID_BEFORENAVIGATE2:
2 {
3 CComBSTR url = ((*pDispParams).rgvarg)[5].pvarVal->bstrVal;
4 if (url == "http://www.adatum.com" || url == "http://www.adatum.com/")
5 {
6 CComPtr<iwebbrowser2> spBrowser;
7 CComPtr<idispatch> spDisp = ((*pDispParams).rgvarg)[6].pdispVal;
8 spDisp->QueryInterface(IID_IWebBrowser2, (void**)&spBrowser);
9 spBrowser->Stop();
10 CComBSTR newURL = L"http://newdomain.com/newpage.htm";
11 spBrowser->Navigate(newURL, NULL, NULL, NULL, NULL);
12 ((*pDispParams).rgvarg)[0].boolVal = TRUE;
13 }
14 break;
15 }
I'll explain what I have while debugging:
variant 1 (opening link in the same window)
DISPID_BEFORENAVIGATE fires
string 12 works fine setting pDispParams->rgvarg[0] to True
browser Navigates to http://newdomain.com/newpage.htm
variant 2 (opening link in new window):
DISPID_NEWWINDOW2 fires
I use such string to cancel Navigation:
((*pDispParams).rgvarg)[0].boolVal = TRUE;
In debugger the value of pDispParams->rgvarg[0] becomes True but nothing happens...
DISPID_BEFORENAVIGATE fires
everything works like in variant 1 except that
string 12 doesn't work setting pDispParams->rgvarg[0] to {???}
browser Navigates to http://www.adatum.com
|
|
|
|
|
I found the problem but don't know how to solve it
The code I gave was not the same I used. I tried to add a header to Navigate2
Who could imagine that additional headers are the reason of the problem?
When the code is like this everything works fine (with additional header) only when link opens in
the same window:
---------------------------------------------------------------------
CComVariant vtEmpty;
VARIANT vtHeaders;
vtHeaders.vt = VT_BSTR;
vtHeaders.bstrVal = SysAllocString(L"addHeader:newHeader");
VARIANT vURL;
vURL.vt = VT_BSTR;
vURL.bstrVal = SysAllocString(L"http://newurl/newpage.htm");
spBrowser->Navigate2(&vURL,&vtEmpty,&vtEmpty,&vtEmpty,&vtHeaders);
---------------------------------------------------------------------
When the code is like this everything works fine (without additional header) both when link opens
in the same window and in a new window:
---------------------------------------------------------------------
CComVariant vtEmpty;
VARIANT vURL;
vURL.vt = VT_BSTR;
vURL.bstrVal = SysAllocString(L"http://newurl/newpage.htm");
spBrowser->Navigate2(&vURL,&vtEmpty,&vtEmpty,&vtEmpty,&vtEmpty);
---------------------------------------------------------------------
So the reason seems to be in headers. But I need to send additional header even if link opens in a
new window.
So the problem remains.
|
|
|
|
|
Under MyKey, on the right panel of the registry, the entries look like:
name data
-----------------------------
Folder c:\myDir
If RegSetValueEx fails, will I see
name data
-----------------------------
Folder no data here
or
name data
-----------------------------
no entry at all
I am not totally sure from MSDN, because I guess I cant decide what the "value" is ----- name or data...
Appreciate your help,
ns
|
|
|
|
|
Sometimes it would be nice to print my source code without comments. When I am in the development stage and am trying to figure out how to code something somewhat complex, I sometimes need to print out where I am, in order to fix it or complete it. e.g. a couple of nested while loops with plenty of comments in between.
Sure would be nice if there was a utility or macro I could run that would strip all comments from my source so I can print it out on a page or two versus what sometimes is a lot longer with comments in it. Currently, I cut and paste a section that I am working on into an editor and then manually remove all comment lines and sometimes some unnecessary code (for display only) such as error handling/checking routines to limit the amount of actual code I want to see.
Anyone know of such a tool?
|
|
|
|
|
Hi
Is it not allowed to start a thread in CDialog?Why isnt the below code working?(where IDC_GRAPH_FRAME is a picture control of Frame type)Please enlighten.
Thanks.
UINT PlotAttenuationThread(LPVOID pParam)<br />
{<br />
CWnd* gFrame = (CWnd*)GetDlgItem(IDC_GRAPH_FRAME);<br />
CDC* pDC = gFrame->GetDC();<br />
ReleaseDC(pDC);<br />
return 0;<br />
}<br />
<br />
<br />
BOOL CGrapDlg::OnInitDialog() <br />
{<br />
CDialog::OnInitDialog();<br />
<br />
AfxBeginThread(PlotAttenuationThread,this);<br />
return TRUE;
}
|
|
|
|
|
raner wrote:
Why isnt the below code working?
What do you mean? Does it not compile, does it not call your thread function, what?
Regards,
Alvaro
All you need in this life is ignorance and confidence, and then success is sure. -- Mark Twain
|
|
|
|
|
|
There is no problem starting a thread in OnInitDialog(), you just have to be very careful when using MFC objects (particularly objects derived from CWnd) in multiple threads.
Anyway, i suspect that here your code isn't compiling (i assume that's what you mean when you said that it doesn't work) because GetDlgItem() doesn't have enough parameters. Since the thread function is a global function, and not a member of CGrapDlg, it does not have access to the member functions of CGrapDlg (and CWnd from where it is derived). This means that when you call GetDlgItem() here, it is actually calling the SDK version, not the CWnd version. The SDK version of GetDlgItem() takes two parameters: the HWND of the dialog box, and then ID of the control. To get around this, you could cast the pParam parameter to a CGrapDlg, and then call the GetDlgItem() member function.
However, there are two issues here:
1) This uses CWnd-derived MFC objects in multiple threads, which is error prone. You could get around this by passing in the HWND instead, and calling the SDK directly.
2) By the sound of the thread function name, you are planning to do some drawing within this thread. In general, this is not recommended, as the dialog will also be painting itself (by handling WM_PAINT and WM_ERASEBACKGROUND), and so it is very likely that anything you draw in your thread will never be seen by the user.
Dave
|
|
|
|
|
regarding issue 2...i need some calculations to know what to draw and i thought if these had to be performed each time WM_PAINT is sent, it'll take a long time. That's why i placed the functions under OnInitDialog().
But after thinking through what you pointed out to me, maybe i should do the calculations in OnInitDialog() and the final display in OnPaint()?
thanks alot...i didnt know a thread is a global function before.;P
|
|
|
|
|
Use this code:
BOOL CGrapDlg::OnInitDialog()
{
CDialog::OnInitDialog();
AfxBeginThread(PlotAttenuationThread, this);
return TRUE;
}
UINT PlotAttenuationThread(LPVOID pParam)
{
CGraphDlg* pDlg=(CGraphDlg*) pParam;
CWnd* gFrame = (CWnd*)pDlg->GetDlgItem(IDC_GRAPH_FRAME);
CDC* pDC = gFrame->GetDC();
ReleaseDC(pDC);
return 0;
}
A. Riazi
|
|
|
|
|
One problem you should be seeing is that the thread function is not a member function of CGrapDlg so you can't call GetDlgItem.
Also what Dave has posted regarding the use of MFC objects accross threads is a problem that cannot be ignored. There are Technical Notes on MSDN regarding this problem.
"No matter where you go, there your are..." - Buckaoo Banzi
<pete/>
|
|
|
|
|
How change a color of the cell and color of the text in Excel table via OBDC.
CDatabase database;
...
database.OpenEx(sSql,CDatabase::noOdbcDialog)
...
sSql = "CREATE TABLE Station (Train CHAR,Times CHAR,Way NUMBER,Comment CHAR)";
database.ExecuteSQL(sSql);
...
sSql.Format("INSERT INTO Station (Train,Times,Way,Comment) VALUES ('%s','%s',%d,'%s')",sTrain,sTime,iWay,sComment);
database.ExecuteSQL(sSql);
I want that color of this record was red.
// Sorry for my Englsih
|
|
|
|
|
Maybe with ADOX? otherwise, why not use the Excel COM objects?
|
|
|
|
|
It is good. But can you write a simple example how to use it? Or tell me how to do it? Or where can i read this in the internet?
|
|
|
|
|
|
|
Hi,
I remember seeing once an articale that showed how you can send email
from a c++ program.
Any help will be appreciated.
Tahnks
Shay
|
|
|
|
|
For starters try this article, http://www.codeproject.com/internet/zsmtp.asp[^]
From the Internet section on CP, you should be able to find several others.
Chris Meech
"what makes CP different is the people and sense of community, things people will only discover if they join up and join in." Christian Graus Nov 14, 2002.
"AAAAAAAAAHHHHHH!!!!! Those leaks are driving me crazy! How does one finds a memory leak in a garbage collected environment ??! Daniel Turini Nov. 2, 2002.
|
|
|
|
|
Thank you,
That was what I was looking for
Shay
|
|
|
|
|
Hi I'm new to SDI programming so I would need some guidance from you all..
How can I make sure that my window is maximised when I run my application? I keep having to click on the maximise button after I compile and run my project.
Thx
|
|
|
|
|
|
In CMainFrame::PreCreateWindow(), put a ShowWindow(SW_SHOWMAXIMIZED);
~RaGE();
|
|
|
|
|
Ok,
I'm creating a Tree that traverses system drives. Is there a way to automatically refresh removable drives and cdrom drives? Is there a windows message that gets sent out when a new cd or floppy is inserted??
Thanks
Dan Willis
|
|
|
|
|
in your mainframe window do :
/////////////////////////////////////////////////////////////////
// OnDeviceChange
/////////////////////////////////////////////////////////////////
#include <dbt.h>
BOOL CMainFrame::OnDeviceChange (UINT nEventType, DWORD dwData)
{
if (nEventType == DBT_DEVICEARRIVAL)
{
DEV_BROADCAST_HDR * pDevBroadcastHdr = (DEV_BROADCAST_HDR*)dwData;
if (pDevBroadcastHdr->dbch_devicetype == DBT_DEVTYP_VOLUME) // Logical Volume
{
DEV_BROADCAST_VOLUME* pDevBroadcastVolume = (DEV_BROADCAST_VOLUME*)pDevBroadcastHdr;
// on cherche la lettre du nouveau disque
if (pDevBroadcastVolume->dbcv_flags & DBTF_MEDIA)
{
char cVolume;
ULONG unitmask = pDevBroadcastVolume->dbcv_unitmask;
for (int i = 0; i < 26; ++i)
{
if (unitmask & 0x1)
break;
unitmask = unitmask >> 1;
}
cVolume = (i + 'A');
}
}
}
if (nEventType == DBT_DEVICEREMOVECOMPLETE)
{
}
return TRUE;
}
=============================
in your mainfrm.h
afx_msg BOOL OnDeviceChange (UINT nEventType, DWORD dwData);
|
|
|
|
|
in your message map of your MainFrame add also:
BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
....
//}}AFX_MSG_MAP
ON_WM_DEVICECHANGE()
_MESSAGE_MAP()
|
|
|
|