|
See this article.
/ravi
Let's put "civil" back into "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
Hi All,
What's the simplest way to get the current date and time as a string that can be used in a filename? I have an app that spits out a lo every time it is run, and I need to make the filename unique for each run.
Thanks
|
|
|
|
|
CTime CurrentTime;
CurrentTime = CTime::GetCurrentTime();
CString strTime = CurrentTime.Format("%Y-%m-%d %H:%M:%S");
Cheers,
Fredrik
<right>Sonork ID: 100.11430:PhatBoy
"Felix qui potuit rerum cognoscere causas."
|
|
|
|
|
OK, thanks for your quick response. But, this is inside an ATL COM object where I don't have MFC. Do you know off hand what the corresponding Win32 calls are?
Thanks again,
aaron
|
|
|
|
|
I'm using MS VC++ 6.0 with MFC.
I want to load an XML string and analize it. So, i'm using msxml3 like this:
IXMLDOMDocument* xdoc;
HRESULT hr;
hr=CoCreateInstance(CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER,
IID_IXMLDOMDocument, (void**)&xdoc);
if(SUCCEEDED(hr))
{
BSTR xmlstr;
xmlstr=(unsigned short*)"<aaa>aa";
VARIANT_BOOL scc;
xdoc->put_async(FALSE);
xdoc->put_resolveExternals(FALSE);
xdoc->put_validateOnParse(FALSE);
xdoc->loadXML(xmlstr, &scc);
if(!scc) AfxMessageBox("Bad xml string");
else AfxMessageBox(" Xml string loaded");
}
else AfxMessageBox("Can't create object");
Problems: when I run it, I get the "Bad xml string".
Here is the debug window:
.....................................................
Loaded 'C:\Me\Documentatie\XML\new\msxml3.dll', no matching symbolic information found.
First-chance exception in TSTCON32.EXE (KERNEL32.DLL): 0xE0000001: (no name).
First-chance exception in TSTCON32.EXE (KERNEL32.DLL): 0xE0000001: (no name).
First-chance exception in TSTCON32.EXE (KERNEL32.DLL): 0xE0000001: (no name).
First-chance exception in TSTCON32.EXE (KERNEL32.DLL): 0xE0000001: (no name).
First-chance exception in TSTCON32.EXE (KERNEL32.DLL): 0xE0000001: (no name).
First-chance exception in TSTCON32.EXE (KERNEL32.DLL): 0xE0000001: (no name).
The program 'C:\Program Files\Microsoft Visual Studio\Common\Tools\TSTCON32.EXE' has exited with code 0 (0x0).
What's the problem ?
|
|
|
|
|
1. You don't create a BSTR like that.
Firstly, IIRC, BSTRs have the length embedded before the BSTR address (like Pascal strings), so either use ::SysAllocString or one of the BSTR wrappers in VC++ (_bstr_t or CComBSTR (well, that's in ATL, but hey!)).
Secondly, you can't just cast a char string (i.e. "aa") to OLECHAR* - OLECHARs on Win32 are wchar_t (16 bit), not char (8 bit), so you need to convert the ASCII string to a wide character string. There is an API function to do it, but it's more hassle than I can be bothered with , so I just use one of the wrappers, as they have a constructor to do the required conversion:
CComBSTR bs = "aa";
The wrapper also deallocates the BSTR afterwards, which helps.
2. You really want to pass VARIANT_BOOL values rather than BOOL values as boolean parameters - in this case, FALSE == VARIANT_FALSE, but using VARIANT_FALSE gets you in the right mindset.
3. (And this is the major reason it won't work as is!) "aa" is NOT a well-formed XML document (which is what loadXML expects). The following would be OK:
<aa/>
<aa></aa>
Stuart Dootson
'Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p'
|
|
|
|
|
Hi,
Considering user interfaces for my (mfc) application.
Basically, the app gathers information from the user in a property sheet style, with about 10 pages. Thats pretty much all it'll do.
I was thinking it'd be rather nice to use some kind of html view, so that I could provide HTML source for each of the pages (probably as a string resource), including images in the html to make it look nice (images also from resource). The pages would consist of html forms, and when you filled them out and clicked submit, that would call functions inside of my code.
So all i really want to do is hijack IE's layout engine. I do not want users to be able to use my app as a web browser, and navigate to other places.
Is there a way to do this? i couldn't see a way of loading my own html source dynamically into CHtmlView.
Thanks
Jon
STL is a religeon. Enquiries to Reverend Christian Graus
|
|
|
|
|
Well the simplest way would be to write your html output to a temp folder, and make the CHtmlView open that (remembering to delete the files afterwards)
--
Help me! I'm turning into a grapefruit!
|
|
|
|
|
Hi,
I´m inserting my ATL ActiveX control into word, all seems to be fine, in run mode and design mode, but when I´m going to print, then Ms Word thinks that the ActiveX is smaller, and it shows my activeX and some lines of text inside my activeX.... (
Do you now any workaround solution or whatever for this big mess ? ( maybe use StarOffice and XML ).
Greetings
Braulio
|
|
|
|
|
The question is simple, i have the following code for my popup menu:
Menu=new CMenu;
Menu->CreatePopupMenu();
(...)
Menu->AppendMenu(MF_STRING | MF_ENABLED, 0, "Insert");
Menu->AppendMenu(MF_STRING | MF_ENABLED, 0, "Delete");
(...)
Menu->TrackPopupMenu( TPM_LEFTALIGN
| TPM_RIGHTBUTTON | TPM_LEFTBUTTON,
Point.x, Point.y, ParentWindow);
Menu->DestroyMenu();
It works ok.
But i need to process commands to make it worth anything.
When I use:
Menu->AppendMenu(MF_STRING | MF_ENABLED,
ID_INSERT_ATTRIBUTE, "Insert");
Menu->AppendMenu(MF_STRING | MF_ENABLED,
ID_DELETE_ATTRIBUTE, "Delete");
These items appear as grayed and unavailable.
I've used CMenu::GetMenuItemID to check if the ID is assigned - it is (returned values were ID_INSERT_ATTRIBUTE and ID_DELETE_ATTRIBUTE).
I also used CMenu::EnableMenuItem to enable these (this function returned MF_ENABLED as a previous state of item ).
Did i missed something?
Krzysztof Szczech
[ CoY0te ]
|
|
|
|
|
Hi,
I want to overwrite 32 caracters in a text file...
For the moment I do :
CStdioFile newFile;
newFile.SeekToBegin();
for(i = 0; i < 9; i++) {
if(!newFile.ReadString(str, MAX_BUFFER_SIZE)) {
MessageBox("End of file prematurely detected");
return;
}
}
newFile.WriteString(strCRC + "\n");
newFile.Close();
but this doesn't work...
I try to understand... Anybody can help me ?
Thanks in advance.
Hello World!!!
from Raphaël
|
|
|
|
|
I don't know what arguments do You pass in the Open() method, but it could be a matter of open mode if You used
CFile::modeRead
instead of
CFile::modeReadWrite
...just guessing...
Krzysztof Szczech
[ CoY0te ]
|
|
|
|
|
I use this:
CFileException exc;
if(!newFile.Open(strFileName, CFile::modeCreate | CFile::modeReadWrite | CFile::typeText, &exc) ) {
exc.ReportError();
return;
}
Next, I fill the file... And then I try to overwrite the same file.
Hello World!!!
from Raphaël
|
|
|
|
|
Sorry, I've missed that Read/Write in Your source code.
But the problem is quite strange. I doubt I'll be able to help, but please take a look at my question above (about CMenu), maybe You could help me with this.
[ CoY0te ]
|
|
|
|
|
Shouldn't you add modeNoTruncate to the flags?
If you use modeCreate only, then the file will be truncated to zero length.
Cheers,
Fredrik
<right>Sonork ID: 100.11430:PhatBoy
"Felix qui potuit rerum cognoscere causas."
|
|
|
|
|
I don't have to add this flag because I fill the file with caracters first (after his creation), and then I overwrite it.
Thus, initially empty or not it's not a problem.
Hello World!!!
from Raphaël
|
|
|
|
|
Then what is your problem? You are a bit unclear.
Do you get exceptions, if so, what do they say?
Cheers,
Fredrik
<right>Sonork ID: 100.11430:PhatBoy
"Felix qui potuit rerum cognoscere causas."
|
|
|
|
|
I don't have any Error or Warning and no more exceptions...
My goal is simply a partial rewriting of a text file. Thus some line change but keep the same number of caracters...
My question is: How to do that?
Hello World!!!
from Raphaël
|
|
|
|
|
You had code for that, right?
So I ask again: what part is not working?
Cheers,
Fredrik
<right>Sonork ID: 100.11430:PhatBoy
"Felix qui potuit rerum cognoscere causas."
|
|
|
|
|
An idea: can't you just append the CRC to the end of the file? (::SeekToEnd() and then ::Write())
Cheers,
Fredrik
<right>Sonork ID: 100.11430:PhatBoy
"Felix qui potuit rerum cognoscere causas."
|
|
|
|
|
No I must respect the RBT file format (it's a text file) because this file is used by another program (who program the Flash component of an electronic board)...
yeap...
Hello World!!!
from Raphaël
|
|
|
|
|
The code:
CStdioFile newFile;
CFileException exc;
if(!newFile.Open(strFileName, CFile::modeCreate | CFile::modeReadWrite | CFile::typeText, &exc) ) {
exc.ReportError();
return;
}
newFile.SeekToBegin();
for(i = 0; i < 9; i++) {
if(!newFile.ReadString(str, MAX_BUFFER_SIZE)) {
MessageBox("End of file prematurely detected");
return;
}
}
newFile.WriteString(strCRC + "\n");
newFile.Close();
Compilation is OK...
Finaly the 9th line (of the file) is not rewrited. Why?
Hello World!!!
from Raphaël
|
|
|
|
|
I change my method... I'll create a buffer then I'll copy this buffer inside the file...
Thanks neverthless
Hello World!!!
from Raphaël
|
|
|
|
|
The code above positions to the start of the 10th line. It reads the first 9. If you really want to position to the 9th line, try for (i=0;i<8 ...
|
|
|
|
|
Yes but my first line is the 0th line... Thus that's OK because the 9th line is the 10th in the reality (As you say)...
But, concerning the overwriting of a file, my conclusion is that "that doesn't work" because you must be at the end of the file, and thus you can only Add line to a file (in the end). The reason is that the Write and Read methods are both sequential. What's strange is that no error was detected (for the compilation and execution). Moreover is that in the watch window, during the debug, the pointeur to the file shows well that he wrote(overwrote). But after the execution, when I open the file, no modification was found.... Strange... but it's the live...
Thanks...
Hello World!!!
from Raphaël
|
|
|
|