|
Although this has nothing to do with MFC,this is completely related to C++(GNU Compiler).
Purusottam Mishra
Systems Executive
|
|
|
|
|
Could you please elaborate a bit your question (for instance make an example)?
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
[My articles]
|
|
|
|
|
if I am to Parse a Command line of type:
MyApplication [-v] [-i [filename] | -c [filename] [(-s e|c|v ) | ( -m c|V|v num_passes ) | (-r read:write ratio number_of cycles ) | -id ] [ -d devicenumber] [-o filename]
I m parsing it like:
int main(int argc,char* argv[])
{
char *options,*value;
while(int Opt = getopt(argc,argv,"s ::v:")!=-1)
{
switch(Opt)
{
case 'v':
//Do Something
break;
case 'm':
options = optarg;
while(*options != '\0')
{
switch(getsubopt(&options,&myopts,&value))
{
case 'r' :
cout<<optarg<<endl;
break;
case 'p' :
cout<<optarg<<endl;
break;
}
++optind;
}
break;
}
}
}
then suppose I give the command Like:
My Application -m v 5
Then I should Be able to retrieve 'v' Value and the value 5(Please refer to Comand Line format above).
Thanks agai for ur quick reply.
Purusottam Mishra
Systems Executive
|
|
|
|
|
Please include your code snippet inside <pre> tags (using 'code block' button), I cannot recognize what are you passing to getopt .
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
[My articles]
|
|
|
|
|
int main(int argc,char* argv[])
{
char *options,*value;
while(int Opt = getopt(argc,argv,"s:d:v:")!=-1)
{
switch(Opt)
{
case 'v':
break;
case 'm':
options = optarg;
while(*options != '\0')
{
switch(getsubopt(&options,&myopts,&value))
{
case 'r' :
cout<<optarg<<endl;
break;
case 'p' :
cout<<optarg<<endl;
break;
}
++optind;
}
break;
}
}
}
Purusottam Mishra
Systems Executive
|
|
|
|
|
Looking at you code I cannot understand how could you hope to get the 'm' option.
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
[My articles]
|
|
|
|
|
I have a dialog based application which has a tab control containing a handful of tabs.
For each tab dialog I have overriden the OnOK() and OnCancel() function with (empty) virtual ones, such that when inside the tab the Enter key or ESC key respectively doesn't let the tab content (child dialog resource, derived from CDialog) disappear (Thanks for the hint Cedric)
So far so good. All that works(worked) fine.
To be able to not only 'tab' within the tab control itself, but also out of it to the other controls (e.g. buttons) in my main dialog based application, I have selected the "Control Parent" check box in the Extended Styles for each child dialog.
Again that does the trick and I can now hop happily into the tab control, tab through all the controls there, and - after the last child control - I can tab out again to some of the other controls of the main window.
However, since I have selected the 'contrl parent' feature, all my "effort" regarding the overriding of OnOK) and OnCancel() seems to have been in vain, as now the ESC key or ENTER key will close the whole application, basically terminating my application.
I assume that somehow the repective messages get still handled/mapped and hence will be processed by the application to call a "Now-shut-down-the-whole-lot-please"-function, but I just don't have any idea how to avoid that.
I hope this makes sense. Any help would be most appreciated. Many thanks.
|
|
|
|
|
Maybe you could override the OnOK() and OnCancel() of the main dialog on which the tab control is placed.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
As the other reply, you need to override the OnOK and OnCancel in the main dialog too.
But remember to map the WM_CLOSE to OnClose and call EndDialog there. If not your application cannot be closed by clicking the Close button in the titlebar.
- ns ami -
|
|
|
|
|
Thanks guys. I tried to override the OnOK and OnCancel, and ran straight into the problem you describe, (--> couldn't close the main window at all anymore (not with the OnOK button (IDOK), nor with ALT+F4 nor with the close button in the title bar.
I actually had to kill the app via the task manager.
My problem is that I don't know how to override it properly.
Your advice regarding the mapping of WM_CLOSE etc. is probably what I need to do somehow, however, I don't have the knowledge yet what and how exactly to do it.
Would you be so kind to explain more detailed?
Thanks.
|
|
|
|
|
I tried a few more things, but can't get it to work. Still missing something here. Please help!
In the main dialog header I have addded the OnOK() and OnCancel() virtual functions manually to the area where the wizard had already put its virtual function for the DoDataExchange() override, is that the correct place?
protected:
virtual void DoDataExchange(CDataExchange* pDX);
virtual void OnOK();
virtual void OnCancel();
Then I have added the ON_WM_CLOSE() message like this in the .cpp file of the main dialog:
BEGIN_MESSAGE_MAP(CTestDlg, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_CONNECT, OnConnect)
ON_NOTIFY(TCN_SELCHANGE, IDC_Test_MENUS, OnSelchangeTestMenus)
ON_BN_CLICKED(IDC_OK, OnOk)
ON_BN_CLICKED(IDC_TestHELP, OnTesthelp)
ON_BN_CLICKED(IDC_SETTINGS, OnSettings)
ON_WM_CLOSE()
END_MESSAGE_MAP()
But I am stuck now. Any hints would be most appreciated.
|
|
|
|
|
Is there anyone, who could give me some hints/examples as to the problems I have with overriding the OnOK() and OnCancel() function, as per this thread?
Many thanks in advance
|
|
|
|
|
Alt+F4 is same as closing the window by clicking close button. As I said before, you should map WM_CLOSE and call EndDialog there. To map the WM_CLOSE, take the ClassWizard, select the WM_CLOSE for your dialog class, and add it.
- ns ami -
|
|
|
|
|
Thanks for reiterating your advice. The problem I have is that I don't know how to do it properly?
Do I understand you right in that not only the Close button in the title bar (X) as well as the ALT+F4 key combination, BUT ALSO hitting the ESC key or the ENTER key, any of these four events would trigger an WM_CLOSE message?
I gave it a go and as per your post I have added ON_WM_CLOSE using the ClassWizard (see excerpt of header below)...
virtual void OnOK();
afx_msg void OnClose();
DECLARE_MESSAGE_MAP()
private:
...and it is also in the message map in the *.cpp file:
BEGIN_MESSAGE_MAP(CTestDlg, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_CLOSE()
END_MESSAGE_MAP()
However when running the application, the ESC key as well as the ENTER key are still closing the program. So that didn't really do the trick.
I would appreciate if you could please specify a bit more detailed.
Many thanks
|
|
|
|
|
Let me make things clear...
Overriding the OnOK and OnCancel and keeping them blank (like void OnOK() { /*nothing to do*/ } ) will avoid the processing of Enter key and Escape key hits.
Clicking the close button or pressing Alt+F4 will send WM_CLOSE message to the window/dialog. In dialog, it will call the OnClose, if mapped. Its default implementation will send the WM_COMMAND with IDCANCEL inturn the OnCancel will be called. So when the OnCancel is overridden and kept doing nothing, will cause the dialog unable to be closed. So in this scenario, the OnClose should be implemented and the EndDialog should be called explicitly, instead of calling CDialog::OnClose().
So if my understandings about your problems are correct, you have to override the OnOK, OnCancel and OnClose (in the main dialog). The OnOK and OnCancel should be kept blank. And in the OnClose you have to call EndDialog().
If you are still facing problem, please let me know.
- ns ami -
|
|
|
|
|
Dear -ns ami- ...many thanks for your detailed reply, which was very helpful.
It now makes perfect sense to me and I think I have a much better understanding of the whole WM_xxx stuff and about overriding virtual functions.
What you explained works fine now; exactly in the way I wanted it.
I am grateful that you took the time to write everything down.
Can I ask one more question (for now ), please?
I have added a button and upon clicking this (&Close) button I want to shut down the application. I thought I just grab the ON_BN_CLICKED (the ID is IDC_OK) and map/call the same function OnClose , as the one that the ON_WM_CLOSE calls, ... like the // line below:
ON_BN_CLICKED(IDC_SETTINGS, OnSettings)
ON_WM_CLOSE()
ON_BN_CLICKED(IDC_OK, OnAbort)
END_MESSAGE_MAP()
...but that wasn't such a good idea, because then the Class Wizard complains with a 'PARSER ERROR'.
So as a next step I have added the
ON_BN_CLICKED(IDC_OK, OnAbort) map entry and then further down the member function like this:
void CTestDlg::OnClose()
{
EndDialog(true);
}
void CTestDlg::OnAbort()
{
EndDialog(true);
}
What I don't like is that I now have twice the same code (...calling the EndDialog()).
Is that the right way of doing it? Or am I missing something here again, ... and I can actually (somehow) map the button event to the same OnClose member function?
If so, how?
Thanks again in advance.
|
|
|
|
|
Sorry for the late reply...
There is no problem in calling EndDialog() from multiple functions.
But if you want to do something in common before application exits, then the following method will be useful.
void CTestDlg::AppShutDown()
{
SaveSettings();
EndDialog( 0 );
}
void CTestDlg::OnClose()
{
AppShutDown();
}
void CTestDlg::OnAbort()
{
AppShutDown();
}
- ns ami -
|
|
|
|
|
Many thanks ns ami,
...you don't have to apologise at all; I find it very nice from you to even answer my beginner's questions.
Thanks for the idea with 'bundling' functions in the way you describe - good idea!
I might try that, ...see how my little project goes.
|
|
|
|
|
B_U_A wrote: Many thanks ns ami,
You are welcome...
- ns ami -
|
|
|
|
|
can someone tell me where i can get a good and very simple tutorial to create toolbar for IE using atl/com....i quite surprised coz after googling i didnt get one useful tutorial......i need it so that i can have a skeleton to start making mine.....
Thanks A Ton
Ash_VCPP
|
|
|
|
|
Ash_VCPP wrote: i quite surprised coz after googling i didnt get one useful tutorial..
This is the first link i got after googling IE toolbar tutorial [^]
I hope it helps.
Regards,
Sandip.
|
|
|
|
|
hi sandip,
Thanks for the reply....i already saw that one but its too big to understand actually i am looking to get very basic and simple one just for starting...and further coding i will do according to my requirement.
Thanks A Ton
Ash_VCPP
|
|
|
|
|
Codeproject.
Of one Essence is the human race
thus has Creation put the base
One Limb impacted is sufficient
For all Others to feel the Mace
(Saadi )
|
|
|
|
|
in the fifth edition of Windows via C/C++(written by Jeffery Richter)
in many places i saw this phrase "commit storage", for example in Chapter 17, section "Memory-Mapped Executables and Dlls", there is this note:
" When a process is loaded, the system examines all the file image's pages. The system commits storage in the paging file immediately for pages that would normally be protected with the copy-on-write attribute. These pages are simply committed; they are not touched in any way. When a page in the file image is accessed, the system loads the appropriate page. If that page is never modified, it can be discarded from memory and reloaded when necessary. If the file's page is modified, however, the system swaps the modified page to one of the previously committed pages in the paging file."
what does he mean by "commit storage"? What if a page is committed? What does the system do to commit a page? what does this sentence mean "If the file's page is modified, however, the system swaps the modified page to one of the previously committed pages in the paging file."
Can somebody help me?
Thanks!
Jack
|
|
|
|
|
Committed means the memory that is ready for use. It's at the disposal.
JackPuppy wrote: When a page in the file image is accessed, the system loads the appropriate page. If that page is never modified, it can be discarded from memory and reloaded when necessary.
You should know about Paging to understand these terminologies. That's Bascically about maintaining virtual memory. To trick your process to believe it's got 2GB of address at it's disposal. You might have heard every process in windows is allocated a virtual memory of 2GB for userspace. But they are "virtual". Even you have just 512 KB of virtual memory, your process can use upto 2GB - because of memory gets mapped to virtual memory. Here the chunks of memory are termed as "pages". In the quoted text, what it means is that, until a specific page from your application is not required, it's not loaded into memory. And the pages that the OS predicts to be required would be kept in the page file (VM). If the application searches for a page that is not found the the physical memory(RAM), it searches the page files table & loads the required page. And if the phyiscal memory is full, it does a swapping based on some page replacement algorithms. Ok enough of the story, Search for "Paging" &"virtual memory". May be you can add "win32" if are specific about the OS implementation. byebye.
He never answers anyone who replies to him. I've taken to calling him a retard, which is not fair to retards everywhere.-Christian Graus
|
|
|
|