Friday, December 4, 2009

Database Connection Using DAO in VC++

File Name :: DAOConnView.cpp

Coding ::

void CDAOConnView::OnMoveFirst()

{

// TODO: Add your control notification handler code here

UpdateData();

m_pSet->MoveFirst();

UpdateData(FALSE);

}

void CDAOConnView::OnMovePrev()

{

// TODO: Add your control notification handler code here

UpdateData();

m_pSet->MovePrev();

if(m_pSet->IsBOF() == TRUE)

{

MessageBox("First Record","Alert");

m_pSet->MoveFirst();

}

UpdateData(FALSE);

}

void CDAOConnView::OnMoveNext()

{

// TODO: Add your control notification handler code here

UpdateData();

m_pSet->MoveNext();

if(m_pSet->IsEOF() == TRUE)

{

MessageBox("Last Record","Alert" );

m_pSet->MoveLast();

}

UpdateData(FALSE);

}

void CDAOConnView::OnMoveLast()

{

// TODO: Add your control notification handler code here

UpdateData();

m_pSet->MoveLast();

UpdateData(FALSE);

}

void CDAOConnView::OnAdd()

{

// TODO: Add your control notification handler code here

UpdateData();

m_pSet->AddNew();

UpdateData(FALSE);

}

void CDAOConnView::OnSave()

{

// TODO: Add your control notification handler code here

UpdateData();

m_pSet->Update();

UpdateData(FALSE);

}

void CDAOConnView::OnUpdate()

{

// TODO: Add your control notification handler code here

m_pSet->Edit();

}

void CDAOConnView::OnDelete()

{

// TODO: Add your control notification handler code here

UpdateData();

m_pSet->Delete();

m_pSet->Requery();

m_pSet->MoveNext();

UpdateData(FALSE);

}

OLEDB CONNECTION IN VC++

COledb_connectView.h
public:
COledb_connectDoc* GetDocument();
bool flag;



COledb_connectView.cpp
void COledb_connectView::OnInitialUpdate()
{
m_pSet = &GetDocument()->m_oledb_connectSet;
{
CWaitCursor wait;
HRESULT hr = m_pSet->Open();
if (hr != S_OK)
{
AfxMessageBox(_T("Record set failed to open."), MB_OK);
// Disable the Next and Previous record commands,
// since attempting to change the current record without an
// open RecordSet will cause a crash.
m_bOnFirstRecord = TRUE;
m_bOnLastRecord = TRUE;
}
}
m_rollno=m_pSet->m_rollno;
m_marks=m_pSet->m_marks;
COleDBRecordView::OnInitialUpdate();

}
void COledb_connectView::Onfirst()
{
// TODO: Add your control notification handler code here
UpdateData();
m_pSet->MoveFirst();
m_rollno=m_pSet->m_rollno;
m_marks=m_pSet->m_marks;

UpdateData(false);
}

void COledb_connectView::Onlast()
{
// TODO: Add your control notification handler code here
UpdateData();
m_pSet->MoveLast();
m_rollno=m_pSet->m_rollno;
m_marks=m_pSet->m_marks;
UpdateData(false);

}

void COledb_connectView::Oninsert()
{
// TODO: Add your control notification handler code here
UpdateData();
m_rollno=0;
m_marks=0;
UpdateData(false);
}

void COledb_connectView::Onsave()
{
// TODO: Add your control notification handler code here
UpdateData();
m_pSet->m_rollno=m_rollno;
m_pSet->m_marks=m_marks;
if(flag==true)//if flag is true then update operation will perform
{

m_pSet->SetData();
}
else //if flag is true then INSERT operation will perform
{
m_pSet->Insert();
}
flag=false;

UpdateData(false);
}

void COledb_connectView::Onnext()
{
// TODO: Add your control notification handler code here
UpdateData();
m_pSet->MoveNext();
m_rollno=m_pSet->m_rollno;
m_marks=m_pSet->m_marks;

UpdateData(false);
}

void COledb_connectView::Onprevious()
{
// TODO: Add your control notification handler code here
UpdateData();
m_pSet->MovePrev();
m_rollno=m_pSet->m_rollno;
m_marks=m_pSet->m_marks;

UpdateData(false);
}

void COledb_connectView::Onupdate()
{
// TODO: Add your control notification handler code here
UpdateData();
m_pSet->m_rollno=m_rollno;
m_pSet->m_marks=m_marks;
m_pSet->Update();
flag=true;
UpdateData(false);
}

void COledb_connectView::Ondelete()
{
// TODO: Add your control notification handler code here
UpdateData();
m_pSet->Delete();
m_pSet->MoveFirst();

m_rollno=m_pSet->m_rollno;
m_marks=m_pSet->m_marks;
UpdateData(false);

}

Thursday, December 3, 2009

Practical Assignment

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


(1)
Develop GDI application Using Menu and Toolbar to Change Shape and Color.


(2)
Write application for the GDI that use the ColorDialog and FontDialog.



(3)
 Write application for the GDI that use the Bitmap,Icon and Cursor.


(4) 
Write dialog based application that Write and Read data using the Seek() function.  


(5)
Write application that show the FileStatus with Exception Handling.


(6)
Write application that implement Serialization 



(7)
Develop a simple MDI application.



(8)
Develop simple Web Browser using CHtmlView



(9)
Develop application which can perform Insert, Update, Delete, Search using ODBC.



(10)
Develop application which can perform Insert, Update, Delete, Search using DAO.



(11)
Develop application which can perform Insert, Update, Delete, Search using OLEDB.


(12) 
 Develop Simple Active-X program.


Submission Date 

For Theory and Practical Assignment
On or Before 
26 - 12 - 2009 , Saturday 

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