|
If you were using MFC, this would be easy (and only 4 lines of code).
COleDateTime dtDOB(1,1,1960,0,0,0);
COleDateTime dtToday = COleDateTime::GetCurrentTime();
COleDateTimeSpan dtDiff = dtToday - dtDOB;
int nDays = dtDiff.GetDays();
This is typed from memory, so you may have to adjust some stuff, but you get the idea.
---------------------------------------------------------------------
If you absolutely cannot use MFC, look at this article here on CP:
http://www.codeproject.com/datetime/datetimedisc.asp[^]
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Ok I modified a few things but I believe that it is still off...
[code]
//Program Name: Days On Earth
//Author: Charles Covington
//Date:
//Description :
#include <iostream>
#include <windows.h>
#include <string>
using namespace std;
//begin main program
int main () {
//declare variables
SYSTEMTIME st; //declare the date/time structure
int year, month, day;
float daysInYear = 365.25;
int months = 30.4375;
cout <<"Enter your year of birth. " <<endl;
cin="">> year;
cout << "Enter your month of birth. " <<endl;
cin="">> month;
cout << "Enter your day of birth. " <<endl;
cin="">> day;
int GMT_CONVERSION = 5; //local time is GMT-5
GetSystemTime(&st);
cout << "Current Year= " << st.wYear <
|
|
|
|
|
If it's worth doing, it's worth doing right.
Don't use an approx. daysInYear.
Caclulate the Julian day for the current day and the birth date.
Subtract one from the other to get age in days.
See:
http://en.wikipedia.org/wiki/Julian_day[^]
(calculating the JD from YMD is 4 lines of code, no excuse not to use it)
...cmk
Save the whales - collect the whole set
|
|
|
|
|
Good day to you all! I have a program where a CSTRING contains a string of hex value then turn it to INT. The way I convert basically is to use a for loop and convert each char one-by-one till I get the result. Now, this for me is a problem since I am doing a char per char conversion which takes long to process especially when I am having a huge hex value. I would like to know if there is a better way of doing a hex to int conversion.
for(nindex = 0;nindex < nlength; nindex++)<br />
{<br />
ctemp = buffstrdata.GetAt(nindex);<br />
ntemp = GetIntValue(ctemp);
result = result + (int)pow(16, nlength - 1 - nindex) * ntemp;<br />
}
Thanks a lot for the time and help!
|
|
|
|
|
what about:
char *p;
int i = strtol(pHexString, &p, 16);
|
|
|
|
|
NICE! It does work! thanks a lot for the help! It really does help if you know your APIs. thank you!
|
|
|
|
|
Hey I am making a wallpaper changer in MFC its a regurlar dialog box. I have it all working that it changes the windows wallpaper of a click of a button. The only thing I would like to add to this would be a thumbnail view of the windows wallpaper. Any help?
http://www.endlesscillia.com/Images/walpapers.jpg[^]
I included a picture so you can see what I'm trying to do visualy.
Thanks.
|
|
|
|
|
There's lots of ways to load and display a bitmap image.
The easiest way I know is using GDI+. Here's an example of loading an image and drawing it on
a MFC window (specified by "this") with upper left corner at 50,50. The same DrawImage method
will stretch the resultig image to whatever size you specify. I use te original bitmap size
below.
Gdiplus::Bitmap SrcBitmap(L"C:\\test.bmp", FALSE);
Graphics DstGraphics(*this);
DstGraphics.DrawImage(&SrcBitmap, 50, 50, SrcBitmap.GetWidth(), SrcBitmap.GetHeight());
Mark
Great job, team. Head back to base for debriefing and cocktails.
|
|
|
|
|
|
I'm trying to implement a CEdit box that has a horizantal scroll bar that will fill up to 1000 characters at a time. I used SetLimitText to set the limit to 1000 characters. The problem cropped up when I tried to use SetRect(). After I called the function it would not let me place the cursor in the box anymore. I can still call ReplaceSel() and place text in the box that way, but I cannot type it in with the keyboard. Some of the code:
<br />
SearchStringEditBoxPtr->SetLimitText(1000);<br />
RECT EditBoxDimensions;<br />
EditBoxDimensions.left = 0;<br />
EditBoxDimensions.top = 0;<br />
EditBoxDimensions.right = 3000;<br />
EditBoxDimensions.bottom = 12;<br />
SearchStringEditBoxPtr->SetRect(&EditBoxDimensions);<br />
Resource defenition statement for the edit box:
<br />
EDITTEXT IDC_DLGS_SEARCHSTRING_STRINGTEXT, 83, 190, 200, 24, ES_MULTILINE | WS_HSCROLL<br />
I would appreciate any help. -John
|
|
|
|
|
Are you sure 12 is large enough for the height?
Mark
Great job, team. Head back to base for debriefing and cocktails.
|
|
|
|
|
That solved the problem. I can type text into it now. It dosen't scroll anymore though. HMMhmmm....
|
|
|
|
|
Are you trying to keep all the entered text on one line? The default formatting rect should work
fine in that case (updating the horizontal scrollbar appropriately).
Great job, team. Head back to base for debriefing and cocktails.
|
|
|
|
|
Yes...I don't know why I always do things the hard way. Man I feel stupid. It works now though.
|
|
|
|
|
By the way, I tried it just for the heck of it (I've never changed the formatting rect on
a regular edit before). If you enter enough text until you reach 3000 pixels width then the
scrollbar starts to work. I suppose, then, that the appropriate width for the rect when you have
a horizontal scrollbar is the width of the control. Kewl.
Cheers!
Mark
Great job, team. Head back to base for debriefing and cocktails.
|
|
|
|
|
I've got a midi mapper program that take midi input and remapps it before it goes to output.. So I can plug in say, a keyboard, and select it as the midi input device.. no problem..
Then I have to use a program like MidiYoke or some Virtual Midi Device Driver to map the output device to another porgram.
I would like for the software to have it's own midi output port that I can simpily select within another program if you get my drift..
the closest thing I have come to is this
http://www.hurchalla.com/Maple_driver.html
The only problem with this is it's a permanent virtual midi device.. So when my program is shut down, the port is still there.. And the ports are turned on and off through registry key's which requires a restart in order to take effect.. There must be a better way to go about this..
Thanks is advance..
|
|
|
|
|
Linking...
D:\LOG4CXX\DEBUG\log4cxx.dll : fatal error LNK1136: invalid or corrupt file
Error executing link.exe.
siva1.exe - 1 error(s), 0 warning(s)
This is wt error i m getting while i m building a sample code which needs the log4cxx.dll.
pls tell the ans i need it urgent
|
|
|
|
|
Please let us know who we are talking to, and then we might be able to help you
|
|
|
|
|
WalderMort wrote: Please let us know who we are talking to
|
|
|
|
|
|
Hi ,
IIRC, there is a problem between VS and the SDK. For example, using Visual Studio 6.0 and the February 2005 SDK.
It finally made me move to Visual Studio .NET and Visual Studio 2005. I personally prefer VS 6.0.
Jeff
|
|
|
|
|
check if the file log4cxx.dll is corrupt (i.e. has a size of 0 bytes) and/or try to download/install log4cxx.dll again.
|
|
|
|
|
What is the best Code Snippets Manager? I’ve found only this:
1) Total .NET SourceBook
http://www.fmsinc.com/dotnet/SourceBook/index.asp
2) Code Library .NET
http://myweb.hinet.net/home4/s630417/CodeLib.htm
3) Code Warehouse 2007
http://www.xcca.com
|
|
|
|
|
Hi!
I'm porting a library from unix/posix to Win32, and i have some troubles with the memory mapped file access.
I use mmap to read pages from the file, but use the normal write API to write the pages.
On unix, it looks like this:
buffer=mmap(0, size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, position);
On win32, it's a bit longer, as usual:
DWORD fsize=GetFileSize(fd, 0);
mmaph=CreateFileMapping(fd, 0, PAGE_READONLY, 0, fsize, 0);
buffer=MapViewOfFile(mmaph, PAGE_READWRITE, 0, (unsigned long)position, size);
My first problem is that CreateFileMapping is called whenever i read a page from the file. Is it an expensive operation? I just don't see a way to avoid this. If i cache the mmaph handle, and the file is resized because a page is appended, then this page is not covered by the file mapping...
The second problem: it just doesn't work. CreateFileMapping returns 0 and GetLastError is 5 (ACCESS_DENIED) when it's called for the very first time (fd is a valid file handle, and fsize is 4096).
The file handle was created with
CreateFile(filename, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL|FILE_FLAG_OVERLAPPED, 0);
Thanks for any help
Chris
|
|
|
|
|
I never used mapped files on Unix so I am unable to give you a comparison. If you wish to append data to a mapped file, try to specify a larger file size. In you code example you get the file size and use that, but it's perfectly safe to specify larger ( try to round it up to a 4k boundary for best performance ). Opening and closing the file is more expensive than mapping. I believe there is a flag to automatically grow the file for win2000+, but for the moment I just can't remember.
For your second problem, try using GENERIC_READ|GENERIC_WRITE, and try dropping the FILE_FLAG_OVERLAPPED.
|
|
|
|