what is the difference between MFC and Win32

Answers were Sorted based on User's Feedback



what is the difference between MFC and Win32..

Answer / john k gummadi

Win32 is a set of Windows APIs written in C and MFC is a
framework built arround Win32. All MFC functions internally
use Win32 APIs. And MFC is written in C++.

Is This Answer Correct ?    63 Yes 3 No

what is the difference between MFC and Win32..

Answer / nandu

// 2709test1.cpp : Defines the entry point for the application.
//

#include "stdafx.h"
#include "2709test1.h"
#include <windows.h>
#define ID_EDIT 1
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK EditProc (HWND, UINT, WPARAM, LPARAM);
TCHAR szAppName[] = TEXT ("PopPad1") ;
WNDPROC OldEdit ;
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE
hPrevInstance, LPSTR szCmdLine, int iCmdShow)
{
HWND hwnd ;
MSG msg ;
WNDCLASS wndclass ;
wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH) GetStockObject
(WHITE_BRUSH) ;
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = szAppName ;
if (!RegisterClass (&wndclass))
{
MessageBox (NULL, TEXT ("This program requires Windows NT!"),
szAppName, MB_ICONERROR) ;
return 0 ;
}
hwnd = CreateWindow (szAppName, szAppName,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL) ;
ShowWindow (hwnd, iCmdShow) ;
UpdateWindow (hwnd) ;
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM
wParam, LPARAM lParam)
{
static HWND hwndEdit ;
switch (message)
{
case WM_CREATE :
hwndEdit = CreateWindow (TEXT ("edit"), NULL,
WS_CHILD | WS_VISIBLE | //WS_HSCROLL | WS_VSCROLL |
WS_BORDER | ES_LEFT |
ES_MULTILINE |
ES_AUTOHSCROLL | ES_AUTOVSCROLL,
0, 0, 0, 0, hwnd, (HMENU) ID_EDIT,
((LPCREATESTRUCT) lParam) -> hInstance, NULL) ;
OldEdit = (WNDPROC) SetWindowLong (hwndEdit, GWL_WNDPROC,
(LPARAM) EditProc);
return 0 ;
case WM_SETFOCUS :
SetFocus (hwndEdit) ;
return 0 ;
case WM_SIZE :
MoveWindow (hwndEdit, 100,100, 100, 20, TRUE) ;
return 0 ;
case WM_COMMAND :
if (LOWORD (wParam) == ID_EDIT)
if (HIWORD (wParam) == EN_ERRSPACE ||
HIWORD (wParam) == EN_MAXTEXT)
MessageBox (hwnd, TEXT ("Edit control out of
space."),szAppName, MB_OK) ;
return 0 ;
case WM_DESTROY :
PostQuitMessage (0) ;
return 0 ;

}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
LRESULT CALLBACK EditProc (HWND hwnd, UINT message, WPARAM
wParam, LPARAM lParam)
{
TCHAR ARR[100];
TCHAR buff[1024];


if (message == WM_KEYDOWN && wParam == VK_RETURN)
{

GetWindowText( hwnd, buff, 1024);



MessageBox( hwnd, buff, L"TEST", MB_OK);
}

return CallWindowProc (OldEdit, hwnd, message, wParam,
lParam) ;
}

Is This Answer Correct ?    0 Yes 0 No

what is the difference between MFC and Win32..

Answer / pavan

We can build Console Application using Win32. Where as MFC
we can build GUI based Application.

Is This Answer Correct ?    5 Yes 6 No

what is the difference between MFC and Win32..

Answer / nandu

// 2609a2.cpp : Defines the entry point for the application.
//

#include "stdafx.h"
#include "2609a2.h"

// 2409a3.cpp : Defines the entry point for the application.
//
// 2209a1.cpp : Defines the entry point for the application.
//

#include <windows.h>
#include "resource.h"
#include "stdio.h"
#include "stdlib.h"
#include <string>
#include <stdio.h>
#include <sstream>
#include <commctrl.h>

//#include <boost/spirit/include/qi.hpp>

#define ID_SLIDER 1
#define ID_BUTTON 2
#define ID_SQUARE 3
#define ID_CIRCLE 4
#define ID_CHECK 5
#define ID_RED 6
#define ID_GREEN 7
#define WM_CTLCOLORBTN 8
#define WM_CTLCOLORBTN1 9
#define ID_PAINT 10
LRESULT _stdcall MyWindowFun(HWND,UINT,WPARAM,LPARAM);
LRESULT _stdcall ChWndProc(HWND,UINT,WPARAM,LPARAM);
HWND hWnd1;
//HINSTANCE hInstance;
/*int iCurrectcheck=0 ;*/
int shape=ID_SQUARE;
int color=0;
static LRESULT res = 0;
static int check ;




TCHAR szAppName[] = TEXT ("PopPad1") ;
HINSTANCE g_hInstance = NULL;
HWND g_hwnd = NULL;
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,
LPSTR lpCmdLine,int nShowCmd)
{
WNDCLASS wc = {0};
WNDCLASS chwc = {0};
HWND hwnd;
MSG msg;

g_hInstance = hInstance;

wc.hInstance = hInstance;
wc.hbrBackground = CreateSolidBrush(RGB(255,255,255));
wc.lpfnWndProc = MyWindowFun;
wc.lpszClassName = L"kishore";
wc.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wc.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
//wc.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1);

chwc.hInstance = hInstance;
chwc.hbrBackground = CreateSolidBrush(RGB(0,255,255));
chwc.lpfnWndProc = ChWndProc;
chwc.lpszClassName = L"trust";

RegisterClass(&wc);
RegisterClass(&chwc);

hwnd = CreateWindow(L"kishore",L"My
Window",WS_OVERLAPPEDWINDOW,
0,0, CW_USEDEFAULT,
0,NULL,LoadMenu(hInstance,MAKEINTRESOURCE(IDR_MENU1)),hInstance,NULL);

g_hwnd = CreateWindow(L"trust",L"Child Window",WS_CHILD |
//WS_OVERLAPPEDWINDOW
WS_CAPTION | WS_POPUP | WS_SYSMENU | DS_SETFONT |
DS_MODALFRAME | DS_FIXEDSYS
,CW_USEDEFAULT,CW_USEDEFAULT,300,180
,hwnd,NULL,NULL,NULL);

hWnd1 = hwnd;
ShowWindow(hwnd,SW_SHOW);
while(GetMessage(&msg,0,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;

}


void PaintWindow(HWND hWn,static LRESULT res1,int
shape1,int color1,int check1)
{

HDC hdc;
RECT rect ;
HBRUSH hBrush ;
hdc = GetDC(hWnd1);

GetClientRect (hWnd1, &rect) ;
if(check1 == 1)
{
if(color1 == 1)
{
hBrush = CreateSolidBrush(RGB(255,0,0));
hBrush = (HBRUSH) SelectObject (hdc, hBrush) ;
}
if(color1 == 2)
{
hBrush = CreateSolidBrush(RGB(0,255,0));
hBrush = (HBRUSH) SelectObject (hdc, hBrush) ;
}
//hBrush = (HBRUSH) SelectObject (hdc, hBrush) ;
}
if(shape1 == 1)
Rectangle(hdc,250,250,250+(int)res1,250+(int)res1);
if(shape1 == 2)
Ellipse(hdc,250,250,250+(int)res1,250+(int)res1);
//DeleteObject (SelectObject (hdc, hBrush)) ;
ReleaseDC(hWnd1,hdc);
}

void PaintTheBlock (HWND hWn,static LRESULT res2,int
shape2,int color2,int check2)
{
InvalidateRect (hWn, NULL, TRUE) ;
UpdateWindow (hWn) ;
PaintWindow (hWn, res2,shape2, color2,check2);
}

void ClientResize(HWND hWnd, int Width, int Height)
{
RECT rcClient, rcWindow;
POINT Diff;
GetClientRect(hWnd, &rcClient);
GetWindowRect(hWnd, &rcWindow);
Diff.x = (rcWindow.right - rcWindow.left) - rcClient.right;
Diff.y = (rcWindow.bottom - rcWindow.top) - rcClient.bottom;
MoveWindow(hWnd,rcWindow.left, rcWindow.top, Width +
Diff.x, Height + Diff.y, TRUE);
}

/*void ClientResize(HWND hWnd, int Width, int Height)
{
x = LOWORD(lp);
y = HIWORD(lp);
}*/


LRESULT _stdcall MyWindowFun(HWND hwnd,UINT nMessage,WPARAM
wp,LPARAM lp)
{
int wmId, wmEvent;
PAINTSTRUCT ps ;
//HDC hdc;
hWnd1 = hwnd;
switch( nMessage )
{


case WM_CREATE:
{



HMENU hMenu, hSubMenu;
HICON hIcon, hIconSm;
HBITMAP hBitmap;
hMenu = CreateMenu();
int id = 1;
//HINSTANCE hInst ;

/*hSubMenu = CreatePopupMenu();
AppendMenu(hSubMenu, MF_STRING, IDM_EXIT,L"E&xit");
AppendMenu(hMenu, MF_STRING | MF_POPUP,
(UINT)hSubMenu, L"&File");*/

hSubMenu = CreatePopupMenu();
AppendMenu(hSubMenu, MF_STRING, ID_DIALOG_SHOW,
L"&Show\tShift+3");
AppendMenu(hMenu, MF_STRING | MF_POPUP,
(UINT)hSubMenu, L"&Dialog");
//hInst = (lParam)->hInst ;
//hBitmap = LoadBitmap (hInst, TEXT("bitmap1")) ;
//hMenu = GetMenu(hWnd);
hSubMenu = GetSubMenu(hMenu, 0);
UINT MenuID1 = GetMenuItemID(hSubMenu, 0);
UINT MenuID2 = GetMenuItemID(hSubMenu, 1);
hBitmap =
(HBITMAP)LoadImage(g_hInstance,MAKEINTRESOURCE(IDB_BITMAP1),
IMAGE_BITMAP, 12, 12, 0);
SetMenuItemBitmaps(hSubMenu,MenuID1, MF_BYCOMMAND,
hBitmap,hBitmap);
SetMenu(hwnd, hMenu);



}
break;
case WM_COMMAND:
wmId = LOWORD(wp);
wmEvent = HIWORD(wp);
switch (wmId)
{
case ID_DIALOG_SHOW:
if ( g_hwnd == NULL )
{
g_hwnd = CreateWindow(L"trust",L"Child Window",WS_CHILD
| //WS_OVERLAPPEDWINDOW
WS_CAPTION | WS_POPUP | WS_SYSMENU | DS_SETFONT |
DS_MODALFRAME | DS_FIXEDSYS
,CW_USEDEFAULT,CW_USEDEFAULT,300,180
,hwnd,NULL,NULL,NULL);
}
ShowWindow(g_hwnd,SW_SHOW);
InvalidateRect (hwnd, NULL, TRUE) ;
default:
return DefWindowProc(hwnd,nMessage, wp, lp);
}
case WM_PAINT:
BeginPaint (hwnd, &ps) ;
//PaintWindow (hwnd,res,shape,color,check ) ;
EndPaint (hwnd, &ps) ;

return 0 ;

case WM_CHAR:
if ( wp == '#' )
{
g_hwnd = CreateWindow(L"trust",L"Child Window",WS_CHILD
| //WS_OVERLAPPEDWINDOW
WS_CAPTION | WS_POPUP | WS_SYSMENU | DS_SETFONT |
DS_MODALFRAME | DS_FIXEDSYS
,CW_USEDEFAULT,CW_USEDEFAULT,300,180
,hwnd,NULL,NULL,NULL);
ShowWindow(g_hwnd,SW_SHOW);
}
return 0;


case WM_CLOSE:
if ( IDOK == MessageBox(hwnd,L"Do you want to close
???",L"Close",MB_OKCANCEL) )
{
return DefWindowProc(hwnd,nMessage,wp,lp);
}
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hwnd,nMessage,wp,lp);
}
}



LRESULT _stdcall ChWndProc(HWND hwnd,UINT nMessage,WPARAM
wp,LPARAM lp)
{
static HWND hSlider ;
static HWND hwndButton;
PAINTSTRUCT ps ;
static HWND hCtrlBlock ;
static HWND hwndRadio1;
static HWND hwndRadio2;
static HWND hwndcheck;
static HWND hwndRadio3;
static HWND hwndRadio4;
static HWND hwndgroup1;
static HWND hwndgroup2;
static HWND hwndpaint;
static int iSquare=0 ;
static int iCircle=0 ;
static int iRed=0 ;
static int iGreen=0 ;

static HWND hwndLeftLabel;
static HWND hwndRightLabel;

switch(nMessage)
{

case WM_CREATE :
hSlider = CreateWindowEx(NULL, TRACKBAR_CLASS,
L"Trackbar", WS_CHILD | WS_VISIBLE | TBS_AUTOTICKS |
TBS_ENABLESELRANGE,
0, 0, 0, 0, hwnd, (HMENU)ID_SLIDER, NULL, NULL );

SendMessage(hSlider, TBM_SETRANGE,TRUE,MAKELONG (0, 500));
SendMessage(hSlider, TBM_SETPOS,TRUE,0);
//SendMessage(hSlider, TBM_SETPAGESIZE,0,100);
SendMessage(hSlider, TBM_SETTICFREQ,30,0);
//SendMessage(hSlider, TBM_SETSELSTART,30,100);
//SendMessage(hSlider, TBM_SETSEL,TRUE,MAKELONG (0, 500));
//SendMessage(hSlider, TBM_SETTHUMBLENGTH,0,(lp)L"30");
//SetFocus(hSlider);


hwndButton=CreateWindow(
L"BUTTON",
L"OK",
WS_TABSTOP|WS_VISIBLE|WS_CHILD|BS_DEFPUSHBUTTON,
0, 0, 0, 0, hwnd,
(HMENU) ID_BUTTON,
NULL,NULL);

/*hwndpaint=CreateWindow(
L"TEXT",
L"",
WS_VISIBLE|WS_CHILD,
0, 0, 0, 0, hwnd,
(HMENU) ID_PAINT,
NULL,NULL);*/

hwndRadio1 = CreateWindowEx(0,
TEXT("BUTTON"),
TEXT("SQUARE!"),
WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON | WS_GROUP |
WS_TABSTOP,
0, 0, 0, 0,
hwnd,
(HMENU) ID_SQUARE,
NULL,NULL);

hwndRadio2 = CreateWindowEx(0,
TEXT("BUTTON"),
TEXT("CIRCLE!"),
WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON,
0, 0, 0, 0,
hwnd,
(HMENU) ID_CIRCLE,
NULL,NULL);

hwndRadio2 = CreateWindowEx(0,
TEXT("BUTTON"),
TEXT("CIRCLE!"),
WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON,
0, 0, 0, 0,
hwnd,
(HMENU) ID_CIRCLE,
NULL,NULL);

hwndgroup1 = CreateWindow(L"BUTTON", L"", WS_CHILD |
WS_VISIBLE | BS_GROUPBOX | WS_GROUP,
9, /* X Position */
65, /* Y Position */
234, /* X Width */
42, /* Y Height */
hwnd, (HMENU) WM_CTLCOLORBTN,((LPCREATESTRUCT)
lp) -> hInstance, NULL);
hwndgroup2 = CreateWindow(L"BUTTON", L"", WS_CHILD |
BS_GROUPBOX,
9, /* X Position */
135, /* Y Position */
234, /* X Width */
42, /* Y Height */
hwnd, (HMENU) WM_CTLCOLORBTN1,((LPCREATESTRUCT)
lp) -> hInstance, NULL);

hwndcheck = CreateWindowEx(0,
TEXT("BUTTON"),
TEXT("COLOR!"),
WS_VISIBLE | WS_CHILD | BS_AUTOCHECKBOX,// |
BS_OWNERDRAW,
0, 0, 0, 0,
hwnd,
(HMENU)ID_CHECK,
NULL,
NULL
);
hwndRadio3 = CreateWindowEx(0,
TEXT("BUTTON"),
TEXT("RED!"),
WS_CHILD | BS_AUTORADIOBUTTON | WS_GROUP,
0, 0, 0, 0,
hwnd,
(HMENU) ID_RED,
NULL,NULL);
hwndRadio4 = CreateWindowEx(0,
TEXT("BUTTON"),
TEXT("GREEN!"),
WS_CHILD | BS_AUTORADIOBUTTON,
0, 0, 0, 0,
hwnd,
(HMENU) ID_GREEN,
NULL,NULL);
hwndLeftLabel = CreateWindow(L"STATIC", L"0",
WS_CHILD | WS_VISIBLE,
20, 45, 200, 20,
hwnd, (HMENU)1, NULL, NULL);

hwndRightLabel = CreateWindow(L"STATIC", L"500",
WS_CHILD | WS_VISIBLE,
190,45, 25, 20,
hwnd, (HMENU)2, NULL, NULL);

SendMessage (hwndRadio1, BM_SETCHECK,1, 0);
//SendMessage (hwndRadio1, BM_SETSTATE, 1, 0);
/*shape=ID_SQUARE;
iSquare=1;*/
return 0;

case WM_SIZE :
MoveWindow (hSlider, 20,10, 200,35, TRUE) ;
MoveWindow (hwndButton, 230,10, 50, 30, TRUE) ;
MoveWindow (hwndRadio1, 15,80, 100, 20, TRUE) ;
MoveWindow (hwndRadio2, 135,80, 100, 20, TRUE) ;
MoveWindow (hwndcheck, 75,115, 100, 20, TRUE) ;
MoveWindow (hwndRadio3, 15,150, 100, 20, TRUE) ;
MoveWindow (hwndRadio4, 135,150, 100, 20, TRUE) ;

return 0 ;
case WM_INITDIALOG:
iSquare=1;
//shape=ID_SQUARE;
//color=ID_RED;
hCtrlBlock = GetDlgItem (g_hwnd, ID_PAINT) ;
SetFocus (hwndRadio1) ;
SetFocus (GetDlgItem (g_hwnd, color)) ;

break;
return (INT_PTR)TRUE;

case WM_SETFOCUS :

return TRUE ;

case WM_COMMAND:

switch (LOWORD (wp))
{
case ID_SQUARE:
iSquare = SendMessage (hwndRadio1, BM_GETCHECK, 0, 0);
iCircle=0;
//SetFocus((HWND)BM_GETCHECK);
return TRUE;
case ID_CIRCLE:
iCircle = SendMessage (hwndRadio2, BM_GETCHECK, 0, 0);
iSquare=0;
return TRUE;
case ID_CHECK:
check = SendMessage (hwndcheck, BM_GETCHECK, 0, 0);
if(check == 1)
{
ShowWindow(hwndRadio3,SW_SHOW);
ShowWindow(hwndRadio4,SW_SHOW);
ShowWindow(hwndgroup2,SW_SHOW);
//MoveWindow (g_hwnd,,, 300,220, TRUE) ;
/*xchild=300;
ychild=220;
ShowWindow(hwnd,SW_SHOW);*/
//OnSizing(g_hwnd, WM_SIZING, 300, 220);
ClientResize(g_hwnd, 300, 200);

}
if(check == 0)
{
ShowWindow(hwndRadio3,SW_HIDE);
ShowWindow(hwndRadio4,SW_HIDE);
ShowWindow(hwndgroup2,SW_HIDE);
//MoveWindow (g_hwnd,,, 300,175, TRUE) ;
/*xchild=300;
ychild=175;
ShowWindow(hwnd,SW_SHOW);*/
//OnSizing(g_hwnd, WM_SIZING, 300, 175);
ClientResize(g_hwnd, 300, 150);
}

return TRUE;
case ID_RED:
iRed = SendMessage (hwndRadio3, BM_GETCHECK, 0, 0);
iGreen=0;

return TRUE;
case ID_GREEN:
iGreen = SendMessage (hwndRadio4, BM_GETCHECK, 0, 0);
iRed=0;

return TRUE;

/*case WM_RBUTTONDOWN:
x = LOWORD(lp);
y = HIWORD(lp);
sprintf(a,"x = %d , y = %d",x,y);
MessageBox(hwnd,a,"RBD",MB_OKCANCEL);
return 0;*/
case ID_BUTTON:

//HDC hdc;

shape=1;
color=0;
if(iSquare==1)
{
shape=1;
iCircle=0;
}
else if(iCircle==1)
{
shape =2;
iSquare=0;
}
if(iRed==1)
{
color=1;
iGreen=0;
}
else if(iGreen==1)
{
color =2;
iRed=0;
}
res = SendMessage(hSlider, TBM_GETPOS, 0, 0);
PaintTheBlock(hCtrlBlock, res,shape, color,check);


/*DestroyWindow(g_hwnd);
g_hwnd = NULL;
iSquare=0 ;
iCircle=0 ;
iRed=0 ;
iGreen=0 ;*/
return TRUE;
//return DefWindowProc(g_hwnd,nMessage,wp,lp);
}
return 0 ;


case WM_CLOSE:
DefWindowProc(g_hwnd,nMessage,wp,lp);
g_hwnd = NULL;
shape=0;
color=0;
check=0;
iSquare=0 ;
iCircle=0 ;
iRed=0 ;
iGreen=0 ;

return 0;
default:
return DefWindowProc(hwnd,nMessage,wp,lp);
}
}

Is This Answer Correct ?    0 Yes 2 No

what is the difference between MFC and Win32..

Answer / raj

MFC is a set of classes funtions and structures where win32
is combination of functions and structures

Is This Answer Correct ?    13 Yes 19 No

Post New Answer

More Win32API Interview Questions

What is preemption ? context switching ?

3 Answers  


describe process of creating a new class of windows ??

1 Answers  


what is use of the createWindow object

4 Answers   HCL,


What is Function entry for DLL in win3.1?

0 Answers  


What are the COM components

2 Answers   SunSoft Technologies,






Explain Win32 Program Execution flow?

0 Answers  


What is an Hash Mapping in java?

0 Answers   Cisco, Syntel,


what are the design patterns of an MFC application

5 Answers   Samsung, SunSoft Technologies,


What is Win32?

14 Answers   AAA, Genpact, HCL, Wipro,


System call executable binary file into a process

2 Answers  


In win32 application if defining a variable of CString then it gives the error "CString:Undeclared identifier" how to solve the problem? What headerfile need to include??

2 Answers  


what API used to hide window

2 Answers  


Categories