|
First hold the strings of all the function names that can be passed as command line. Upon receiving the command line, compare it with the available strings. Based on the result, call the corresponding function.
Come online at:-
jubinc@skype
|
|
|
|
|
A simple approach is choosing the function to call based on a numeric argument.
Suppose the application name is myapp.exe (I suppose you're writing a console application), you can type
myapp.exe 1
to make the application call func1 ,
myapp.exe 2
to make it call func2 and so on, provided your application main is structured a way similar to the following:
void main(int argc, char * argv[])
{
int n;
if (argc != 2)
{
printf("usage %s <number>\n", argv[0]);
return;
}
n = atoi(argv[1]);
switch(n)
{
case 1:
func1();
break;
case 2:
func2();
break;
default:
printf("invalid function number\n");
break;
}
}
</number>
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.
[my articles]
|
|
|
|
|
Thanks a lot for your replay. But few wired point with me here.
I work on console application and use VS.Net 2003 for all of this. So my first question is how should I give command line parameter.
Second one is, say this is my function.
void CAdd::addNumbers(void)
{
int iOne = 10;
int iTwo = 12;
int iSum = iOne + iTwo;
cout << iSum << endl;
}
How can I deal it with the following explanation. Thanks in advanced.
CPallini wrote: Suppose the application name is myapp.exe (I suppose you're writing a console application), you can type
myapp.exe 1
I appreciate your help all the time...
Eranga
|
|
|
|
|
Eranga Thennakoon wrote: I work on console application and use VS.Net 2003 for all of this. So my first question is how should I give command line parameter.
Choose the menu item Project-> your_project_name Properties , then select the Configuration Properties->Debugging node (on the appeared window) and assign 1 to the Command Arguments item of the listbox on the right.
Eranga Thennakoon wrote: How can I deal it with the following explanation. Thanks in advanced.
CPallini wrote:
Suppose the application name is myapp.exe (I suppose you're writing a console application), you can type
myapp.exe 1
if your method is static then you can call directly it (CAdd::addNumbers() ), on the other hand, if it isn't static , then you have to create an instance of the class:
...
case 1:
{
CAdd objAdd;
objAdd.addNumbers();
}
break;
...
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.
[my articles]
|
|
|
|
|
CPallini wrote: if it isn't static, then you have to create an instance of the class:
Yes it is, all my members are public. So I use an instance there.
As you said set the arguments. But it not display any...
int _tmain(int argc, _TCHAR* argv[])
{
CAdd m_Add;
if(argc < 2)
{
cout << "Less" << endl;
return EXIT_FAILURE;
}
int n;
n = atoi(argv[1]);
switch(n)
{
case 1:
m_Add.addNumbers();
break;
case 2:
m_Add.diffNumbers();
break;
default:
cout << "Invalid argument" << endl;
break;
}
cin.get();
return 0;
}
I think this correct.
I appreciate your help all the time...
Eranga
|
|
|
|
|
Did it compile (I mean is it a ANSI build)?
What can you see using the debugger?
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.
[my articles]
|
|
|
|
|
CPallini wrote: Did it compile (I mean is it a ANSI build)?
Yes it is.
CPallini wrote: What can you see using the debugger?
You mean in debug mode. It seems work fine. That's why I confused. Go through step by step there.
I appreciate your help all the time...
Eranga
|
|
|
|
|
Eranga Thennakoon wrote: You mean in debug mode. It seems work fine. That's why I confused. Go through step by step there.
What I mean is:
(1) put a break point on the following line
n = atoi(argv[1]);
(2) use the debugger to follow program execution step by step (F10 key) and see what happens (and when appropriate use F11 to step into functions).
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.
[my articles]
|
|
|
|
|
Yep, that what I have done pal.
Different thing is that, all my members are public. It wont be a case use of instance, isn't it.
I appreciate your help all the time...
Eranga
|
|
|
|
|
And what were results?
(1) n is proper assigned, i.e. it corrensponds to the numerical value of the argument you passed.
(2) Lets suppose n=1 . Did execution reach
m_Add.addNumbers();
line?
(3) if the answer to point (2) is yes, had you follow execution inside your method? What did happen?
I think you can figure out some other interesting tests.
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.
[my articles]
|
|
|
|
|
Yes, everything works fine. I couldn't find where the error. So what I have done is write another application, follows same steps which as previously do. It works.
I don't know why is that. But Little worried about another thing. I try change the argument to text. Something like this,
func.exe sum
rather than use of a number as argument. Set the arguments as 'sum' and tried it. But no luck. Is there any additional changes I have to done, which I don't have done in previous case.
I appreciate your help all the time...
Eranga
|
|
|
|
|
Eranga Thennakoon wrote: Is there any additional changes I have to done, which I don't have done in previous case
Yes, you have to test against strings, change
int n;
n = atoi(argv[1]);
switch(n)
{
case 1:
m_Add.addNumbers();
break;
case 2:
m_Add.diffNumbers();
break;
default:
cout << "Invalid argument" << endl;
break;
}
into
if ( strcmp(argv[1], "sum") == 0 )
{
m_Add.addNumbers();
}
else if ( strcmp(argv[1], "diff") == 0) )
{
m_Add.diffNumbers();
}
else
{
cout << "Invalid argument" << endl;
}
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.
[my articles]
modified on Wednesday, January 23, 2008 3:50:22 AM
|
|
|
|
|
I've test this, but gives an error on following code line.
CPallini wrote: if ( _tcscmp(argv[1], _T("sum") == 0 )
Error is,
'_tcscmp' : cannot convert parameter 2 from 'bool' to 'const char *'
I appreciate your help all the time...
Eranga
|
|
|
|
|
OOOPS...My bad
change
Eranga Thennakoon wrote: if ( _tcscmp(argv[1], _T("sum") == 0 )
into (mind the closing brace around the strcmp function)
if ( strcmp(argv[1], "sum") == 0 )
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.
[my articles]
|
|
|
|
|
Wow, it's work. Thanks a lot pal.
I appreciate your help all the time...
Eranga
|
|
|
|
|
I am a beginner who wants to restore the main window of a clock program that resides in the System Tray when running. What I want to do programatically is done normally by right clicking on the clock program's icon in the System Tray, then selecting "Restore Main Window" from the context menu.
I have tried many things, and the closest I can get is using SetForegroundWindow, which will only work when I have already selected "Restore Main Window" from the context menu and then minimized the restored main window.
I think I must be missing some fundamental concept about what I am trying to do.
Consider the pseudocode below...
void MyApp::OnLaunchSysTrayApp<br />
{<br />
CWnd*m_hWnd = FindWindow(NULL, "System Tray Application Name")<br />
if (m_hWnd)<br />
{<br />
m_hWnd->SetForegroundWindow();
<br />
BOOL m_bIconic;<br />
m_bIconic=m_hWnd->IsIconic()<br />
if (m_bIconic)<br />
{<br />
} etc.<br />
}<br />
}<br />
<br />
I would appreciate any suggestions about how I might achieve my goal, or information about whatever basic concept I (probably) currently fail to understand.
Thank you.
"For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash
|
|
|
|
|
Too much of this depends on the particular application to usefully answer.
Maybe the clock window is destroyed, or maybe it is the main window for the application but is hidden. Maybe, maybe...
In short, I don;t think there is a generic way of doing this.
Iain.
|
|
|
|
|
Try posting the SW_RESTORE command to the application.
|
|
|
|
|
Dear all
anyone know how to stop show when output of screen displays full screen..which function is available? thanks
Li Zhiyuan
5/10/2006
|
|
|
|
|
Can you more explain,please?
|
|
|
|
|
thanks, i mean when my program is runing, screen of output will display content continuously, no stop, so i want to see something, but passed already, how to do the screen will stop after display one full screen...thanks
Li Zhiyuan
5/10/2006
|
|
|
|
|
How do you show the content? What kind of application is yours?
|
|
|
|
|
i use win32 console application...when my program is runing..it will display something
Li Zhiyuan
5/10/2006
|
|
|
|
|
The only way of stopping the display is simply not to display anything in your code.
You'll have to manage it yourself: in your code, wait for the user to press a key before going to the next step.
|
|
|
|
|
In addition to Cedric Moonen said...
You can use GetConsoleScreenBufferInfo for getting the screen size.
|
|
|
|