|
|
I'm trying to write a small and simple GUI library in C++. Kind of like CDialog in MFC and all.. The problem is, I learnt C, and I've always had problems getting into the C++ part. I know the syntax and all, but it's rather the concept I can't always grasp. Now this may seem trivial, but it matters to me. My problem is this:
Let's say I want to encapsulate a Window class into its own class, and also a normal overlapped window.
Now my reasoning would be something like this: A window is based on a window class, so to make a window we'll need to pass our window object a windowclass object when we create it.
Now I have several questions. First of all, look at two different approaches to implement the WindowClass class:
WindowClass::WindowClass(HINSTANCE hInstance)
{
if(!RegisterClassEx(&_wcex))
}
As u can see we call api function RegisterClassEx() to register the class in the constructor, so this class would only have a constructor and a destructor, and perhaps some additional constructors to allow more parameters to be passed to the WNDCLASSEX structure for greater customisation.
Great idea, u just pick the constructor u need and ur window class is registered just by creating the object.
Now the other approach:
WindowClass::WindowClass(HINSTANCE hInstance)
{
_wcex.hInstance = hInstance;
}
void WindowClass::Register()
{
if(!RegisterClassEx(&_wcex))
}
In this implementation the only difference is we put the actual api call in a seperate method, so we can add Set() methods to the class for any field of the WNDCLASSEX structure, so we can customize the entire class. The only downside is it will result in more method calls depending on how much we want to customize.
Now I realize this probably doesn't make much difference in practice, it both works, but I was wondering what you feel is the right way to do it. Personally I feel the right thing to do is to actually avoid API calls in constructors/destructors. I suppose it's more of a OO philosophical question though. If you could share your opinions on it, or direct me to some articles about this I'd be very grateful.
I have another problem, but seeings this post is already kind of longwinded, I think i'll hold it back until i've had this one answered.
P.S.: I've already read Relisofts tutorials, and though I think they're great, I don't always agree on their methods, they're taking it a bit too far if u ask me.
Kuniva
--------------------------------------------
|
|
|
|
|
What you want to do is to encapsulate all low level API details, so that your library can be used anywhere. Right?
Well, if that's the case, you should not create a light wrapper. What you are doing is coupling the API calls in one object.
What you want to be doing is define a set of styles for the window. Define all the other stuff yourself also (windows messages, controls, etc..) and in your code, translate this stuff into windows API calls. This way, you can provide different implementations (makes your project portable). In the ideal case, you don't have to modify your application when you compile it under Linux or whatever GUI. The only thing that has to be done is to use a different implementation of your library!
To get back on track here and to answer your question: I think that you should go for the two stage window construction. One rule is to never throw an exception from a constructor. So here you have almost no way of notifying the caller of your code that creation failed.
One other suggestion though. For abstraction purposes, you should hide implementation details. The win API is an implementation detail. So hInstance variables should be hidden. The raw styles should be hidden. Try to hide as much handles as you can, etc, etc..
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
Hi, Im developing a speaker identification security system for my computer. I've created the software but I need help in making it block the screen while it runs. Your suggestions will be highly appreciated.
|
|
|
|
|
Perhaps you should explain in more detail what "block the screen" means.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
Yeah, because at first I was thinking he could stand in front of it
My wife often proclaims, "You make a better door than a window!' whilst I stand in front of the TV when her soap opera is on
|
|
|
|
|
My best guess is a "how to lock" a screen. You can draw a big form, maximized, borderless, on top of all the rest.
michael.code.ae
|
|
|
|
|
Can anyone point out the differences between Visual C++ 7.0 (.Net) and Visual C++ 6.0?
Thanks
|
|
|
|
|
For strict C++/MFC code, the compiler is a lot more compliant and strict; I believe there are minor changes to MFC and ATL to merge some classes ( I think the CString is one of them ).
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
|
I am a c++ beginner programmer
I want to take an image from my webcam and put it in buffer using directshow,
and any directshow tutorial.
Please help me.
Gohary
|
|
|
|
|
Here are several Tutorials to DirectShow, also for Capturing. Perhaps you also want to have a look at the DirectShow Docs coming with your DXSDK.
http://www.codeguru.com/Cpp/G-M/directx/
rya.
Scorcher24
|
|
|
|
|
when variable i increase to some value(not definite),exception occurs,is it a bug of ie6.0? Thx a not!
Source code goes as follows:
IHTMLDocument2* pDoc2=NULL;
IHTMLElementCollection* ppCollection=NULL;
IDispatch* ppvdispOption=NULL;
pDoc2->get_all(&ppCollection);
Assert(ppCollection);
ppCollection->get_length(&Count);
for (long i=0;i<count;i++)
{
=""
="" _variant_t="" index="" ;
="" try
="" ppcollection-="">item(index,index,&ppvdispOption);
}
catch (...)
{
tagstr.Format("%d",i);
AfxMessageBox(tagstr);
return FALSE;
}
if(!ppvdispOption)
continue;
ppvdispOption->QueryInterface(IID_IHTMLElement,(void **) &pElement);
ppvdispOption->Release();
//.........
}
|
|
|
|
|
123ivan123 wrote:
IHTMLDocument2* pDoc2=NULL;
IHTMLElementCollection* ppCollection=NULL;
IDispatch* ppvdispOption=NULL;
PROBLEM IS HERE
pDoc2->get_all(&ppCollection);
pDoc2 haven't got any memory!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
u r there but "not" luking at my problem... i meant it,, but toxxct gave the answer for that ..
V
|
|
|
|
|
if he doesn't know the answer, why would he overload the servers ?
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
Vivekuniq wrote:
u r there but "not" luking at my problem.
Yeah i looked at your problem, But when I see Tox already given you the answer, So i think there is no need of redundancy .
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
toxcct wrote:
if he doesn't know the answer
Usually I don't answer when somebody already given the answer
toxcct wrote:
why would he overload the servers ?
, Hain Tox i would be working On VC Forum Q&A 5 now (i.e. 2 and 3 is on you).
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
ThatsAlok wrote:
On VC Forum Q&A 5 now
ok... i'm on a now project at work, but i'm doing my best to mix everything in time...
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
Hi,
I downloaded a sample mfc project that builds and runs fine. But when I add any ActiveX control on one of the forms, it fails to start. What could be the problem?
Emmanuel Mwesigwa @ Mwemat
|
|
|
|
|
Could it be that the ActiveX control has not been registered? You can confirm this by ensuring that the dialog has the DS_NOFAILCREATE style.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
Hi all.
I have a dialog, that is a plugin for another application.
The problem is that my dialog works nice when i launch it from the other application, except TASB navigation and shortcuts.
When i test the dialog from Layout->Test, the TAB navigation works nice, but when i try to use tab navigation from my dialog launched from the host application i am not able to navigate with the TAB key.
In addition accelerators keys don't work with my dialog.
Any clues, maybe i have to explicitely get the TAB control? how can i do this?
Thanks
|
|
|
|
|
Could it be that the other application is trapping (e.g., not processing) the tab key such that your dialog does not see it?
lisux wrote:
Any clues, maybe i have to explicitely get the TAB control?
A tabbed dialog box (i.e., property sheet) has nothing to do with using the tab key to navigate controls on a dialog.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
This is a sign that the other application is not calling IsDialogMessage, to give your dialog a chance to process 'dialog messages' like accelerators and tab keys between controls. Perhaps because it does not know that a dialog is up on the screen?
If the other application has a custom message loop, check it to make sure it at least does TranslateMessage() and DispatchMessage, but the handling you are missing is definitely performed by the IsDialogMessage call.
|
|
|
|
|
Hi!
My problem is that when i move my application to another machine it doesn't work. The problem is with the links. I have a very simple cdhtmldialog dialog and here is its html resource. it contains two frames and i want to load a file to each one of them. Everything works fine on my computer, but when i deploy the application links stop working. How i fix this links...i tryid src="file:///juqu.htm", src="juqu.htm", src="./juqu.htm",... and much more...but nothing works...The html file that i want to load is in release directory with .exe file. thax for the help.
<title>A simple frameset document
<P>This frameset document contains:</p>
hussein
|
|
|
|