banner despecable me2

วันศุกร์ที่ 26 กรกฎาคม พ.ศ. 2556

lab17 การเขียนโปรแกรมกราฟฟิกส์ด้วย GDI+1


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing.Drawing2D;

namespace lab17
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            Pen bluepen = new Pen(Color.Blue, 2);
            g.DrawRectangle(bluepen, 10, 10, 100, 100);
            bluepen.Dispose();

            
        }
    }
}

----------------------------------------------------
โดยการผสมค่าสี
private void Form1_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            Pen bluepen = new Pen(Color.Blue, 2);
            g.DrawRectangle(bluepen, 10, 10, 100, 100);
            bluepen.Dispose();

            Pen somePen = new Pen(Color.FromArgb(255, 120, 200));
            g.DrawEllipse(somePen, 20, 20, 200, 200);
            somePen.Dispose();


---------------------------------------------
โดยการใช้ methode FromName

 Graphics g = e.Graphics;
            Pen bluepen = new Pen(Color.Blue, 2);
            g.DrawRectangle(bluepen, 10, 10, 100, 100);
            bluepen.Dispose();

            Pen somePen = new Pen(Color.FromArgb(255, 120, 200));
            g.DrawEllipse(somePen, 20, 20, 200, 200);
            somePen.Dispose();

            Color col = Color.FromName("LightGreen");
            this.BackColor = col;

--------------------------------------------
เปลี่ย นขนาดและสีของปากกา
private void Form1_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            Pen mypen = new Pen(Color.Black, 1);
            g.DrawRectangle(mypen, 10, 10, 200, 200);
            mypen.Width = 4;
            mypen.Color = Color.Pink;
            g.DrawEllipse(mypen, 10, 10, 200, 200);

          
        }
---------------------------------------------
เปลี่ย นชนิดของปากกาเป็นเส้นประ



 private void Form1_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            Pen mypen = new Pen(Color.Black, 1);
            mypen.DashStyle = DashStyle.Dash;
            g.DrawRectangle(mypen, 10, 10, 200, 200);
            mypen.Width = 4;
            mypen.Color = Color.Pink;
            g.DrawEllipse(mypen, 10, 10, 200, 200);

           
        }

------------------------------------------------
ใช้ Pen ร่วมกับ Brush
private void Form1_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            Brush myBrush = new SolidBrush(Color.DarkGreen);
            Pen mypen = new Pen(myBrush, 5);

            g.DrawEllipse(mypen,10,10,200,200);
            mypen.Dispose();
            myBrush.Dispose();
         }

------------------------------------------------
การใช้ Pen ร่วมกับ HatchBrush
    
private void Form1_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            Brush myBrush = new HatchBrush(HatchStyle.DarkVertical, Color.White, Color.Violet);
            Pen mypen = new Pen(myBrush, 5);

            g.DrawEllipse(mypen,10,10,200,200);
            mypen.Dispose();
            myBrush.Dispose();
         }

---------------------------------
ทดลองเปลีย น Color และ HatchStyle เป็นแบบต่างๆ


 private void Form1_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            Brush myBrush = new HatchBrush(HatchStyle.DarkVertical, Color.Red, Color.Black);
            Pen mypen = new Pen(myBrush, 5);

            g.DrawEllipse(mypen,10,10,200,200);
            mypen.Dispose();
            myBrush.Dispose();
         }







วันศุกร์ที่ 12 กรกฎาคม พ.ศ. 2556

lab16 การเพิ่ม progress control ใน Dialog based Application


// lab16Dlg.cpp : implementation file
//

#include "stdafx.h"
#include "lab16.h"
#include "lab16Dlg.h"
#include "afxdialogex.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CAboutDlg dialog used for App About

class CAboutDlg : public CDialogEx
{
public:
CAboutDlg();

// Dialog Data
enum { IDD = IDD_ABOUTBOX };

protected:
virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support

// Implementation
protected:
DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialogEx(CAboutDlg::IDD)
{
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)
END_MESSAGE_MAP()


// Clab16Dlg dialog



Clab16Dlg::Clab16Dlg(CWnd* pParent /*=NULL*/)
: CDialogEx(Clab16Dlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void Clab16Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Control(pDX, IDC_PROGRESS, m_progress);
DDX_Control(pDX, IDC_SLIDER, m_slider);
}

BEGIN_MESSAGE_MAP(Clab16Dlg, CDialogEx)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_NOTIFY(NM_CUSTOMDRAW, IDC_SLIDER, &Clab16Dlg::OnNMCustomdrawSlider)
ON_WM_HSCROLL()
END_MESSAGE_MAP()


// Clab16Dlg message handlers

BOOL Clab16Dlg::OnInitDialog()
{
CDialogEx::OnInitDialog();

// Add "About..." menu item to system menu.

// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);

CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
BOOL bNameValid;
CString strAboutMenu;
bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
ASSERT(bNameValid);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}

// Set the icon for this dialog.  The framework does this automatically
//  when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon

// TODO: Add extra initialization here
m_slider.SetRange(0,100);
m_progress.SetRange (0,100);
m_progress.SetPos(1);
m_progress.SetStep(1);
return TRUE;  // return TRUE  unless you set the focus to a control
}

void Clab16Dlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialogEx::OnSysCommand(nID, lParam);
}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void Clab16Dlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting

SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;

// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialogEx::OnPaint();
}
}

// The system calls this function to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR Clab16Dlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}



void Clab16Dlg::OnNMCustomdrawSlider(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMCUSTOMDRAW pNMCD = reinterpret_cast<LPNMCUSTOMDRAW>(pNMHDR);
// TODO: Add your control notification handler code here
*pResult = 0;
}


void Clab16Dlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
CSliderCtrl *slider;
slider = (CSliderCtrl*) pScrollBar;
int pos = 0;
if(slider ==&m_slider)
{
UpdateData(TRUE);
pos = m_slider.GetPos();
m_progress.SetPos(pos);
UpdateData(FALSE);
// TODO: Add your message handler code here and/or call default

CDialogEx::OnHScroll(nSBCode, nPos, pScrollBar);
}
}


lab15 การเพิ่ม slider control ใน Dialog based Application



// lab15Dlg.cpp : implementation file
//

#include "stdafx.h"
#include "lab15.h"
#include "lab15Dlg.h"
#include "afxdialogex.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CAboutDlg dialog used for App About

class CAboutDlg : public CDialogEx
{
public:
CAboutDlg();

// Dialog Data
enum { IDD = IDD_ABOUTBOX };

protected:
virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support

// Implementation
protected:
DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialogEx(CAboutDlg::IDD)
{
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)
END_MESSAGE_MAP()


// Clab15Dlg dialog



Clab15Dlg::Clab15Dlg(CWnd* pParent /*=NULL*/)
: CDialogEx(Clab15Dlg::IDD, pParent)
, m_value(0)
, m_sliderValue(0)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void Clab15Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Control(pDX, IDC_SLIDER, m_slider);
DDX_Text(pDX, IDC_EDIT1, m_value);
DDX_Slider(pDX, IDC_SLIDER, m_sliderValue);
}

BEGIN_MESSAGE_MAP(Clab15Dlg, CDialogEx)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_NOTIFY(NM_CUSTOMDRAW, IDC_SLIDER, &Clab15Dlg::OnNMCustomdrawSlider)
ON_WM_HSCROLL()
END_MESSAGE_MAP()


// Clab15Dlg message handlers

BOOL Clab15Dlg::OnInitDialog()
{
CDialogEx::OnInitDialog();

// Add "About..." menu item to system menu.

// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);

CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
BOOL bNameValid;
CString strAboutMenu;
bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
ASSERT(bNameValid);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}

// Set the icon for this dialog.  The framework does this automatically
//  when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon

// TODO: Add extra initialization here
m_slider.SetRange(1,10);
return TRUE;  // return TRUE  unless you set the focus to a control
}

void Clab15Dlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialogEx::OnSysCommand(nID, lParam);
}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void Clab15Dlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting

SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;

// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialogEx::OnPaint();
}
}

// The system calls this function to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR Clab15Dlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}



void Clab15Dlg::OnNMCustomdrawSlider(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMCUSTOMDRAW pNMCD = reinterpret_cast<LPNMCUSTOMDRAW>(pNMHDR);
// TODO: Add your control notification handler code here
*pResult = 0;
}


void Clab15Dlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
CSliderCtrl *slider;
slider = (CSliderCtrl*) pScrollBar;
if(slider == &m_slider)
{
UpdateData(TRUE);
m_value = m_sliderValue;
UpdateData(FALSE);
}// TODO: Add your message handler code here and/or call default

CDialogEx::OnHScroll(nSBCode, nPos, pScrollBar);
}

lab14 การเพิ่ม spin button ใน Dialog based Application


m_spin.SetRange(1,100);
m_spin.SetBuddy(&m_edit);
m_spin.SetPos(1);



-------------------------------------------------
m_spin.SetRange(1,10);
m_spin.SetBuddy(&m_edit);
m_spin.SetPos(1);


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

m_spin.SetRange(1,100);
                     m_spin.SetBuddy(&m_edit);
m_spin.SetPos(1);
m_spin.SetBase(16);




lab13 การเพิ่ม Combobox ใน Dialog based Application




void Clab13Dlg::OnBnClickedButtonAdd()
{
CString srcText;
m_editSource.GetWindowText (srcText);
m_comboBox1.AddString(srcText);
// TODO: Add your control notification handler code here
}


void Clab13Dlg::OnCbnSelchangeCombo1()
{
CString str;
int idx = m_comboBox1.GetCurSel();
if( idx < 0 )
return;
m_comboBox1.GetLBText( idx, str);
m_staticDestination.SetWindowTextW(str );// TODO: Add your control notification handler code here
}

วันพุธที่ 10 กรกฎาคม พ.ศ. 2556

lab12 การเพิ่ม Edit Control ใน Dialog based Application


lab12

void Clab12Dlg::OnEnChangeEditSource()
{
// TODO:  If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialogEx::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.

// TODO:  Add your control notification handler code here
CString srcText;
m_editSource.GetWindowText(srcText);
m_editDestination.SetWindowText(srcText);
m_staticDestination.SetWindowText(srcText);
}

lab11 การเพิ่ม button ใน Dialog based Application

lab11 Button1
void Clab11Dlg::OnBnClickedButton1()
{
MessageBox(_T("Visual C++ is very Easy"));// TODO: Add your control notification handler code here
}





lab11 : Button2


void Clab11Dlg::OnBnClickedButton2()
{
MessageBox(_T("Loving You Too Much So Much Very Much Right Now "));// TODO: Add your control notification handler code here
}



lab10 การพัฒนาโปรแกรมโดยใช้ AppWizard

lab10a : Lab7SingleDoc


lab10b :Lab7MultipleDoc


lab10c : Lab7Dialogbased



lab10d : Lab7MultipleTopLevel


วันพฤหัสบดีที่ 4 กรกฎาคม พ.ศ. 2556

lab9 การเขียนโปรแกรม MFC #6



-----------------------------------------h---------------------------------------
#include "afxwin.h"
#define IDC_PAD 100
#define IDC_CLSBUTTON 101
#define IDC_COPYBUTTON 102
#define IDC_PASTEBUTTON 103
#define IDC_EXITBUTTON 104

class CApp:public CWinApp{
 public: virtual BOOL InitInstance();
};

class CWin:public CFrameWnd{
 int response;
 CEdit *EditPad;
 CButton *CLSButton;
 CButton *CopyButton;
 CButton *PasteButton;
 CButton *ExitButton;

public: CWin();
  ~CWin();
  afx_msg void onExit();
  afx_msg void onCopy();
  afx_msg void onPaste();
  afx_msg void onCLS();
  DECLARE_MESSAGE_MAP();
};
__________________________________cpp__________________________________

#include "lab9.h"

CApp app;

BEGIN_MESSAGE_MAP(CWin, CFrameWnd)
 ON_BN_CLICKED(IDC_EXITBUTTON, onExit)
 ON_BN_CLICKED(IDC_COPYBUTTON, onCopy)
 ON_BN_CLICKED(IDC_PASTEBUTTON, onPaste)
 ON_BN_CLICKED(IDC_CLSBUTTON, onCLS)
END_MESSAGE_MAP();

void CWin::onExit(){
 response=MessageBox("Do you want to quit!!\n Yes or No?",
  "Lab9: Little note pad", MB_ICONQUESTION|MB_YESNO);
 if (response==IDYES) DestroyWindow();
}

void CWin::onCopy(){
 EditPad->SetSel(0,-1,TRUE);
 EditPad->Copy();
 EditPad->SetFocus();
}

void CWin::onCLS(){
 EditPad->SetSel(0,-1,TRUE);
 EditPad->Copy();
 EditPad->SetFocus();
}

void CWin::onPaste(){
 EditPad->SetSel(0,-1,TRUE);
 EditPad->Copy();
 EditPad->SetFocus();
}

BOOL CApp::InitInstance(){
 m_pMainWnd=new CWin();
 m_pMainWnd->ShowWindow(m_nCmdShow);
 m_pMainWnd->UpdateWindow();
 return TRUE;
}
CWin::CWin(){
 Create(NULL,"Little note pad",
  WS_OVERLAPPED|WS_SYSMENU|WS_MINIMIZEBOX, CRect(0,0,290,245));
 EditPad=new CEdit();
 CLSButton=new CButton();
 CopyButton=new CButton();
 PasteButton=new CButton();
 ExitButton=new CButton();
 EditPad->Create(WS_CHILD|WS_VISIBLE|WS_BORDER|WS_TABSTOP| \
  ES_AUTOVSCROLL|ES_AUTOHSCROLL|ES_MULTILINE,
  CRect(10,10,270,140), this, IDC_PAD);
 CLSButton->Create("Clear",WS_CHILD|WS_VISIBLE|WS_BORDER|WS_TABSTOP,
  CRect(10,145,90,170), this, IDC_CLSBUTTON);
 CopyButton->Create("Copy",WS_CHILD|WS_VISIBLE|WS_BORDER|WS_TABSTOP,
  CRect(100,145,180,170), this, IDC_COPYBUTTON);
 PasteButton->Create("Paste",WS_CHILD|WS_VISIBLE|WS_BORDER|WS_TABSTOP,
  CRect(190,145,270,170), this, IDC_PASTEBUTTON);
 ExitButton->Create("Exit",WS_CHILD|WS_VISIBLE|WS_BORDER|WS_TABSTOP,
  CRect(10,175,270,200), this, IDC_EXITBUTTON);
}

CWin::~CWin(){
 delete EditPad;
 delete CLSButton;
 delete CopyButton;
 delete PasteButton;
 delete ExitButton;

}