|
I think you should be misunderstanding, or else it is my fault. i suppose to post my coding and lets you all expertise and checking the error for me. However, the system now is workable for space. one more question is if i would like to get some particular word, lets say 3rd word from the sentence. then what should i add inside?
the following is the coding:
#include <iostream>
using std::cout;
using std::endl;
using std::cin;
#include <cstring>
int main()
{
char string[256];
char *tokenPtr;
cout << "Enter sentence\n";
cin.getline(string,sizeof(string),'\n');
cout << "The string to be tokenized is:\n" << string
<< "\n\nThe tokens are:\n";
tokenPtr = strtok( string, " " );
while ( tokenPtr != NULL ) {
cout << tokenPtr << '\n';
tokenPtr = strtok( NULL, " " );
}
return 0;
}
|
|
|
|
|
I was positioning my richedit so that it hugged the bottom edge of my UI at all times using (in OnSize):
m_editright1.MoveWindow(cx - 200, 390 - VScrollDistance, 200, <code>cy-350+ VScrollDistance</code>);
This works well, but the edge hugged is the visible bottom edge, not the region hidden by the scrollbars of my MFC MDI app. (Strange fact: If I scroll down completely and resize it does elongate (beyond?) to the real bottom edge ). SO in order to make sure I definitely get the bottom hugging behavior (with or without scrolling and resizing) I made the box superlong:
cy+ VScrollDistance .
The problem is that the vertical scrollbars never develop for the control even if I shrink my UI to be less tall and the text gets obscured. If it truly hugged the bottom at all times, I feel the scrollbars would develop. Any ideas on how I can get it to align itself along the TRUE bottom edge of the UI and not just the visible region right from the start.( I do this positioning in the OnSize event which seems to run after OnInitialUpdate, so any positioning I do in the latter will be overridden)?
Thanks,
ns
|
|
|
|
|
Greetings
I have been able to automate Word using my application. I have been able to write three lines of text into it.
Now how should I create tables and format text in it.
Now how should I add tables for formatting.
Ritesh
Below is the code which i am using
=============================================================================
#include <ole2.h>
#include <stdio.h>
int main(int argc, char* argv[])
{
// ******************* Declare Some Variables ********************
// Variables that will be used and re-used in our calls
DISPPARAMS dpNoArgs = {NULL, NULL, 0, 0};
VARIANT vResult;
OLECHAR FAR* szFunction;
BSTR bstrTemp;
// IDispatch pointers for Word's objects
IDispatch* pDispDocs; //Documents collection
IDispatch* pDispSel; //Selection object
IDispatch* pDispActiveDoc; //ActiveDocument object
// DISPID's
DISPID dispid_Docs; //Documents property of Application object
DISPID dispid_DocsAdd; //Add method of Documents collection
//object
DISPID dispid_Sel; //Selection property of Applicaiton object
DISPID dispid_TypeText; //TypeText method of Selection object
DISPID dispid_TypePara; //TypeParagraph method of Selection object
DISPID dispid_ActiveDoc; //ActiveDocument property of Application
//obj
DISPID dispid_SaveAs; //SaveAs method of the Document object
DISPID dispid_Quit; //Quit method of the Application object
// ******************** Start Automation ***********************
//Initialize the COM libraries
::CoInitialize(NULL);
// Create an instance of the Word application and obtain the pointer
// to the application's IDispatch interface.
CLSID clsid;
CLSIDFromProgID(L"Word.Application", &clsid);
IUnknown* pUnk;
HRESULT hr = ::CoCreateInstance( clsid, NULL, CLSCTX_SERVER,
IID_IUnknown, (void**) &pUnk);
IDispatch* pDispApp;
hr = pUnk->QueryInterface(IID_IDispatch, (void**)&pDispApp);
// Get IDispatch* for the Documents collection object
szFunction = OLESTR("Documents");
hr = pDispApp->GetIDsOfNames (IID_NULL, &szFunction, 1,
LOCALE_USER_DEFAULT, &dispid_Docs);
hr = pDispApp->Invoke (dispid_Docs, IID_NULL, LOCALE_USER_DEFAULT,
DISPATCH_PROPERTYGET, &dpNoArgs, &vResult,
NULL, NULL);
pDispDocs = vResult.pdispVal;
// Invoke the Add method on the Documents collection object
// to create a new document in Word
// Note that the Add method can take up to 3 arguments, all of which
// are optional. We are not passing it any so we are using an empty
// DISPPARAMS structure
szFunction = OLESTR("Add");
hr = pDispDocs->GetIDsOfNames(IID_NULL, &szFunction, 1,
LOCALE_USER_DEFAULT, &dispid_DocsAdd);
hr = pDispDocs->Invoke(dispid_DocsAdd, IID_NULL, LOCALE_USER_DEFAULT,
DISPATCH_METHOD, &dpNoArgs, &vResult, NULL,
NULL);
// Get IDispatch* for the Selection object
szFunction = OLESTR("Selection");
hr = pDispApp->GetIDsOfNames (IID_NULL, &szFunction, 1,
LOCALE_USER_DEFAULT, &dispid_Sel);
hr = pDispApp->Invoke (dispid_Sel, IID_NULL, LOCALE_USER_DEFAULT,
DISPATCH_PROPERTYGET, &dpNoArgs, &vResult,
NULL, NULL);
pDispSel = vResult.pdispVal;
// Get the DISPIDs of the TypeText and TypeParagraph methods of the
// Selection object. We'll use these DISPIDs multiple times.
szFunction = OLESTR("TypeText");
hr = pDispSel->GetIDsOfNames(IID_NULL, &szFunction, 1,
LOCALE_USER_DEFAULT, &dispid_TypeText);
szFunction = OLESTR("TypeParagraph");
hr = pDispSel->GetIDsOfNames(IID_NULL, &szFunction, 1,
LOCALE_USER_DEFAULT, &dispid_TypePara);
// The TypeText method has and requires only one argument, a string,
// so set up the DISPPARAMS accordingly
VARIANT vArgsTypeText[1];
DISPPARAMS dpTypeText;
bstrTemp = ::SysAllocString(OLESTR("Metallica"));
vArgsTypeText [0].vt = VT_BSTR;
vArgsTypeText [0].bstrVal = bstrTemp;
dpTypeText.cArgs = 1;
dpTypeText.cNamedArgs = 0;
dpTypeText.rgvarg = vArgsTypeText;
//Invoke the first TypeText and TypeParagraph pair
hr = pDispSel->Invoke (dispid_TypeText, IID_NULL,
LOCALE_USER_DEFAULT, DISPATCH_METHOD,
&dpTypeText, NULL, NULL, NULL);
hr = pDispSel->Invoke (dispid_TypePara, IID_NULL,
LOCALE_USER_DEFAULT, DISPATCH_METHOD,
&dpNoArgs, NULL, NULL, NULL);
::SysFreeString(bstrTemp);
//Invoke the second TypeText and TypeParagraph pair
bstrTemp = ::SysAllocString(OLESTR("Pantera"));
hr = pDispSel->Invoke (dispid_TypeText, IID_NULL,
LOCALE_USER_DEFAULT, DISPATCH_METHOD,
&dpTypeText, NULL, NULL, NULL);
hr = pDispSel->Invoke (dispid_TypePara, IID_NULL,
LOCALE_USER_DEFAULT, DISPATCH_METHOD,
&dpNoArgs, NULL, NULL, NULL);
::SysFreeString(bstrTemp);
//Invoke the third TypeText and TypeParagraph pair
bstrTemp = ::SysAllocString(OLESTR("Godsmack"));
hr = pDispSel->Invoke (dispid_TypeText, IID_NULL,
LOCALE_USER_DEFAULT, DISPATCH_METHOD,
&dpTypeText, NULL, NULL, NULL);
hr = pDispSel->Invoke (dispid_TypePara, IID_NULL,
LOCALE_USER_DEFAULT, DISPATCH_METHOD,
&dpNoArgs, NULL, NULL, NULL);
::SysFreeString(bstrTemp);
// Get IDispatch* for the ActiveDocument object
szFunction = OLESTR("ActiveDocument");
hr = pDispApp->GetIDsOfNames (IID_NULL, &szFunction, 1,
LOCALE_USER_DEFAULT,
&dispid_ActiveDoc);
hr = pDispApp->Invoke (dispid_ActiveDoc, IID_NULL,
LOCALE_USER_DEFAULT, DISPATCH_PROPERTYGET,
&dpNoArgs, &vResult, NULL, NULL);
pDispActiveDoc = vResult.pdispVal;
//Set up the DISPPARAMS for the SaveAs method (11 arguments)
VARIANT vArgsSaveAs[11];
DISPPARAMS dpSaveAs;
dpSaveAs.cArgs = 11;
dpSaveAs.cNamedArgs = 0;
dpSaveAs.rgvarg = vArgsSaveAs;
BSTR bstrEmptyString;
bstrEmptyString = ::SysAllocString(OLESTR(""));
VARIANT vFalse;
vFalse.vt = VT_BOOL;
vFalse.boolVal = FALSE;
bstrTemp = ::SysAllocString(OLESTR("c:\\doc1.doc"));
vArgsSaveAs[10].vt = VT_BSTR;
vArgsSaveAs[10].bstrVal = bstrTemp; //Filename
vArgsSaveAs[9].vt = VT_I4;
vArgsSaveAs[9].lVal = 0; //FileFormat
vArgsSaveAs[8] = vFalse; //LockComments
vArgsSaveAs[7].vt = VT_BSTR;
vArgsSaveAs[7].bstrVal = bstrEmptyString; //Password
vArgsSaveAs[6].vt = VT_BOOL;
vArgsSaveAs[6].boolVal = TRUE; //AddToRecentFiles
vArgsSaveAs[5].vt = VT_BSTR;
vArgsSaveAs[5].bstrVal = bstrEmptyString; //WritePassword
vArgsSaveAs[4] = vFalse; //ReadOnlyRecommended
vArgsSaveAs[3] = vFalse; //EmbedTrueTypeFonts
vArgsSaveAs[2] = vFalse; //SaveNativePictureFormat
vArgsSaveAs[1] = vFalse; //SaveFormsData
vArgsSaveAs[0] = vFalse; //SaveAsOCELetter
//Invoke the SaveAs method
szFunction = OLESTR("SaveAs");
hr = pDispActiveDoc->GetIDsOfNames(IID_NULL, &szFunction, 1,
LOCALE_USER_DEFAULT, &dispid_SaveAs);
hr = pDispActiveDoc->Invoke(dispid_SaveAs, IID_NULL,
LOCALE_USER_DEFAULT, DISPATCH_METHOD,
&dpSaveAs, NULL, NULL, NULL);
::SysFreeString(bstrEmptyString);
//Invoke the Quit method
szFunction = OLESTR("Quit");
hr = pDispApp->GetIDsOfNames(IID_NULL, &szFunction, 1,
LOCALE_USER_DEFAULT, &dispid_Quit);
hr = pDispApp->Invoke (dispid_Quit, IID_NULL, LOCALE_USER_DEFAULT,
DISPATCH_METHOD, &dpNoArgs, NULL, NULL, NULL);
//Clean-up
::SysFreeString(bstrTemp);
pDispActiveDoc->Release();
pDispSel->Release();
pDispDocs->Release();
pDispApp->Release();
pUnk->Release();
::CoUninitialize();
return 0;
}
|
|
|
|
|
http://www.codeproject.com/com/xoffice.asp
Papa
Murex Co.
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
It looks like you have a working technique to communicate with the Word app. If you are asking about the specific commands to issue to word to create the table and do the formatting, I suggest you let the Word program tell you.
Turn on the macro recorder, perform the operations of interest (create table). Then turn off the recorder and read the macro. It will contain the commands you need to implement. The implementation is just like the stuff you already have coded.
|
|
|
|
|
Thanks...I will take a look at it.
Ritesh
|
|
|
|
|
I have written a Server Client Chat Program using CAsyncSocket. I can get the Remote Hosts I.P. Address using the GetPeerName() Function. I also want the Host Name. To do this I sent a message with the OnConnect() and OnAccept() functions. This only works intermittently and if I disconnect the Client Leaving the Server Listening and then re-connect it does not work at all. What is a better and more reliable way to do this?
|
|
|
|
|
getnameinfo (WinSock2) returns the hostname for a given IP-address
(gethostbyaddr is simpler in usage, but deprecated)
|
|
|
|
|
You guys are all familiar with SDI and MDI models of application design (ie Document View Architecture).
Im reading through Prosise (MFC) and came across this:
Alternatives to MDI
A workspace-based model that groups related documents in objects called worspaces and allows documents
contained in a workspace to be viewed and edited in MDI-like document frames that are children of a top
level frame window. Visual C++ is one example of an application that uses the workspace
containment model. I would be interested to know if anyone has had any success programming an application with a model similar
to this. I am interested in this model mainly because the application I am designing is going to need
"modular" documents. That is, a user is going to be able to add many different types of documents to their
workspace. The workspace object will need to be serialized so that it can be saved and loaded. Its a major
undertaking because there is also a document designer application that the user can use to generate active
documents that can be loaded into the workspace. These documents are just "views" of data objects that will
also have to be serialized along with a workspace.
In other words containment is
workspace
--> multiple data objects (dynamically added)
--> multiple documents (views) (dynamically added)
Has anyone seen or read any articles on this style? Seen any similar open source projects / examples? The
model has also been called the "floating Document Interface". Apparantly CodeWarrior uses it as a
stock programming model (along with MDI / SDI).
Ryan Baillargeon
Software Specialist
Fuel Cell Technologies Inc.
|
|
|
|
|
Has anyone even read this?
Ryan Baillargeon
Software Specialist
Fuel Cell Technologies Inc.
|
|
|
|
|
|
I have a loop that first gets a value of "PAGE" for the Cedit WindowText. Why doesnt it stop at
GetWindowText() the second time it comes around? I stepped through and after finding "PAGE" the first time, it sails through the lines in red on a second pass, and of course I never got a chance to change the CEdit entry, so the variable is still "PAGE", and an infinite for loop starts....
bool bExistingEntry;
do
{
<code> m_editAddNewKeyword.SetFocus();
m_editAddNewKeyword.GetWindowText(m_newKW);</code>
bExistingEntry = false;
for (int i = 0 ; i < m_numFields && !bExistingEntry ; i++)
if (bExistingEntry = (m_AddKWFldsHolder[i] == m_newKW))
{
AfxMessageBox("Keyword already exists in database. Add new Keyword or Cancel");
}
}
while (bExistingEntry);
Probably something goofy, but I cant see it....
Thanks,
ns
|
|
|
|
|
It does!! GetWindowText() just gets the text from the edit control into m_newKW . The proper way to validate input is in your dialog's OnOK() handler. Like so:
m_editAddNewKeyword.GetWindowText (m_newKW);
for (int i = 0 ; (i < m_numFields); i++) {
if (m_AddKWFldsHolder[i] == m_newKW) {
AfxMessageBox("Keyword already exists in database. Add new Keyword or Cancel");
return;
}
}
CDialog::OnOK();
/ravi
Let's put "civil" back in "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
How do I get my UI to pop up again after the messagebox is dismissed. I cant dismiss the messagebox, it keeps looping because I never get a chance to change the entry. I thought setfocus would do it, but it sails through that line I found...
|
|
|
|
|
See my edited reply. I figured I'd left out the essentials.
/ravi
Let's put "civil" back in "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
thanks a bunch! I didnt think of that!
|
|
|
|
|
Here is the message from VC Debug tool ,Can somebody tell me What does it mean?
First-chance exception in DMSClient.exe (KERNEL32.DLL): 0xE06D7363: Microsoft C++ Exception.
SIMPLE IS BEAUTY
|
|
|
|
|
ZBUILDER wrote:
First-chance exception in DMSClient.exe (KERNEL32.DLL): 0xE06D7363: Microsoft C++ Exception.
What does it mean?
Some code in Kernel32.dll threw an exception.
That is the meaning of that line, and as you choose not to give more information about the context, it is about all one can say about it.
|
|
|
|
|
A first-change exception normally is not a problem: it's the debugger's opportunity to see an exception before it is being handled by an exception handler (or catch-block). If no exception is propagated to your code, that means the writer of the library has foreseen the possibility of this exception and written an appropriate catch-block.
So don't worry about it.
|
|
|
|
|
Thank you very much.See you later?
SIMPLE IS BEAUTY
|
|
|
|
|
I make a program in window 95, In this environment it runs. Now I have took it to windows Millenium but when i run, it gives me a error "Debug Assertion faif, file: barstat.cpp, line 266". I have made a packet but it does not run.
thank in advances.
|
|
|
|
|
Simply look in barstat.cpp at line 266. The expression within ASSERT() (or similar) at that line evaluates to false running under ME, not in Windows95.
Or even easier: open in MS VC++, place somewhere before barstat.cpp 266, and trace the value of the expression.
|
|
|
|
|
Hi,
This is really annoying me.
char *buffer;
GetData(&buffer);
the plan here is that the GetData function will allocate buffer:-
void GetData( char ** ppBuf)
{
*ppBuf = new char [length];
strcpy (*ppBuf,"other data");
}
this appears to work. In fact, back in the original code block:-
printf(buffer);
works correctly.
But when i try and delete the allocated memory in the original code block:-
delete [] buffer;
I get a nasty debug "damage after normal block" type error. Both the main block and the called function exist within the same thread. I've traced through step by step in the debugger, and the address of the block of memory that is allocated by the new keyword is definately the very same block of memory that i am trying to delete.
Why does this occur????
thanks,
Jon
STL is a religeon. Enquiries to Reverend Christian Graus
|
|
|
|
|
Whats the value of length and does it include the \0 terminating character?
Roger Allen
Sonork 100.10016
I think I need a new quote, I am on the prowl, so look out for a soft cute furry looking animal, which is really a Hippo in disguise. Its probably me.
|
|
|
|
|
Ahah. Roger, you are a top banana. Whereas I am an idiot.
thankyou for your help!
|
|
|
|
|