VC++孙鑫课本代码.docx
- 文档编号:17927293
- 上传时间:2023-08-05
- 格式:DOCX
- 页数:20
- 大小:18.54KB
VC++孙鑫课本代码.docx
《VC++孙鑫课本代码.docx》由会员分享,可在线阅读,更多相关《VC++孙鑫课本代码.docx(20页珍藏版)》请在冰点文库上搜索。
VC++孙鑫课本代码
来自孙鑫的视频教程
1、画图
HDChdc;
hdc=:
:
GetDC(m_hWnd);
MoveToEx(hdc,m_Point.x,m_Point.y,NULL);
LineTo(hdc,point.x,point.y);
:
:
ReleaseDC(m_hWnd,hdc);
*/
/*CDC*pDC=GetDC();
pDC->MoveTo(m_Point);
pDC->LineTo(point);
ReleaseDC(pDC);
*/
//CClientDCdc(this);
/*CClientDCdc(GetParent());
dc.MoveTo(m_Point);
dc.LineTo(point);*/
/*
CWindowDCdc(GetDesktopWindow());
dc.MoveTo(m_Point);
dc.LineTo(point);
*/
/*CPenpen(PS_DOT,1,RGB(255,0,20));
CClientDCdc(this);
CPen*pOldPen=dc.SelectObject(&pen);
dc.MoveTo(m_Point);
dc.LineTo(point);
dc.SelectObject(pOldPen);
*/
/*CBrushbrush(RGB(255,0,0));
CClientDCdc(this);
dc.FillRect(CRect(m_Point,point),&brush);
*/
/*位图
CBitmapbitmap;
bitmap.LoadBitmap(IDB_BITMAP1);
CBrushbrush(&bitmap);
CClientDCdc(this);
dc.FillRect(CRect(m_Point,point),&brush);
*/
//可以看到先前的内容。
/*CClientDCdc(this);
CBrush*pBrush=CBrush:
:
FromHandle((HBRUSH)GetStockObject(NULL_BRUSH));
CBrush*pOldBrush=dc.SelectObject(pBrush);
dc.Rectangle(CRect(m_Point,point));
dc.SelectObject(pOldBrush);*/
2单文档//定时器、字体变色、字体选择、输入文字。
voidCsingledocView:
:
OnDraw(CDC*pDC)
{
CsingledocDoc*pDoc=GetDocument();
ASSERT_VALID(pDoc);
if(!
pDoc)
return;
//TODO:
在此处为本机数据添加绘制代码
CStringstr;str="jianghuming";
CSizesz=pDC->GetTextExtent(str);
pDC->TextOut(59,57,str);str.LoadString(101);pDC->TextOut(0,400,str);
pDC->BeginPath();
pDC->Rectangle(59,57,59+sz.cx,57+sz.cy);
pDC->EndPath();
pDC->SelectClipPath(RGN_DIFF);
for(inti=0;i<300;i+=10)
{
pDC->MoveTo(0,i);
pDC->LineTo(300,i);
pDC->MoveTo(i,0);
pDC->LineTo(i,300);
}}
intCsingledocView:
:
OnCreate(LPCREATESTRUCTlpCreateStruct)
{
if(CView:
:
OnCreate(lpCreateStruct)==-1)
return-1;
//TODO:
在此添加您专用的创建代码
CClientDCdc(this);
TEXTMETRICtm;
dc.GetTextMetrics(&tm);
//CreateSolidCaret(tm.tmAveCharWidth/8,tm.tmHeight);
bitmap.LoadBitmapA(IDB_BITMAP1);
CreateCaret(&bitmap);
ShowCaret();
SetTimer(1,100,NULL);
return0;
}
voidCsingledocView:
:
OnChar(UINTnChar,UINTnRepCnt,UINTnFlags)
{
//TODO:
在此添加消息处理程序代码和/或调用默认值
CClientDCdc(this);
CFontfont;
font.CreatePointFont(300,"华文行楷",NULL);
CFont*old=dc.SelectObject(&font);
TEXTMETRICtm;
dc.GetTextMetrics(&tm);
if(0x0d==nChar)
{
m_String.Empty();
m_Point.y+=tm.tmHeight;
}
elseif(0x08==nChar)
{
COLORREFclr=dc.SetTextColor(dc.GetBkColor());
dc.TextOut(m_Point.x,m_Point.y,m_String);
m_String=m_String.Left(m_String.GetLength()-1);
dc.SetTextColor(clr);
}
else
{
m_String+=(char)nChar;
}
CSizesz=dc.GetTextExtent(m_String);
CPointpt;
pt.x=m_Point.x+sz.cx;
pt.y=m_Point.y;
SetCaretPos(pt);
dc.TextOut(m_Point.x,m_Point.y,m_String);
dc.SelectObject(old);
CView:
:
OnChar(nChar,nRepCnt,nFlags);
}
voidCsingledocView:
:
OnLButtonDown(UINTnFlags,CPointpoint)
{
//TODO:
在此添加消息处理程序代码和/或调用默认值
SetCaretPos(point);
m_String.Empty();
m_Point=point;
CView:
:
OnLButtonDown(nFlags,point);
}
voidCsingledocView:
:
OnTimer(UINT_PTRnIDEvent)
{
//TODO:
在此添加消息处理程序代码和/或调用默认值
m_nwidth+=5;
CClientDCdc(this);
TEXTMETRICtm;
dc.GetTextMetrics(&tm);
CRectrect;
rect.left=0;
rect.top=400;
rect.right=m_nwidth;
rect.bottom=rect.top+tm.tmHeight;
dc.SetTextColor(RGB(255,0,0));
CStringstr;
str.LoadString(101);
dc.DrawText(str,rect,DT_LEFT);
CRectrect2;
rect2.left=0;
rect2.top=100;
rect2.right=m_nwidth;
rect2.bottom=rect.top+tm.tmHeight;
dc.DrawText(str,rect2,DT_RIGHT);
CSizesz=dc.GetTextExtent(str);
if(m_nwidth>sz.cx)
{
m_nwidth=0;
dc.SetTextColor(RGB(0,255,0));
dc.TextOut(0,400,str);
}
CView:
:
OnTimer(nIDEvent);
}
3、对话框1
voidCTestDlg:
:
OnBtnAdd()
{
//TODO:
Addyourcontrolnotificationhandlercodehere
/*staticBOOLbIsCreate=FALSE;
//if(m_bIsCreate==FALSE)
if(bIsCreate==FALSE)
{
m_btn.Create("维新",BS_DEFPUSHBUTTON|WS_VISIBLE|WS_CHILD,
CRect(0,0,100,100),this,123);
//m_bIsCreate=TRUE;
bIsCreate=TRUE;
}
else
{
m_btn.DestroyWindow();
//m_bIsCreate=FALSE;
bIsCreate=FALSE;
}*/
/*if(!
m_btn.m_hWnd)
{
m_btn.Create("维新",BS_DEFPUSHBUTTON|WS_VISIBLE|WS_CHILD,
CRect(0,0,100,100),this,123);
}
else
{
m_btn.DestroyWindow();
}*/
/*intnum1,num2,num3;
charch1[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);*/
/*intnum1,num2,num3;
charch1[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);*/
/*intnum1,num2,num3;
num1=GetDlgItemInt(IDC_EDIT1);
num2=GetDlgItemInt(IDC_EDIT2);
num3=num1+num2;
SetDlgItemInt(IDC_EDIT3,num3);*/
/*UpdateData();
m_num3=m_num1+m_num2;
UpdateData(FALSE);*/
/*intnum1,num2,num3;
charch1[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);*/
/*intnum1,num2,num3;
charch1[10],ch2[10],ch3[10];
//:
:
SendMessage(GetDlgItem(IDC_EDIT1)->m_hWnd,WM_GETTEXT,10,(LPARAM)ch1);
//:
:
SendMessage(m_edit1.m_hWnd,WM_GETTEXT,10,(LPARAM)ch1);
//GetDlgItem(IDC_EDIT1)->SendMessage(WM_GETTEXT,10,(LPARAM)ch1);
m_edit1.SendMessage(WM_GETTEXT,10,(LPARAM)ch1);
m_edit2.SendMessage(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);*/
intnum1,num2,num3;
charch1[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,0,-1);
m_edit3.SetFocus();
}
voidCTestDlg:
:
OnNumber1()
{
//TODO:
Addyourcontrolnotificationhandlercodehere
CStringstr;
if(GetDlgItem(IDC_NUMBER1)->GetWindowText(str),str=="Number1:
")
{
GetDlgItem(IDC_NUMBER1)->SetWindowText("数值:
");
}
else
{
GetDlgItem(IDC_NUMBER1)->SetWindowText("Number1:
");
}
}
voidCTestDlg:
:
OnButton2()
{
//TODO:
Addyourcontrolnotificationhandlercodehere
CStringstr;
if(GetDlgItemText(IDC_BUTTON2,str),str=="收缩<<")
{
SetDlgItemText(IDC_BUTTON2,"扩展>>");
}
else
{
SetDlgItemText(IDC_BUTTON2,"收缩<<");
}
staticCRectrectLarge;
staticCRectrectSmall;
if(rectLarge.IsRectNull())
{
CRectrectSeparator;
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);
}
}
voidCTestDlg:
:
OnOK()
{
//TODO:
Addextravalidationhere
//GetDlgItem(IDC_EDIT1)->GetNextWindow()->SetFocus();
//GetFocus()->GetNextWindow()->SetFocus();
//GetFocus()->GetWindow(GW_HWNDNEXT)->SetFocus();
GetNextDlgTabItem(GetFocus())->SetFocus();
//CDialog:
:
OnOK();
}
WNDPROCprevProc;
LRESULTCALLBACKWinSunProc(
HWNDhwnd,//handletowindow
UINTuMsg,//messageidentifier
WPARAMwParam,//firstmessageparameter
LPARAMlParam//secondmessageparameter
)
{
if(uMsg==WM_CHAR&&wParam==0x0d)
{
//:
:
SetFocus(:
:
GetNextWindow(hwnd,GW_HWNDNEXT));
//SetFocus(:
:
GetWindow(hwnd,GW_HWNDNEXT));
SetFocus(:
:
GetNextDlgTabItem(:
:
GetParent(hwnd),hwnd,FALSE));
return1;
}
else
{
returnprevProc(hwnd,uMsg,wParam,lParam);
}
}
BOOLCTestDlg:
:
OnInitDialog()
{
CDialog:
:
OnInitDialog();
//TODO:
Addextrainitializationhere
prevProc=(WNDPROC)SetWindowLong(GetDlgItem(IDC_EDIT1)->m_hWnd,GWL_WNDPROC,
(LONG)WinSunProc);
returnTRUE;//returnTRUEunlessyousetthefocustoacontrol
//EXCEPTION:
OCXPropertyPagesshouldreturnFALSE
}
4、对话框2
BOOLCProp1:
:
OnSetActive()
{
//TODO:
Addyourspecializedcodehereand/orcallthebaseclass
((CPropertySheet*)GetParent())->SetWizardButtons(PSWIZB_NEXT);
returnCPropertyPage:
:
OnSetActive();
}
LRESULTCProp1:
:
OnWizardNext()
{
//TODO:
Addyourspecializedcodehereand/orcallthebaseclass
UpdateData();
if(m_occupation==-1)
{
MessageBox("请选择你的职业!
");
return-1;
}
if(m_workAddr=="")
{
MessageBox("请选择你的工作地点!
");
return-1;
}
returnCPropertyPage:
:
OnWizardNext();
}
BOOLCProp1:
:
OnInitDialog()
{
CPropertyPage:
:
OnInitDialog();
//TODO:
Addextrainitializationhere
((CListBox*)GetDlgItem(IDC_LIST1))->AddString("北京");
((CListBox*)GetDlgItem(IDC_LIST1))->AddString("天津");
((CListBox*)GetDlgItem(IDC_LIST1))->AddString("上海");
returnTRUE;//returnTRUEunlessyousetthefocustoacontrol
//EXCEPTION:
OCXPropertyPagesshouldreturnFALSE
}
///////////////////////////////////////////////////////////////////////////////////
BOOLCProp2:
:
OnSetActive()
{
//TODO:
Addyourspecializedcodehereand/orcallthebaseclass
((CPropertySheet*)GetParent())->SetWizardButtons(PSWIZB_BACK|PSWIZB_NEXT);
returnCPropertyPage:
:
OnSetActive();
}
LRESULTCProp2:
:
OnWizardNext()
{
//TODO:
Addyourspecializedcodehereand/orcallthebaseclass
UpdateData();
if(m_football||m_basketball||m_volleyball||m_swim)
{
returnCPropertyPage:
:
OnWizardNext();
}
else
{
MessageBox("请选择你的兴趣爱好!
");
return-1;
}
}
///////////////////////////////////////////////////////////////////////////////////////
BOOLCProp3:
:
OnSetActive()
{
//
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- VC 课本 代码