|
Use the difftime() function.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hi,,
In my application I have to use large number of buttons(AROUND 112),
all buttons will call the same function " DoMyDuty(int a) ",
variable 'a' is different for all buttons.
here is sample code for better understand
void MyClass::OnB1()
{
int a;
a=1; -----Only this value changed
DoMyDuty(a);
}
void MyClass::OnB2()
{
int a;
a=15; -------Only this value changed
DoMyDuty(a);
}
.....
.
.
.
.
.....
void MyClass::OnB112()
{
int a;
a=30; -------Only this value changed
DoMyDuty(a);
}
The CODE SEEMS TO BIG but simple to do...
iS THERE ANY ALTERNATIVE LOGIC TO DO THIS......??????
Any other control behaves like this????
thank u.
verma
|
|
|
|
|
If you are using MFC, you can have a single handler respond to a group of controls using ON_CONTROL_RANGE() [^]. This would let you have a single handler, like this:
ON_CONTROL_RANGE(BN_CLICKED,IDC_B1,IDC_B112,OnB)
void MyClass::OnB(UINT ID)
{
static struct {
UINT ID;
int a;
} table[] = {
{ IDC_B1, 1 },
{ IDC_B2, 15 },
{ IDC_B112, 30 }
};
for (int i = 0; i < (sizeof(table) / sizeof(table[0])); i++) {
if (table[i].ID == ID) {
DoMyDuty(table[i].a);
break;
}
}
} The handler is called with the resource ID of the button that was clicked. It then uses a simple table to look up the value of 'a' to use for the call to the DoMyDuty() function.
|
|
|
|
|
Another similar approach:
ON_CONTROL_RANGE(BN_CLICKED,IDC_B1,IDC_B112,OnB)
void MyClass::OnB(UINT ID)
{
DoMyDuty(ID - IDC_B1 + 1);
}
Hope that helps.
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
|
|
|
|
|
I don't think that works. The value of 'a' in his original post didn't vary predictably according to the button pressed, so you needed a lookup table approach.
|
|
|
|
|
Thanks gary!!!!!
It works fine.....
|
|
|
|
|
|
I don't understand you problem. Could you elaborate? Anyway, there's a Math forum [^] here at CP.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
I dont know why after you answer to questions we cant see orginal question!?
|
|
|
|
|
Timid children, I suppose.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
CPallini wrote: Timid children, I suppose.
No Hamid Children.
OK,. what country just started work for the day ? The ASP.NET forum is flooded with retarded questions. -Christian Graus
Best wishes to Rexx[^]
|
|
|
|
|
Maybe Hamid child or....Are there a lot of him ?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
CPallini wrote: Maybe Hamid child or....Are there a lot of him ?
I think its yet for me
|
|
|
|
|
Hey you back,where are you,do you remember me yet?
|
|
|
|
|
I was looking for a MFC control which can show HTML or plain-text content. Is there an existing one or do I have to write my own wrapper ?
Thanks
Cage
|
|
|
|
|
Do you want to use of CDhtmlDialog orCHtmlView?
|
|
|
|
|
I had considered them but wanted something which is as simple as an intelligent edit box which can render HTML, thought dialog or view was an overkill.
Thanks for helping Hamid...
Regards
Cage
|
|
|
|
|
|
Thanks Gary, this definitely gives me more options.
|
|
|
|
|
You're welcome .
|
|
|
|
|
Hello friends,
How do I check if a file is open or close?
Suppose I've 1 file and I want to find out if it is open or not How can
we do that?
I don't want to open the file for which I am going to check if it is open
or close.
Thanks in advance to all of you.
ritz1234
|
|
|
|
|
u an use this function in case of CFile.
BOOL GetStatus(
CFileStatus& rStatus
) const;
static BOOL PASCAL GetStatus(
LPCTSTR lpszFileName,
CFileStatus& rStatus
);
|
|
|
|
|
u can use this in case of fstream
bool is_open( );
IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH
|
|
|
|
|
To use is_open() function we have to open the file first.
I don't want to open the file to check it is open or close.
ritz1234
|
|
|
|
|
it works dear,
Case:1 if u run the apliation than it shows msg box means file is open.
fstream fs("C:\\fstream.txt", ios::out );
//fs.close();
if(fs.is_open())
{
AfxMessageBox("Test::File is Open");
}
Case:2 if u run the apliation than it is not show the msg box means file is not open.
fstream fs("C:\\fstream.txt", ios::out );
fs.close();
if(fs.is_open())
{
AfxMessageBox("Test::File is Open");
}
IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH
|
|
|
|