|
The reason for the failure is not in the way you write to the file; it is in the way you open it. The CFile::modeCreate flag instructs the constructor to create a new file. If there is an existing file with the same name, it is truncated to zero length, thus wiping it clean.
In order to accomplish the desired result, you must open the file with a combination (OR) of flags CFile::modeCreate and CFile::modeNoTruncate . This combination will, if the file exists, open the file normally, and if it doesn't, it will create a new file. Removing both flags causes the function to fail if the file doesn't exist.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
|
Thank you very much. Best wishes.
|
|
|
|
|
Hello.
I have problems with my homework...i'm a newbie in programming. I did some easy progs by my self, but i'm stucked with this one, if anyone had done similary program please help me.
The computer have N-CPUs. On this computer is executing M jobs at the same time. Every job have it's own execution time. Write a program, which find the optimal arrange M-jobs on N-CPUs. Optimal is, when the time of executing all jobs is smallest.
I must write this with a recursion...but I almost gave up.
I was looking about permutations...but here isn't really same story...cause of N CPU-s.
I don't need whole program or anything, if anyone just know some advices, pleas help me.
tnx.
my english sux...
|
|
|
|
|
Let us approach the problem from a completely abstract level..
Firstly, your problem description does not specify the environment of the CPUs. If they are capable of multithreading, there should be some reference value of how many jobs one processor can simultaneously execute. But, as none is given (?), we will assume that each processor handles a single job first before accepting a new one.
This assumption will quickly lead us into mathematical equations: considering that the execution time of a random job is X seconds and is independent of the selected processor (equal speeds), then the equation would form up to something like "time = (M/N)*X".
As for the actual programming problem, recursion is a very effective way in solving equations that have an exponential form, such as 2^4. It would be a recursive function that multiplies 2 by 2 and gets executed 3 times. Your job here would then be to find the minimum of variable 'time' from the above equation. Needless to say, probably, that if X is equal on each job, the optimized result is when M = N.
Unfortunately I have no prepared example code for this purpose. The best way is to dig up some pen and paper, then attempt to create an exponential expression for 'time'. This expression can then be easily formatted into a recursive function.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
I need to figure out a way to drop objects, text, images (of buttons, checkboxes, listbox's, etc) on a control/form and be able to click on them at a later point and move them around. A great example of this dialog editor in Visual Studio, in the resources tab where I can drop text, controls, etc...
Thanks
Ralph Krausse
|
|
|
|
|
I'm trying to make an Owner-Draw Button Class in pure Win32 SDK (without any MFC Class), but I can get a WM_DRAWITEM message.
I changed the default WNDPROC for the control, so it can deal with his own messages, like WM_MOUSEMOVE, WM_MOUSEHOVER and WM_MOUSLEAVE, using:
m_OldWndProc = (WNDPROC)SetWindowLong(m_hWnd, GWL_WNDPROC, (LONG)BottonProc)
Nether, the window and the control receive the WM_DRAWITEM.
I’m not using a dialog template or resource. I’m drawing the dialog with code.
I don’t know what’s happened, what to do, or when to draw the button.
If anybody knows how to do it, please let me know.
Thanks.
|
|
|
|
|
Have you set the owner draw style bit when you created the control?
onwards and upwards...
|
|
|
|
|
Yes!
I create the button this way:
hButton = CreateWindow("BUTTON", "X", BS_OWNERDRAW, x, y, 30, 30, hWnd, NULL,(HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE), NULL)
|
|
|
|
|
Dont forget the WS_CHILD and WS_VISIBLE styes to make sure the window is shown correctly
Roger Allen - Sonork 100.10016
Roger Wright: Remember to buckle up, please, and encourage your friends to do the same. It's not just about saving your life, but saving the quality of life for those you may leave behind...
|
|
|
|
|
At last!!!
Thanks a lot!!!
|
|
|
|
|
Is there a way to print a .net bitmap with mfc? Thanks
|
|
|
|
|
I have a dialog app and I'm trying to change the background of most of the controls on the dialog. This is the code I'm using, but it isn't changing the controls backgrounds.
if (nCtlColor == CTLCOLOR_STATIC)
pDC->SetBkColor (RGB (255, 255, 255)) This code is in the OnCtlColor function of my dialog class. When I run the program only static controls colors are changing and not my checkboxes or groupboxes. According to my reading CTLCOLOR_STATIC is the same id passed into the function for statics, groupboxes, checkboxes, and a couple other control types. Am I wrong? If so how do I go about changing the background of those controls.
Thanks.
- monrobot13
|
|
|
|
|
Hi,
First, I'm a beginner and I'm doing a little project in MFC and i'm using VS .NET 2003.
I want to put the current month concatenated with an other word as default save name when I save my document. So I want to be able to pass a CString variable to the IDR_MAINFRAME string.
Example: JanuaryDave.sav
I searched on the internet and found nothing on the subject.
Can someone indicate me an article or an example of what I want to do.
Thanks.
David
|
|
|
|
|
I have seen software where the user clicks Update
and the software goes and checks and then downloads
an update and replaces itself with that update. Does
a demo project exist that does something like this?
Please, any response any one can give me will be
greatly appreciated.
Sincerely,
Danielle (an overworked graduate student)
|
|
|
|
|
the usual question, my application crashes and I can't really figure out where and what I did since yesterday ... and I'm kinda stumped
the only difference is that I "updated" my computer with the windows updater, maybe I need to reinstall VC service pack ( which I will, it doesn't hurt does it ? ). and build using BoundChecker instrumentation, ( but I scrapped the objects files and libs. and rebuild without instrumentation after !)
anyway, it's crashing/asserting in low level routines when allocating (with new ) and freeing (delete) objects; in DEBUG mode; if I continue (F5) it continues without a itch ...
it's an MFC application using Visual C++ 6 sp5.
( in the output window )
HEAP[app.exe]: HEAP: Free Heap block 1919740 modified at 19199e0 after it was freed
I know it's not much, but I can't reduce the error to some line of code that I post here.
any thoughts ?
Much Thanks ...
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
I'd say whatever is causing this has been there all along and has decided to appear because of the PC updates, but has nothing to do with them. This is often the case with memory corruption problems unfortunately.
The Debug info is telling you that you are modifing memory that has previously been free'd. This will happen if you use a pointer that has been free'd or you have some erant code (pointers) writing into memory where they shouldn't be.
Break into the debugger when the error occures and dump the memory at the spec'd address and see if its contents means anything to you.
Also after freeing a pointer set it to NULL so you will get an exception if it used again. Make sure all pointers are initialized. Try to move away from using new and delete and look at smart pointers and RAII.
Hope that helps.
Neville Franks, Author of ED for Windows www.getsoft.com and coming soon: Surfulater www.surfulater.com
|
|
|
|
|
Neville Franks wrote:
Break into the debugger when the error occures and dump the memory at the spec'd address and see if its contents means anything to you.
will check this ... I never think of looking in the memory dump.
Neville Franks wrote:
Also after freeing a pointer set it to NULL so you will get an exception if it used again. Make sure all pointers are initialized. Try to move away from using new and delete and look at smart pointers and RAII.
yes I do this and I'm also maintaining old C code and I try to go update as much as I can when I can.
and what are RAII ?
Thanks.
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
Maximilien wrote:
and what are RAII ?
"Resource Acquisition Is Initialization". Do a Google search on "C++ RAII" etc.
Neville Franks, Author of ED for Windows www.getsoft.com and coming soon: Surfulater www.surfulater.com
|
|
|
|
|
i get the handle of a textbox in an opened window using the function
EnumChildWindows(,,)..
after i obtained the handle of this textbox i want to set a specific
string in this textbox.
"HINT" : the function SetWindowText(,) isn't a valid to this task(why?)
more--->
the opened window has a textbox ,a button ,a label;
and when i used the spy++ program of Microsoft tools to get the caption
to each of them after using SetWindowtext(,),i observed that:
the caption of the label is same as the value appears on it<the
caption="" and="" value="" appears="" are="" equal="" to="" each="" other="" the="" string
posted="" by="" setwindowtext()=""> ,BUT
the caption of the textbox isn't the same as the value appears on it
<the value="" is="" nothing="" but="" the="" caption="" equal="" to="" string="" posted="" by=""
setwindowtext()="" function="">then i want an API function to set the value of the textbox not the
caption..
thank you very much for any help..
Sender :Amr abdel mohsen
Email: app_prog@yahoo.com
amr abdel mohsen
|
|
|
|
|
You can't use SetWindowText to set the text of a textbox; SetWindowText sets the text of the window itself.
- Nick Parker My Blog
|
|
|
|
|
No.....
SetWindowText sets the text of _any_ window. Everything in Windows is a window, including simple controls. What the window does when it gets a WM_SETTEXT message varies between what it is.
A popup window (ie a normal window with a caption) sets it's caption
A button sets it's label
A edit control sets it's text
"This function changes the text of the specified window’s title bar, if it has one. If the specified window is a control, the text of the control is changed. For an edit control, the text is the contents of the edit control. For a combo box, the text is the contents of the edit-control portion of the combo box. For a button, the text is the button name. For other windows, the text is the window title."
Etc etc.
Assume when you say "textbox" you mean edit control. What may be causing you grief is the fact that the window handle belongs to another process and SetWindowText first validates the Window (if it's a control) to see if it belongs to the calling process.
Rather than use SetWindowText, do it manually with WM_SETTEXT
LPCTSTR pszTextToSet = "Hello";
::SendMessage(hWndTheControl, WM_SETTEXT, 0, (LPARAM)pszTextToSet);
|
|
|
|
|
Diddy wrote:
SetWindowText sets the text of _any_ window. Everything in Windows is a window, including simple controls. What the window does when it gets a WM_SETTEXT message varies between what it is.
Thanks for correcting me Diddy.
- Nick Parker My Blog
|
|
|
|
|
Hi All,
I am converting a project from VC6 to .net2003 and am running into a compiler error with my (user) message maps. I can't see what is wrong - worked fine in VC6...
Here is the compiler error:
SimParamsDialog.cpp(80) : error C2440: 'static_cast' : cannot convert from 'void (__thiscall CSimParamsDialog::* )(void)' to 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)'
None of the functions with this name in scope match the target type
Here are the message maps:
- these defines are actually in a .h file
#define WM_LOADSENSORSTOGRID WM_USER + 1
#define WM_LOADCALDATATOGRID WM_LOADSENSORSTOGRID + 1
BEGIN_MESSAGE_MAP(CSimParamsDialog, CFormView)
//{{AFX_MSG_MAP(CSimParamsDialog)
ON_BN_CLICKED(IDC_BUTTON_SENDALARM, OnButtonSendAlarm)
ON_WM_TIMER()
ON_MESSAGE(WM_LOADSENSORSTOGRID, OnLoadSensorsToGrid)
ON_MESSAGE(WM_LOADCALDATATOGRID, OnLoadCalDataToGrid)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
and the function(s):
void CSimParamsDialog::OnLoadSensorsToGrid(WPARAM wParam, LPARAM lParam)
{
etc
}
void CSimParamsDialog::OnLoadCalDataToGrid(WPARAM wParam, LPARAM lParam)
{
etc
}
Any ideas? Again this works in VC6...
Thanks
John
|
|
|
|
|
AFAIK your functions have to return an LRESULT, not a void.
LRESULT CSimParamsDialog::onloadSensorsToGrid(WPARAM wParam, LPARAM lParam)
{
...
return 0;
}
LRESULT CSimParamsDialog::onloadCalDataToGrid(WPARAM wParam, LPARAM lParam)
{
...
return 0;
}
Sonork 100.11743 Chicken Little
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
Within you lies the power for good - Use it!
|
|
|
|
|