Re: How to encapsulate a winapi Dialog in a class?
Originally Posted by krs0
I have made a simple Pane class so that I can encapsulate a winapi Dialog.
1) Tell me what this line does:
Code:
Pane(&hDlg, hInstance, nCmdShow);
Whatever you believe it's doing, it isn't doing it, and probably the reason you're not seeing a dialog.
2) Nowhere do you check your return codes for your API calls. What if CreateDialogParam returns an error? You now have a useless object being potentially used in an application.
3) If you forget to call onClose(), your Pane destructor is not coded to clean up the resources. Look up the term "RAII". As a matter of fact, what happens if that Pane object goes out of scope without an onClose() call? You now have a resource leak.
Regards,
Paul McKenzie
Last edited by Paul McKenzie; February 28th, 2013 at 04:39 AM.
Re: How to encapsulate a winapi Dialog in a class?
1. Pane(&hDlg, hInstance, nCmdShow);
This is how I want to create and display the dialog. I put the handler in hDlg so that I can use it later in IsDialogMessage(hDlg, &msg).
2. Can you post a short example of check on one of the calls please?
3. I will add onClose() to the destructor is that enough?
Re: How to encapsulate a winapi Dialog in a class?
Originally Posted by krs0
I have made a simple Pane class so that I can encapsulate a winapi Dialog.
To add, you really haven't encapsulated anything. You are using global (static) variables in the Pane class. All you did was rearrange where you're declaring your global variables.
If it were truly encapsulated, there would be no globals (except maybe the dialog procedure function). It takes much more thought and design to really encapsulate a dialog window than just moving your globals to a class.
Re: How to encapsulate a winapi Dialog in a class?
Originally Posted by krs0
1. Pane(&hDlg, hInstance, nCmdShow);
This is how I want to create and display the dialog. I put the handler in hDlg so that I can use it later in IsDialogMessage(hDlg, &msg).
That line of code creates a temporary and that temporary is immediately destroyed. That's why I asked you what it did, and obviously you weren't aware of what it was doing.
If you want proof, put a breakpoint in the Pane destructor. When that line of code is executed, you will see the destructor magically get called. That object that was created is gone after that line is executed.
2. Can you post a short example of check on one of the calls please?
All of those functions return a value. Are you reading the documentation for those functions you're calling?
Re: How to encapsulate a winapi Dialog in a class?
Hi,
You have to debug the code and need to check what is the value returned by CreateDialogParam.You can get the error info by using GetLastError. During debug if found any then mention it in the post.
Please refer http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx
Bookmarks