|
Hi,
this is my try:
<code>
CTime t = CTime::GetCurrentTime();
CString csTime;
csTime.Format("%d:%d:%d", t.GetYear(), t.GetMonth(), t.GetDay());
</code>
thanx
break;
|
|
|
|
|
There are also formatting functions directly in the CTime class.
|
|
|
|
|
What is the standard coding practice for using the keyword virtual? I know that a base class can call a method in a derived class through virtual functions, but what if you simply want to over ride the default behaviour of a function? The virtual keyword is not always necessary but all the articles/tutorials say to use it. Also, when over riding a virtual method I sometimes see and sometimes don't see the use of virtual again in the derived class. Is there some rule about using this keyword or is it simply 'under advisment'?
|
|
|
|
|
It all depends on whether you use the base pointer, or the derived pointer
class CBase1
{
virtual void Message() { cout << "CBase!1"; }
}
class CDerived1 : public CBase1
{
virtual void Message() { cout << "CDerived1!"; }
}
class CBase2
{
void Message() { cout << "CBase2!"; }
}
class CDerived2 : public CBase2
{
void Message() { cout << "CDerived2!"; }
}
CBase1* obj1 = new CBase1();
obj1->Message();
CBase1* obj2 = new CDerived1();
obj2->Message();
CDerived1* obj3 = new CDerived1();
obj3->Message();
CBase2* obj4 = new CBase2();
obj4->Message();
CBase2* obj5 = new CDerived2();
obj5->Message();
CDerived2* obj6 = new CDerived2()
obj6->Message();
So if you have a complex class hierarchy, with lots of objects derived from a single base class, and you want to store a vector of objects, and have each perform their unique operations, you'll need to use virtual, since your vector doesn't know what type the objects are, it just thinks of them all as base class objects
|
|
|
|
|
You are talking about polymorphism, which doesn'a answer my question about when and when not virtual should be used.
|
|
|
|
|
Personally, I use virtual so I know at a glance that it may be an override.
It's your choice. It only needs to be used at the base class.
|
|
|
|
|
Looking at samples of other peoples code, I guessed this was the case. I have to admit it is handy to know quickly which methods you are overriding, but the keyword virtual here and there in the header file tends to make it a little unreadable. I like to group my function types and evenly space them, makes scanning the header a lot easier. I guess I will have to devise a method of incorporating virtual into my coding style.
|
|
|
|
|
It depends entirely on how your classes will be used. If the callers will be using polymorphism, then you need virtual on the methods that you want to be polymorphic.
virtual is only necessary in the base class. When a derived class overrides a virtual method, it's still virtual. You can write virtual in the derived class, but it's not required.
|
|
|
|
|
Hello,
I want to assign a string stored in a CString to char data type. I am unfamiliyar with char data types. They are, somehow, totally beyond my understanding!
Basically, I am getting the path of a file in strFileName. I want to extract only the file name from it. This is what I am trying to do:
if (dlg.DoModal() == IDOK)
{
strFileName.Format("%s",dlg.GetPathName());
AfxGetApp()->AddToRecentFileList(strFN);
char filePath[_MAX_PATH];
char drive[_MAX_DRIVE];
char dir[_MAX_DIR];
char fname[_MAX_FNAME];
char ext[_MAX_EXT];
filePath = strFN;
_splitpath( filePath, drive, dir, fname, ext );
CString st; st.Format("%s%s",fname,ext);
SetWindowText(st);
pDoc->IsNew = FALSE;
}
Thanks.
Fortitudine Vincimus!
|
|
|
|
|
Tara14 wrote: I am unfamiliyar with char data types. They are, somehow, totally beyond my understanding!
Yet you understand CString ??
Tara14 wrote: strFileName.Format("%s",dlg.GetPathName());
Why not simply:
strFileName = dlg.GetPathName(); Tara14 wrote: filePath = strFN; // ---> this is wrong. Plz can you tell me the correct way. _splitpath( filePath, drive, dir, fname, ext );
Should be:
_splitpath(strFileName, NULL, NULL, fname, NULL);
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
DavidCrow wrote: Should be:
_splitpath(strFileName, NULL, NULL, fname, NULL);
As simple as that! ! Silly me. Trying unnecessary stuff!!
Thank you.
Fortitudine Vincimus!
|
|
|
|
|
Hello,
is this an CFileDialog Object, right???
Use:
CString csFileName = FileOpenDlg.GetFileName();
regards
break;
|
|
|
|
|
Hi,
Please tell me how to access the PoolNonPagedBytes from the Win32_PerfFormattedData_PerfProc_Process for only one process.
Please help me.
Thanks in advance.
Regards,
Suresh
|
|
|
|
|
|
Hi Mark Salsbery,
I know this. But the problem is how to access the objects of that class. And the what are the steps to access the objects.
Please provide me some tips.
Thanks,
Suresh
|
|
|
|
|
Hi,
I have an simple MFC single document application(e.g TestApp). When application stop working for little time it shows in task bar icon not responding(i.e TestApp(NotResponding)). If I go in TaskManeger then I can find that status of my application is not responding.
Then after some little time my application again runs normally but task bar icon still shows not responding(i.e TestApp(NotResponding)) though it was supposed to show only application name (i.e TestApp).I can verify that application is running normally by seeing the status in TaskManeger.The name in TaskBar Icon remains until I exit from application.
In short I want the the application name only in task bar icon when application returns to normal state. Can anybody help me out?
Thanks:-
Mike
|
|
|
|
|
Your app is doing some extreme processing? Maybe you need to pump windows messages periodically
so the system knows your app is alive
|
|
|
|
|
Can you please elaborate which windows message need to pump?
|
|
|
|
|
Assuming you're not stuck in a thread deadlock or endless loop, you can do something like this
periodically (PumpMessage() is in CWinThread class):
MSG msg;
while (::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
{
if (!PumpMessage())
{
::PostQuitMessage(0);
break;
}
}
Is your app really working that hard?
|
|
|
|
|
Hi all,
How can i give multi line support for CStatic control?
Please help me.
Dream bigger... Do bigger...Expect smaller
aji
|
|
|
|
|
see me wrote: How can i give multi line support for CStatic control?
Doesn't putting a "\n" in the string being displayed do the same.
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
No...
I want to do it through my code.
If the Text size is greater than the static control size, i need to split the text in to two line.
Hope you understand my requirement.
Dream bigger... Do bigger...Expect smaller
aji
|
|
|
|
|
see me wrote: No...
I want to do it through my code.
Actually adding \n is the correct method. If it's not working, then you're not doing it correctly.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
It depends on the style of your static control. SS_SIMPLE will will display the text on a single line with no wrapping. SS_LEFT, SS_CENTER, and SS_RIGHT will automatically break the string and wrap the text to the next line.
You may be right I may be crazy -- Billy Joel --
Within you lies the power for good, use it!!!
|
|
|
|
|
Is it possible to hide the application from the tastlist? I have not find any code for it?
|
|
|
|