|
ldsdbomber wrote: there must be a very, very simple way
You mean like you read the data from the source control and you write it to the target control? That is very simple.
led mike
|
|
|
|
|
what source control? I want it to display the current time, but I am getting confused about the formats. I have a DateTimePicker control, but have seen documentation for a DateTime control. I've seen where you can send a SetTime message with CTime, but the control I'm using has SetTimer not SetTime. I think I'm just getting mixed up. I've dropped a picker onto my dialog, set it to display in time format, I just want that to update every second with the real time.
|
|
|
|
|
ldsdbomber wrote: I just want that to update every second with the real time.
Get the current time using GetSystemTime(). That result is your source data. Then write that data to the DateTimePicker control.
led mike
|
|
|
|
|
I realise I'm not at your standard, but are you meaning to take the mickey by just repeating my question? Obviously if I'm asking how to update a datetimepicker control I would do it, so telling me to get the current time and update the control is not an answer.
There is no SetTime function for my control. Maybe this is why I am getting confused. I am expecting to see a SetTime function, but I only see SetDlgItemText. Perhaps I need to pass in a pointer to GetSystemTime, then use that somehow formatted to pass to set the control text, but that wasn't what I was expecting, I now see I also need a timer event
|
|
|
|
|
Are you working from a book or tutorial? If not you should be. You should aquire some basic knowledge before posting questions here. Trying to use a forum to get people to teach you basic programming constructs is not going to be productive.
led mike
|
|
|
|
|
Have you set up a timer by calling SetTimer(1000) ? In response to the WM_TIMER message, update the control with the current time.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
no I haven't done that, thanks, I will look into that.
|
|
|
|
|
Hi David,
I'm only used to knocking out dialog apps with the MFC app wizard so am just a bit unsure where to put the timer in, and whats the proper syntax (and where to put it) for a function that the timer calls etc.
any tips or links to external tutorials?
|
|
|
|
|
ldsdbomber wrote: ...am just a bit unsure where to put the timer in...
A common place to call SetTimer() is in the OnInitDialog() method.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
yep, I thought as much, it was the function that settimer calls I was unsure if it was just a function you can slap anywhere, or does it need to be "tied in" somehow to the appwizard generated stuff with the message maps and stuff.
|
|
|
|
|
ldsdbomber wrote: I was unsure if it was just a function you can slap anywhere, or does it need to be "tied in" somehow to the appwizard generated stuff with the message maps and stuff.
Revisit the link I provided. It shows how to call SetTimer() and how to respond to the WM_TIMER message.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Hello,
I would like to get the size of un array of strings that I pass as paramater to a function but I am not comfortable with pointers.
could you please tell me what I did wrong with this code?
extern const char* test[] = { "Data", "Data","Data","Data", "Data","Data", "Data", "Data"};
int MyFunc(const char* test[])
{
int size = sizeof(list) / sizeof(list[0]);
return size;
}
int sz = MyFunc(test) // return 1 instead of 8
|
|
|
|
|
C arrays are not arrays they are pointers, therefore there is no way to determine size.
led mike
|
|
|
|
|
Hi,
thanks for reply.
I'm afraid the problem is elsewhere.
If I bring const char* test[] into the function (no extern declaration) I get the right size.
I think that i do something wrong with the function's parameter.
Any idea?
int MyFunc(const char* test[])
{
const char* test[] = { "Data", "Data","Data","Data", "Data","Data", "Data", "Data"};
int size = sizeof(list) / sizeof(list[0]);
return size;
}
int sz = MyFunc(test) // It works , return 8
|
|
|
|
|
Arris7 wrote: int size = sizeof(list) / sizeof(list[0]);
Unless list is defined elsewhere, how are you not getting a compiler error here?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Sorry it is a wrong copy and paste. It is test instead of list.
|
|
|
|
|
the problem is that after you've 'passed' the array to a function, the function only sees a pointer. the function has no way to know it's an array of anything.
you have to pass the size along as a separate parameter.
|
|
|
|
|
hi,
Thanks for your help.
Actually I have several const arrays of strings with different sizes. So I would like to calculate the size at compilation time or run time.
I think to use enum but I have no clue about knowing how many items it contains at compilation time or run time.
Any other idea?
|
|
|
|
|
Arris7 wrote: Any other idea?
every time you pass a pointer to an array, pass the number of elements in the array, too.
or, use a vector of std::strings or a CStringArray of CStrings (or a vector of CStrings). that way, the vector/CStringArray can keep track of how many elements it has, and you can ask it, when you want to know.
|
|
|
|
|
What is sometimes done is to place a NULL as the last "string" in the array. That way, you can walk the array until you find an element with a value of NULL , and that indicates the end of the array.
Example:
LPCSTR g_cpaStrings[] = { "One", "Two", "Three", "Four", <code>NULL</code> };
DWORD dwIndex = 0;
while( g_cpaStrings[ dwIndex ] )
{
TRACE( "String: %s\n", g_cpaStrings[ dwIndex++ ] );
} Peace!
-=- James Please rate this message - let me know if I helped or not!<HR> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
how does that work if you're passing g_cpaStrings into a function?
or, are you assuming g_cpaStrings is a global variable ?
|
|
|
|
|
It works the same, regardless of g_cpaStrings being global or even if it was cpaStrings as a local, or if it is used locally or passed to a function.
Passing it to a function causes it to decay from array to pointer in either case. But that only changes how the variable appears, not the data behind it.
LPCSTR g_cpaStrings[] = { "One", "Two", "Three", "Four", NULL };
void TestFunc1( LPCTSTR cpaStrings[] )
{
DWORD dwIndex = 0;
while( cpaStrings[ dwIndex ] )
{
TRACE( _T( "String1: %s\n" ), cpaStrings[ dwIndex++ ] );
}
return;
}
void TestFunc2( LPCTSTR *paStrings )
{
DWORD dwIndex = 0;
while( paStrings[ dwIndex ] )
{
TRACE( _T( "String2: %s\n" ), paStrings[ dwIndex++ ] );
}
return;
}
int main( int iArgC, char paArgV[] )
{
LPCSTR cpaStrings[] = { "Five", "Six", "Seven", "Eight", NULL };
DWORD dwIndex = 0;
while( g_cpaStrings[ dwIndex ] )
{
TRACE( _T( "String: %s\n" ), g_cpaStrings[ dwIndex++ ] );
}
dwIndex = 0;
while( cpaStrings[ dwIndex ] )
{
TRACE( _T( "String: %s\n" ), cpaStrings[ dwIndex++ ] );
}
TestFunc1( g_cpaStrings );
TestFunc1( cpaStrings );
TestFunc2( g_cpaStrings );
TestFunc2( cpaStrings );
return( 0 );
} Note that all things being equal, you solution of passing a count of valid data with all pointers is a better solution, and the one I usually suggest first. I am simply offering this solution as an alternative and to better allow the OP to understand how things work.
Peace!
-=- James Please rate this message - let me know if I helped or not!<HR> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
hmmm.
i asked because when i first tried your code with a function, i couldn't get it compile (char *[5] vs char*[] errors). but your code compiles fine.
i must've mistyped something somewhere and given up too easily.
|
|
|
|
|
No problem!
Peace!
-=- James Please rate this message - let me know if I helped or not!<HR> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
Very clear and good explanation.
Thank you so much.
|
|
|
|