CPB Mailing List

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: MFC? OWL?



>     I know it sound silly but what exactly does OWL and MFC stand for and
> what are their actually Differences.

Object Windows Library  and Micro$oft Foundation Classes are both
application frameworks (wrappers) around the windows environment.  They
are intended to make it much easier to get a handle on a windows API (if
you will pardon the pun).  The API, Application Programmer's Interface
are your basic functions to interface with the windows environment.  OWL
was fairly well done, but MFC was a very thin wrapper.  Many of the API
calls require a handle to a window (usually the first parameter), and
MFC will often force you to provide a handle to the window, whereas OWL
would embed the handle in the wrapper class.

It is obvious that you have never written a windows program in C, or you
would be well acquainted with these two options (and more), but if you
are really interested I would suggest you search the used book stores
for a copy of "Programming Windows" by Charels Petzold (he also wrote
"Programming Windows 95" but you may not find it in used book stores). 
Your basic "Hello World" program is 150 lines long.  True, you only
copied those 150 lines from a program that someone else wrote and pasted
in your code, but you get the idea: RAD not used here.

OWL, and to a lesser extent MFC, buried the details in C++ classes like
CWnd.  Also the message handling was a great improvement.  The fact that
MFC was a very thin wrapper was often claimed as an advantage, as
someone who had programmed in C could easily recognize the MFC
equivalent, whereas OWL looked different because Borland was doing more
of the work for you.
Respond to a "WM_PAINT" message:

OWL:
void TWndw::Paint( TDC &paintDC, BOOL, TRect&) {
  // user code follows
  paintDC.TextOut( point, "Hellow World" );
}

MFC:
void CMainWindow::OnPaint() {
  CPaintDC dc (this);
  // user code follows
  dc.TextOut( x, y, "Hello World" );
}

API:
LRESULT CALLBACK WndProc( HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM
lParam) {
  HDC         hdc;
  PAINTSTRUCT ps;
  char        Hello[ 80 ];

  switch ( iMsg ) {
    case WM_PAINT:
      hdc = BeginPaint( hwnd, &ps );
      /* copy all of the above, new code goes here */
      strcpy( Hello, "Hello World" );
      TextOut ( hdc, x, y, Hello, strlen( Hello ));

      EndPaint ( hwnd, &ps );
      return 0;
}

And that is without any of the fun stuff like background color, text
color, font size, color, attributes, etc, which is where OWL and MFC
really make life easier.

Of course with BCB you would simply put a label on the form, set the
caption to "Hello World", do anything you want with the attributes, and
write no code at all.
-- Clifton Mayo



W Komornicki's Home Page | Main Index | Thread Index