//添加按钮方法,可以在CMainFrame,CTWinTest02View中添加
//先添加CButton m_btn变量,
//在oncreate 中添加 m_btn.Create(_T("My button"), WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON, CRect(10,10,100,30), this, 1);
//CTWinTest02View 要在消息映射中WM_Create中添加
int Ctest1View::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: 在此添加您专用的创建代码
m_btn.Create(_T("My button"), WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
CRect(10,10,100,30), this, 1);
return 0;
}
//画直线 在view中添加消息映射
BEGIN_MESSAGE_MAP(Ctest1View, CView)
// 标准打印命令
ON_COMMAND(ID_FILE_PRINT, &CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, &CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CView::OnFilePrintPreview)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_CREATE()
END_MESSAGE_MAP()
//SDK全局函数画线
void Ctest1View::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
// 首先获得窗口的设备描述表
HDC hdc;
hdc = ::GetDC(m_hWnd);
//移动到线条的起点
MoveToEx(hdc, m_ptOrigin.x, m_ptOrigin.y, NULL);
//画线
LineTo(hdc, point.x, point.y);
//释放设备描述表
::ReleaseDC(m_hWnd,hdc);
CView::OnLButtonUp(nFlags, point);
}
int Ctest1View::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: 在此添加您专用的创建代码
m_btn.Create(_T("My button"), WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
CRect(10,10,100,30), this, 1);
return 0;
}
//CDC类
CDC* pDC = GetDC();
pDC->MoveTo(m_ptOrigin);
pDC->LineTo(point);
ReleaseDC(pDC);
//画曲线
CDC* pDC = GetDC();
pDC->MoveTo(m_ptOrigin);
//pDC->LineTo(point);
POINT p[4] = {
(POINT)m_ptOrigin,
{500,20},
{500,500},
(POINT)point
};
pDC->PolyBezier(p,4);
ReleaseDC(pDC);
//CClientDC类
// CClientDC dc(GetParent());//在父窗口
CClientDC dc(this);
//CWindowDC dc(GetDesktopWindow()); //在桌面
// CWindowDC dc(GetParent());
CPen pen(PS_DOT,1,RGB(255,0,0));//变色
CPen* pOldPen = dc.SelectObject(&pen);
dc.MoveTo(m_ptOrigin);
dc.LineTo(point);
dc.SelectObject(pOldPen);
/* //创建一个红色画刷
CBrush brush(RGB(255,0,0));
//创建并获得设备描述表
CClientDC dc(this);
//利用红色画刷填充鼠标拖曳过程中形成的矩形区域
dc.FillRect(CRect(m_ptOrigin,point),&brush);
*/
/* //创建位图对象
CBitmap bitmap;
//加载位图资源
bitmap.LoadBitmap(IDB_BITMAP1);
//创建位图画刷
CBrush brush(&bitmap);
//创建并获得设备描述表
CClientDC dc(this);
//利用红色画刷填充鼠标拖曳过程中形成的矩形区域
dc.FillRect(CRect(m_ptOrigin,point),&brush);
*/
//创建并获得设备描述表
/* CClientDC dc(this);
//创建一个空画刷
CBrush *pBrush = CBrush::FromHandle((HBRUSH)GetStockObject(NULL_BRUSH));
//将空画刷选入设备描述表
CBrush *pOldBrush = dc.SelectObject(pBrush);
//绘制一个矩形
dc.Rectangle(CRect(m_ptOrigin,point));
//恢复先前的画刷
dc.SelectObject(pOldBrush);
*/
CDC::SetROP2(R2_BLACK)
//生成提示符
int CTextView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
/* //创建设备描述表
CClientDC dc(this);
//定义文本信息结构体变量
TEXTMETRIC tm;
//获得设备描述表中的文本信息
dc.GetTextMetrics(&tm);
//根据字体大小,创建合适的插入符
CreateSolidCaret(tm.tmAveCharWidth/8, tm.tmHeight);
//显示插入符
ShowCaret();
*/
bitmap.LoadBitmap(IDB_BITMAP1);
CreateCaret(&bitmap);
ShowCaret();
//重绘,
void CTextView::OnDraw(CDC* pDC)
{
CTextDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
//CString str("VC++ 深入编程");
CString str;
str = "VC++ 深入编程";
pDC->TextOut(50,50,str);
CSize sz = pDC->GetTextExtent(str);
str.LoadString(IDS_STRINGVC);//取资源
pDC->TextOut(0,200,str);
pDC->BeginPath();
pDC->Rectangle(50,50,50+sz.cx,50+sz.cy);
pDC->EndPath();
pDC->SelectClipPath(RGN_AND);
for(int i=0; i<300; i+=10)
{
pDC->MoveTo(0,i);
pDC->LineTo(300,i);
pDC->MoveTo(i,0);
pDC->LineTo(i,300);
}
}
//.省略了一部份178
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
..
// TODO: 如果不需要可停靠工具栏,则删除这三行
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
CMenu menu;
menu.CreateMenu();
// GetMenu()->AppendMenu(MF_POPUP,(UINT)menu.m_hMenu,"Test");
GetMenu()->InsertMenu(2,MF_POPUP | MF_BYPOSITION,(UINT)menu.m_hMenu,_T("Test"));
menu.AppendMenu(MF_STRING,ID_TEST,_T("Hello"));
menu.AppendMenu(MF_STRING,112,_T("Bye"));
menu.AppendMenu(MF_STRING,113,_T("Mybole"));
GetMenu()->GetSubMenu(0)->AppendMenu(MF_STRING,114,_T("Welcome"));
GetMenu()->GetSubMenu(0)->InsertMenu(ID_FILE_OPEN,MF_BYCOMMAND | MF_STRING,115,_T("VC编程"));
menu.Detach();
GetMenu()->DeleteMenu(1,MF_BYPOSITION);
GetMenu()->GetSubMenu(0)->DeleteMenu(2,MF_BYPOSITION);
GetMenu()->GetSubMenu(0)->CheckMenuItem(ID_FILE_NEW,MF_BYCOMMAND | MF_CHECKED);//添加复选区
GetMenu()->GetSubMenu(0)->SetDefaultItem(0,true);//设置默认菜单项
//.省略了一部份239 对话框
void Ctest1View::OnTest()
{
//CTestDlg dlg;
//dlg.DoModal();
CTestDlg *pDlg=new CTestDlg;
pDlg->Create(IDD_DIALOG1,this);
pDlg->ShowWindow(SW_SHOW); //需要释放资源 1.*pDlg为成员变量 2.重载PostNcDestory delete this;CDialog::PostNcDestory();
}
//动态创建按钮
if(m_bIsCreated == FALSE)//m_bIsCreated 为成员变量
{
m_btn.Create("New",BS_DEFPUSHBUTTON | WS_VISIBLE | WS_CHILD,
CRect(0,0,100,100),this,123);
m_bIsCreated = TRUE;
}
else
{
m_btn.DestroyWindow();
m_bIsCreated = FALSE;
}
------------------------------------
if(!m_btn.m_hWnd)//窗口句柄
{
m_btn.Create("New",BS_DEFPUSHBUTTON | WS_VISIBLE | WS_CHILD,
CRect(0,0,100,100),this,123);
}
else
{
m_btn.DestroyWindow();
}
//静态文本 Notify true
void CTestDlg::OnNumber1()
{
// TODO: Add your control notification handler code here
CString str;
if(GetDlgItem(IDC_NUMBER1)->GetWindowText(str), str == "Number1:")
{
GetDlgItem(IDC_NUMBER1)->SetWindowText("数值1:");
}
else
{
GetDlgItem(IDC_NUMBER1)->SetWindowText("Number1:");
}
}
//按钮动作
方法1
int num1, num2, num3;
char ch1[10], ch2[10], ch3[10];
GetDlgItem(IDC_EDIT1)->GetWindowText(ch1,10);
GetDlgItem(IDC_EDIT2)->GetWindowText(ch2,10);
num1 = atoi(ch1);
num2 = atoi(ch2);
num3 = num1 + num2;
itoa(num3,ch3,10);
GetDlgItem(IDC_EDIT3)->SetWindowText(ch3);
方法2
int num1, num2, num3;
char ch1[10], ch2[10], ch3[10];
GetDlgItemText(IDC_EDIT1,ch1,10);
GetDlgItemText(IDC_EDIT2,ch2,10);
num1 = atoi(ch1);
num2 = atoi(ch2);
num3 = num1 + num2;
itoa(num3,ch3,10);
SetDlgItemText(IDC_EDIT3,ch3);
方法3好
int num1, num2, num3;
num1 = GetDlgItemInt(IDC_EDIT1);
num2 = GetDlgItemInt(IDC_EDIT2);
num3 = num1 + num2;
SetDlgItemInt(IDC_EDIT3,num3);
方法4好
添加成员变量int
UpdateData();
m_num3 = m_num1 + m_num2;
UpdateData(false);
添加范围
DDV_MinMaxInt(pDX, m_num1, 0, 100);
DDV_MinMaxInt(pDX, m_num2, 0, 100);
DDV_MinMaxInt(pDX, m_num3, 0, 200);
方法5
添加成员变量control
int num1, num2, num3;
char ch1[10], ch2[10], ch3[10];
m_edit1.GetWindowText(ch1,10);
m_edit2.GetWindowText(ch2,10);
num1 = atoi(ch1);
num2 = atoi(ch2);
num3 = num1 + num2;
itoa(num3,ch3,10);
m_edit3.SetWindowText(ch3);
方法6
利用SDK 消息机制
int num1, num2, num3;
char ch1[10], ch2[10], ch3[10];
::SendMessage(GetDlgItem(IDC_EDIT1)->m_hWnd, WM_GETTEXT, 10,(LPARAM)ch1);
::SendMessage(m_edit2.m_hWnd, WM_GETTEXT, 10,(LPARAM)ch2);
num1 = atoi(ch1);
num2 = atoi(ch2);
num3 = num1 + num2;
itoa(num3,ch3,10);
m_edit3.SendMessage(WM_SETTEXT, 0, (LPARAM)ch3);
方法7
利用SDK 消息机制 直接发送给子控件
int num1, num2, num3;
char ch1[10], ch2[10], ch3[10];
SendDlgItemMessage(IDC_EDIT1, WM_GETTEXT, 10,(LPARAM)ch1);
SendDlgItemMessage(IDC_EDIT2, WM_GETTEXT, 10,(LPARAM)ch2);
num1 = atoi(ch1);
num2 = atoi(ch2);
num3 = num1 + num2;
itoa(num3,ch3,10);
SendDlgItemMessage(IDC_EDIT3, WM_SETTEXT, 0, (LPARAM)ch3);
SendDlgItemMessage(IDC_EDIT3, EM_SETSEL,1,3);//设置选中 EM_GETSEL取到选中
m_edit3.SetFocus(); //EM开头的消息是指编辑框中的消息
添加分隔窗体 添加一个图片控件 IDC_SEPARATOR 一个按钮 IDC_BUTTON1
CString str;
if(GetDlgItemText(IDC_BUTTON1, str), str == "收缩<<")
{
SetDlgItemText(IDC_BUTTON1,_T("扩展>>"));
}
else
{
SetDlgItemText(IDC_BUTTON1,_T("收缩<<"));
}
static CRect rectLarge;
static CRect rectSmall;
if(rectLarge.IsRectNull())
{
CRect rectSeparator;
GetWindowRect(&rectLarge);
GetDlgItem(IDC_SEPARATOR)->GetWindowRect(&rectSeparator);
rectSmall.left=rectLarge.left;
rectSmall.top=rectLarge.top;
rectSmall.right=rectLarge.right;
rectSmall.bottom=rectSeparator.bottom;
}
if(str=="收缩<<")
{
SetWindowPos(NULL,0,0,rectSmall.Width(),rectSmall.Height(),
SWP_NOMOVE | SWP_NOZORDER);
}
else
{
SetWindowPos(NULL,0,0,rectLarge.Width(),rectLarge.Height(),
SWP_NOMOVE | SWP_NOZORDER);
}
//----------265--------------------------略一部份
//先添加CButton m_btn变量,
//在oncreate 中添加 m_btn.Create(_T("My button"), WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON, CRect(10,10,100,30), this, 1);
//CTWinTest02View 要在消息映射中WM_Create中添加
int Ctest1View::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: 在此添加您专用的创建代码
m_btn.Create(_T("My button"), WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
CRect(10,10,100,30), this, 1);
return 0;
}
//画直线 在view中添加消息映射
BEGIN_MESSAGE_MAP(Ctest1View, CView)
// 标准打印命令
ON_COMMAND(ID_FILE_PRINT, &CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, &CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CView::OnFilePrintPreview)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_CREATE()
END_MESSAGE_MAP()
//SDK全局函数画线
void Ctest1View::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
// 首先获得窗口的设备描述表
HDC hdc;
hdc = ::GetDC(m_hWnd);
//移动到线条的起点
MoveToEx(hdc, m_ptOrigin.x, m_ptOrigin.y, NULL);
//画线
LineTo(hdc, point.x, point.y);
//释放设备描述表
::ReleaseDC(m_hWnd,hdc);
CView::OnLButtonUp(nFlags, point);
}
int Ctest1View::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: 在此添加您专用的创建代码
m_btn.Create(_T("My button"), WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
CRect(10,10,100,30), this, 1);
return 0;
}
//CDC类
CDC* pDC = GetDC();
pDC->MoveTo(m_ptOrigin);
pDC->LineTo(point);
ReleaseDC(pDC);
//画曲线
CDC* pDC = GetDC();
pDC->MoveTo(m_ptOrigin);
//pDC->LineTo(point);
POINT p[4] = {
(POINT)m_ptOrigin,
{500,20},
{500,500},
(POINT)point
};
pDC->PolyBezier(p,4);
ReleaseDC(pDC);
//CClientDC类
// CClientDC dc(GetParent());//在父窗口
CClientDC dc(this);
//CWindowDC dc(GetDesktopWindow()); //在桌面
// CWindowDC dc(GetParent());
CPen pen(PS_DOT,1,RGB(255,0,0));//变色
CPen* pOldPen = dc.SelectObject(&pen);
dc.MoveTo(m_ptOrigin);
dc.LineTo(point);
dc.SelectObject(pOldPen);
/* //创建一个红色画刷
CBrush brush(RGB(255,0,0));
//创建并获得设备描述表
CClientDC dc(this);
//利用红色画刷填充鼠标拖曳过程中形成的矩形区域
dc.FillRect(CRect(m_ptOrigin,point),&brush);
*/
/* //创建位图对象
CBitmap bitmap;
//加载位图资源
bitmap.LoadBitmap(IDB_BITMAP1);
//创建位图画刷
CBrush brush(&bitmap);
//创建并获得设备描述表
CClientDC dc(this);
//利用红色画刷填充鼠标拖曳过程中形成的矩形区域
dc.FillRect(CRect(m_ptOrigin,point),&brush);
*/
//创建并获得设备描述表
/* CClientDC dc(this);
//创建一个空画刷
CBrush *pBrush = CBrush::FromHandle((HBRUSH)GetStockObject(NULL_BRUSH));
//将空画刷选入设备描述表
CBrush *pOldBrush = dc.SelectObject(pBrush);
//绘制一个矩形
dc.Rectangle(CRect(m_ptOrigin,point));
//恢复先前的画刷
dc.SelectObject(pOldBrush);
*/
CDC::SetROP2(R2_BLACK)
//生成提示符
int CTextView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
/* //创建设备描述表
CClientDC dc(this);
//定义文本信息结构体变量
TEXTMETRIC tm;
//获得设备描述表中的文本信息
dc.GetTextMetrics(&tm);
//根据字体大小,创建合适的插入符
CreateSolidCaret(tm.tmAveCharWidth/8, tm.tmHeight);
//显示插入符
ShowCaret();
*/
bitmap.LoadBitmap(IDB_BITMAP1);
CreateCaret(&bitmap);
ShowCaret();
//重绘,
void CTextView::OnDraw(CDC* pDC)
{
CTextDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
//CString str("VC++ 深入编程");
CString str;
str = "VC++ 深入编程";
pDC->TextOut(50,50,str);
CSize sz = pDC->GetTextExtent(str);
str.LoadString(IDS_STRINGVC);//取资源
pDC->TextOut(0,200,str);
pDC->BeginPath();
pDC->Rectangle(50,50,50+sz.cx,50+sz.cy);
pDC->EndPath();
pDC->SelectClipPath(RGN_AND);
for(int i=0; i<300; i+=10)
{
pDC->MoveTo(0,i);
pDC->LineTo(300,i);
pDC->MoveTo(i,0);
pDC->LineTo(i,300);
}
}
//.省略了一部份178
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
..
// TODO: 如果不需要可停靠工具栏,则删除这三行
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
CMenu menu;
menu.CreateMenu();
// GetMenu()->AppendMenu(MF_POPUP,(UINT)menu.m_hMenu,"Test");
GetMenu()->InsertMenu(2,MF_POPUP | MF_BYPOSITION,(UINT)menu.m_hMenu,_T("Test"));
menu.AppendMenu(MF_STRING,ID_TEST,_T("Hello"));
menu.AppendMenu(MF_STRING,112,_T("Bye"));
menu.AppendMenu(MF_STRING,113,_T("Mybole"));
GetMenu()->GetSubMenu(0)->AppendMenu(MF_STRING,114,_T("Welcome"));
GetMenu()->GetSubMenu(0)->InsertMenu(ID_FILE_OPEN,MF_BYCOMMAND | MF_STRING,115,_T("VC编程"));
menu.Detach();
GetMenu()->DeleteMenu(1,MF_BYPOSITION);
GetMenu()->GetSubMenu(0)->DeleteMenu(2,MF_BYPOSITION);
GetMenu()->GetSubMenu(0)->CheckMenuItem(ID_FILE_NEW,MF_BYCOMMAND | MF_CHECKED);//添加复选区
GetMenu()->GetSubMenu(0)->SetDefaultItem(0,true);//设置默认菜单项
//.省略了一部份239 对话框
void Ctest1View::OnTest()
{
//CTestDlg dlg;
//dlg.DoModal();
CTestDlg *pDlg=new CTestDlg;
pDlg->Create(IDD_DIALOG1,this);
pDlg->ShowWindow(SW_SHOW); //需要释放资源 1.*pDlg为成员变量 2.重载PostNcDestory delete this;CDialog::PostNcDestory();
}
//动态创建按钮
if(m_bIsCreated == FALSE)//m_bIsCreated 为成员变量
{
m_btn.Create("New",BS_DEFPUSHBUTTON | WS_VISIBLE | WS_CHILD,
CRect(0,0,100,100),this,123);
m_bIsCreated = TRUE;
}
else
{
m_btn.DestroyWindow();
m_bIsCreated = FALSE;
}
------------------------------------
if(!m_btn.m_hWnd)//窗口句柄
{
m_btn.Create("New",BS_DEFPUSHBUTTON | WS_VISIBLE | WS_CHILD,
CRect(0,0,100,100),this,123);
}
else
{
m_btn.DestroyWindow();
}
//静态文本 Notify true
void CTestDlg::OnNumber1()
{
// TODO: Add your control notification handler code here
CString str;
if(GetDlgItem(IDC_NUMBER1)->GetWindowText(str), str == "Number1:")
{
GetDlgItem(IDC_NUMBER1)->SetWindowText("数值1:");
}
else
{
GetDlgItem(IDC_NUMBER1)->SetWindowText("Number1:");
}
}
//按钮动作
方法1
int num1, num2, num3;
char ch1[10], ch2[10], ch3[10];
GetDlgItem(IDC_EDIT1)->GetWindowText(ch1,10);
GetDlgItem(IDC_EDIT2)->GetWindowText(ch2,10);
num1 = atoi(ch1);
num2 = atoi(ch2);
num3 = num1 + num2;
itoa(num3,ch3,10);
GetDlgItem(IDC_EDIT3)->SetWindowText(ch3);
方法2
int num1, num2, num3;
char ch1[10], ch2[10], ch3[10];
GetDlgItemText(IDC_EDIT1,ch1,10);
GetDlgItemText(IDC_EDIT2,ch2,10);
num1 = atoi(ch1);
num2 = atoi(ch2);
num3 = num1 + num2;
itoa(num3,ch3,10);
SetDlgItemText(IDC_EDIT3,ch3);
方法3好
int num1, num2, num3;
num1 = GetDlgItemInt(IDC_EDIT1);
num2 = GetDlgItemInt(IDC_EDIT2);
num3 = num1 + num2;
SetDlgItemInt(IDC_EDIT3,num3);
方法4好
添加成员变量int
UpdateData();
m_num3 = m_num1 + m_num2;
UpdateData(false);
添加范围
DDV_MinMaxInt(pDX, m_num1, 0, 100);
DDV_MinMaxInt(pDX, m_num2, 0, 100);
DDV_MinMaxInt(pDX, m_num3, 0, 200);
方法5
添加成员变量control
int num1, num2, num3;
char ch1[10], ch2[10], ch3[10];
m_edit1.GetWindowText(ch1,10);
m_edit2.GetWindowText(ch2,10);
num1 = atoi(ch1);
num2 = atoi(ch2);
num3 = num1 + num2;
itoa(num3,ch3,10);
m_edit3.SetWindowText(ch3);
方法6
利用SDK 消息机制
int num1, num2, num3;
char ch1[10], ch2[10], ch3[10];
::SendMessage(GetDlgItem(IDC_EDIT1)->m_hWnd, WM_GETTEXT, 10,(LPARAM)ch1);
::SendMessage(m_edit2.m_hWnd, WM_GETTEXT, 10,(LPARAM)ch2);
num1 = atoi(ch1);
num2 = atoi(ch2);
num3 = num1 + num2;
itoa(num3,ch3,10);
m_edit3.SendMessage(WM_SETTEXT, 0, (LPARAM)ch3);
方法7
利用SDK 消息机制 直接发送给子控件
int num1, num2, num3;
char ch1[10], ch2[10], ch3[10];
SendDlgItemMessage(IDC_EDIT1, WM_GETTEXT, 10,(LPARAM)ch1);
SendDlgItemMessage(IDC_EDIT2, WM_GETTEXT, 10,(LPARAM)ch2);
num1 = atoi(ch1);
num2 = atoi(ch2);
num3 = num1 + num2;
itoa(num3,ch3,10);
SendDlgItemMessage(IDC_EDIT3, WM_SETTEXT, 0, (LPARAM)ch3);
SendDlgItemMessage(IDC_EDIT3, EM_SETSEL,1,3);//设置选中 EM_GETSEL取到选中
m_edit3.SetFocus(); //EM开头的消息是指编辑框中的消息
添加分隔窗体 添加一个图片控件 IDC_SEPARATOR 一个按钮 IDC_BUTTON1
CString str;
if(GetDlgItemText(IDC_BUTTON1, str), str == "收缩<<")
{
SetDlgItemText(IDC_BUTTON1,_T("扩展>>"));
}
else
{
SetDlgItemText(IDC_BUTTON1,_T("收缩<<"));
}
static CRect rectLarge;
static CRect rectSmall;
if(rectLarge.IsRectNull())
{
CRect rectSeparator;
GetWindowRect(&rectLarge);
GetDlgItem(IDC_SEPARATOR)->GetWindowRect(&rectSeparator);
rectSmall.left=rectLarge.left;
rectSmall.top=rectLarge.top;
rectSmall.right=rectLarge.right;
rectSmall.bottom=rectSeparator.bottom;
}
if(str=="收缩<<")
{
SetWindowPos(NULL,0,0,rectSmall.Width(),rectSmall.Height(),
SWP_NOMOVE | SWP_NOZORDER);
}
else
{
SetWindowPos(NULL,0,0,rectLarge.Width(),rectLarge.Height(),
SWP_NOMOVE | SWP_NOZORDER);
}
//----------265--------------------------略一部份