Click here to Skip to main content
16,004,412 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: CString to char* (((IN A UNICODE APPLICATION))) Pin
Murad Duraidi17-Aug-05 3:59
Murad Duraidi17-Aug-05 3:59 
GeneralRe: CString to char* (((IN A UNICODE APPLICATION))) Pin
Blake Miller17-Aug-05 4:08
Blake Miller17-Aug-05 4:08 
GeneralRe: CString to char* (((IN A UNICODE APPLICATION))) Pin
Alan C. Balkany17-Aug-05 11:19
Alan C. Balkany17-Aug-05 11:19 
GeneralRe: CString to char* (((IN A UNICODE APPLICATION))) Pin
PJ Arends17-Aug-05 14:34
professionalPJ Arends17-Aug-05 14:34 
GeneralRe: CString to char* (((IN A UNICODE APPLICATION))) Pin
Jose Lamas Rios17-Aug-05 18:30
Jose Lamas Rios17-Aug-05 18:30 
GeneralRe: CString to char* (((IN A UNICODE APPLICATION))) Pin
TheGreatAndPowerfulOz17-Aug-05 13:54
TheGreatAndPowerfulOz17-Aug-05 13:54 
GeneralRe: CString to char* (((IN A UNICODE APPLICATION))) Pin
PJ Arends17-Aug-05 14:42
professionalPJ Arends17-Aug-05 14:42 
QuestionGood OOP practice? Pin
Kuniva17-Aug-05 3:31
Kuniva17-Aug-05 3:31 
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:

// Implementation nr.1
// _wcex is a member variable of WindowClass of type WNDCLASSEX
WindowClass::WindowClass(HINSTANCE hInstance)
{
   // Fill in all parts of _wcex structure with default values
   if(!RegisterClassEx(&_wcex))
       // throw exception
}


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:
// Implementation nr.2
WindowClass::WindowClass(HINSTANCE hInstance)
{
    // Fill in _wcex fields
    _wcex.hInstance = hInstance; // ...
}

void WindowClass::Register()
{
    if(!RegisterClassEx(&_wcex))
       // throw exception
}


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
--------------------------------------------
AnswerRe: Good OOP practice? Pin
Bob Stanneveld17-Aug-05 8:12
Bob Stanneveld17-Aug-05 8:12 
Questionhow to block the screen Pin
Dogunkanmi17-Aug-05 3:12
Dogunkanmi17-Aug-05 3:12 
AnswerRe: how to block the screen Pin
David Crow17-Aug-05 3:40
David Crow17-Aug-05 3:40 
GeneralRe: how to block the screen Pin
Blake Miller17-Aug-05 4:11
Blake Miller17-Aug-05 4:11 
AnswerRe: how to block the screen Pin
Michael Hendrickx17-Aug-05 6:39
Michael Hendrickx17-Aug-05 6:39 
GeneralDifferences between VC 6.0 and VC 7.0 Pin
bbluey17-Aug-05 3:00
bbluey17-Aug-05 3:00 
GeneralRe: Differences between VC 6.0 and VC 7.0 Pin
Maximilien17-Aug-05 3:05
Maximilien17-Aug-05 3:05 
GeneralRe: Differences between VC 6.0 and VC 7.0 Pin
Kevin McFarlane17-Aug-05 4:40
Kevin McFarlane17-Aug-05 4:40 
GeneralDirectShow Pin
gohary_cs17-Aug-05 2:28
gohary_cs17-Aug-05 2:28 
GeneralRe: DirectShow Pin
scorcher2417-Aug-05 4:04
scorcher2417-Aug-05 4:04 
GeneralHelp! Exception in gaining element in HTMLDocument2 document Pin
123ivan12317-Aug-05 1:53
123ivan12317-Aug-05 1:53 
GeneralRe: Help! Exception in gaining element in HTMLDocument2 document Pin
ThatsAlok17-Aug-05 2:05
ThatsAlok17-Aug-05 2:05 
General"Not" missed! Pin
Eytukan17-Aug-05 3:14
Eytukan17-Aug-05 3:14 
GeneralRe: **to Mr Alok*** Pin
toxcct17-Aug-05 3:03
toxcct17-Aug-05 3:03 
GeneralRe: "Not" missed! Pin
ThatsAlok17-Aug-05 18:00
ThatsAlok17-Aug-05 18:00 
GeneralRe: **to Mr Alok*** Pin
ThatsAlok17-Aug-05 17:58
ThatsAlok17-Aug-05 17:58 
GeneralRe: off topic Pin
toxcct17-Aug-05 20:31
toxcct17-Aug-05 20:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.