|
you can find some pretty good document about this issue with some sample code.
Search for "Automating Microsoft Office 97 and Office 2000"
As for your quetion about loading logo into first page header, do the following:
1.Open a Word doc
2.Tools/Macros/start Recording a Macro
3.Create a header with your logo
4.Stop macro
5.Check what you recorded
The contents of 5./ (somewhat optimized) you will have to put into your MFC automation code.
Peter Molnar
|
|
|
|
|
Peter,
I'm aware about the possibility of recording macro in word then checking the VB code, but there are worlds of difference between VB(wich I know next to nothing about) and VC++ and MFC...thats why I'm looking for some sample VC++ and MFC code to help me understand. And like I said, I know how to create the word .doc...etc.
|
|
|
|
|
I just have done what described above, namely I recorded a header inserting macro. This was recorded when I clicked: View/Header-Footer/Insert pic from file
Sub Fejlec()
'
' Fejlec Makró
' Rögzítés: 11/23/2003, készíto: Pepe
'
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow.ActivePane.View.Type = wdOutlineView Then
ActiveWindow.ActivePane.View.Type = wdPrintView
End If
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.InlineShapes.AddPicture FileName:="c:\pic.jpg", LinkToFile:=False, SaveWithDocument:=True
End Sub
If you take a look at its contents, the if statements are useless for this task, you can delete them. (that was meant under "somewhat optimize").
What remains is:
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.InlineShapes.AddPicture FileName:="c:\pic.jpg", LinkToFile:=False, SaveWithDocument:=True
What does it mean? What it reads:
1. line: start editing the header of the current page
2. line: add a pic to the selection (i.e. header) with the given filename, and save the file within the word document not linking to it as an external file.
This is how you code this with MFC:
COleVariant vTrue((short)TRUE),vFalse((short)FALSE),vOpt((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
Documents oDocs = oApp.GetDocuments();
_Document oDoc = oDocs.Add(vOpt, vOpt);
Window oWin = oApp.GetActiveWindow();
Pane oPane = oWin.GetActivePane()
View oView = oPane.GetView();
oView.SetSeekView(wdSeekCurrentPageHeader);
Selection oSel = oApp.GetSelection();
Shapes oShapes = oSel.GetInlineShapes();
oShapes.AddPicture("c:\\pic.jpg",vFalse,vTrue,vOpt,vOpt,vOpt,vOpt,vOpt);
Some remarks:
1.The Word wrapper class was produced from Word 8 with VC6, because Word 8 is compatible with later word versions and VC6 produces one file for one type lybrary unlike VS.NET which does one file for every object in the tlb.
A similar wrapper is recommended to use.
2.The additon of different header for first file is left for you for practice, (ActiveDocument.PageSetup.DifferentFirstPageHeaderFooter = True)
Peter Molnar
|
|
|
|
|
Peter,
I appreciate the practice you are attempting to let me try, but I'm pressed for tie in this thing. I'm trying to make the code you suggest work, and I will learn from it and then be able to practice. I adapted your code. Here is my version:
COleVariant vTrue((short)TRUE),vFalse((short)FALSE),vOpt((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
//Creates new doc
Documents documents = application.GetDocuments();
_Document document = documents.Add(vOpt,vOpt,&varEmpty,&varEmpty); //First line
Window oWin = application.GetActiveWindow();
Pane oPane = oWin.GetActivePane();
View oView = oPane.GetView();
oView.SetSeekView(wdSeekCurrentPageHeader);
//Second line
Selection oSel = application.GetSelection();
Shapes oShapes = oSel.GetInlineShapes();
oShapes.AddPicture("c:\\Inspec\\LogoInspec.jpg",vFalse,vTrue,vOpt,vOpt,vOpt,vOpt,vOpt);
//**************
Notice I just changed the names of the app and doc objects to match what I already had, and I added &varEmpty paramters to the :
_Document document = documents.Add(vOpt,vOpt,&varEmpty,&varEmpty) because Add does not take 2 arguments where I'm at.
As for the code:
(ActiveDocument.PageSetup.DifferentFirstPageHeaderFooter = True)
I was aware of the "DifferentFirstPageHeaderFooter = True"..but as I said, can't quite figure out how to set it up...since you are starting from the ative document,then page setup objects, and from the functions available in the PageSetup class , I guess I would have to use the :
void PageSetup::SetDifferentFirstPageHeaderFooter(long nNewValue)
function. So, here goes:
PageSetup pageSetup;
pageSetup.SetDifferentFirstPageHeaderFooter(TRUE);
So, the total code would be:
COleVariant vTrue((short)TRUE),vFalse((short)FALSE),vOpt((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
//Creates new doc
Documents documents = application.GetDocuments();
_Document document = documents.Add(vOpt,vOpt,&varEmpty,&varEmpty);
//First line
Window oWin = application.GetActiveWindow();
Pane oPane = oWin.GetActivePane();
View oView = oPane.GetView();
oView.SetSeekView(wdSeekCurrentPageHeader);
//Second line
Selection oSel = application.GetSelection();
Shapes oShapes = oSel.GetInlineShapes();
oShapes.AddPicture("c:\\Inspec\\LogoInspec.jpg",vFalse,vTrue,vOpt,vOpt,vOpt,vOpt,vOpt);
PageSetup pageSetup;
pageSetup.SetDifferentFirstPageHeaderFooter(TRUE);
Am I on the right track ?? Because this compiles ok, but gives me an error at runtime that says "Error...member not found"
I have 1 week to complete getting this straightened out...I would appreciate yoour help. I may certainly have other questions if you can help me ok on this one.
|
|
|
|
|
You are much on the right track.
Remarks:
1.
_Document document = documents.Add(vOpt,vOpt,&varEmpty,&varEmpty);
You use a word version 9 (Word2000) or 10 (XP) for your C++ wrapper because your add function has 4 parameters (mine has only 2 because it was taken from Word8=Word97). This is no problem as far as you don' wanna target Word97, and you fill the params properly. Use for all 4 params vOpt, or declare vEmpty the way vOpt was.
2.
Start ALWAYS from the Application object going "down" (the VB code does the same, or it explicitely declares another)
PageSetup pageSetup;
pageSetup.SetDifferentFirstPageHeaderFooter(TRUE);
YOur pagesetup object is not initialized for proper usage with your doc, you just declared it (i.e: it compiles but does not run)
Use:
_Document oDoc = application.GetActiveDocument();
PageSetup oPageSetup = oDoc.GetPageSetup();
oPageSetup.SetDifferentFirstPageHeaderFooter(1);
3.
The constants (like wdSeekCurrentPageHeader) are not declared in my wrapper classes (if you could compile your above code then they were declared in yours).
If you don't have their values, you can either experiment around or try figuring it out from the macro editor.
Peter Molnar
|
|
|
|
|
Hi!
With your help, this is what I have put together so far...no compile errore, but still crashes at run time:
COleVariant vTrue((short)TRUE),vFalse((short)FALSE),vOpt((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
//Creates new doc
Documents documents = application.GetDocuments();
_Document document = documents.Add(vOpt,vOpt,&varEmpty,&varEmpty);
Selection selection(application.GetSelection());
Window oWin = application.GetActiveWindow();
Pane oPane = oWin.GetActivePane();
View oView = oPane.GetView();
oView.SetSeekView(wdSeekCurrentPageHeader);
//since a doc has already been opened, you just have to find the active one
_Document oDocument = application.GetActiveDocument();//
PageSetup oPageSetup = oDocument.GetPageSetup();
//This initializes oPageSetup properly
oPageSetup.SetDifferentFirstPageHeaderFooter(1);
//Second line
Selection oSel = application.GetSelection();
Shapes oShapes = oSel.GetInlineShapes();
oShapes.AddPicture("c:\\Inspec\\LogoInspec.jpg",vFalse,vTrue,vOpt,vOpt,vOpt,vOpt,vOpt);
//***************************
The line it's having problems with is the :
oPageSetup.SetDifferentFirstPageHeaderFooter(1);
The error says "The parameter is incorrect" ???? I do see this function in the PageSetup class...here it is:
void PageSetup::SetDifferentFirstPageHeaderFooter(long nNewValue)
{
static BYTE parms[] =
VTS_I4;
InvokeHelper(0x74, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,
nNewValue);
}
Looks like I'm almost there...I await your help please "
|
|
|
|
|
Unfortunately, this is a real problem since the functions themselves are undocumented, and TRUE is defined as 1, so this would be an obvious value.
I just could recommend you to try other values as well.
Sorry to tell, but no real/other solution to this.
Peter Molnar
|
|
|
|
|
I am building a simple c++ project with database support and I am stuck. It has multiple forms and I want to add Forms to the mainfram menu with on command ability to open the indiviual forms from the menu by selecting the name. I can not figure out how to do it. I am only self taught in visual c++. Please help I have researched and can find no reference anywhere to help me.
EeyoreBabe
|
|
|
|
|
|
Hi!
Is there any equivalent function to the function FormatRange of a Rich Edit Control for the Microsoft Html Edit Control?
This useful function displays the content of the control in another device (printer, window,...).
If not, is there a way to display the content of an hidden window into another window?
This will be very useful for me to display HTML code in a window.
Thks in advance!
Appstmd
http://www.appstmd.com
|
|
|
|
|
The only thing I can think of is getting the document's html and show them in the default webbrowser.
Use GetDoumentHTML for putting the html into a CString and then save it to file and do a ShellExecute on it.
Peter Molnar
|
|
|
|
|
Thanks for your answer. But I want to display the content of my Html Edit Control to another window without using another control, like it is possible to do with Rich Edit Control FormatRange function.
Thks in advance!
Appstmd
http://www.appstmd.com
|
|
|
|
|
|
I was wondering, if I want to get the address located in an Internet Shortcut in Windows, how can I open the file (parse it?) and get the address? I don't want to go to the shortcut, I just want to be able to get the address.
I cant open the file as a text doc, even if I rename it? What should I do?
Kevin Shaffer
kshaff03@msn.com
|
|
|
|
|
I figured this out already. If anyone wants to know...
I went into DOS and the file name is stored as
<file_name>.url
You can then open it and parse it.
Kevin Shaffer
kshaff03@msn.com
|
|
|
|
|
You should use the COM interface provided for reading shortcuts, that way your code will still work if/when the file format changes in the future. Check out the CLSID_InternetShortcut coclass and IUniformResourceLocator , and the sample code in Q229092.
--Mike--
Ericahist | CP SearchBar v2.0.2 | Homepage | RightClick-Encrypt | 1ClickPicGrabber
#include "witty-quote.h"
|
|
|
|
|
Hi,
I've created a Socket (TCP/IP - Synchronous Socket - SOCK_STREAM) program in which I've spawned a new thread to accept client connections. Again, for every accepted connection through a new client socket, i've spawned another new thread for message transaction. Here, the Receive function does not block until the data is filled in the buffer. Instead, the receive function tries to read data which is either NULL or junk, which leads to assertion failure.
Is there any solution to make the client socket block untill receive? Or does a thread affect the state of the socket by any chance.
shenthil
senthilkkumar@rediffmail.com
|
|
|
|
|
The receive function of a connected socket is very much blocking provided you use CSocket::Receive or the Winsock API' recv (and not CAsyncSocket).
The reasons for a receive to not block might be:
1.The passed in data buffer is full with data
2.The connection went lost
So, check for the above.
Peter Molnar
|
|
|
|
|
I have never had problems with blocking sockets and threads. Anyway, I assume you are just using plain socket, accept and recv. If then the only thing that comes to mind is that you are mistaken the length of the buffer you are passing (the buffer you expect filled ) with the actual number of bytes read.
if you try something like this do you get to DebugBreak()?
int received = recv( s, buf, sizeof buf, 0 );
if( ( SOCKET_ERROR == received ) && (WSAEWOULDBLOCK == WSAGetLastError() ) )
{
//something has changed your socket to non-blocking mode
DebugBreak();
}
else
{
CopyMemory( workerBuf, buf, received );
//work with worker buf using the n received bytes
}
Hope this helps
Gabriel
Old C programmers never die. They just cast into void
|
|
|
|
|
Gabriel,
receive function (CSocket::Receive) neither returns SOCKET_ERROR nor WASEWOULDBLOCK ), rather it simply crashes out. even while debuggin, when the receive function returns, the application crashes.
shenthil
shenthil
|
|
|
|
|
Shenthil,
I would like to help but i just know about plain sockets. I don´t have any idea about how they work in MFC, even less what the problem could be.
About the subject of the original post (the socket not bloking,) CSocket inherits from CAsyncSocket which is asynchronous, and taking a quick glance at the code <sockcore.cpp> you can see CSocket simulates a blocking socket using a loop. But i don´t think this is the cause of the problem.
If your threads are just pumping bytes from a network connection and you need to work directly with them you are better off using and alternative to CSocket, because there is a lot of overhead in the way they work (asyncrhonous notifications through a windows message queue) which was the only option when they appeared in win3.1 because the apps were single threaded and there was no real multitasking in the OS
Gabriel
Old C programmers never die. They just cast into void
|
|
|
|
|
Gabriel,
How to stop the Thread from Pumping Messages.
Shenthil
Shenthil
|
|
|
|
|
Shenthil,
If you refer to stop pumping the messages that are sent to you over the network, unless you call Receive or recv, the data is going to stand still until your winsock implementation runs out of network buffer space.
If you refer to message pumping from the window queue as Receive does, this is not desirable because this is intrinsic to the mechanism CSocket uses.
Here at CP in the Internet & Networking section you have plain sockets programming tutorials and classes, and also MFC CSocket derived classes. (Nish has written great tutorials on sockets)
I´m biased but IMHO CSocket misuses resources and adds uneeded complexity.
Hope this helps
Gabriel
Old C programmers never die. They just cast into void
|
|
|
|
|
Thanks Gabriel. Now I've changed the algorithm, but the problem is still unsolved.
Shenthil
|
|
|
|
|
Is your app still crashing? What´s the error? Access violation?
Gabriel
Old C programmers never die. They just cast into void
|
|
|
|
|