|
Hello everyone.In my program,I want to change a file's content,so I create a create file to copy data from source file and write new data,too.
When all file reading and writing completed,I want to delete the source file and rename the temp file to the source file name.If the source file path is sourcePath,and the temp file path is tempPath,my codes look like following:
if(remove(sourcePath)==0)//sourcePath is the full path of the source file
rename(tempPath,sourcePath);
Of course,the source and temp file are in the same directory.
But it is strange that,if i separate the codes as a short test console project,it works well!
Someones would like to tell me why?
Thanks.
GOOD LUCK
|
|
|
|
|
kcynic wrote: But it is strange that,if i separate the codes as a short test console project,it works well!
Someones would like to tell me why?
If rename() is failing, check errno .
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Are you sure path is correct?
|
|
|
|
|
Hello. I'm trying to parse some web data with the following code. It's going reasonably well, but I seem to get control characters (little squares) in the CString, making the parsing more difficult. If they're on the end I can use Trim() to remove them, but if they're in the middle it's more problematic. Since I can't represent them with the keyboard it's difficult to use the Span functions. Does anyone have any suggestions? Thank you.
IHTMLElement* pElem;
hr = pHTMLDocument2->get_body( &pElem );
if ( hr == S_OK && pElem != NULL )
{
pElem->get_innerText(&bstr);
CString strInnerText = bstr;
ScrapeFuturesSettlementData( strInnerText );
}
pHTMLDocument2->Release();
Tom
|
|
|
|
|
Do you know the ASCII value of said "square" characters?
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
|
How to load a image from a file and show it with a dialog box in VC++ 6?
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
If you are using MFC, and your dialog template has a static control on it, check out CStatic::SetBitmap() . Otherwise, if you want the image to be the dialog's background, see here.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
modified on Wednesday, December 05, 2007 8:57:09 AM
|
|
|
|
|
Or you can use of WM_ERASEBKGND .
|
|
|
|
|
In trying to add WM_VSCROLL to message handler for slider control in VS 2005 with C++ and MFC, I ran into problem that the slider only supports 4 NMXXXXXXXXX messages or events. What wizards and tabs/menu selections do I choose to get to a place where I can add the WM_VSCROLL message handler to handle messages for the slider so I can get access to it's current value. This is probably an easy thing to do, but it seems like it has gotten more difficult since access to all the messages has been limited, leaving only a very small subset.
GrizMan
|
|
|
|
|
The messages are sent to the trackbar control's parent by default.
You could right click the parent window class in the class view window,
choose properties, select the messages tab in the properties window,
and add the WM_VSCROLL handler there.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
In the MSDN source code for some GDI+ methods, the authors use malloc and free. Why would they do this if RectF is a class? Is this a hint that it is merely the equivalent to a struct with the ctor and dtor doing nada? Should we follow this convention or use new/delete instead?
Here's an example for GetRegionScans()...
VOID Example_GetRegionScansRect(HDC hdc)
{
Graphics graphics(hdc);
SolidBrush solidBrush(Color(255, 255, 0, 0));
Pen pen(Color(255, 0, 0, 0));
GraphicsPath path;
Matrix matrix;
Rect* rects = NULL;
INT count = 0;
path.AddEllipse(10, 10, 50, 300);
Region pathRegion(&path);
graphics.FillRegion(&solidBrush, &pathRegion);
graphics.GetTransform(&matrix);
count = pathRegion.GetRegionScansCount(&matrix);
rects = (Rect*)malloc(count*sizeof(Rect));
pathRegion.GetRegionScans(&matrix, rects, &count);
for(INT j = 0; j < count; ++j)
graphics.DrawRectangle(&pen, rects[j]);
free(rects);
}
modified on Tuesday, December 04, 2007 1:45:44 PM
|
|
|
|
|
bob16972 wrote: Why would they do this if RectF is a class?
Does its constructor/destructor do anything?
Keep in mind that just because it's an MSDN sample, that does not imply it's also perfect code. Folks that supply samples to MSDN are not infallible. MSDN does provide lots of great code, some of which can be used unaltered, but it should still be scrutinized regardless.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
DavidCrow wrote: Does its constructor/destructor do anything?
I'm not sure the GDI+ source code is available for inspection (except the declaration files of course)
DavidCrow wrote: Keep in mind that just because it's an MSDN sample, that does not imply it's also perfect code. Folks that supply samples to MSDN are not infallible. MSDN does provide lots of great code, some of which can be used unaltered, but it should still be scrutinized regardless.
I understand what your saying. I was scrutinizing it and I couldn't determine why they were doing it. I thought I'd post the question to see if it made sense to anybody and if they could explain what benefits the author is realizing here or if the code is flawed.
Thanks for the input.
|
|
|
|
|
Hi, I gess is using malloc and free to avoid a loop for alocation a "count" number of Rect objects, alocation all of them in one malloc
look at
malloc(count*sizeof(Rect)<code> parameter of malloc.<br />
<br />
<br />
<br />
|
|
|
|
|
Hi
there is a dll with cpp and h and lib file that is usable in VC++ we need to define it and use it in VB or VC# please help me.
Best regards
|
|
|
|
|
|
Does anyone know of any free alternatives to using iexpress.exe to package an installer/msi into a self-extracting/self-installing executable? I've been using iexpress until I upgraded to Vista/VS2008 and now whenever I run a package I get the error "This installation package could not be opened. Verify that the package exists and that you can access it, or contact the application vendor to verify that this is a valid Windows Installer package."
{o,o}.oO( Did somebody say MouseDown? )
|)””’)
-”-”-
|
|
|
|
|
Hi,
I am working on an application which generates a tree data structure. Whilst this can be presented to the user using the standard windows tree control; I feel that the data would be best represented as a heirarchy:
(please ignore initial dots)
.....[ ]<br />
..../ | \<br />
..[ ][ ][ ]
I have been searching the net extensively for an algorithm which computes the output rectangle for each node. I have not been able to find anything of use; however on one website somebody mentioned Walker's algorithm.
It would be great if somebody could either explain or refer me to a useful resource which details how this could be achieved.
I intend to use the MFC framework when drawing the tree.
Any advice would be greatly appreciated!
Lea Hayes
|
|
|
|
|
I spent 18 months on and off on exactly this problme when I was 12-13 and writing a family history app. I was laying out descendant trees and struggled with getting them correctly organised for a long time. In the end I found a 3 pass algorithm worked best. Top down to get the structure and child groupings. Bottom up to establish the required width for the descendants of each node and then top down again to centre each set of child nodes under the parent/parents. I was very proud of my tree layout algorithm although I'm sure it's pretty standard stuff and in lots of books. My mother's second cousin tried to commercialize the app wihtout crediting me but as far as I know it didn't work out.
I was highly ammused when I got my first copy of MS Windows and found MS had outsourced development of the organisation chart application. Perhaps I could have made some money out of my trees after all
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
Matthew Faithfull wrote: My mother's second cousin tried to commercialize the app wihtout crediting me
Nice guy.
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.
|
|
|
|
|
To draw the 2D Tree, first you need to find out the maximum width of the tree, which means you need to use BFS solution to iterate the tree.Once you have done that, you can draw whatever you want.
|
|
|
|
|
Hello everyone,
Why the below code segment will result in compile error? When I change code to the comment one (constructor), it can compile. The compiler is too stupid?
I am using Visual Studio 2005.
--------------------
main.cpp(13) : error C2758: 'Foo::vi' : must be initialized in constructor base/member initializer list
see declaration of 'Foo::vi'
--------------------
#include <vector>
using namespace std;
class Foo {
private:
vector<int>& vi;
public:
Foo (vector<int>& vi_in)
{
vi = vi_in;
}
};
int main()
{
vector<int> vi;
Foo foo = Foo (vi);
return 0;
}
thanks in advance,
George
|
|
|
|
|
George_George wrote: The compiler is too stupid?
Nope.
Reference types need initialization. See there http://www.devx.com/getHelpOn/10MinuteSolution/17298/1954?pf=true[^]
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.
|
|
|
|
|
So, it happened to you too ?!
|
|
|
|