|
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
|
|
|
|
|
Wow, thanks, a great answer.
After my searching and reading, it should be pointed out that if the application searches for a page that is not found in the RAM, sometimes it will search for exe/dll file somewhere in disk other than page file,for example when the exe/dll file mapped into process address without relocation-that means it doesn't need page files to store relacated pages.
Thanks for your kind!
|
|
|
|
|
I'm handling ::OnSize() of my CView and I want my CListCtrl resize accordingly .
void CMyView::OnSize(UINT nType, int cx, int cy)
{
RECT rc;
POINT p;
p.x = cx;
p.y = cy;
GetClientRect(&rc);
m_cMyList.SetWindowPos(NULL,0,0,rc.right,rc.bottom,1);
}
As you see I tried out damn things [Of course the wrong way!]. Nothing works. Any help?
|
|
|
|
|
Check SetWindowPos[^] documentation.
grassrootkit wrote: m_cMyList.SetWindowPos(NULL,0,0,rc.right,rc.bottom,1);
Here instead of NULL you should specify &CWnd::wndTop because it seems that it is the only control on your dialog.
Also last parameter instead of 1 pass SWP_SHOWWINDOW i am not sure 1 is defined for which constant.
grassrootkit wrote: GetClientRect(&rc);
You do not need this instead you can use cx,cy parameters. I think you doing this because first time when you get the WM_SIZE notification these values are zero. You can simply put a check for that instead of that call.
Also when you resizing the window in OnSize always verify the m_cMylist has valid handle and it is visible. This should be done because WM_SIZE notification is sent multiple times when the main window is being created.
I hope it helps.
Regards,
Sandip.
|
|
|
|
|
SandipG wrote: SWP_SHOWWINDOW
Does the matter. I put 1 just to quickly test the functionality. What a crap. This wasted almost half an hour. Thanks for pointing it out.
|
|
|
|
|
Actually he may specify NULL as the first parameter and use the SWP_NOZORDER flag to indicate he doesn't wish to change the Z-order of the window...
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
Yes.. i forgot about the SWP_NOZORDER
Regards,
Sandip.
|
|
|
|
|
Being forgetful is a common...erm...what's it called...umm...sympthom by programmers, because...umm...erm...what were we talking about again?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
Hello
Actually I want to have a class which supports Fonts along with colors.
For which I have a class Font derived from CFont and a member variable of type COLORREF
class Font1 :public CFont
{
public:
Font1(const Font1& F) ;
Font1(CString FontName = TIMESNEWROMAN,
int FontSize = 15,
bool Bold = false,
bool Italic = false,
bool Underline = false,
COLORREF tFontColor = RGB(0,0,255));
COLORREF FontColor;
bool operator =(const Font1& v) ;
void Heading();
virtual ~Font1();
};
I am not able to write the copy constructor for the class and cannot initialize COLORREF variable
Any ideas how should I go about writing.
Thanks
Prithaa
|
|
|
|
|
I fI were you, I wouldn't inherit from CFont but create my own class which contains a CFont and a COLORREF object. You should also remember the font settings along with the font (face name, font size, italic, ...)
As far as I remember, you won't be able to copy CFont objects because the assignement operator is not public (this was made on purpose to avoid copying CFont objects). So what you could do is only copy the font information and create your CFont object based on those informations.
|
|
|
|