Monday, November 30, 2009

Dialog Box in The Shape of Circle













BOOL CSonal2Dlg::OnInitDialog()
{
CDialog::OnInitDialog();

// TODO: Add extra initialization here
CDialog::OnInitDialog();
CRect rect;
CRgn hc;
GetWindowRect(&rect);
hc.CreateEllipticRgn(0,0,rect.right,rect.bottom);
SetWindowRgn(hc,true);
return TRUE; // return TRUE unless you set the focus to a control
}

void CSonal2Dlg::OnPaint()
{
if (IsIconic())
{
…………
………....
}
else
{

CPaintDC pDC(this);
CRect rect;
GetClientRect(&rect);
CBrush mybrush;
mybrush.CreateSolidBrush(RGB(255,128,192));
CBrush *oldbrush=pDC.SelectObject(&mybrush);
pDC.FillRect(&rect,&mybrush);
pDC.SelectObject(oldbrush);
pDC.SetBkMode(TRANSPARENT);
CDialog::OnPaint();
}
}

Friday, November 27, 2009

Draw a Triangle

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);
}

void CTriangleView::OnLButtonDown(UINT nFlags, CPoint point)
{
    // TODO: Add your message handler code here and/or call default
    int i=0;
   
    CClientDC *pDC = new CClientDC (this);
    ct.x = point.x;
    ct.y = point.y;
    rad=20;
    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);
    CView::OnLButtonDown(nFlags, point);
}

Saturday, November 21, 2009

How to Change Cursor in VC++? Different Type of Cursor

*.header

public:
bool c1,c2,c3,c4;

*.cpp

void CCursor1View::OnMouseMove(UINT nFlags, CPoint point)
{

if(c1)
{
::SetCursor (::LoadCursor (NULL,IDC_CROSS));
}
else if(c2)
{
::SetCursor(::LoadCursor (NULL,IDC_APPSTARTING));
}
else if(c3)
{
::SetCursor (::LoadCursor (NULL,IDC_HELP));
}
else if(c4)
{
::SetCursor (::LoadCursor (NULL,IDC_WAIT));
}

}


void CCursor1View::OnMouseeventCross()
{
// TODO: Add your command handler code here

c1=true;
c2=false;
c3=false;
c4=false;

}

void CCursor1View::OnMouseeventAppstarting()
{
// TODO: Add your command handler code here
c1=false;
c2=true;
c3=false;
c4=false;


}

void CCursor1View::OnMouseeventHelp()
{
// TODO: Add your command handler code here
c1=false;
c2=false;
c3=true;
c4=false;

}

void CCursor1View::OnMouseeventWait()
{
// TODO: Add your command handler code here
c1=false;
c2=false;
c3=false;
c4=true;


}


you can also select this cursor:

1.IDC_APPSTARTING
2.IDC_ARROW
3.IDC_CROSS
4.IDC_HAND
5.IDC_HELP
6.IDC_ICON
7.IDC_NO
8.IDC_SIZE
9.IDC_SIZEALL
10.IDC_SIZENESW
11.IDC_SIZENS
12.IDC_SIZENWSE
13.IDC_SIZEWE
14.IDC_UPARROW
15.IDC_WAIT

Serialize : File Handling using CArchive

--write into file--
*.cpp

void CDLGSerializeDlg::OnWRITE()
{
// TODO: Add your control notification handler code here
CFile cf;
UpdateData();
cf.Open("D:\\test.txt",CFile::modeCreate|CFile::modeWrite);
CArchive ar(&cf,CArchive::store);
Serialize(ar);
//ar.WriteString(m_ftxt);
m_ftxt="";
ar.Flush();
cf.Close();
UpdateData(FALSE);

}

--read--

void CDLGSerializeDlg::OnREAD()
{
// TODO: Add your control notification handler code here
CFile cf;
//char data[50];
UpdateData();
cf.Open("D:\\test.txt",CFile::modeRead);
CArchive ar(&cf,CArchive::load);
Serialize(ar);
/*
ar.Read(data,cf.GetLength());
for(unsigned int i=0;i<< m_ftxt; } else { // loading code ar >> m_ftxt;
}

}


Friday, November 20, 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;
}

Wednesday, November 18, 2009

VC++ File Handling : Reading File from Particular Position Using Seek( ) Function





void CFile1Dlg::OnWrite()

{

// TODO: Add extra validation here

UpdateData();
CFile cf;
char ch[100];
cf.Open("d://aits.txt",CFile::modeCreateCFile::modeWrite);
strcpy(ch,m_edit1);
cf.Write(ch,m_edit1.GetLength());
cf.Close();
m_edit1="";
UpdateData(FALSE);


}

void CFile1Dlg::OnRead()
{

// TODO: Add your control notification handler code here
UpdateData();
if(m_pos1==0)
{
MessageBox("please enter position other wise start reading from begining of file");
}

pos=m_pos1;

CFile cf;
char ch[100];
cf.Open("d://aits.txt",CFile::modeRead);

cf.SeekToBegin();
cf.Seek(pos,CFile::begin);
cf.Read(ch,cf.GetLength());

m_edit1="";
for(unsigned int i=0;i

{
m_edit1+=ch[i];
}

cf.Close();
UpdateData(FALSE);
}

VC++ File Handling : Code for Reading And Writing Data from File.




void CFile1Dlg::OnWrite()
{

// TODO: Add extra validation here
UpdateData();
CFile cf;
char ch[100];
cf.Open("d://aits.txt",CFile::modeCreateCFile::modeWrite);
strcpy(ch,m_edit1);
cf.Write(ch,m_edit1.GetLength());
cf.Close(); m_edit1="";
UpdateData(FALSE);
}
void CFile1Dlg::OnRead()
{

// TODO: Add your control notification handler code here
CFile cf;
char ch[100];
UpdateData();
cf.Open("d://aits.txt",CFile::modeRead);
cf.Read(ch,cf.GetLength());
for(unsigned int i=0;i
{

m_edit1+=ch[i];
}
cf.Close();
UpdateData(FALSE);
}

Tuesday, November 17, 2009

How to Write a Program in Exam?

(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.

Monday, November 16, 2009

VC++ (Visual C++) Program List for Submission

 
M.Sc (IT & CA) Sem – I
Object Oriented Programming using Visual C++
List of Practical

----------------------------------------------------------------------------------

(1)
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.
(2)

Develop Calculator using Dialog.
Hint: 1 Edit Box, 4 Radio Buttons,
Error Message like Divide by 0 Error,
Use Appropriate Controls.
(3)
Create Dialog based Application as shown below with use of ListBox (3a) and ComboBox.(3b)

(4)
Create Dialog based Applications with two EditBox to show use of different String function and Show final answer in MessageBox.
Hint: 2 EditBox, Radio Buttons (Min 5), CheckBox (Min 5)
Create all Controls through Coding.
(5)
Create Dialog based Applications with multiple Dialog Box to Show functionality of ProgressBar and Slider.
Hint: 3 DialogBox ,
1-> Create and Send Message (Slider)
2-> Show the Status of Message (Progress Bar)
3-> Read Message
* If Possible Implement Vice-Versa and Use Animation.
(6)
Create Dialog based Application with Multiple Dialog box.

Create Dynamic Static Box in 1st Dialog with following values.
* Position where user press Left Button.
* Caption = Text in EditBox of 2nd Dialog Box.
(7)
Write a program to draw a line using three different mouse events.
Hint:

1-> LBUTTONDOWN
2-> LBUTTONUP
3-> MOUSEMOVE
(8)
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.
(9)
Write a program to Animate Circle.
Hint:

* Circle should be Moved from one Point to Another.
* While Moving towards another Point its size should be Changed.
(10)
Write a program to Make Simple Text Editor.
Hint:

* Use Virtual Key.
* User Can Enter and Edit Text.

Submission Date : 15-Nov-2009

VC++ Practical List - Done in Class and LAB

List of Practical For LAB


(1) TAKE TWO EDITBOX ENTER VALUE IN IT AND PRINT THE ADDITION OF THE VALUE IN THIRD EDITBOX BY CLICK ON BUTTON.

(2) WRITE A PROGRAM TO ENABLE & DISABLE EDIT BOX.

(3) WRITE A PROGRAM TO CREATE TWO EDIT BOX DYNAMICALLY & THEN SWAP THE VALUE OF EDIT BOX WHEN CLICK ON BUTTON.

(4) WRITE A PROGRAM TO SWAP THE VALUE OF STATICBOX & EDITBOX.

(5) STRING MANIPULATION ON SELECTION OF RADIO BUTTON
  - CHANGE INTO UPPER CASE
  - CHANGE INTO LOWER CASE
  - REVERSE THE STRING
  - CALCULATE CHARACTER IN STRING
  - MAKE STRING IN PROPER CASE

(6) WRITE A PROGRAM TO DEVELOP SIMPLE CALCULATOR.

(7) WRITE A PROGRAM TO SPLIT THE SENTENCE ENTER IN TEXTBOX TO LIST BOX
HINT : TEXT BOX: "THIS IS MY BOOK"
 LIST BOX:   THIS
                        IS
                        MY
                        BOOK

(8) TAKE TWO LIST BOX AND TRANSFER VALUES ONE LISTBOX TO ANOTHER LISTBOX ONE BY ONE AND ALL AT ONCE WHEN USER CLICKS TWO DIFFERENT BUTTONS RESPECTIVELY.
(Develop Same Application Using COMBOBOX Also)

(9) WRITE A PROGRAM TO IMPLEMENT SCROLLBAR AND PRINT THE POSITION OF SCROLLBAR IN NON CLIENT AREA. (TITLE BAR OF DIALOG)

(10) MAKE AN APPLICATION OF SALES DETAIL WHICH CONTAIN FOLLOWING DETAIL.
 - ITEM NAME
 - ITEM PRICE
 - QUANTITY
 - TOTAL AMOUNT.

(11) MAKE YOUR OWN FUCTION AND MAP IT WITH ANY WINDOWS OR CONTROL EVENT USING MESSAGE MAP.

(12) PRINT CURRENT CURSOR POSITION INTO EDITBOX AND ON TITLEBAR.

(13) PRINT TEXT FROM EDITBOX WHERE USER CLICK ON SCREEN.

(14) Create Dialog based Applications with multiple Dialog Box to Show functionality of ProgressBar and Slider.
Hint: 3 - DIALOGBOX,
          1-> Create and Send Message (Slider)
          2-> Show the Status of Message (Progress Bar)
          3-> Read Message

(15) DRAW LINE USING ALL MOUSE EVENTS.
    (1) BUTTONDOWN AND BUTTONUP
    (2) MOUSEMOVE

(16) 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.

(17) Write a program to Animate Circle OR Rectangle.
Hint: * Circle should be Moved from one Point to Another.
            * While Moving towards another Point its size AND COLOR   should be Changed.

(18) Write a program to draw a circle, a polygon and a rectangle in the client area. Shape should be selected from Menu or Toolbar.(Create New Menu and Buttons in Toolbar)

(19) Write a program to change font using font Dialog.

(20) Write a Program to Change Color of Text, Pen and Brush using Color Dialog.

Saturday, November 14, 2009

VC++ (Visual C++) Syllabus , AITS (Atmiya Institute) , 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

Thursday, November 12, 2009

Create Animated Rectangle in VC++

filename:animateView.cpp


global variable:

int i=10,j=100;



void CAnimateView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default

CClientDC *pdc=new CClientDC(this);

while(i<300) { RedrawWindow(); CBrush br; br.CreateSolidBrush(RGB(i*3,0,j*6)); pdc->SelectObject(&br);
pdc->Rectangle(i,i,j,j);
i=i+5;
j=j+5;
Sleep(100);
}




CView::OnLButtonDown(nFlags, point);
}

How to Use Bitmap in SDI? ( VC++)

void CBitmapView::OnDraw(CDC* pDC)
{
CBitmapDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);



CBitmap bm;
CRect rc;
CBrush br;
bm.LoadBitmap(IDB_BITMAP1);
br.CreatePatternBrush(&bm);
GetClientRect(&rc);
//rc.bottom=100;
//rc.top=50;
//rc.left=50;
//rc.right=100;
pDC->FillRect(rc,&br);


// TODO: add draw code for native data here


}


void CBitmapView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CClientDC * Bms=new CClientDC(this);
if(point.x >= i && point.x <=j && point.y >=i && point.y <= j) { RedrawWindow(); CBrush br1; br1.CreateSolidBrush(RGB(100,100,50)); CRect rc1(i,i,j,j); Bms->FillRect(rc1,&br1);

}
CView::OnLButtonDown(nFlags, point);
}

Wednesday, November 11, 2009

nSBCode value for ScrollBar Control

SB_UP -- Scroll far to up.
SB_DOWN -- Scroll far to down.
SB_LINEUP -- Scroll to Upper side.
SB_LINEDOWN -- scroll to down side.
SB_LEFT -- Scroll far to left.
SB_RIGHT -- Scroll far to right.
SB_ENDSCROLL -- End scroll.
SB_LINELEFT -- Scroll left.
SB_LINERIGHT -- Scroll right.
SB_PAGELEFT -- Scroll one page left.
SB_PAGERIGHT -- Scroll one page right
SB_THUMBTRACK --
Drag scroll box to specified position.
nPos is the position that the scroll box has been dragged to.
SB_THUMBPOSITION --
Scroll to absolute position. nPos is the position of the
scroll box at the end of the drag operation.

Monday, November 9, 2009

Create RunTime EditBox,Radio Buttons & Check Box

BOOL CMy4_EdRdCkDlg::OnInitDialog()
{
CEdit *ed=new CEdit;
CEdit *ed1=new CEdit;

ed->Create(ES_MULTILINE|WS_CHILD|WS_VISIBLE
|WS_TABSTOP|WS_BORDER,CRect(30,30,130,70),this,1);

ed1->Create(ES_MULTILINE|WS_CHILD|WS_VISIBLE
|WS_TABSTOP|WS_BORDER,CRect(150,30,270,70),this,2);

CButton *ck1=new CButton;
CButton *ck2=new CButton;
CButton *ck3=new CButton;
CButton *ck4=new CButton;
CButton *ck5=new CButton;

ck1->Create("Check1",WS_CHILD|WS_VISIBLE
|BS_AUTOCHECKBOX,CRect(30,80,150,110),this,21);

ck2->Create("Check2",WS_CHILD|WS_VISIBLE
|BS_AUTOCHECKBOX,CRect(30,110,150,140),this,22);

ck3->Create("Check3",WS_CHILD|WS_VISIBLE
|BS_AUTOCHECKBOX,CRect(30,140,150,170),this,23);

ck4->Create("Check4",WS_CHILD|WS_VISIBLE
|BS_AUTOCHECKBOX,CRect(30,170,150,200),this,24);

ck5->Create("Check5",WS_CHILD|WS_VISIBLE
|BS_AUTOCHECKBOX,CRect(30,200,150,230),this,25);

CButton *rd1=new CButton;
CButton *rd2=new CButton;
CButton *rd3=new CButton;
CButton *rd4=new CButton;
CButton *rd5=new CButton;

rd1->Create("Redio1",WS_CHILD|WS_VISIBLE|WS_GROUP
|WS_TABSTOP|BS_AUTORADIOBUTTON,CRect(150,80,270,110),this,11);

rd2->Create("Redio2",WS_CHILD|WS_VISIBLE|WS_TABSTOP
|BS_AUTORADIOBUTTON,CRect(150,110,270,140),this,11);

rd3->Create("Redio3",WS_CHILD|WS_VISIBLE|WS_TABSTOP
|BS_AUTORADIOBUTTON,CRect(150,140,270,170),this,11);

rd4->Create("Redio4",WS_CHILD|WS_VISIBLE|WS_TABSTOP
|BS_AUTORADIOBUTTON,CRect(150,170,270,200),this,11);

rd5->Create("Redio5",WS_CHILD|WS_VISIBLE|WS_TABSTOP
|BS_AUTORADIOBUTTON,CRect(150,200,270,230),this,11);

return TRUE; // return TRUE unless you set the focus to a control
}

List Box with Fully Validation

//on ltor means left to right
//on alltor means all data of left to right


void CLISTBOXDlg::Onltor()
{
// TODO: Add your control notification handler code here


UpdateData(TRUE);
int i1;
i1=m_list1.GetCount();

/* int ii;
ii=m_list1.GetCount();

int a=m_list1.GetCurSel();*/

if(i1==0)
{
MessageBox("no more item ");

}
else if(m_list1.GetCurSel()==-1)
{
MessageBox("first select value");
}



else
{
CString str;
m_list1.GetText(m_list1.GetCurSel(),str);

m_list2.AddString(str);
m_list1.DeleteString(m_list1.GetCurSel());

int i;
i=m_list1.GetCount();
m_pos=i;
}

UpdateData(FALSE);
}

void CLISTBOXDlg::Onalltor()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
CString str;
int i1,j;
i1=m_list1.GetCount();
for(j=0;j {
m_list1.GetText(0,str);
m_list2.AddString(str);
m_list1.DeleteString(0);
}

int i;
i=m_list1.GetCount();
m_pos=i;
UpdateData(FALSE);

}

void CLISTBOXDlg::Onrtol()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);

int i1;
i1=m_list2.GetCount();

int ii;
ii=m_list2.GetCount();

int a=m_list2.GetCurSel();

if(i1==0)
{
MessageBox("no more item ");

}
else if(m_list2.GetCurSel()==-1)
{
MessageBox("first select value");
}


else
{
CString str;
m_list2.GetText(m_list2.GetCurSel(),str);

m_list1.AddString(str);
m_list2.DeleteString(m_list2.GetCurSel());


int i;
i=m_list1.GetCount();
m_pos=i;
}


UpdateData(FALSE);

}

void CLISTBOXDlg::Onalltol()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
CString str;
int i1,j;
i1=m_list2.GetCount();
for(j=0;j {
m_list2.GetText(0,str);
m_list1.AddString(str);
m_list2.DeleteString(0);
}
int i;
i=m_list1.GetCount();
m_pos=i;
UpdateData(FALSE);
}

void CLISTBOXDlg::Oninsert()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);

int len;
len=m_val.GetLength();

if(len==0)
{


MessageBox("insert item");

}
else
{
m_list1.InsertString(m_pos,m_val);
m_val=" ";
int i;
i=m_list1.GetCount();
m_pos=i;
}
UpdateData(FALSE);
}

void CLISTBOXDlg::Ondelete()
{
// TODO: Add your control notification handler code here

UpdateData(TRUE);



int ii,iii;
ii=m_list1.GetCount();
iii=m_list2.GetCount();

if(ii==0) //|| iii==0
{
MessageBox("you can not delete b/c no more item");
}
else if(m_list1.GetCurSel()==-1 ) //|| m_list2.GetCurSel()==-1
{
MessageBox("first select value");
}


else
{
m_list1.DeleteString(m_list1.GetCurSel());
int i;
i=m_list1.GetCount();
m_pos=i;
}
UpdateData(FALSE);
}

Draw a line in every movement of mouse with different color

void CSdi1View::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
count+=1;

start.x=point.x;
start.y=point.y;
if(count%5==0)
{
i=0;
j=255;
k=0;
newb.DeleteObject();
newb.CreatePen(PS_SOLID,1,RGB(i,j,k));
}
else if(count%3==0)
{
i=255;
j=0;
k=0;
newb.DeleteObject();
newb.CreatePen(PS_SOLID,1,RGB(i,j,k));
}
else if(count%2==0)
{
i=0;
j=0;
k=255;
newb.DeleteObject();
newb.CreatePen(PS_SOLID,1,RGB(i,j,k));
}
CView::OnLButtonDown(nFlags, point);
}





void CSdi1View::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
end.x=point.x;
end.y=point.y;

CClientDC * pcd=new CClientDC(this);
pcd->MoveTo(start.x,start.y);


pcd->SelectObject(&newb);

pcd->LineTo(end.x,end.y);


CView::OnMouseMove(nFlags, point);
}

Line Draw Program Using MouseMove Event With CPen Class

void CTryView::OnMouseMove(UINT nFlags, CPoint point)
{
//RedrawWindow();
// TODO: Add your message handler code here and/or call default

CClientDC *pDC = new CClientDC(this);

CPen p1;
if(m_i<100)
{

p1.CreatePen(PS_SOLID,2,RGB(255,235,65));
pDC->SelectObject(&p1);

pDC->MoveTo(m_start);
pDC->LineTo(point);
m_start=point;
}
else if(m_i<200)
{

p1.CreatePen(PS_SOLID,2,RGB(100,230,82));
pDC->SelectObject(&p1);

pDC->MoveTo(m_start);
pDC->LineTo(point);
m_start=point;
}
else if(m_i<300)
{

p1.CreatePen(PS_SOLID,2,RGB(50,130,182));
pDC->SelectObject(&p1);

pDC->MoveTo(m_start);
pDC->LineTo(point);
m_start=point;
}
else if(m_i<400)
{

p1.CreatePen(PS_SOLID,2,RGB(255,0,0));
pDC->SelectObject(&p1);

pDC->MoveTo(m_start);
pDC->LineTo(point);
m_start=point;
}
else
{

p1.CreatePen(PS_SOLID,2,RGB(10,30,242));
pDC->SelectObject(&p1);

pDC->MoveTo(m_start);
pDC->LineTo(point);
m_start=point;

}

if(m_i==0)
{
m_start=point;
}
if(m_i==400)
{
m_i=0;
}
else
{
pDC->MoveTo(m_start);
pDC->LineTo(point);
m_start=point;
}

m_i++;

CView::OnMouseMove(nFlags, point);
}

Moving ball around screen

void CDrawCPRView::OnLButtonDblClk(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default

CClientDC *cr = new CClientDC(this);

CPen pn1;

pn1.CreatePen(PS_SOLID,2,RGB(255,0,0));

cr->SelectObject(pn1);

CBrush br1(RGB(255,0,0));

cr->SelectObject(br1);

//RedrawWindow();

while(1)
{

CRect rc;
GetClientRect(rc);
int x1=0,y1=0,a=0,b=0;

while(1)
{
if(a==0 && b==0)
{
x1+=5;
y1+=5;
}

if(a==0 && b==1)
{
x1+=5;
y1-=5;
}

if(a==1 && b==0)
{
x1-=5;
y1+=5;
}

if(a==1 && b==1)
{
x1-=5;
y1-=5;
}

if(x1 < a="0;" b="0;"> rc.right-2)
{
a=1;
}
else if(y1 > rc.bottom-2)
{
b=1;
}

RedrawWindow();
cr->Ellipse(x1,y1,x1+10,y1+10);
Sleep(20);
}

}

CView::OnLButtonDblClk(nFlags, point);
}

Saturday, November 7, 2009

List of Function in VC++, Explain with Example


  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.

Code To Make Edit Box Enable and Disable

GetDlgItem(IDC_EDIT1)->EnableWindow();
GetDlgItem(IDC_EDIT1)->EnableWindow(FALSE);

Friday, November 6, 2009

How to Get System Time in VC++

How can we get system time ?

void CTimeDlg::OnButton1()
{
// TODO: Add your control notification handler code here
CTime t=CTime::GetCurrentTime();

CString str;
str.Format("%d:%d:%d",t.GetHour(),t.GetMinute(),t.GetSecond());

this->SetWindowText(str);
}

Move Eye Ball When We Move Cursor Position

//Global Variable


int i,j;

int k,l;


// CFaceView drawing

void CFaceView::OnDraw(CDC* pDC)
{
CFaceDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
CClientDC *abc = new CClientDC(this);

CPen pen;

pen.CreatePen(PS_SOLID,2,RGB(255,0,0));

abc->SelectObject(pen);

CRect rc;
GetClientRect(rc);

j= rc.bottom/2;

i = rc.right/2;

abc->Ellipse(i-100,j-100,i+100,j+100);

abc->Ellipse(i-60,j-60,i-30,j-30);
abc->Ellipse(i+60,j-60,i+30,j-30);
//abc->Ellipse(i-60,j-60,i-50,j-50);
//abc->Ellipse(i-10,j-10,i+10,j+10);


}




void CFaceView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default

CClientDC *abc = new CClientDC(this);

CPen pen;

pen.CreatePen(PS_SOLID,2,RGB(255,0,0));

abc->SelectObject(pen);


// For Left and Right
if(point.x > i)
{
RedrawWindow();
abc->Ellipse(i-30,j-50,i-40,j-40);
abc->Ellipse(i+50,j-50,i+60,j-40);
}
else
{
RedrawWindow();
abc->Ellipse(i-50,j-50,i-60,j-40);
abc->Ellipse(i+30,j-50,i+40,j-40);
}


//For up and Down
/*
if(point.y <>
{
RedrawWindow();
abc->Ellipse(i-40,j-60,i-50,j-50);
abc->Ellipse(i+40,j-60,i+50,j-50);
}
else
{
RedrawWindow();
abc->Ellipse(i-40,j-40,i-50,j-30);
abc->Ellipse(i+40,j-40,i+50,j-30);
}
*/

CView::OnMouseMove(nFlags, point);
}

Thursday, November 5, 2009

Code for Simple Text Editor Which We have done in Class

FileName : TextandFontView.h
class CTextandFontView : public CView
{
...
public:
  CString str[10];
....
};

FileName : TextandFontView.cpp

Global variable:
      int x=0,y=0,i=0;

void CTextandFontView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
    // TODO: Add your message handler code here and/or call default
    CClientDC *pDC = new CClientDC (this);
    pDC->SetBkColor (RGB(100,100,0));
    pDC->SetBkMode (TRANSPARENT);
        CFont ft;
    ft.CreatePointFont (100,"Arial");
    pDC->SelectObject(&ft);
   
    if(nChar==VK_BACK)
    {
     RedrawWindow ();
     if(str[i].IsEmpty ())
     {
         i--;
         y-=20;
     }
     for(int j=0;j
     {
        pDC->TextOut (x,j*20,str[j]);
     }
      
     str[i]=str[i].Mid (0,str[i].GetLength()-1);
     pDC->TextOut (x,y,LPCTSTR(str[i]),str[i].GetLength());
    }
    else if(nChar==VK_RETURN)
    {
        y+=20;
        i++;
        pDC->TextOut(x,y,str[i]);
       
    }
    else
    {
    RedrawWindow ();
   
    for(int j=0;j
    {
        pDC->TextOut (x,j*20,str[j]);
    }
         str[i]+=nChar;
   
        pDC->TextOut (x,y,str[i]);
    }

    CView::OnChar(nChar, nRepCnt, nFlags);
}



 

Wednesday, November 4, 2009

Line Draw Program OnMouseMove_Evet

void CMouse_Move_EventView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
//start=point;
if(i==0)
{
start=point;
}
else
{
CClientDC *kBC = new CClientDC(this);
kBC->MoveTo (start);
kBC->LineTo (point.x,point.y);
start=point;
}
i++;


CView::OnMouseMove(nFlags, point);
}

void CMouse_Move_EventView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
/*start=point;

CClientDC *kBC = new CClientDC(this);
kBC->MoveTo (start);
kBC->LineTo (point.x,point.y);*/
CView::OnLButtonDown(nFlags, point);
}

How to get Font from CFontDialog class

//Using CFontDialog

void CColorDialogView::OnFont()
{
// TODO: Add your command handler code here

CFontDialog fnt;
fnt.DoModal();
ft.DeleteObject();
ft.CreateFontIndirect (fnt.m_cf.lpLogFont);


//kBC->TextOut (50,50,"AITS VC++",9);
//Invalidate();
}

void CColorDialogView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default

CClientDC *kBC = new CClientDC (this);
//RedrawWindow();
kBC->SelectObject (&ft);
kBC->TextOut (point.x,point.y,"AITS VC++ dfgf",9);
CView::OnLButtonDown(nFlags, point);
}