|
CMainFrame header
CMenu m_menu;
HMENU SetNewMenu(UINT nMenu);
CMainFrame body
HMENU CMainFrame::SetNewMenu(UINT nMenu)
{
m_menu.LoadMenu(nMenu);
m_menu.LoadToolbar(nMenu);
return (m_menu.Detach());
}
Code that sets menu
CMenu* pMenu = AfxGetMainWnd()->GetMenu();
if (pMenu)
pMenu->DestroyMenu();
CMainFrame* pFrame = reinterpret_cast<CMainFrame*>(m_pMainWnd)->SetNewMenu(IDR_MENU1);
ASSERT(pFrame != NULL);
HMENU hMenu = pFrame->NewMenu();
CMenu* pNewMenu = CMenu::FromHandle( hMenu );
ASSERT(pNewMenu != NULL);
AfxGetMainWnd()->SetMenu(pNewMenu);
Ant.
|
|
|
|
|
Thanks, that helped me so much.
Actually i used it in Pocket PC, but using the different way.
I used there CCeCommandBar, and just did this:
AfxSetResourceHandle(hInst);
CMainFrame* pMainFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;
pMainFrame->m_wndMenuBar.ResetCommandBar();
pMainFrame->m_wndMenuBar.InsertMenuBar(IDR_MAINFRAME);
pMainFrame->m_wndMenuBar.LoadToolBar(IDR_TOOLBAR1);
Thanks again.
|
|
|
|
|
I'm glad it helped as I have just noticed that I did not format the code correctly for HTML and therefore some of it is missing.
I'll modify it just for the records!
Ant.
|
|
|
|
|
Hi.
Everything is nice about what u said to me for reading and writing to files. Except one or two things.
Well first of all it cannot convert from objectA to char*.
That's why I didn't use this method before, because I couldn't handle this stuff.
Anyway why do u have to use binary files?
outfile.write ((char*)objectA, sizeof(objectA));
objectA(field by field) into the file test.txt.
Remember, the file contents are now binary.
So u may see many strange character when you open test.txt in a notepad.
THX
|
|
|
|
|
Ah. You've been told how to without any understanding of what's happening, which makes it difficult to fix this minor problem.
The line
outfile.write( (char*) objectA, sizeof(objectA));
should probably read
outfile.write( (char*)&objectA, sizeof(objectA));
as you need to specify the address.
Essentially, it's writing everything from memory to do with objectA's storage out to disk. This is not necessarily a good thing.
If objectA contains any pointers, or has other objects embedded within it, you may well be able to read objectA back some time later, but then not be able to use it.
Serialising an object is something that the object itself should know how to do, since it is possibly the only entity aware of all it's members. A blind write (and read) of the space occupied does not take into account the fact that the object may refer to other things, such as a char* member. In that case, the address in the char* member would be written out, and not the string it's pointing to1. When the object is later read back, the same address is assigned. Now if the memory map has changed significantly, it's possible that the address is not only not pointing to the right data, but it may in fact be pointing to unallocated or deallocated memory, which will cause an exception in your app.
Steve S
1Yes, I know it's not a proper string, it's only an illustration, so calm down...
|
|
|
|
|
Thanx steve for pointing out my error , i wrote that reply in a hurry.
I'll make no such mistakes in future.;)
Remember... testing & debugging are always part of programming ...so exterminate those stinking bugs
|
|
|
|
|
dairiseky wrote:
Anyway why do u have to use binary files?
See if these help:
http://www.felgall.com/cplus4.htm
http://www.techtv.com/screensavers/answerstips/story/0,24330,3373133,00.html
http://forums.devshed.com/archive/t-105787
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
ok got y. thx again.
Though u didn't say to me what u meant by the lenght of a line. Does space and zero count in this lenght? i'm talking about the seekg().
Is this seekg() givin' me the possibility to read only a certain length of the file?
THX
|
|
|
|
|
dairiseky wrote:
Is this seekg() givin' me the possibility to read only a certain length of the file?
I'm not exactly sure what you are asking here, but seekg() can be used to get a file's length.
file.seekg(0, ios::end);
long filesize = file.tellg();
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
Sorry! my mistake. Thanks a lot to Steve for clearing the doubts.
You need not even include the (char*) part in read and write functions.
Only outfile.write (&objectA, sizeof(objectA)); should also work.
Keep in ur mind the things told by Steve about Pointers.
Avoid including pointers in classes that you have to write to the disk. But as far as simple data types and arrays are concerned, it would do just fine.
I hope that you know by now "why binary?"
Sorry again for the mistake on my part. thx steve
Remember... testing & debugging are always part of programming ...so exterminate those stinking bugs
|
|
|
|
|
yep is ok about binary. Yet there is still a problem. The objectA must be a const char*, that is not.
U said to me :
class A
{
public:
double x;
double y;
double speed;
double z;
};
As u can see here if I want to write the x, y, z. I could do as:
main(int argc, char *argv[])
{
A objectA;
fstream File;
File.open ("test.txt", ios::binary);
File.seekp(0);
objectA.x=25.314;
objectA.y=-478.215;
objectA.z=34821.01;
Up to here nothing wierd.
But then when I want to write into file I will use:
File.write(&objectA.x, sizeof(objectA.x));
And the error will be:
'class ostream &__thiscall ostream::write(const char *,int)' : cannot convert parameter 1 from 'double *' to 'const char *'
And even if I will write simply :
File.write(&objectA, sizeof(objectA));
There will still be the same error:
'class ostream &__thiscall ostream::write(const char *,int)' : cannot convert parameter 1 from 'class A *' to 'const char *'
I might have get things wrong...
THX
|
|
|
|
|
Ooops! a small mistake on my part again. I was actually mixing the read function of C with read member of C++.
In C++, the prototype for write is:
istream& read(signed char*, int);
So whatever we write, we have to cast its pointer to (char*)
So if we have to write some object AAA to the file, we will use the following syntax:
ofstream outfile("test.txt", ios::binary);
outfile.write((char *) &AAA, sizeof(AAA));
Now let me tell you a few things:
Dont try to retrieve data from a file using read where you have manually entered data. What i mean is, if you have created a file from notepad and have manually typed in the data, you cannot retrieve those data using istream::read()
So the point is:- retrieve only those data from the file using istream::read that have been written to it using ostream::write .
The following code is tested on my system and will help you in understanding all this better. After running the program, open the "123.txt" file in c:\ drive to view how data has been written in binary.
#include <iostream.h>
#include <fstream.h>
int main()
{
class A
{
public:
double x;
double y;
double z;
};
A objectA,objectB;
objectA.x=123.345;
objectA.y=345.003;
objectA.z=456.2;
cout<<"Following data will be written to 123.txt"<<endl;
cout<<"A.x="<<objectA.x<<endl;
cout<<"A.y="<<objectA.y<<endl;
cout<<"A.z="<<objectA.z<<endl;
ofstream outfile("c:\\123.txt",ios::binary);
outfile.write((char*)&objectA,sizeof(objectA));
outfile.close();
cout<<"object A has been written to the file"<<endl<<endl;
cout<<"reading data from 123.txt"<<endl;
ifstream infile("c:\\123.txt",ios::binary);
infile.read((char*)&objectB,sizeof(objectB));
outfile.close();
cout<<"B.x="<<objectB.x<<endl;
cout<<"B.y="<<objectB.y<<endl;
cout<<"B.z="<<objectB.z<<endl;
return 0;
}
Avoid that seek stuff.
Suppose you have performed 5 writes to a file(i.e. you have written 5 objects one after the other) and you want to read the 3rd object later, then use the following technique.
ifstream infile("test.txt", ios::binary);<br />
A objectA;<br />
for(i=0;i<3;i++)<br />
{<br />
infile.read((char *) &objectA, sizeof(objectA));<br />
}<br />
infile.close(); After the for loop, objectA will contain the data from the 3rd record;
Ask if u have any problems.
|
|
|
|
|
Ooops! a small mistake on my part again. I was actually mixing the read function of C with read member of C++.
In C++, the prototype for write is:
istream& read(signed char*, int);
So whatever we write, we have to cast its pointer to (char*)
So if we have to write some object AAA to the file, we will use the following syntax:
ofstream outfile("test.txt", ios::binary);
outfile.write((char *) &AAA, sizeof(AAA));
Now let me tell you a few things:
Dont try to retrieve data from a file using read where you have manually entered data. What i mean is, if you have created a file from notepad and have manually typed in the data, you cannot retrieve those data using istream::read()
So the point is:- retrieve only those data from the file using istream::read that have been written to it using ostream::write .
The following code is tested on my system and will help you in understanding all this better. After running the program, open the "123.txt" file in c:\ drive to view how data has been written in binary.
#include <iostream.h>
#include <fstream.h>
int main()
{
class A
{
public:
double x;
double y;
double z;
};
A objectA,objectB;
objectA.x=123.345;
objectA.y=345.003;
objectA.z=456.2;
cout<<"Following data will be written to 123.txt"<<endl;
cout<<"A.x="<<objectA.x<<endl;
cout<<"A.y="<<objectA.y<<endl;
cout<<"A.z="<<objectA.z<<endl;
ofstream outfile("c:\\123.txt",ios::binary);
outfile.write((char*)&objectA,sizeof(objectA));
outfile.close();
cout<<"object A has been written to the file"<<endl<<endl;
cout<<"reading data from 123.txt"<<endl;
ifstream infile("c:\\123.txt",ios::binary);
infile.read((char*)&objectB,sizeof(objectB));
outfile.close();
cout<<"B.x="<<objectB.x<<endl;
cout<<"B.y="<<objectB.y<<endl;
cout<<"B.z="<<objectB.z<<endl;
return 0;
}
Avoid that seek stuff.
Suppose you have performed 5 writes to a file(i.e. you have written 5 objects one after the other) and you want to read the 3rd object later, then use the following technique.
ifstream infile("test.txt", ios::binary);<br />
A objectA;<br />
for(i=0;i<3;i++)<br />
{<br />
infile.read((char *) &objectA, sizeof(objectA));<br />
}<br />
infile.close(); After the for loop, objectA will contain the data from the 3rd record;
Ask if u have any problems.
...Avenger
Remember... testing & debugging are always part of programming ...so exterminate those stinking bugs
|
|
|
|
|
Ok, I see. I just tested a bit this, and it's working ok. I will need some time to digest all this info (and faked info too ). If new quiery appear I will shout for help.
Thx, can I send to u some info about the robot, and some methods I intend to use to solve some problems?
By the way are u good in maths? (probability and statistics?) If u want to answer to this, send the answer on my e-mail, plz.
_____________________________
THX
|
|
|
|
|
My problem is this, i have a stored procedure in oracle,
and i which authenticates a user on the basis of loginName
and password.
the problem is that when i accesssed it through C#
giving the two parameter as input and one parameter as output.
there is no value return in output parameter.
can some on tell me how to get the output parameter value in my code
Thanks In Advance
//------------- stored procedure name is
===========SecurityPkg.Authenticate=============
PROCEDURE Authenticate(loginName IN VARCHAR2,loginPassword IN VARCHAR2, loginResult OUT INT )
IS
objectId NUMBER := -1;
objectPwd VARCHAR2(100);
passwordExpiredDate DATE;
BEGIN
Select OBJECT_ID,PASSWORD,PASSWORD_EXPIRES INTO objectId,objectPwd,passwordExpiredDate
From Application_User
Where Application_User.Login_Name=loginName;
IF(objectId = -1) THEN
loginResult := ACCOUNT_DOESNOT_EXITS;
END IF;
IF(objectPwd != loginPassword) THEN
loginResult := WRONG_PASSWORD;
End if;
IF(passwordExpiredDate < SYSDATE) THEN
loginResult := PASSWORD_EXPIRED;
END IF;
EXCEPTION
WHEN NO_DATA_FOUND THEN
loginResult := ACCOUNT_DOESNOT_EXITS;
END Authenticate;
//------------------- csharp code that access the above stored procedure of oracle
OracleCommand cmd=new OracleCommand();
cmd.CommandText="Security_Pkg.Authenticate";
cmd.Connection=myConnection;
cmd.CommandType=CommandType.StoredProcedure;
// first param
OracleParameter loginNameParam=new OracleParameter("loginName",OracleDbType.Varchar2);
loginNameParam.Direction=ParameterDirection.Input;
loginNameParam.Value="Ali";
// 2nd param
OracleParameter loginPasswordParam=new OracleParameter("loginPassword",OracleDbType.Varchar2);
loginPasswordParam.Direction=ParameterDirection.Input;
loginPasswordParam.Value="pass";
// 3rd param
OracleParameter loginResultParam=new OracleParameter("loginResult",OracleDbType.Int16);
loginResultParam.Direction=ParameterDirection.Output;
cmd.Parameters.Add(loginNameParam);
cmd.Parameters.Add(loginPasswordParam);
cmd.Parameters.Add(loginResultParam);
cmd.ExecuteNonQuery();
Now when i check the value of loginResultParam, its null.
can any one tell me how to get its value
|
|
|
|
|
Hi
I am currently trying to use Bitmap::FromFile function provided by GDI+. It seems that the method does not provide any notification when the specified file does not exist. Subsequent calls to Bitmap::GetPixel also does not raise any error, it just gives a result of 255 for all the A, R,G, and B values. My question is, is there a way to check whether the FromFile method has successfully loaded an image or whether the image does not exist?
Thanks!
|
|
|
|
|
GDI+ is implemented strangely. The public interface is C++ classes, but to get around the fact that there's no common Application Binary Interface for C++ on Windows, and to allow both .NET and non-Microsoft compilers to use GDI+, the main body of the implementation is contained in a DLL with a 'flat', C-style interface.
The implementation of the GDI+ classes is contained entirely within the GDI+ headers, in terms of this flat API. The Bitmap class is implemented in GdiPlusBitmap.h. Bitmap::FromFile simply creates a new Bitmap object, using the Bitmap(const WCHAR* filename, BOOL useEmbeddedColorManagement) constructor.
If an error occurs, the underlying flat API call (GdipCreateBitmapFromFileICM or GdipCreateBitmapFromFile depending on whether the second parameter is set or not) returns an error code, which the Bitmap constructor stores internally. This error code can be retrieved using the GetLastStatus method (inherited from Image ). I would expect that, if the file was not found, this method will return FileNotFound from the Status enumeration.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
It's a bit dirty, but how about..
FILE* ofp = fopen("yourfile", "r");
if(ofp != NULL)
{
fclose(ofp);
// File exists - go ahead and call Bitmap::FromFile
}
else
{
// File does NOT exist - warn the user
}
..should work alright.
Success is 99% failure
|
|
|
|
|
Hi,
I want to do something in my app when the user doesn't do anything for a period of time (doesn't move the mouse and doesn't touch any key on the keyboard). MSN Messenger, for example, makes you idle when you are inactive. I want to lock some sections of my app.
How can I test this from my app? How can I get the windows idle time?
Thanks
-----
We are what we repeatedly do. Excellence, then, is not an act, but a habit.
|
|
|
|
|
You could use :
virtual BOOL CWinApp::OnIdle( LONG lCount );
Or maybe, use a timer and handle WM_MOUSE_MOVE and WM_KEY_DOWN but this is resource consuming ( I mean polling all the time to see if something changes).
~RaGE();
|
|
|
|
|
I don't want the idle time in my app. In windows in general. I thought OnIdle is called when the application is idle.
-----
We are what we repeatedly do. Excellence, then, is not an act, but a habit.
|
|
|
|
|
Then you'll have to set a hook on the mouse and the keyboard inputs, that's the only way to know that nothing happened in "windows in general". Search for hook on Code Project (especially the article by J. Newcomer).
~RaGE();
|
|
|
|
|
Thanks for your time.
Regards,
-----
We are what we repeatedly do. Excellence, then, is not an act, but a habit.
|
|
|
|
|
I think this might be of some help:
GetLastInputInfo
The GetLastInputInfo function retrieves the time of the last input event.
BOOL GetLastInputInfo(<br />
PLASTINPUTINFO plii
);
Parameters
plii
[out] Pointer to a LASTINPUTINFO structure that receives the time of the last input event.
Return Values
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero.
Remarks
This is useful for input idle detection
Remember... testing & debugging are always part of programming ...so exterminate those stinking bugs
|
|
|
|
|
I'm just curious, where does this comes from ? the online MSDN ? I do not have it in my 2000 version.
~RaGE();
|
|
|
|
|