|
I have a dialog based application.In this I have a button which takes the value in a textbox and adds it to a combobox.I have to enter values in three textboxes.All these values have to be written into a file.
I have writen the code as follows:
GetDlgItemText(IDC_EDIT1,str1);<br />
GetDlgItemText(IDC_EDIT1,str2);<br />
GetDlgItemText(IDC_EDIT1,str3);<br />
fstream f;<br />
f.open("myfile.txt",ios::in|ios::out);<br />
f.write(str1,str1.length());
When i open the file to view the contents,its not written properly.Also I want to append the details each time I enter values in the textboxes.
|
|
|
|
|
How str1, str2, str3 are declared.
What values were assigned to such variables?
What is written inside the file, insted?
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
[My articles]
|
|
|
|
|
All of str1,str2 and str3 are CString variables.the str3 im using is the name of a camera.appending is not done properly.file contents are not written properly...
|
|
|
|
|
How can we help you if you are so reluctant to provide meaningful info?
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
[My articles]
|
|
|
|
|
You wrote only the first string. What isnt properly?
Read the docs to fstream. This is really beginners stuff.
Greetings from Germany
|
|
|
|
|
try this
change the fopen as
f.open(myfile.txt",ios::in|ios::out|ios::app);
vineesh
|
|
|
|
|
projectip wrote: ...its not written properly.
Is this supposed to mean something?
"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
|
|
|
|
|
Hi all.
I am trying to open Xml file using parser..
I am using MSXML2.dll.
When i debug It is throughing Exception in this line
/////////////////////////////
EVAL_HR(objDOMDoc.CreateInstance("Msxml2.DOMDocument.2.0"));
/////////////////////////
In this line i am getting Error...
when I used MSXML4.dll..It is showing error "Cannot open MSXML4.dll..
any suggestions.
Here is the code..
////////////////////////////////
#include "stdafx.h"
#include "stdio.h"
#import "msxml4.dll"
using namespace MSXML2;
inline void EVAL_HR( HRESULT _hr )
{ if FAILED(_hr) throw(_hr); }
int main(int argc, char* argv[])
{
try
{
IXMLDOMDocumentPtr objDOMDoc;
EVAL_HR(CoInitialize(NULL));
EVAL_HR(objDOMDoc.CreateInstance(__uuidof(MSXML2::DOMDocument40)));
_variant_t varXml("C:\\book.xml");
_variant_t varOut((bool)TRUE);
objDOMDoc->async = false;
varOut = objDOMDoc->load(varXml);
if ((bool)varOut == FALSE)
throw(0);
printf(_bstr_t(objDOMDoc->xml)) ;
printf("\n\nPress ENTER to continue...\n");
getchar();
}
catch(...)
{
printf("Exception occurred");
printf("\n\nPress ENTER to continue...\n");
getchar();
return -1;
}
try
{
MSXML2::IXMLDOMProcessingInstructionPtr pPI = NULL;
MSXML2::IXMLDOMDocument2Ptr pXMLDoc = NULL;
MSXML2::IXMLDOMNodePtr pNode = NULL;
MSXML2::IXMLDOMNodeListPtr pXMLDomNodeList = NULL;
MSXML2::IXMLDOMNodePtr pRootNode= NULL;
EVAL_HR(CoInitialize(NULL));
EVAL_HR(pXMLDoc.CreateInstance(("Msxml2.DOMDocument.4.0")));
pPI = pXMLDoc->createProcessingInstruction
("xml", "version='1.0' encoding='UTF-8'");
_variant_t vNullVal;
vNullVal.vt = VT_NULL;
pXMLDoc->insertBefore(pPI, vNullVal);
_variant_t varNodeType((short)MSXML2::NODE_ELEMENT);
pRootNode= pXMLDoc->createNode(varNodeType,
("Root"),(""));
pXMLDoc->appendChild(pRootNode);
MSXML2::IXMLDOMNodePtr pAttNode= NULL;
MSXML2::IXMLDOMAttributePtr pattIdAttr = NULL;
pattIdAttr= pXMLDoc->createAttribute(("Name"));
pattIdAttr->nodeTypedValue = ("Namevalue");
pAttNode->attributes->setNamedItem(pattIdAttr);
pXMLDoc->save("C:\\s2.xml");
}
catch(...)
{
}
CoUninitialize();
return 1;
}
//////////////////////////////
Hi..
I am Mnaju.I have Completed my B.E Computers Science.Lokking for a job.I am interested in VC++
manju
|
|
|
|
|
You better write "MSXML2.DOMDocument.2.0"
is MSXML4.dll correctly installed?
Greetings from Germany
|
|
|
|
|
KarstenK wrote: You better write "MSXML2.DOMDocument.2.0"
is MSXML4.dll correctly installed?
I changed it and wrote..MSXML2.DOMDocument.2.0
MSXML4.dll is also installed..but same problem
Hi..
I am Mnaju.I have Completed my B.E Computers Science.Lokking for a job.I am interested in VC++
manju
|
|
|
|
|
Hi..
I have changed the code bit..
Its working fine..now
thank you
manju
Hi..
I am Mnaju.I have Completed my B.E Computers Science.Lokking for a job.I am interested in VC++
manju
|
|
|
|
|
Please modify your previous question instead.
Regards,
Sandip.
|
|
|
|
|
// Create a .h and .cpp file and create a new project include these file//
----------code for .h file---------------
#import <msxml.dll> named_guids
using namespace MSXML;
class CXMLEngine
{
public:
IXMLDOMDocumentPtr objDOMDoc;
BSTR mXML;
public:
CXMLEngine(){}
~CXMLEngine();
int CXMLEngine::Initialize(char *sFileName);
IXMLDOMNodePtr GetNode(BSTR sKey);
HRESULT DeleteNode(CString strName);
HRESULT SaveXML_To_File(char *filename);
HRESULT AddNodeKey(char *name,char *folderpath,char *moddate,char *ssd);
HRESULT ModifyKey(char *searchName,char *name,char *folderpath,char *moddate,char *ssd);
//HRESULT SetAttribute(IXMLDOMElement *oNode,char *sAttributeName, char *sAttributeValue);
void Refresh();
};
----------END code for .h fil------------
----------Code for .cpp file-------------
#include "stdafx.h"
#include "Xmltemp.h"
inline void EVAL_HR( HRESULT _hr )
{ if FAILED(_hr) throw(_hr); }
int CXMLEngine::Initialize(char *sFileName)
{
char searchPath[200];
try
{
EVAL_HR(CoInitialize(NULL));
//EVAL_HR(objDOMDoc.CreateInstance("Msxml2.DOMDocument.3.0"));
EVAL_HR(objDOMDoc.CreateInstance("microsoft.xmldom"));
GetCurrentDirectory(200, searchPath);
strcat(searchPath,"\\");
strcat(searchPath,sFileName);
_variant_t varXml(searchPath);
_variant_t varOut((bool)TRUE);
objDOMDoc->async = false;
varOut = objDOMDoc->load(sFileName); // (varXml);
mXML=objDOMDoc->xml;
if ((bool)varOut == FALSE)
throw(0);
return 0;
}
catch(...)
{
// AfxMessageBox("Exception occurred");
return -1;
}
CoUninitialize();
}
IXMLDOMNodePtr CXMLEngine::GetNode(BSTR sKey)
{
/*
Purpose:locate a specific node in the
xml structure by its "key" value
*/
CString sCriteria;
IXMLDOMNodePtr oNode;
sCriteria="Root/folders[@name $eq$ '";
sCriteria+=sKey;
sCriteria+= "']";
oNode=objDOMDoc->selectSingleNode(_bstr_t(sCriteria)); // (_bstr_t(sCriteria));
if (oNode!=NULL)
{
return(oNode);
}
else
{
AfxMessageBox("Node Not Found");
return(NULL);
}
}
HRESULT CXMLEngine::DeleteNode(CString strName)
{
IXMLDOMNodePtr urlsPtr = objDOMDoc->selectSingleNode(_T("Root")); // (_T("xml_api_reply"));
IXMLDOMNodeListPtr nodeListPtr = urlsPtr->selectNodes(_bstr_t("folders")); // (_bstr_t("weather"));
long item=nodeListPtr->Getlength();
for(int i=0;i<nodeListPtr->Getlength();i++)
{
_bstr_t tr1 =nodeListPtr-> item[i]->nodeName;
IXMLDOMNamedNodeMapPtr objAtrrValue= nodeListPtr-> item[i]->attributes;
VARIANT vFilePath, vFileName;
objAtrrValue->Getitem(0)->get_nodeValue(&vFileName);
CString strFileName = vFileName.bstrVal;
objAtrrValue->Getitem(1)->get_nodeValue(&vFilePath);
CString strFilePath = vFilePath.bstrVal;
if( strFileName == strName)
{
IXMLDOMNodePtr nodePtr= nodeListPtr->Getitem(i);
HRESULT hr =urlsPtr->removeChild(nodePtr); // remove node
}
}
objDOMDoc->save("foldre.xml"); // save file with this name
return(S_OK);
}
HRESULT CXMLEngine::AddNodeKey(char *name,char *folderpath,char *moddate,char *ssd)
{
IXMLDOMNodePtr urlsPtr = objDOMDoc->selectSingleNode(_T("Root")); // (_T("xml_api_reply"));
IXMLDOMNodeListPtr nodeListPtr = urlsPtr->selectNodes(_bstr_t("folders")); // (_bstr_t("weather"));
IXMLDOMElementPtr oElementNode=objDOMDoc->createElement("folders");
HRESULT hr=oElementNode->setAttribute(_bstr_t("name"),_bstr_t(name));
hr=oElementNode->setAttribute(_bstr_t("folderpath"),_bstr_t(folderpath));
hr=oElementNode->setAttribute(_bstr_t("moddate"),_bstr_t(moddate));
hr=oElementNode->setAttribute(_bstr_t("SSD"),_bstr_t(ssd));
urlsPtr->appendChild(oElementNode); // add node in file
objDOMDoc->save("foldre.xml"); // save file
return(S_OK);
}
HRESULT CXMLEngine::ModifyKey(char *searchName,char *name,char *folderpath,char *moddate,char *ssd)
{
IXMLDOMNodePtr urlsPtr = objDOMDoc->selectSingleNode(_T("Root")); // (_T("xml_api_reply"));
IXMLDOMNodeListPtr nodeListPtr = urlsPtr->selectNodes(_bstr_t("folders")); // (_bstr_t("weather"));
long item=nodeListPtr->Getlength();
for(int i=0;i<nodeListPtr->Getlength();i++)
{
IXMLDOMNamedNodeMapPtr objAtrrValue= nodeListPtr-> item[i]->attributes;
VARIANT vFilePath, vFileName;
objAtrrValue->Getitem(0)->get_nodeValue(&vFileName);
CString strFileName = vFileName.bstrVal;
objAtrrValue->Getitem(1)->get_nodeValue(&vFilePath);
CString strFilePath = vFilePath.bstrVal;
if( strFileName == searchName )
{
IXMLDOMNodePtr nodePtr= nodeListPtr->Getitem(i);
HRESULT hr;
IXMLDOMElementPtr oElementNode=objDOMDoc->createElement("folders");
hr=oElementNode->setAttribute(_bstr_t("name"),_bstr_t(name));
hr=oElementNode->setAttribute(_bstr_t("folderpath"),_bstr_t(folderpath));
hr=oElementNode->setAttribute(_bstr_t("moddate"),_bstr_t(moddate));
hr=oElementNode->setAttribute(_bstr_t("SSD"),_bstr_t(ssd));
urlsPtr->replaceChild(oElementNode,nodePtr);
}
}
objDOMDoc->save("foldre.xml");
return(S_OK);
}
----------End code for .cpp file---------
I hope this will solve the problem
modified on Monday, December 28, 2009 6:55 AM
|
|
|
|
|
I want to create a List Control with ComboBox and Progress Bar in CListCtrl subitem.
Thanks in Advance.
-@SuDhIrKuMaR@-
|
|
|
|
|
Well, you have two completely different questions there.
If you look in the Button section of articles, you'll find a bunch of pretty buttons with a drop down arrow just like combo boxes. Then you can monitor for the "I've been clicked!" message, and show a List Control if you so wish.
As for showing a progress bar in a List Ctrl, there's an article under the List Control section called "List Control Extended for Progress Control". I can't think how searching could find you a better option.
It's all on here [*] if you look for it!
Iain.
[*] OK, not *all*, but lots...
Plz sir... CPallini CPallini abuz drugz, plz plz help urgent.
|
|
|
|
|
sudhir_Kumar wrote: I want to create a List Control with ComboBox and Progress Bar in CListCtrl subitem.
Atleast search in the codeproject before asking a question.
see here [^] or here[^]
|
|
|
|
|
In windows vista, whenever windows security requires your permission to do something, it pops up a dialog box asking whether to allow/cancel, and everything on the screen behind the dialog box becomes dark. It is like the rest of the screen has a black tinted glass over it and only that dialog is bright and shiny in the middle. How do I replicate this behavior with a popup in visual c++ with MFC ?? If you could recommend some API or link me to an article you know of on the topic it would be great. I am using VS2008 if that matters.
|
|
|
|
|
garyofcourse wrote: a dialog box asking whether to allow/cancel
When ever a UAC dialog is displayed in vista, it takes screeshot of the current desktop, then creates another desktop with that image in the background. That means, they apply the effect to the image they captured from the original desktop.
|
|
|
|
|
I have a combo box in my dialog.after entering a text in a text box,i get it in the combobox.this is achieved by pressing an add button.what i want is to clear the text box after the item is added.what to do?
|
|
|
|
|
myTextBox.SetWindowText(_T(""));
|
|
|
|
|
What about MyCombo.SetWindowText(_T("")); ?
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
[My articles]
|
|
|
|
|
Okay I don't have answer to your question but I have few english tips for you.
1. There is a space after a .
2. There is a space after a ,
3. Every first letter of a sentence should be capitalized.
4. 'i' should be capital (upper case.
Of course there are many more rules, please buy a book and read it. It will help us help you better. If you already know this then stop being lazy and type properly.
As it is you questions are very hard to read this.
-Saurabh
|
|
|
|
|
Saurabh.Garg wrote: 4. 'i' should be capital (upper case.
5. Every parenthesis opened '(' must be closed by a ')' and not a '.'
I agree with your post, but I couldn't resist joking.
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Visual C++ MVP
|
|
|
|
|
-Saurabh
|
|
|
|
|
void CTestDlg::OnAdd_Click(void)
{
CString strText = _T("");
GetDlgItemText(IDC_EDIT1, strText);
m_ctrlCombo.AddString(strText);
SetDlgItemText(IDC_EDIT1, _T(""));
}
|
|
|
|