|
Hmm what if I want to load the html document saved to disk?
|
|
|
|
|
Try this. It uses ATL. It extracts the text from google and prints it in a message box. I wipped it up pretty quickly so it's not perfect, but it works.
---
// Only needed if you're using an old SDK that hasn't got this. Remove
// if it clashes with your SDK.
MIDL_INTERFACE("3050f613-98b5-11cf-bb82-00aa00bdce0b")
HTMLDocumentEvents2 : public IDispatch
{
};
// Class to wait for the ready state to change to "complete"
// while running a message loop.
class ATL_NO_VTABLE CReadyStateComplete :
public CComObjectRootEx<CComSingleThreadModel>,
public IDispatch
{
public:
CReadyStateComplete() : m_spDoc2(NULL)
{
m_hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
}
~CReadyStateComplete()
{
CloseHandle(m_hEvent);
}
void SetDocument(IHTMLDocument2* pDoc2)
{
m_spDoc2 = pDoc2;
}
DECLARE_NO_REGISTRY()
BEGIN_COM_MAP(CReadyStateComplete)
COM_INTERFACE_ENTRY(IDispatch)
END_COM_MAP()
void Wait()
{
AtlWaitWithMessageLoop(m_hEvent);
}
public:
STDMETHOD(GetTypeInfoCount)(UINT* pctinfo)
{
return E_NOTIMPL;
}
STDMETHOD(GetTypeInfo)(UINT itinfo, LCID lcid, ITypeInfo** pptinfo)
{
return E_NOTIMPL;
}
STDMETHOD(GetIDsOfNames)(REFIID riid, LPOLESTR* rgszNames, UINT cNames,
LCID lcid, DISPID* rgdispid)
{
return E_NOTIMPL;
}
STDMETHOD(Invoke)(
/*[in]*/ DISPID dispIdMember,
/*[in]*/ REFIID riid,
/*[in]*/ LCID lcid,
/*[in]*/ WORD wFlags,
/*[in, out]*/ DISPPARAMS * pDispParams,
/*[out]*/ VARIANT * pVarResult,
/*[out]*/ EXCEPINFO * pExcepInfo,
/*[out]*/ UINT * puArgErr)
{
if ( dispIdMember == DISPID_READYSTATECHANGE )
{
CComBSTR State;
if ( SUCCEEDED(m_spDoc2->get_readyState(&State)) )
{
if ( wcscmp(State, L"complete")==0 )
{
SetEvent(m_hEvent);
}
}
return S_OK;
}
return DISP_E_MEMBERNOTFOUND;
}
private:
CComPtr<IHTMLDocument2> m_spDoc2;
HANDLE m_hEvent;
};
void ExtractText()
{
HRESULT hr;
// Get a stream on the URL.
CComPtr<IMoniker> spMk;
hr = CreateURLMoniker(NULL, OLESTR("http://www.google.com/"), &spMk);
if ( FAILED(hr) )
{
return;
}
CComPtr<IBindCtx> spCtx;
hr = CreateBindCtx(0, &spCtx);
if ( FAILED(hr) )
{
return;
}
CComPtr<IStream> spStream;
hr = spMk->BindToStorage(spCtx, 0, IID_IStream, (void**)&spStream);
if ( FAILED(hr) )
{
return;
}
// Create the HTMLDocument object.
CComPtr<IUnknown> spUnk;
hr = spUnk.CoCreateInstance(CLSID_HTMLDocument);
if ( FAILED(hr) )
{
return;
}
CComQIPtr<IPersistStreamInit> spPSI(spUnk);
if ( !spPSI )
{
return;
}
CComQIPtr<IHTMLDocument2> spDoc2(spUnk);
if ( !spDoc2 )
{
return;
}
// Set up our object which watches the ready state of the document.
CComObjectGlobal<CReadyStateComplete> RS;
RS.SetDocument(spDoc2);
DWORD Cookie;
hr = AtlAdvise(spUnk, &RS, __uuidof(HTMLDocumentEvents2), &Cookie);
if ( FAILED(hr) )
{
return;
}
// Load the data from the URL into the object.
hr = spPSI->Load(spStream);
if ( FAILED(hr) )
{
AtlUnadvise(spUnk, __uuidof(HTMLDocumentEvents2), Cookie);
return;
}
// Wait (while running a message pump so MSHTML can work) till ready.
RS.Wait();
AtlUnadvise(spUnk, __uuidof(HTMLDocumentEvents2), Cookie);
// Print out the text in a message box.
CComPtr<IHTMLElement> spBodyElement;
hr = spDoc2->get_body(&spBodyElement);
if ( FAILED(hr) )
{
return;
}
CComBSTR Text;
hr = spBodyElement->get_outerText(&Text);
if ( FAILED(hr) )
{
return;
}
MessageBoxW(NULL, Text, L"Text", MB_OK);
}
Steve
-- modified at 7:41 Friday 3rd February, 2006
Added AtlUnadvise calls without testing......
|
|
|
|
|
Hi,
I am using Visual Studio .Net 2003. I compiled my MFC application in release mode. I then clicked on the executable, and my MFC GUI started. However, when I transfer the executable to other companies, the GUI doesn't start (actually, no response at all) when I click on the executable file. So does anyone why is this?
Thank you very much!!!!!!
|
|
|
|
|
the problem would be related mfc 7.0 dlls or dotnet 1.1 env..
Anderson Sheen (exteide@gmail.com)
The Extension IDE: http://www.exteide.com
|
|
|
|
|
You need to make sure that you send the MFC libraries along with your application. The libraries for the version of MFC in VS2003 are version 7.1.
I'm not sure this is all of your problem, however. Missing libraries usually causes a message box to appear. If you're not getting any response from the application, then there may be an additional problem involved.
Software Zen: delete this;
|
|
|
|
|
Thanks for your help
Now, I ask my friend to open my project and then re-compile, however, he got these 2 error messages:
LNK4098: defaultlib "LIBC" conflicts other libraries, please use /NODEFAULTLIB:Libray
LNK4098: reference to all of 'OLEAUT32.dll' are deleted by /OPT:REF
So what do these two messages mean? How can I fix them?
Thanks a lot
|
|
|
|
|
Hi all,
I am trying to write an application that will allow me to create a new Email account in Outlook Express.
The app has 3 fields that will need to be filled out:
- Display Name
- Username
- Password
Now, the problem that I have is, that the Password value from this field doesn't get written correctly into the Registry.
I am using the following code:
RegSetValueEx(hKey, "POP3 Password2", 0, REG_BINARY,(const BYTE *)&custpass,sizeof(custpass));
Can anyone help me out with this???
Thanks
amano
|
|
|
|
|
Could you show the type of the variable custpass .
Steve
|
|
|
|
|
Hi Steve,
I think that's the type here
CString custpass;
amano
|
|
|
|
|
Ok then. Try this:
<br />
RegSetValueEx(<br />
hKey,<br />
"POP3 Password2",<br />
0,<br />
REG_BINARY,<br />
reinterpret_cast<const BYTE*>(static_cast<LPCTSTR>(custpass))<br />
);<br />
Steve
PS: This is the kind of problem you get when you mix the low level (the RegSetValueEx API) with the high level (CString).
|
|
|
|
|
I just tried to compile it with the new code, but am getting the following error message:
error C2660: 'RegSetValueExA' : function does not take 5 parameters
|
|
|
|
|
Ok, I forgot the size parameter. Try this:
RegSetValueEx(<br />
hKey,<br />
"POP3 Password2",<br />
0,<br />
REG_BINARY,<br />
reinterpret_cast<const BYTE*>(static_cast<LPCTSTR>(custpass)),<br />
(custpass.GetLength()+1)*sizeof(TCHAR)<br />
);
Steve
|
|
|
|
|
Ok...just been able to try this out.
The password is still not being saved to the Registry.
Does it matter where i am trying to write it to?
I am writing it to HKEY_CURRENT_USER\Software\Microsoft\Internet Account Manager\Accounts\
amano
|
|
|
|
|
amano8u wrote: HKEY_CURRENT_USER\Software\Microsoft\Internet Account Manager\Accounts\
HI,
first try by writing some dummy text there!, if you successful in writing that, then try the ansqwer mentioned by Mr. Hewitt
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow cheers, Alok Gupta VC Forum Q&A :- I/ IV
|
|
|
|
|
Hi Alok,
I don't understand what you mean? I am able to write text there and create the keys and etc. if that is what you are referring to. I am unable to write the correct data there.
amano
|
|
|
|
|
Are you sure you need to save it as binary, not as text? I don't know what OE expects.
Also, does your user account have permissions to alter this part of the registry?
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Hey Ryan,
i am trying to replicate what the OE wizard does. That one stores the value as a Binary.
But if text will do the trick i am happy to use that. Do you have an example how it would be written if it is to store it as text?
Would i be replacing the "REG_BINARY" to "REG_SZ" ??
and yeah permissions are available to alter the Registry.
amano
|
|
|
|
|
I have two monitors. They are connected with one graphic cards, which one from vga port and one from dvi port. How can I send different dialogs to different monitors and with one globle mouse.
Thanks in advance
|
|
|
|
|
you can use following apis.
MonitorFromWindow
EnumDisplayMonitors
Anderson Sheen (exteide@gmail.com)
The Extension IDE: http://www.exteide.com
|
|
|
|
|
I have an application which works with multiple monitors. I follow the process shown below (C not MFC, but the idea is the same.)
Start by setting up the monitors in Windows so they display diferent information.
Use EnumDisplayMonitors(NULL, NULL, MonitorInfoProc, 0) - the MonitorInfoProc callback procedure is called once for each monitor, and receives a handle to each monitor.
Using that handle (within MonitorInfoProc ), you can get the parameters for each monitor, by using GetMonitorInfo(hMon1, &monitorInfo) , and then access the various parameters such as lMonitorTop[uMonitorBeingEnumerated] = monitorInfo.rcMonitor.top and lMonitorLeft[uMonitorBeingEnumerated] = monitorInfo.rcMonitor.left .
Look at the members of the MONITORINFO structure to see what information is available.
Once you have the top left of each monitor and the size of each monitor, use SetWindowPos to position your windows where you want them.
|
|
|
|
|
I have keypad as a input. It use usb to connect. There is a driver to drive it. Is there anybody can give me an idea to use joystick as a mouse and keypay button(only number) to chose the button on the windows.
Thanks in advance
|
|
|
|
|
you can use DirectX input library.
DirectX input supports APIs related human interface device(HID) like joystick, light pen and etc.
you don't need to init the video mode even if you're using DirectX.
DirectX is just library.
And there are so many sources on the internet about DX input.
Good luck.
Anderson Sheen (exteide@gmail.com)
The Extension IDE: http://www.exteide.com
|
|
|
|
|
Hi .
Does anyone have a working code to change a file attributes from FILE_ATTRIBUTE_DIRECTORY to FILE_ATTRIBUTE_NORMAL.
Simply speaking I need to make a file from the directory.
student
|
|
|
|
|
You could try SetFileAttributes() but I doubt it will work. Stranger things have happened, though.
"The greatest good you can do for another is not just to share your riches but to reveal to him his own." - Benjamin Disraeli
|
|
|
|
|
I don't know what you are trying to achieve, but I doubt whether changing the attribute will do it! A file which is actually a set of directory entries (if that is what this would give) would not be useable in other applications (i.e. if you opened it with notepad or word, I don't think it would give anything recognisable as a directory listing, in case this is what you are trying to achieve.)
Maybe this would be a way to hide your directory full of smut, but if someone else runs scandisk, the clusters occupied by the files would be freed, since they are apparently unused (I guess that's what might happen - I've forgotten about directory structures, etc.)
Try the other suggestion regarding setting attributes, but if that does not do what you want, I suggest that you try to describe what you are trying to achieve in a few sentences - maybe someone can give ideas then.
|
|
|
|
|