Thursday, November 26, 2009

CImageList Class

CImageList Class

An "image list" is a collection of same-sized images, each of which can be referred to by its zero-based index. Image lists are used to efficiently manage large sets of icons or bitmaps. All images in an image list are contained in a single, wide bitmap in screen device format. An image list may also include a monochrome bitmap that contains masks used to draw images transparently (icon style). The Microsoft Win32 application programming interface (API) provides image list functions that enable you to draw images, create and destroy image lists, add and remove images, replace images, merge images, and drag images.

 
CImageList::Create

Initializes an image list and attaches it to a CImageList Class object.

BOOL Create(
   int cx,
   int cy,
   UINT nFlags,
   int nInitial,
   int nGrow 
);
BOOL Create(
   UINT nBitmapID,
   int cx,
   int nGrow,
   COLORREF crMask 
);
BOOL Create(
   LPCTSTR lpszBitmapID,
   int cx,
   int nGrow,
   COLORREF crMask 
);
BOOL Create(
   CImageList& imagelist1,
   int nImage1,
   CImageList& imagelist2,
   int nImage2,
   int dx,
   int dy 
);
BOOL Create(
   CImageList* pImageList 
);
 

Parameters
cx
Dimensions of each image, in pixels.
cy
Dimensions of each image, in pixels.
nFlags
Specifies the type of image list to create. This parameter can be a combination of the following values, but it can include only one of the ILC_COLOR values.
Value
Meaning
ILC_COLOR
Use the default behavior if none of the other ILC_COLOR* flags is specified. Typically, the default is ILC_COLOR4; but for older display drivers, the default is ILC_COLORDDB.
ILC_COLOR4
Use a 4-bit (16 color) device-independent bitmap (DIB) section as the bitmap for the image list.
ILC_COLOR8
Use an 8-bit DIB section. The colors used for the color table are the same colors as the halftone palette.
ILC_COLOR16
Use a 16-bit (32/64k color) DIB section.
ILC_COLOR24
Use a 24-bit DIB section.
ILC_COLOR32
Use a 32-bit DIB section.
ILC_COLORDDB
Use a device-dependent bitmap.
ILC_MASK
Uses a mask. The image list contains two bitmaps, one of which is a monochrome bitmap used as a mask. If this value is not included, the image list contains only one bitmap. See Drawing Images from an Image List for additional information on masked images.
nInitial
Number of images that the image list initially contains.
nGrow
Number of images by which the image list can grow when the system needs to resize the list to make room for new images. This parameter represents the number of new images the resized image list can contain.
nBitmapID
Resource IDs of the bitmap to be associated with the image list.
crMask
Color used to generate a mask. Each pixel of this color in the specified bitmap is changed to black, and the corresponding bit in the mask is set to one.
lpszBitmapID
A string containing the resource IDs of the images.
imagelist1
A reference to a CImageList object.
nImage1
Index of the first existing image.
imagelist2
A reference to a CImageList object.
nImage2
Index of the second existing image.
dx
Offset of the x-axis of the second image in relationship to the first image, in pixels.
dy
Offset of the y-axis of the second image in relationship to the first image, in pixels.
pImageList
A pointer to a CImageList object.
  
Return Value
 
Nonzero if successful; otherwise 0.


 Example


m_myImageList.Create(32, 32, ILC_COLOR8, 0, 4);


CImageList::Add
Call this function to add one or more images or an icon to an image list.

int Add(
   CBitmap* pbmImage,
   CBitmap* pbmMask 
);
int Add(
   CBitmap* pbmImage,
   COLORREF crMask 
);
int Add(
   HICON hIcon 
);

Parameters
pbmImage
Pointer to the bitmap containing the image or images. The number of images is inferred from the width of the bitmap.
pbmMask
Pointer to the bitmap containing the mask. If no mask is used with the image list, this parameter is ignored.
crMask
Color used to generate the mask. Each pixel of this color in the given bitmap is changed to black and the corresponding bit in the mask is set to one.
hIcon
Handle of the icon that contains the bitmap and mask for the new image.

Return Value
 
Zero-based index of the first new image if successful; otherwise – 1.

Example


// Add my icons.
 
m_myImageList.Add(AfxGetApp()->LoadIcon(IDI_ICON1));
m_myImageList.Add(AfxGetApp()->LoadIcon(IDI_ICON2));
 
// Add my bitmap, make all black pixels transparent.
 
CBitmap bm;
bm.LoadBitmap(IDB_BITMAP1);
m_myImageList.Add(&bm, RGB(0, 0, 0));

CImageList::Attach
Call this function to attach an image list to a CImageList object.

BOOL Attach(
   HIMAGELIST hImageList 
);

Parameters
hImageList
A handle to an image list object.

Return Value
 
Nonzero if the attachment was successful; otherwise 0.

 Example


void AddQuestion(HIMAGELIST hmyImageList)
{
   CImageList imgList;
 
   // Attach the image list handle to the CImageList object.
   imgList.Attach(hmyImageList);
 
   // Add a new icon to the image list.
   imgList.Add(AfxGetApp()->LoadStandardIcon(IDI_QUESTION));
 
   // Detach the handle from the CImageList object.
   imgList.Detach();
}


CImageList::Write
Call this function to write an image list object to an archive.

BOOL Write(
   CArchive* pArchive 
);

Parameters
pArchive
A pointer to a CArchive object in which the image list is to be stored.

Return Value
Nonzero if successful; otherwise 0.

Example

// Open the archive to store the image list in.
CFile   myFile(_T("myfile.data"), CFile::modeCreate | CFile::modeWrite);
CArchive ar(&myFile, CArchive::store);
 
// Store the image list in the archive.
m_myImageList.Write(&ar);

How to Draw Triangle in VC++

FileName : TriangleView.h

class CTriangleView : public CView
{
 ...
 CPoint tr[3],ct;
 int rad;
 double rd;
 CRect rc;
...
};


FileName : TriangleView.cpp


 #include "math.h"
...

CTriangleView::CTriangleView()
{
    // TODO: add construction code here
    rd=0.0174532935;
}

void CTriangleView::OnDraw(CDC* pDC)
{
    CTriangleDoc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);
    // TODO: add draw code for native data here
    int i=0;
    GetClientRect (rc);
    ct.x = (rc.left + rc.right )/2;
    ct.y = (rc.top + rc.bottom )/2;
    rad=ct.x/2;
    while(i<3)
    {
    tr[i].x = ct.x + rad * sin(i*120*rd);
    tr[i].y = ct.y - rad * cos(i*120*rd);
    i++;
    }
    pDC->Polygon (tr,3);
}

CDC Text Functions

CDC::DrawText
Draws formatted text in the specified rectangle.
CDC::DrawTextEx
Draws formatted text in the specified rectangle using additional formats.
CDC::ExtTextOut
Writes a character string within a rectangular region using the currently selected font.
CDC::GetCharABCWidthsI
Retrieves the widths, in logical units, of consecutive glyph indices in a specified range from the current TrueType font.
CDC::GetCharacterPlacement
Retrieves various types of information on a character string.
CDC::GetCharWidthI
Retrieves the widths, in logical coordinates, of consecutive glyph indices in a specified range from the current font.
CDC::GetOutputTabbedTextExtent
Computes the width and height of a character string on the output device context.
CDC::GetOutputTextExtent
Computes the width and height of a line of text on the output device context using the current font to determine the dimensions.
CDC::GetOutputTextMetrics
Retrieves the metrics for the current font from the output device context.
CDC::GetTabbedTextExtent
Computes the width and height of a character string on the attribute device context.
CDC::GetTextAlign
Retrieves the text-alignment flags.
CDC::GetTextCharacterExtra
Retrieves the current setting for the amount of intercharacter spacing.
CDC::GetTextExtent
Computes the width and height of a line of text on the attribute device context using the current font to determine the dimensions.
CDC::GetTextExtentExPointI
Retrieves the number of characters in a specified string that will fit within a specified space and fills an array with the text extent for each of those characters.
CDC::GetTextExtentPointI
Retrieves the width and height of the specified array of glyph indices.
CDC::GetTextFace
Copies the typeface name of the current font into a buffer as a null-terminated string.
CDC::GetTextMetrics
Retrieves the metrics for the current font from the attribute device context.
CDC::GrayString
Draws dimmed (grayed) text at the given location.
CDC::SetTextAlign
Sets the text-alignment flags.
CDC::SetTextCharacterExtra
Sets the amount of intercharacter spacing.
CDC::SetTextJustification
Adds space to the break characters in a string.
CDC::TabbedTextOut
Writes a character string at a specified location, expanding tabs to the values specified in an array of tab-stop positions.
CDC::TextOut
Writes a character string at a specified location using the currently selected font.


Question List

Practical Question

Dialog Based Program

1. Write an Application to show the current ProgressBar value in EditBox as it incremented 1 to 100.
2. Create Dialog based Application with command button and MessageBox () (Use all Parameters) to print the message with no of clicks whenever user clicks on command button.
3.Write an Application to Split the Entered Text in EditBox and then enter them in ListBox with Uppercase.
(Hint : EditBox :"this is my book"
List Box: THIS
IS
MY
BOOK
4. Write a program to move values from one ListBox to another (1. One by One as User Select, All at Once).
5.Create a Dialog based Application with Static Texts to get the information like Computer Name, Total Memory, Free Memory and Total Load on processor.
6.Create Dialog Based Application to Read and Write a Data from Text file. Use EditBox to Show data.
7.Craete Dialog based Application Which read data from Text file in Reverse order. Show data in EditBox.


SDI/MDI Program

1. Write a program to Animate Circle.
2. Write a program to draw a line using three different mouse events.
3.Write an Apllication to Change Font in SDI.
(Hint : Use Menu for Opening CFontDialog)
4.Write a VC++ project that Draws a Polygon. And Clicking within it Changes its Border Color.
5.Write an Application to Show Current Cursor Position of Mouse in StatusBar.
6.Write an Application to Show Current Date(DD-MM-YYYY) format in StatusBar.
7. Write an Application to Make Simple Web Browser using HtmlView and ReBar.
8. Write an Application to Manipulate Database using (ODBC/ADO/DAO) Connectivity. User can perform Add, Update, Delete, MoveNext, MovePrevious, MoveLast and MoveFirst.

Important Questions


Visual C++ Question List

Theory Question

  1. What is OOP ? Explain Inheritance and Polymorphism.
  2. Explain Visual C++ Development Environment.
  3. Explain CFile and CArchive with suitable example.
  4. Explain Microsoft Foundation Class in VC++.
  5. What is Serialization? Explain with Example.
  6. Explain VC++ Development Environment.
  7. List and Explain Different Extension used in VC++ project file.
  8. List out different category of Messages. Explain Message Mapping with Example.
  9. What is Document/View Architecture? Explain in Brief.
10. What is Device Context? Explain in Brief.
11. Explain Exception Handling in VC++.
12. List out Classes for GDI objects. Explain any two.
13. What is Active-X? Explain in Brief.

VC++ Question Paper

M.Sc Sem - I (IT) Examination
December - 2004
103 : Building Application Using VC++
(NEW)
1. Attemp any FOUR of the following.
(1) What is OOP?Explain Inheritance in brief.
(2) Diffrentiate : SDI v/s MDI
(3) What is Resource View? Explain its utility in VC++ Project.
(4) List the Tools of Dialog Toolbar. Explain any Four of them.
(5) Explain the process of setting Tab Order.

Thursday, November 19, 2009

VC++ Code For Drawing Analog and Digital Clock




//CGDIClockView.h
class CGDIClockView : public CView
{
...
// Attributes
public:
      CString str;
      bool start;
 ...
};

// CGDIClockView.cpp
 CGDIClockView::CGDIClockView()
{
    // TODO: add construction code here
    start=false;
}

void CGDIClockView::OnStart()
{
    // TODO: Add your command handler code here
    start = true;

    int x=125,y=125;
    int a=125,b=50;
    int r=75;
    long int i=0,m=0,s=0,h=0;
    int j=12;
    double dtor=0.0174532935;

    CClientDC *pDC = new CClientDC (this);
   
    CPen cp;
    cp.CreatePen(2,1,RGB(255,0,255));
    pDC->SelectObject(&cp);
//Draw Clock

   

while(start)
  {
 

    cp.DeleteObject();
    cp.CreatePen(PS_SOLID,1,RGB(0,0,0));
    pDC->SelectObject(&cp);
   
    //Code for Drawing Circle with Number 1 to 12
    pDC->Ellipse (10,10,240,240);
    while(i<360)
    {
    a = x - x * sin(i*dtor);
    b = y - y * cos(i*dtor);
    str.Format("%d",j);
    pDC->TextOut(a-3,b-3,str);
    j--;
    i=i+30;
    }

    //Code for Drawing Second Hand
    cp.DeleteObject();
    cp.CreatePen(1,2,RGB(255,0,0));
    pDC->SelectObject(&cp);
   
    a = 125 + 110 * sin(s*dtor);
    b = 125 - 110 * cos(s*dtor);
   
    pDC->MoveTo(a,b);
    pDC->LineTo(x,y);
   
   
   //Code for Drawing Minute Hand
    cp.DeleteObject();
    cp.CreatePen(1,2,RGB(0,255,255));
    pDC->SelectObject(&cp);

       a = 125 + 90 * sin(m*dtor);
       b = 125 - 90 * cos(m*dtor);
   
    pDC->MoveTo(a,b);
    pDC->LineTo(x,y);

    //Code for Drawing Hour Hand
    cp.DeleteObject();
    cp.CreatePen(1,3,RGB(255,255,0));
    pDC->SelectObject(&cp);
   
    a = 125 + 70 * sin(h*dtor);
        b = 125 - 70 * cos(h*dtor);
   
    pDC->MoveTo(a,b);
    pDC->LineTo(x,y);
   
    s=s+6;
   
    str.Format("Hour : %ld Min : %ld Second : %ld",((s/6)/3600)%24,((s/6)/60)%60,(s/6)%60);
    pDC->TextOut (20,300,"                                                   ",50);
    pDC->TextOut (20,300,str);
    Sleep(500);
   
    //Code for Incrementing Value of Minute and Hour as per value of Seconds
    if(s%360==0 && s>0)
    {
       m=m+6;

       if(m%72==0 && m>0)
       {
          h=h+6;
       }

    }

    //Code for Reseting All Values after 24 Hours
    if(s==86400)
    {
       s=0;
    }

    Sleep(500);
    UpdateWindow();
   
  }
}

void CGDIClockView::OnStop()
{
    // TODO: Add your command handler code here
    start=false;
}

Monday, November 16, 2009

Visual C++ Program Format for Submission of Practical Assignment.

(1) Program or Question Title.
(2)Design




(3) Control Information.

Control Type
Control Name / ID
Member Variable Name
Variable Type
Validation / Extra Info.
EditBox
IDC_EDIT1
m_op1
int
value in[0,100]
EditBox
IDC_EDIT2
m_op2
int
value in[0,100]
EditBox
IDC_EDIT3
m_ans
int
value in[0,200]
Button
IDOK



Button
IDCANCEL




(4) Coding.

Filename : TempDlg.cpp



void CTempDlg::OnOK()
{
            UpdateData();
            m_ans=m_op1+m_op2;
            UpdateData(FALSE);
}         


* If you have done any initialization write with file and function/class structure.
** Always write the function signature in Code.

Friday, November 13, 2009

M.Sc (IT & CA), VC++ (Visual C++) Syllabus, AITS, Rajkot

Paper - 101 Object Oriented Programming using Visual C++


* Introduction to OOP
* Basic OOP Concepts & Applications
* Introduction of VC++
* Controls usages in Application
* Mouse and Keyboard integration
* Dialog based Application
* Message Handling Mechanism
* Multiple Dialog Handling
* Documents, Views, and the Single Document Interface
* Scroll Views, HTML Views, and Other View Types
* Menu Environment
* Text and Fonts handling
* Incorporating Graphics, Drawing and Bitmaps
* Device Contexts and GDI Objects
* Single Document Interface Application
* Multiple Documents and Multiple Views
* CArchive and CFile classes
* Database handling using ODBC
* Database handling using DAO
* Database handling using OLEDB
* Error Detection and Exception Handling
* Toolbars, Status Bars, and Rebars
* Serialization
* Creating DLLs (COM) using ATL & App Wizard
* ActiveX Controls integration in VC++ application
* Creating ActiveX controls


Reference Books:

Mastering VC++, BPB Publication
Practical VC++, PHI Publication
VC++ Unleashed, Techmedia Publication
Programming VC++, Microsoftpress Publication

Friday, November 6, 2009

List of Function in VC++. Explain with Example (Theory and Practical)

1. GetClientRect
2. CloseWindow
3. GetDlgItem
4. EnableWindow
5. Invalidate
6. RedrawWindow
7. GetWindowText
8. SetWindowText
9. GetScrollPos
10. GetScrollRange
11. SetScrollPos
12. SetScrollRange
13. SetTimer
14. MessageBox
15. GetCurSel
16. GetLBText
17. GetLBTextLen
18. AddString
19. DeleteString
20. InsertString
21. ResetContent
22. GetCount
23. GetText
24. GetTextLen
25. UpdateData
26. MoveTo
27. LineTo
28. Rectangle
29. Ellipse
30. DoModal
31. atoi
32. IsEmpty
33. Empty
34. GetAt
35. SetAt
36. MakeLower
37. MakeUpper
38. MakeReverse
39. Remove
40. Format
41. Insert
42. Delete
43. Find
44. ReverseFind
45. SetRange
46. GetRange
47. GetPos
48. SetPos
49. OffsetPos
50. SetStep
51. StepIt

Explain All Function in Brief. Write Explanation in Notebook.

Sunday, November 1, 2009

Extra Practical List for Practice in VC++

1. Print Hello World! at top-left corner of the window using MDI
Application.

2. Change the color of Ellipse when the user presses the left mouse
button while the mouse pointer is inside the rectangle that bounds
the ellipse using MDI Application.

3. Change the color of Ellipse when the user presses the left mouse
button while the mouse pointer is inside the ellipse using MDI
Application.

4. Create Dialog based Application with command button and MessageBox()
(Use all Parameters) to print the message whenever user clicks on
command button.

5. Create Dialog based Application with command button and MessageBox()
(Use all Parameters) to print the message and to count the no. of
clicks on command button.

6. Create Dialog based Application with Five command buttons (First
two have the caption Disable & Hide accordingly). If user presses
the Disable button the rest of the three buttons (Left, Center &
Right) should disable and the Caption is changed to Enable. Apply
the same thing for the Hide button. Hide the buttons and change the
Caption to Show.

7. Create a dialog based Application with Radio Buttons to display the
message with the place user selected along with hotel type (Luxury,
Standard & Economy).

8. Create a Dialog based Application with Static Texts to get the
information like Computer Name, Total Memory, Free Memory and Total
Load on processor.

9. Create a Dialog based Application with Edit Boxes to give the
effect of first text box into second as user changes the text in
first.

10. Write a program that sorts strings stored in an object of
CStringList class.( Use Win32 Console Application)

11. Write a program to create chessboard like boxes (8 X 8) in the
client area. If the window is resized the boxes should also get
resized so that all the 64 boxes would be visible at all times.

12. Write a program to draw a circle, a polygon and a rectangle in the
client area. Create your own pen and brush. Each shape should be
drawn with different pen and brush.

13. Draw a graph . Take suitable points to draw the graph. Draw the lines representing x and y-axis in blue color. Draw rectangles with blue pen and yellow brush.

14. Write a program to draw three rectangles of suitable size using
following three brushes to fill the insides of the rectangle:
- Solid brush of yellow color
- Hatch brush of green color and a suitable pattern
- Pattern brush of blue color with the pattern showing small
dots.

15. Write a program to draw two lines, a vertical and a horizontal, so
that they intersect each other in the center of the window. Draw a
circle having the point of intersection of lines as the center and
radius as 100. Make a provision that if size of the window is
changed the lines and circle should get readjusted accordingly.

16. Write a program to draw 10 successive circles starting from the
smallest to biggest. All the circles must be visible.

17. Write a program through which the user would be able to draw a
rectangle interactively having a border of red color and thickness
5 pixels. One corner of the rectangle would be chosen by clicking
the left mouse button, whereas, for selecting the other corner the
user must be able to drag the mouse. As the mouse is dragged the
size of the rectangle must change.

18. Write a program such that when the user clicks left mouse button in
the client area then a string Hello should get displayed at the
point where the mouse has been clicked. Also make a provision that
every time the user clicks, the string should get written with
different font. Every time the font should be selected randomly.

19. Write a program to draw a freehand drawing.

20. Write a program that displays an animated cursor for the client
window.

21. Write a program that displays four graphical images in the view
window. When a user clicks on any one of the images other images
should be wiped off and the selected one should get enlarged so that
it covers the entire view window.

22. Write a program to display an image in the view window. Suppose the
image contains three colorspink, yellow and brown. If the user clicks
on the pink color a message box should pop up and display the red,
green and blue components of the color.

23. Create an application that provides a menu containing options like-
Color, Font, Attributes, Remove and Copy. On clicking a menu item a
common dialog related to the selected option should get displayed
from where user can make selections.

24. Create an application that would allow to set a different desktop
wallpaper, menu color, mouse double-click time, swap mouse buttons
etc.

25. Create an application for client-server communication (Chat
Application).

26. Create a FTP client which will allows you to download and upload
files on FTP Server.

27. Create a dialog-based application. On clicking Start button,
filenames should get displayed in the static control. The displaying
of filenames should stop the moment user click Stop button. The
window should get closed on clicking the Close. (Hint : Use
Multithreading).

28. Create a Web Browser. (Hint : Use SDI Application and derive the
class from CHtmlView class.

29. Create a line drawing Application using SDI Application and Document
View Architecture support. ( Hint : Derive class from CScrollView).

30. Create an ActiveX Control digital clock.


Courtesy by: Dhaval Thaker,Lecturer,Department of Computer Science,HNGU,Patan