|
Does it really have to be particularly efficient?
void FormatDate( int nDay, int nYear)
{
int nLeapYear;
nDay-=31;
if (nDay <= 0) {
}
if (( (nYear /4) * 4) == nYear) nLeapYear=1
nDay= nDay - 28 - nLeapYear;
if (nDay <= 0) {
}
}
not tested that, but shouldn't be too far from the correct one
Sorry to dissapoint you all with my lack of a witty or poignant signature.
|
|
|
|
|
[edited message]
This will not work for 2100, 1900, 1800. The rule is:
If the year is divisible by 4, it’s a leap year.
But—if the year is also divisible by 100, it’s not a leap year.
Double but—if the year is also divisible by 400, it is a leap year.
BTW: just use % operator instead of dividing/multiplying by 4
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
2000 *was* a leap year... so my original suggestion worked from 1901 until 2099 !
We all have to work together for another arbitrary date limitation in the software we write: this way, we can be sure that we get consultancy fees a la Y2K !!!!!
Sorry to dissapoint you all with my lack of a witty or poignant signature.
|
|
|
|
|
2000 *was* a leap year
Yes it was - I've already edited my first response.
this way, we can be sure that we get consultancy fees a la Y2K
January 18, 2038 is the day when time_t stops working. Now imagine how TV 'experts' would try to explain the problem to average Joe Viewer.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
I do that:
struct tm tpTime = { 0, 0, 0, 1, 0, 80};
time_t newtime;
tpTime.tm_mday += nDays;
newtime = mktime(&tpTime);
in newtime you have the time 1/1/1980 + nDays
and you have the correct date in the newtime struct
nDayofMonth = newtimw.tm_mday;
nMonth = newtime.tm_mon + 1; //(Jan = 0)
nYear = newtime.tm_year + 1900;
Good Luck...
note
Thiscode can fail because I wrote the code directly in codeproject. (I don't have a compiler here for test bugs....)
Carlos Antollini.
|
|
|
|
|
I need to send text to another running program, such as Notepad.. I've done this so far:
CWnd* notepad;
if ( notepad = FindWindow(NULL,"Untitled - Notepad")) {
notepad->SetForegroundWindow();
//This is where I'm stumped.
}
I'm simply trying to send something like "Hello" to the main Notepad edit box.
Thanks. -Sinoth
|
|
|
|
|
First, use FindWindow is not good, beause you can find more than one window with the same text. For this is better to search for each handle starting with the desktop handle looking ever for the next handle.
When you found the Notepad, ypu need to find the handle of the edit, the handle that you found is the window handle, if you send a message to that handle the text wil be changed in the title bar, and not in the edit.
I hope to help you.
Carlos Antollini.
|
|
|
|
|
use EnumChildWindows to enumerate all the child windows
now call GetWindowLong on each of those child handles and try and figure out which is the edit box. using the GWL_STYLE try and see if you can get the window having the ES_MULTILINE style. that will inall probability be notepad's edit window. Now use SetWindowText()
I hope this helped....
Regards
Nish [BusterBoy]
|
|
|
|
|
Hi All,
I'm happy to get responce of my earlier problem. I'll look into that. I appreciate you all.
Here I've another problem. I want the text of an edit box to be hilighted when focus goes onto it. Suppose one has selected a Radio button then I want the Edit Box to be focused with it's text content hilighted. So that pressing any key would delete the entire old text, and write a new what ever is pressed.
Thanks
Dhirendra Mishra
|
|
|
|
|
Handle the EN_SETFOCUS notification for the edit control.
Put this in the event handler:
m_Edit.SetSel(0,-1,TRUE);
where m_Edit is the name of your control.
Sorry to dissapoint you all with my lack of a witty or poignant signature.
|
|
|
|
|
You need to use the CEdit::SetSel(); function
Cheers!!!
Carlos Antollini.
|
|
|
|
|
Hi, I have a function to download a file using FTP. Maybe, sometimes, the server is too busy, and the operation is too long, how can I limit the download time to abort if it is necessary?
This is the function I have:
void getMetar()
{
CString strServerName;
CString strObject;
INTERNET_PORT nPort;
DWORD dwServiceType;
CFtpConnection* pConn = NULL;
CInternetSession* m_pInetSession;
CString fileMetar;
CString vacio ="";
CWaitCursor EsperaRaton;
fileMetar =vacio+ selEstacion + ".TXT";
m_pInetSession = new CInternetSession("Unknown",1,INTERNET_OPEN_TYPE_PRECONFIG);
if(!m_pInetSession)
AfxMessageBox("Not valid session found");
AfxParseURL("ftp://tgftp.nws.noaa.gov", dwServiceType, strServerName, strObject, nPort);
if((dwServiceType==INTERNET_SERVICE_FTP)&&!strServerName.IsEmpty())
{
try
{
pConn = m_pInetSession->GetFtpConnection(strServerName, "", "", nPort, FALSE);
}
catch(CInternetException* pEx)
{
char szErr[1024];
pEx->GetErrorMessage(szErr,1024);
AfxMessageBox(szErr);
pEx->Delete();
pConn = NULL;
}
}
else
AfxMessageBox("Invalid URL");
pConn->SetCurrentDirectory("/data/observations/metar/stations/");
if(!pConn->GetFile(fileMetar, "tempMet.txt",INTERNET_FLAG_RESYNCHRONIZE|INTERNET_FLAG_RELOAD ,FALSE))
AfxMessageBox("File not found");
if(m_pInetSession!=NULL)
{
m_pInetSession->Close();
delete m_pInetSession;
}
if (pConn!=NULL)
pConn->Close();
}
|
|
|
|
|
We're developing our first internet application and there's something I'd like to know. The problem is that when debugging asp in the server, only one person can be debugging at a time. What I'd like to know is if there's any way to know (using Visual C++) if somebody is debugging at the moment, because we're having problems when two persons try to debug at the same time.
Thanks for the answer,
|
|
|
|
|
Hi All,
May be it's a basic thing for u guys... but I'm new, How can I remove all the files in a folder. I can give path to the folder. I'm not in position to give the names of all the files. Had it been possible, I would have used Remove(). I want to remove the files, what ever they are.....
Looking forward for a quick solutions from all of u.......
Dhirendra Mishra
|
|
|
|
|
look up CFilefind. You can iterate through a directory. Of course you can also step above it and delete it, I reckon you could also use shellexecute to del *.*
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
if you don't wanna use mfc there is an api - possibility
FindFirstFile and FindNextFile
Have fun
Bernhard
"I went on a diet, swore off drinking and heavy eating, and in fourteen days I had lost exactly two weeks." Joe E. Lewis [American humorist]
|
|
|
|
|
There's an easier way than enumerating files and deleting them one at the time. SHFileOperation with FO_DELETE command supports wildcards, so you should add *.* to folder name and call SHFileOperation. FOF_SILENT and FOF_NOCONFIRMATION will block any dialogs/messages displayed during delete.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
If it is the case that your EXE and DLLs are all linked to use the same runtime library -- do you have to worry about memory allocated in the DLL (with new), and then free'd in the EXE (with delete).
What about malloc and free?
And -- what if the RTL you use is the shared library DLL.
What about threaded RTL?
Did this question cover the possiblities....?
Thanks in advance!
-peter
|
|
|
|
|
|
|
I want to create an Excel file using VC++. Also i would like to append records in this file programatically. I want to do it without using ODBC. Can any body help me out
|
|
|
|
|
It can be done using Excel as a COM object, although obviously you need Excel installed to do it.
I don't recall the details, but I know they came from a CUJ or WDJ article.
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
Woo, it's not too difficult to manipulate Excel programmatically, believe me
I've just written a prototype for two-days, and I never "touch" on Excel before, but my application seemed work-well
Tips: Use VB6 for explore the object model of Excel (and any Office applications), read "Office 2000 Developer's Guide" in MSDN, and the last,
#import "Excel.exe" and GO!!!
good luck,
|
|
|
|
|
|
It's time for the experts to help out.
I have a situation where I need to guarantee that an object is created and deleted from the same point. Better said that if it is "new'd" in a DLL, the delete must happen there too. [the linkage of the new and delete must be from the same source]
Or created in the EXE and deleted there.
The twist of this -- is that these objects are being created, and then fed into a machine object, which will dispose them when done. After I create this object, and feed it to the machine, then I am done with it. The machine object will use it, and dispose of it when done.
So, here's an example:
class BaseObject
{
public:
virtual void DeleteThis() = 0;
virtual void DoSomething() = 0;
};
class MyClass : public BaseObject
{
static New();
MyClass();
virtual void DeleteThis();
virtual void DoSomething();
};
MyClass *MyClass::New()
{
return new MyClass();
}
MyClass::MyClass()
{
}
void MyClass::DeleteThis()
{
delete this;
}
void MyClass::DoSomething()
{
printf( "%s", "I did it" );
}
/// some code
...
MyClass pObj = MyClass::New();
pObj->DoSomething();
pObj->DeleteThis();
...
this works -- but the question of safety has come up -- and this sample forces the linkage of new and delete to reside in the same .OBJ file (does this make sense?).
Is "delete this" safe in this situation?
|
|
|
|