|
Hi guys
How can I add code to the Standard Save on a menu of a SDI app?
Best Regards
Dr.Pi
|
|
|
|
|
|
If your using MFC override the Serialize() function in your derived class, call the base class function first and then add your code. I'm assuming you've set up the message map stuff for the standard save menu button correctly. If your using win32, then it depends...we need more info
|
|
|
|
|
Just noted JWood's response, if you want to do something extra before or after a save (pop a dialog box etc. then override OnSaveDocument(), but if you want to save extra stuff or mess with the io methods you'll need to override Serialize(). Hope this helps you. Check either of these methods out in MSDN for a deeper explanation. .
|
|
|
|
|
Thanks to everybody, I'll take a look on Serialize.
I had to save thinks like bool,float,arrays etc.. is then Serialize the place to do it? And then, later when I wanted to read it, is in Serialize too?
Best Regards
Dr. Pi
|
|
|
|
|
Replying to myself and waiting your answer.
I had to override serialize in each class where I have data to save, and then automatically when I call Save, all this data will be saved, and when I call Open, all this data will be retrieved (obviously if I implement correctly the serialize).
Is something like this?
if (ar.IsStoring())
{ // storing code
ar<<m_ncode
="" }
="" else
="" {="" loading="" code
="" ar="">>m_nCode
}
It doesnt' matter what m_nCode is?
Bast Regards
Dr.Pi
|
|
|
|
|
I know how to do this through explorer and how to 'open' and 'close' IO to the serial ports but I actually want to disable them.
How would I do this progmatically??
|
|
|
|
|
One solution is to disable the COM port. Check out this reference at MSDN.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/devio/base/device_management_functions.asp
I am not familiar with serial ports, but try openning a connection and keep it alive at all time. That may block any I/O.
Kuphryn
|
|
|
|
|
dear all,
the following lines of code gives wrong value on windows 2000, but on every other operating systems it works fine
<br />
if (sDir.CompareNoCase("M") != 0)<br />
{<br />
.....<br />
}<br />
but if i use a variable with value "M"...it works fine.......
any guesses why
Regards
rIsHaBh
|
|
|
|
|
rishabhs wrote:
if (sDir.CompareNoCase("M") != 0)
use this instead..
if(!sDir.CompareNoCase("M"))
{
}
Rob
Whoever said nothing's impossible never tried slamming a revolving door!
|
|
|
|
|
rishabhs wrote:
...the following lines of code gives wrong value...
Which means what? What does CompareNoCase() return in this case? What are you expecting it to return?
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
I assume sDir is a CString, you're not compiling for Unicode, and you're trying to test for sDir NOT being M (i.e. the if block should be executed if sDir is not M).
I can't see why this would fail on Windows 2000. CompareNoCase uses _tcsicmp , which translates to _stricmp for a non-MBCS, non-Unicode build. For an MBCS build, it translates to _mbsicmp . Check which of MBCS and/or UNICODE you're defining.
Apparently these functions are affected by the LC_CTYPE but not the LC_COLLATE locale parameter. I believe that the locale defaults to the C locale - see the documentation for setlocale .
See also the CodeProject BugList article[^].
|
|
|
|
|
This is probably a UNICODE vs. ANSI (MBCS) issue. If you change your code like this:
#include "tchar.h"
if (sDir.CompareNoCase(_T("M")) != 0)
{
}
that may help.
Software Zen: delete this;
|
|
|
|
|
when i tried to add function for user to edit data, the CString all work correctly but the float numbers become distorted after user edit the fields.
void CEtchDlg::OnEdit()
{
CString a,b,c,d,e,f;
float h,j,k,l;
GetDlgItemText(IDC_EID,a);
GetDlgItemText(IDC_TARGET1,b);
GetDlgItemText(IDC_PROCESS1,c);
GetDlgItemText(IDC_ETCHANT1,d);
GetDlgItemText(IDC_CONCENTRATE,e);
GetDlgItemText(IDC_REMARKS,f);
recordset->Edit();
recordset->SetFieldValue("a",(LPCSTR)a);
recordset->SetFieldValue("b",(LPCSTR)b);
recordset->SetFieldValue("c",(LPCSTR)c);
recordset->SetFieldValue("d",(LPCSTR)d);
recordset->SetFieldValue("e",(LPCSTR)e);
recordset->SetFieldValue("f",(LPCSTR)f);
recordset->SetFieldValue("h",(float)h);
recordset->SetFieldValue("j",(float)j);
recordset->SetFieldValue("k",(float)k);
recordset->SetFieldValue("l",(float)l);
recordset->Update();
}
|
|
|
|
|
When you need a char* , as in SetFieldValue, you need to access it via GetBuffer(0) and ReleaseBuffer(). Casting it your way (LPCSTR) is a bad practise.
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Nah I disagree completely, using LPCSTR returns a constant pointer to a string, which is good if you're only going to read from it and NEVER alter it. GetBuffer(0) returns a MODIFIABLE char* which should be treated with care because you can munch memory and cause the app to crash. Its always good practice to use constants where you can, it offers a little protecting from making silly mistakes.
Alan.
|
|
|
|
|
Whoops, of course you are right. I mixed up LPCSTR and LPSTR :/
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Easy enough to do , all this LPCSTR, LPCTSTR, LPSTR stuff etc... its just asking for it really. I can see why LPSTR would be bad practice mind since the CString buffer isn't protected, as in GetBuffer(0) (which requires you to ReleaseBuffer before the changes are implemented), so cheers for pointing that out. I always use GetBuffer(0) but this discussion has just highlighted that it is the better coding practice of the two, which is nice to know .
|
|
|
|
|
coda_x wrote:
recordset->SetFieldValue("h",(float)h);
recordset->SetFieldValue("j",(float)j);
recordset->SetFieldValue("k",(float)k);
recordset->SetFieldValue("l",(float)l);
Why are you casting a float to a float ? Since none of the SetFieldValue() methods take float as a parameter, this will not work. You'll need to use a COleVariant instead, as in:
COleVariant v(h);
recordset->SetFieldValue("h", v);
or use the LPCTSTR version:
CString s;
s.Format("%f", h);
recordset->SetFieldValue("h", s);
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
In your example, h j k and l are never set to anything. Uninitialized floats will have random values.
You need to get the strings from the dialog items that are supposed to be numbers, convert the strings to numbers, and use those to set the field values.
|
|
|
|
|
thanx! i used the atof to convert and it works
|
|
|
|
|
i encountered an application error: xxxxx reference memory cannot be "read"..., after I run and close my .exe program. I suspect tis to do with my declaration of:
private:
CDaoDatabase database; //prob:application error
CDaoRecordset *recordset;
};
in my header file..... anything wrong with this?
|
|
|
|
|
Run the debugger to find where in the code it crashes.
You're problably using an pointer that points to invalid data.
Rickard Andersson
Here is my card, contact me later!
UIN: 50302279
Sonork: 37318
Interests: C++, ADO, SQL, Winsock, 0s and 1s
|
|
|
|
|
there is no error when i compiled the program, wat do u mean by running the debugger? i simply debug and it can b compiled
|
|
|
|
|
u propose u first learn how to debug software before coding anything!
read tutorials about that...
Don't try it, just do it!
|
|
|
|