Documente Academic
Documente Profesional
Documente Cultură
1. Define a window
A window is a rectangular area on the screen which gets the input from the user and
displays the output in the form of text or graphics. The caption in the caption bar of the
window differentiates each window. A user can view the information on a single screen by
using scroll bars.
3. What is GUI?
GUI stands for Graphical User Interface. All GUIs make use of graphics on a bitmapped
video display. Graphics provides better utilization of screen real estate, a visually rich
environment for conveying information, and the possibility of a WYSIWYG (what you see is
what you get) video display of graphics and formatted text prepared for a printed document.
10. What are the argument used in Message Box and uses.
• The first argument to Message Box is normally a window handle.
• The second argument is the text string that appears in the body of the message
box
• The third argument is the text string that appears in the caption bar of the
message box
• The fourth argument to MessageBox can be a combination of constants
beginning with the prefix MB_ that are defined in WINUSER.H.
• A previously hidden area of the window is brought into view when a user moves a
window or uncovers a window.
• The user resizes the window (if the window class style has the CS_HREDRAW and
CW_VREDRAW bits set).
• The program uses the ScrollWindow or ScrollDC function to scroll part of its client
area.
• The program uses the InvalidateRect or InvalidateRgn function to explicitly generate
a WM_PAINT message.
• As another example, suppose the user opens a first window, again he tries to
open a second window.
• Now this second window partially covers our first application's window.
• The Windows of the first application window will not save the coordinates of the
second window.
• When the second window is closed, then the first window will request that our
program needs to repaint this portion of our client area. Windows is a message-
driven system.
20. What are the steps for Window Creation?
The window creation steps are,
Window Main
• Variable declarations
• Window class registration
• Checking the registration
• Creating the window
• Displaying the window
• Message loop
Window procedure
• WM_CREATE
• WM_PAINT
• WM_DESTROY
• DefWindowProc
21. What is the function used to display the text on the output window?
The function that is used to display the text on the output window is Drawtext()
which is shown below,
• The first argument is a handle to the device context returned from BeginPaint.
• The second argument is the text to draw.
• The third argument is set to -1 to indicate that the text string is terminated with a zero
character.
• The last argument to DrawText is a series of bit flags defined in WINUSER.H.
if (!RegisterClass (&wndclass))
{
MessageBox (NULL, TEXT ("This program requires to register all the
Parameter of the window class "), szName, MB_ICONERROR) ;
return 0 ;
}
25. What is meant by window class?
A window features are created based on the "window class." The window class
identifies the window procedure that processes messages to the window. The multiple
windows can share the same window class and they can use the same window procedure.
Identifier Meaning
Handle to an "instance"—the program itself (
HINSTANCE
kernel )
HWND Handle to a window (user)
27. What are the Data Types used for window creation?
The data types are as follows,
• UINT – This data type is used as second parameter to WndProc and it is simply an
unsigned int,
• PSTR – This data type is the third parameter to WinMain and it’s a pointer to a
nonwide character string, that is, a char *.
• WPARAM - When Windows was a 16-bit system, the third parameter to WndProc
was defined as a WORD, which was a 16-bit unsigned short integer,
• LPARAM - The fourth parameter was defined as a LONG, which was a 32-bit signed
long integer.
• LRESULT – This is the return data type of the window procedure WndProc function.
L denotes LONG.
• Here the variable name begins with a lowercase letter or letters that denote the
data type of the variable.
• For example, the sz prefix in szCmdLine stands for "string terminated by zero."
• The h prefix in hInstance and hPrevInstance stands for "handle;"
• The i prefix in iCmdShow stands for "integer."
• For example, in the WinMain function, the msg variable is a structure of the MSG
type; wndclass is a structure of the WNDCLASS type.
• In the WndProc function, ps is a PAINTSTRUCT structure and rect is a RECT
structure.
The fixed-pitch font has all the characters of same width. In Windows 3.0, the system
font is the variable-pitch font, in which the different characters have different widths. The
system font is a "raster font," in which the characters are defined as blocks of pixels.
39. What are the four methods of Getting a Device Context Handle?
There are four methods for getting the device context handle. The first method of
getting the device context handle is by using BeginPaint and EndPaint function in the
WM_PAINT message:
1) hdc = BeginPaint (hwnd, &ps) ;
[other program lines]
EndPaint (hwnd, &ps);
The variable ps is a structure variable of type PAINTSTRUCT.
The second method of getting the device context handle is by using GetDC and ReleaseDC
function and it can be used in any messages other than WM_PAINT:
2) hdc = GetDC (hwnd) ;
[other program lines]
ReleaseDC (hwnd, hdc) ;
The third method of getting the device context handle is by using GetWindowDC and
ReleaseDC function. This method is used to draw on the entire window that include both the
window's client area and non client area and it as follows,
3) hdc = GetWindowDC (hwnd) ;
[other program lines]
ReleaseDC (hwnd, hdc);
The fourth method of getting the device context handle is used for obtaining a handle to a
device context is CreateDC:
4) hdc = CreateDC (pszDriver, pszDevice, pszOutput, pData) ;
[other program lines]
DeleteDC (hdc);
40. What are the line drawing functions?
Windows can draw straight lines, elliptical lines, and Bezier Splines. The seven
functions that is used to draw the lines are as follows,
LineTo: Draws a straight line.
Polyline, PolylineTo: Draw a series of connected straight lines.
PolyPolyline: Draws multiple polylines.
Arc: Draws elliptical lines.
PolyBezier, PolyBezierTo: Draw Bezier splines.
The extra three line-drawing functions supported by higher versions of windows are,
ArcTo, AngleArc: Draw elliptical lines.
PolyDraw: Draws a series of connected straight lines and Bezier splines.
The functions that draw lines by filling the enclosed area are as follows,
Rectangle: Draws a rectangle.
Ellipse: Draws an ellipse.
RoundRect: Draws a rectangle with rounded corners.
Pie: Draws a part of an ellipse that looks like a pie slice.
Chord: Draws part of an ellipse formed by a chord.
The function MoveToEx sets the attribute of the device context to the current position. The
LineTo function then draws a straight line from the starting position to the destination point
specified in the LineTo function
The coordinates of the entire screen of the system is said to be the "screen coordinates."
The coordinates of the entire application window including the client area and non client area
is called as "Whole-window coordinates" and it includes the title bar, menu, scroll bars, and
border. The coordinate of the client area of the window is called "client area coordinates".
1. PushButton Æ BS_PUSHBUTTON
2. Default PushButton Æ BS_DEFPUSHBUTTON.
• SS_BLACKRECT
• SS_BLACKFRAME
• SS_GRAYRECT
• SS_GRAYFRAME
• SS_WHITERECT
• SS_WHITEFRAME
56. What are the messages sent by the Scroll bar controls?
Scroll bar controls do not send WM_COMMAND messages to the parent window.
The scroll bar controls send WM_VSCROLL and WM_HSCROLL messages to the parent
window. The height and the width of a horizontal scroll bar can be retrieved by the function
GetSystemMetrics as,
GetSystemMetrics (SM_CYHSCROLL);
GetSystemMetrics (SM_CXVSCROLL);
60. What are the types of list box and its style?
The types of the list box are as follows,
• Single selection list box
• Multiple selection list box
The user can select the item by pressing the Spacebar in the single-selection list box. The
arrow keys can be used fro moving the current selected text and for scrolling the contents of
the list box. An item can also be selected by clicking or double-clicking the mouse on the
item. In the multiple-selection list box, the Spacebar toggles the selection state of the item
where the cursor is positioned. In this type, the list box item will be deselected when we
place the cursor on the already selected item. The list box styles are,
• LBS_NOTIFY
• LBS_SORT
• LBS_MULTIPLESEL
UNIT II - VISUAL C++ PROGRAMMING
5. Briefly explain about the CMyApp class and the CmyFrame class.
The CMyApp class—an object of class CMyApp represents an application.
The program defines a single global CMyApp object, theApp. The CWinApp base
class determines most of theApp's behavior.
The CMyFrame class—an object of class CMyFrame represents the
application's main frame window. When the constructor calls the Create member
function of the base class CFrameWnd, Windows creates the actual window
structure and the application framework links it to the C++ object.
10. Mention the usage of source code editor and resource compiler.
• The Source Code Editor
Visual C++ 6.0 includes a sophisticated source code editor that supports
many features such as dynamic syntax coloring, auto-tabbing, keyboard
bindings
• The Resource Compiler
The Visual C++ resource compiler reads an ASCII resource script (RC) file
from the resource editors and writes a binary RES file for the linker.
16. What are the two ways to optimize the painting in windows?
There are two ways to optimize painting in Windows.
First of all, we must be aware that Windows updates only those pixels that are
inside the invalid rectangle. Thus, the smaller you make the invalid rectangle, the
quicker it can be repainted.
Second, it's a waste of time to execute drawing instructions outside the invalid
rectangle. our OnDraw function could call the CDC member function GetClipBox
to determine the invalid rectangle, and then it could avoid drawing objects outside
it.
CPoint x, y
CSize cx, cy
18. What is MM_TEXT mapping mode?
In MM_TEXT, coordinates map to pixels, values of x increase as you move right,
and values of y increase as you move down, But we are allowed to change the origin
through calls to the CDC functions SetViewportOrg and SetWindowOrg.
25. What are the CDC Functions used to translate the logical to device units?
The Windows GDI has two CDC functions to translate the logical to device units and
they are,
• LPtoDP
• DPtoLP
29. Briefly explain the methods for sending window messages in modeless dialogs.
We have two options for sending Windows messages: the CWnd::SendMessage
function or the Post Message function. The former causes an immediate call to the
message-handling function, and the latter posts a message in the Windows message queue.
Because there's a slight delay with the Post Message option, it's reasonable to expect that
the handler function has returned by the time the view gets the message
1. Define menu.
A menu is a list of actions that the user can perform on an application. The actions
are presented in one or more groups. A main menu, also called a top-level menu, displays
categories of menu items using a range of items called a menu bar.
3. How the application framework searches for the message handlers on receiving the
command message from the frame window?
For a SDI application, the searching sequence of the message handlers is as follows,
View
Document
SDI Main frame window
Application
For a MDI application, the searching sequence of the message handlers is as follows,
View
Document
MDI Child frame window
MDI main frame window Application
• In this case, we can provide this functionality by executing a piece of code that
changes the internal state of the menu item to update the menu.
• The MFC library uses a special approach by calling update command user
interface (UI) handler function when there is an empty document to clear.
• The handler function's argument is a CCmdUI object, which contains a pointer to
the corresponding menu item.
• The handler function can then use this pointer to modify the menu item's
appearance.
8. What is a TOOLBARS?
A toolbar consists of horizontally or vertically arranged graphical buttons that are
grouped together. The graphical images for the tool bar buttons are stored in a single bitmap
that are stored in the application's resource file. When a tool bar button is clicked, it sends a
command message. An update command UI message handler is used to update the state of
the tool bar button.
10. How does your view find its main frame window?
In an SDI application, we call the function CWnd::GetParentFrame to find the main
frame window.
• However this function is not used in an MDI application because the view's parent
frame is the MDI child frame, not the MDI frame window.
• Actually the view class should work with both the SDI and MDI applications; so
we must locate the main frame window through the global application object.
• The global function AfxGetApp returns a pointer to the application object and we
use that pointer to get the CWinApp data member m_pMainWnd.
• In an MDI application, the MFC AppWizard generates code that sets the data
member m_pMainWnd.
• In an SDI application, the framework sets m_pMainWnd during the view creation
process and we can use it in our view class and the code is shown below,
CMainFrame*pFrame=(CMainFrame*) AfxGetApp()->m_pMainWnd;
CToolBar* pToolBar = &pFrame->m_wndToolBar;
17. Why do we choose the class CFrameWnd as the base class for a persistent
window rather than choosing persistent view class?
• In an MFC SDI application, the main frame window is the parent of the view window.
• The frame window is created first and then the control bars and the view are created
as child windows.
• The application framework ensures that the child windows maximize and minimize
automatically as the user changes the size of the frame window.
• The CFrameWnd::ActivateFrame member function is used for controlling the
frame's size.
• The standard application framework calls this virtual function during the SDI main
frame window creation process.
• Then the application framework calls CWnd::ShowWindow member function with
the parameter nCmdShow.
TEXTPROC
Text formatting
Font = Arial
Points = 16
Unicode
CString strFirstName("Shyamala");
CString strLastName("Sofia");
CString strTotal = strFirstName + " " + strLastName; // concatenation
AfxMessageBox(strTotal);
The CString class has const char*() operator that converts a CString object to a character
pointer. we can call the AfxMessageBox function as,
char szMessage[] = "Visual Programming";
AfxMessageBox(szMessage);
(Or)
CString strMessage("Visual Programming ");
AfxMessageBox(strMessage);
The formatted string can be generated by using the function CString::Format as,
int nError = 100;
CString strFormatMsg;
strFormatMsg.Format("Error number %d", nError);
AfxMessageBox(strFormatMsg);
21. What are the functions in CWnd that are used to retrieve the window’s position?
• We can retrieve the screen coordinates of a window by calling the CWnd function
GetWindowRect.
• If the window is maximized, GetWindowRect returns the coordinates of the
screen rather than getting the window's unmaximized coordinates.
22. What are the functions in CFrameWnd that are used to save and load the control
bar status in the windows registry?
The MFC library has two member functions in the class CFrameWnd, and they are,
• SaveBarState( )
• LoadBarState( )
The above functions are used to save and load the control bar status to and from the
Registry. These functions process the size and position of the status bar
•
• The function CWnd::GetWindowPlacement retrieves the unmaxi-mized
coordinates together with some flags that indicate whether the window is
currently minimized or maximized.
• The SetWindowPlacement function is used to set the maximized and minimized
status and the size and position of the window.
23. How to create the Default Window Rectangle?
Generally we use the device coordinates or logical coordinates to define the
rectangles. But we have special function parameters in the CRect object which creates the
default rectangle in the output and it is shown below,
CRect rect(CW_USEDEFAULT, CW_USEDEFAULT, 0, 0);
The above statement creates a new window with default rectangle. This function positions
the window in a cascade pattern with the top left corner below and to the right of the window
most recently created. The right and bottom edges of the window are always within the
display's boundaries. The static rectDefault data member is constructed using
CW_USEDEFAULT which is present in CFrameWnd class's.
38. How do we know whether Serialize should read or write data and how the Serialize
connected to a disk file?
• In the MFC library, objects of class CFile represent disk files.
• A CFile object encapsulates the binary file handle that we get through the Win32
function CreateFile.
• It is a handle to a binary file. The application framework uses this file handle for
Win32 ReadFile, WriteFile, and SetFilePointer calls.
• The CArchive object buffers data for the CFile object, and it maintains an internal
flag that indicates whether the archive is storing (writing to disk) or loading (reading
from disk).
• Only one active archive is associated with a file at any one time. The application
framework takes care of constructing the CFile and CArchive objects, opening the
disk file for the CFile object and associating the archive object with the file.
• All we have to do is to load data from or store data in the archive object.
• The application framework calls the document's Serialize function during the File
Open and File Save processes.
39. What is meant by Serializable Class?
A Serializable class must be derived directly or indirectly from CObject. The class
declaration must contain the DECLARE_SERIAL macro call, and the class implementation
file must contain the IMPLEMENT_SERIAL macro call.
We could use the Serialize function, as shown below, but we must construct a new
CTranscript object which is as follows,
Because the CArchive insertion and extraction operators are indeed overloaded for CObject
pointers, we could also write Serialize as,
• If we call Serialize for a CObList collection of CStudent objects, for example, the
Serialize function for each CStudent object will be called in turn.
• If a collection contains pointers to objects of mixed classes, the individual class
names are stored in the archive so that the objects can be properly constructed with
the appropriate class constructor.
• If a container object, such as a document, contains an embedded collection, loaded
data is appended to the existing collection.
• We need to empty the collection before loading from the archive.
• This is usually done in the document's virtual DeleteContents function, which is
called by the application framework.
CMyApp theApp;
The class CMyApp is derived from the class CWinApp, and theApp is a globally declared
instance of the class. This global object is called the Windows application object.
46. What are the execution processes of MFC Library Application?
The startup steps in a MFC library application are as follows:
1. Windows loads our program into memory.
2. The global object theApp is constructed.
3. Windows calls the global function WinMain, which is the main program entry point of
the MFC library.
4. WinMain searches for the one and only instance of a class derived from CWinApp.
5. WinMain calls the InitInstance member function for theApp, which is overridden in our
derived application class.
6. InitInstance function starts the process of loading a document and displaying the
main frame and view windows.
7. WinMain calls the Run member function for theApp, which starts the processes of
dispatching window messages and command messages.
8. The ExitInstance function is called when the application terminates, after all its
windows are closed.
48. List out the resources of the SDI Document Template Resource.
The first AddDocTemplate parameter is IDR_MAINFRAME, the identifier for a string
table resource. The corresponding string that AppWizard generates for an application's RC
file is shown below,
IDR_MAINFRAME
"ex\n" // application window caption
"\n" // root for default document name
"Ex\n" // document type name
"Ex Files (*.ex)\n" // document type description and filter
".ex\n" // extension for documents of this type
"Ex. Document\n" // Registry file type ID
"Ex Document" // Registry file type description
1. Constructs the document object but does not attempt to read data from the disk.
2. Constructs the main frame object of class CMainFrame. The main frame window
includes the IDR_MAINFRAME menu, the toolbar, and the status bar.
3. Constructs the view object which creates the view window but does not show it.
4. Establishes connections among the document, main frame, and view objects.
5. Calls the virtual CDocument::OnNewDocument member function for the document
object, which calls the virtual DeleteContents function.
6. Calls the virtual CView::OnInitialUpdate member function for the view object.
7. Calls the virtual CFrameWnd::ActivateFrame for the frame object to show the main
frame window together with the menus, view window, and control bars.
50. Define the OnFileOpen Function.
When AppWizard generates an application, it maps the File Open menu item to the
CWinApp::OnFileOpen member function. When called, this function invokes a sequence of
functions to accomplish the following steps:
CMultiDocTemplate* pDocTemplate;
54. What is meant by MDI Frame Window and MDI Child Window?
The SDI had only one frame window class and only one frame window object. For
SDI applications, AppWizard generated a class named CMainFrame, which was derived
from the class CFrameWnd. An MDI application has two frame window classes and many
frame objects
Menu
AppWizard- Number
and Contains Object
Base Class Generated of
Control a View Constructed
Class Objects
Bars
In application
class's
CMDIFrameWnd CMainFrame 1 only Yes No
InitInstance
function
By
application
1 per
framework
CMDIChildWnd CChildFrame child No Yes
when a new
window
child window
is opened
63. How the Imported functions are matched with the Exported functions in DLL?
A DLL contains a table of exported functions. These functions are identified by their
symbolic names and by integers called ordinal numbers. The function table also contains
the addresses of the functions within the DLL. When the client program first loads the DLL, it
does not know the addresses of the functions it needs to call, but it does know the symbols
or ordinals. The dynamic linking process then builds a table that connects the client's calls to
the function addresses in the DLL. If we edit and rebuild the DLL, we do not need to rebuild
our client program unless we have changed function names or parameter sequences. Many
DLLs call functions inside other DLLs. Thus, a particular DLL can have both exports and
imports. In the DLL code, we must explicitly declare our exported functions like this:
__declspec(dllexport) int MyFun(int n);
On the client side, we need to declare the corresponding imported function like this:
__declspec(dllimport) int MyFun(int n);
• Implicit linkage.
• Explicit linkage.
• Ordinal linkage.
• Symbolic linkage.
In Explicit linkage, we do not use an import file; instead we call the Win32
LoadLibrary function, specifying the DLL's pathname as a parameter. LoadLibrary returns
an HINSTANCE parameter that we can use in a call to GetProcAddress, which converts a
symbol (or an ordinal) to an address inside the DLL. determine at runtime which DLLs to
load.
3. List out the Similarities between ActiveX Controls and Ordinary Controls.
• ActiveX control is also a child window like an ordinary control.
• If we want to include an ActiveX control in a dialog, we use the dialog editor to place
the ActiveX control.
• The identifiers for the ActiveX control are stored in the resource template.
• If we are creating our own ActiveX control, then we must call a Create member
function for a class that represents the control, usually in the WM_CREATE handler
for the parent window.
• When we want to manipulate an ActiveX control, we call a C++ member function
control class. The window that contains a control is called a container.
4. List out the Differences between ActiveX Controls and Ordinary Controls.
• The ActiveX Controls have properties and methods which is not present in the
ordinary controls.
• The C++ member functions of the ActiveX Controls are used to manipulate a control
instance depends on the properties and methods, which is not involved in the
ordinary controls.
• Properties of the ActiveX Controls have symbolic names that are matched to integer
indexes.
• For each property of the ActiveX Controls, the control designer assigns a property
name, such as BackColor or CellEffect, and a property type, such as string, integer,
or double.
• Even a bitmaps and icons of the ActiveX Controls have a picture type.
• The client program can set an individual ActiveX control property by specifying the
property's integer index and its value.
• The client can get a property by specifying the index and accepting the appropriate
return value.
• The ClassWizard enables us to define the data members in our client window class
that are associated with the properties of the ActiveX controls.
• The generated Dialog Data Exchange (DDX) code exchanges data between the
control properties and the client class data members. The above features are not
present in the ordinary control.
• ActiveX Controls methods are like functions. A method has a symbolic name, a set of
parameters, and a return value.
• We call a method by calling a C++ member function of the class that represents the
control.
• An ActiveX control does not send WM_ notification messages to its container as the
ordinary controls but we call the events of the ActiveX controls as "fires events."
• An event has a symbolic name and can have an arbitrary sequence of parameters
which is a container function that the ActiveX control calls.
• A DLL is used to store one or more ActiveX controls and the DLL file has the file
name extension as .OCX instead of a .DLL extension.
5. What kind of data members we can add to the dialog for an ActiveX control?
• If we want to set a control property before we call DoModal for the dialog, we can add
a dialog data member for that property.
• If we want to change the properties of the ActiveX control inside the dialog member
functions, then we must add a data member that is an object of the wrapper class for
the ActiveX control.
• The CDialog::OnInitDialog function calls CWnd::UpdateData(FALSE) to read the
dialog class data members.
• The CDialog::OnOK function calls UpdateData(TRUE) to write the members.
• Instead of using the above method, we can call Get function.
• To call that function, we must first tell ClassWizard to add a wrapper class object
data member.
• Suppose we have a Calendar wrapper class CCalendar and we have an m_calendar
data member in our dialog class.
• If we want to get the Value property, then we can have a code as follows,
COleVariant var = m_calendar.GetValue();
• If we want to set the day to the 5th of the month before the control is displayed.
• To do this, add a dialog class data member m_sCalDay that corresponds to the
control's short integer Day property.
• Then add the following line to the DoDataExchange function:
DDX_OCShort(pDX, ID_CALENDAR1, 0x11, m_sCalDay);
6. Define DDX.
• The DDX code sets the property value from the data member before the control is
displayed.
• The DDX code sets the data member from the property value when the user clicks
the OK button.
1. Insert the component into our project, so that ClassWizard will create the files for the
wrapper class.
2. Add an embedded ActiveX control wrapper class data member to our dialog class or
other C++ window class.
3. An embedded C++ object is then constructed and destroyed along with the window
object.
4. Choose Resource Symbols from Visual C++'s View menu.
5. Add an ID constant for the new ActiveX control.
6. If the parent window is a dialog, use ClassWizard to map the dialog's
WM_INITDIALOG message, thus overriding CDialog-::OnInitDialog.
7. For other windows, use ClassWizard to map the WM_CREATE message. The new
function should call the embedded control class's Create member function.
8. This call indirectly displays the new control in the dialog. The control will be properly
destroyed when the parent window is destroyed.
9. In the parent window class, manually add the necessary event message handlers
and prototypes for our new control.
8. Define COM
• COM is not a programming language
• COM is not DLL
• COM is not only a set of API or functions
• Its simple and efficient
• It is available on Windows, Windows NT
COM is a protocol that connects one software module with another and then drops out of the
picture. After the connection is made, the two modules can communicate through a
mechanism called an interface. COM is a standard approach to access all kinds of software
services, regardless of how they are provided
• The first GetClassObject parameter, nClsid, is a 32-bit integer that uniquely identifies
the CSpaceship class.
• The second parameter, nIid, is the unique identifier of the interface that we want.
• The third parameter is a pointer to an interface to the object.
16. Draw the structure for accessing a COM object in a Remote Server.
18. How the MFC AppWizard Support for ActiveX Controls to process?
When the MFC AppWizard ActiveX Controls option is checked in the step 3 of
AppWizard, then the MFC AppWizard inserts the following statement in our application class
InitInstance member function:
AfxEnableControlContainer();
It also inserts the following statement in the project's StdAfx.h file #include <afxdisp.h>
22. What are the interfaces used in OLE DRAG AND DROP?
OLE Drag and drop is used for the movement of the data object. OLE supports the
drag and drop operation with two interfaces,
• IDropSource
• IDropTarget
• The MFC library provides good drag-and-drop operation at the view level
• The drag-and-drop transfers are immediate and independent of the clipboard.
• If the user cancels the operation then there is no "memory" of the object being
dragged.
• Drag-and-drop transfers should work consistently between applications, between
windows of the same application, and within a window.
• When the user starts the operation, the cursor should change to an arrow_rectangle
combination.
• If the user holds down the Ctrl key, the cursor turns into a plus sign (+), which
indicates that the object is being copied rather than moved.
• MFC also supports drag-and-drop operations for items in compound documents.
24. How the transfer takes place in Source Side of drag and drop operation?
When our source program starts a drag-and-drop operation for a data object, it calls
the function COleDataSource::DoDragDrop. This function internally creates an object of
MFC class COleDropSource, which implements the IOleDropSource interface.
DoDragDrop is one of the functions that do not return any value for a while, but it returns
when the user drops the object or cancels the operation or when a specified number of
milliseconds have elapsed. If we are perform drag-and-drop operations to work with a
CRectTracker object, we should call DoDragDrop only when the user clicks inside the
tracking rectangle, not on its border, and the function used to check that functionality is
CRectTracker::HitTest. When we call DoDragDrop, we need to set a flag that tells us
whether the user is dropping the object into the same view or document that it was dragged
from.
25. How the transfer takes place in destination Side of drag and drop operation?
If we want to use the MFC library's view class drag-and-drop support, we must add a
data member of class COleDropTarget to our derived view class. This class implements the
IDropTarget interface, and it holds an IDropSource pointer that links back to the
COleDropSource object. In our view's OnInitialUpdate function, we call the Register
member function for the embedded COleDropTarget object. Then after making a view drop
target, we must override four CView virtual functions, which the framework calls during the
drag-and-drop operation.
26. List out the drag and drop functions.
The functions are as follows,
OnDragEnter Adjusts the focus rectangle and then calls OnDragOver
Moves the dotted focus rectangle and sets the drop effect
OnDragOver
(determines cursor shape)
Adjusts the focus rectangle and then calls the DoPaste helper
OnDrop
function to get formats from the data object
• IOleObject
• IOleClientSite
38. What are the types of menus created in the OLE Component project?
• When we use AppWizard to generate an OLE component, then the AppWizard
generates a class derived from each of the base classes, in addition to an application
class, a main frame class, and a view class.
• The COleIPFrameWnd class is similar to CFrameWnd class.
• It is our application's main frame window, which contains the view.
• So when we use OLE Component in our project then we have three menu
IDR_SRVR_INPLACE
IDR_SRVR_EMBEDDED
IDR_MAINFRAME.
40. How the Loading and saving is done for the Component's Native Data?
The component can load and save its native data when the container calls the Load
and Save functions of IPersistStorage. But now the container is going to save the
component's class ID in the storage. The container can read the class ID from the storage
and use it to start the component program prior to calling IPersistStorage::Load. The
embedded object needs to be saved in the storage. The storage must always be available
because the object is constantly loading and saving itself and reading and writing temporary
data. The container manages the whole file, but the embedded components are responsible
for storing inside the storage. There is a main storage for each embedded object and the
container does not know what is actually stored inside.
The object handler is running and has a metafile in its cache, but
Loaded
the EXE component program is not running.
45. How the Interaction occurs between the container and component.
• When the container creates an embedded object, it calls IOleObject::SetClientSite
to establish one of the two connections from component to container.
• The site maintains an IOleObject pointer to its component object.
• When the component decides it’s time to save itself to its storage, it asks the site to
store by calling IOleClientSite::SaveObject.
• The handler needs to save the metafile to the storage.
• The SaveObject function calls IPersistStorage::Save at the handler level, so the
handler can store before calling the component's Save function.
• The component program calls the IOleClientSite function OnShowWindow when it
starts running and when it stops running.
• Inprise Paradox
• Microsoft Access
• Microsoft FoxPro
• Powersoft PowerBuilder
CDatabase
- Manages the Connection to a data source.
- Work as a Database Manager
CRecordSet
- Manages a set of rows returned from the database.
- CRecordset represents scrollable rowsets.
CRecordView
- Simplifies the display of data from CRecordSet Object.
11. What are the Transactions that can be done with CDatabase?
Enables to execute a series of SQL statements as a single operation. In this if any
one of the operations fails, rest of all can be undone. This is most useful future for doing
related updation to various tables at the same time. The functions used are,
CanTransact()
BeginTrans()
ExecuteSQL()
CommitTrans()
Rollback ()
Snapshot:
• Download the entire query in one shot
• Have data as a static copy
• When any changes made to the database will not reflect to the current
Application.
• Occupy more memory to hold the data.
Dynaset:
• Only the records you actually need to fill the screen will get downloaded.
• Take less time to reflect.
• Constantly resynchronizes the recordset, so that any changes will reflect
immediately.
• The snapshot and Dynaset work at the record level. ODBC will only support both
this two options.
Table:
• Work with table level and supported by DAO.
• Places the contents of the query into Temporary table.
• Have a problem with updation.
.
DAO Classes
22. List out the difference between the two types of threads.
• UI threads have message loops and a worker thread does not have message
loops.
• UI threads can create windows and process messages sent to those
windows.
• Worker threads perform background tasks that receive no direct input from
the user and therefore don't need windows and message loops.
The function AfxBeginThread is used to create the worker thread. When called,
AfxBeginThread creates a new CWinThread object, launches a thread and attaches it to the
CWinThread object, and returns a CWinThread pointer. The statement used to create the
worker thread is shown below,
The above statement starts a worker thread and passes it the address of an application-
defined data structure (&threadInfo) that contains input to the thread. ThreadFunc is the
thread function that gets executed when the thread itself begins to execute. The complete
function prototype is as follows:
THREAD_PRIORITY_N The default thread priority value. The thread's base priority
ORMAL level is equal to the process's priority class.
IP datagram layout.
The exceptions help us to write cleaner code because we don't need to have error tests after
every Winsock call. CHttpBlockingSocket is derived from CBlockingSocket and provides
functions for reading HTTP data. CSockAddr and CBlockingSocketException are helper
classes.
59. What are the classes are there to play multimedia files?
• CSoundIn is a wrapper class that lets us to retreive sound from the soundcard. The
main functions are Start() and Stop()
• CSoundOut is a wrapper class that will lets us to play sound on the soundcard. The
main functions are Start() and Stop()
• CSoundFile is a wrapper class of a single wave file, it can either be a file reader or a
file writer object. See the constructor.
• CSoundBase is a very small class that encapsulates the wave format.
• CBuffer is a very small class that encapsulates a simple one dimentional buffer.
BOOL Pause;
if(Pause)
{
MCIWndResume(m_Video);
Pause = FALSE;
}
else
{
MCIWndPause(m_Video);
Pause = TRUE;
}