《零点起飞学Visual C++习题答案》由会员分享,可在线阅读,更多相关《零点起飞学Visual C++习题答案(9页珍藏版)》请在金锄头文库上搜索。
1、习题 2.101.#include int main()for(int i = 7;i int main()int i,j;for( i = 0;i int main()int array10=15,85,94,68,35,78,68,45,84,31;int i,j,temp;for(i = 0;i 0)out m_hWnd)pdlg-ShowWindow(SW_SHOW);elsepdlg = new dlgCreate(NULL);pdlg-Create(IDD_DIALOG2,NULL);pdlg-ShowWindow(SW_SHOW);2.void CMFC3Dlg:OnButton
2、1() /字体对话框/ TODO: Add your control notification handler code hereCFontDialog dlg;dlg.DoModal();void CMFC3Dlg:OnButton2() /颜色对话框/ TODO: Add your control notification handler code hereCColorDialog dlg(RGB(255,255,255);dlg.DoModal();void CMFC3Dlg:OnButton3() /打开对话框/ TODO: Add your control notification
3、handler code herestatic char filter = 文本文件(.txt)|*.txt| 音乐文件(.mp3 )|*.mp3|;CFileDialog dlg(TRUE,wma,NULL,OFN_ALLOWMULTISELECT,filter,NULL);dlg.DoModal();3.void CMFC4Dlg:OnOK() / TODO: Add extra validation here:MessageBox(NULL,DialogBox,chapter 06,MB_YESNO | MB_ICONERROR);CDialog:OnOK();习题 7.101.按确定按
4、钮弹出消息的实现代码void CTestView:OnButton2() / TODO: Add your control notification handler code here UpdateData(true);CString msg;msg = name :;msg += m_name;msg += age: ;char str10;itoa(m_age,str,10);msg += str;msg += phoneNumber: ;msg += m_phoneNumber;AfxMessageBox(msg);习题 8.12void CTestDlg:Onreview() / TO
5、DO: Add your control notification handler code hereCString message = ;message = 个人简历:n 姓名:;CString str;m_name.GetWindowText(str);message += str;message += n 性别:;if(m_boy.GetCheck() = 1)message += 男;else if(m_girl.GetCheck() = 1)message += 女;elsemessage += 未选择;message += n 兴趣爱好:;if(m_eatting.GetCheck
6、() = 1)message += 吃零食 ;if(m_shopping.GetCheck() = 1)message += 逛街 ;if(m_sleep.GetCheck() = 1)message += 睡觉 ;if(m_read.GetCheck() = 1)message += 看书;message += n 政治面貌:;int choose = m_combo1.GetCurSel();m_combo1.GetLBText(choose,str);message += str;m_view.SetWindowText(message);习题 9.101.(3 )void CTestV
7、iew:OnSquare() / TODO: Add your command handler code hereCDraw dlg;dlg.m_point = 左上角点;dlg.m_length = 边长;if(IDOK = dlg.DoModal()CClientDC dc(this);dc.Rectangle(dlg.m_x,dlg.m_y,dlg.m_x + dlg.m_len,dlg.m_y + dlg.m_len);(5 )void CTestView:OnLButtonUp(UINT nFlags, CPoint point) / TODO: Add your message h
8、andler code here and/or call defaultCClientDC dc(this);dc.Rectangle(start.x,start.y,point.x,point.y);CView:OnLButtonUp(nFlags, point);(6 )void CTestView:OnMouseMove(UINT nFlags, CPoint point) / TODO: Add your message handler code here and/or call defaultCString str = ;str.Format(鼠标当前位置:%d %d,point.x
9、,point.y);CMainFrame *pmain = (CMainFrame *)AfxGetMainWnd();CStatusBar*pstatus=(CStatusBar*)pmain-GetDescendantWindow(AFX_IDW_STATUS_BAR);pstatus-SetPaneInfo(1,IDS_MOUSE,SBPS_NORMAL,150);pstatus-SetPaneText(1,str);CView:OnMouseMove(nFlags, point);习题 10.8(3 )dlg.GetCurrentFont((4 )v_blue = dlg.m_blue
10、;v_green = dlg.m_green;v_red = dlg.m_red;v_style = dlg.m_style;v_width = dlg.m_width;v_log = dlg.log;v_text = dlg.m_text;(5 )start = point;end = point;(6 )pDC-MoveTo(start);pDC-LineTo(end);pDC-TextOut(0,0,v_text)习题 11.61.#include #include int main()ofstream out;out.open(say.txt/*,ios:out,filebuf:sh_
11、write */);out #include #include int main()CRegKey key;key.Create(HKEY_CURRENT_USER,Softwaretest);key.SetValue(good,);key.SetValue(123,test1);DWORD value;key.QueryValue(value,test1);cout #include int main()LPCTSTR lpFileName = d:try.ini;CString str;char c10;WritePrivateProfileString(section_1,key1,tr
12、y1,lpFileName);GetPrivateProfileString(section_1,key1,error,c,10,lpFileName);str.Format(%s,c);cout SetWindowText();WaitForSingleObject(semaphoreWrite.m_hObject,INFINITE);CString str;for(int i=0;iGetWindowText(str);g_Arrayi=Z - i;str=str+g_Arrayi;pEdit-SetWindowText(str);Sleep(1000);ReleaseSemaphore(
13、semaphoreWrite.m_hObject,1,NULL);return 0;(5 )void CTestDlg:OnShow() / TODO: Add your control notification handler code hereCWinThread *pWriteA=AfxBeginThread(WriteA, /线程 1&m_A,THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);pWriteA-ResumeThread();CWinThread *pWriteZ=AfxBeginThread(WriteZ, /线程 2&m_Z,THRE
14、AD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);pWriteZ-ResumeThread();习题 16.6/client.cpp#include #include #include #pragma comment(lib,WS2_32.lib)int main()WSADATA wsaData; /声明 WSADATA 结构体WORD sockVersion = MAKEWORD(2,2); /声明 sock 版本信息SOCKET sock = 0; /声明套接字if(WSAStartup(sockVersion,&wsaData) != 0) /初始化 WSA
15、DATA 结构体cout 0)buffernRecv = 0; /添加结束字符cout #include #include #pragma comment(lib,WS2_32.lib)int main()WSADATA wsaData;WORD sockVersion = MAKEWORD(2,2);SOCKET sListen = 0;/声明套接字sockaddr_in sin = 0; /声明本地套接字地址结构sockaddr_in remoteAddr = 0; /声明远程套接字地址结构char szText = This Message is from TCP Server; /发送信息int nAddrLen = 0; /地址长度nAddrLen = sizeof(sockaddr_in);/填充套接字地址结构sin.sin_port = htons(4567);/端口sin.sin_family = AF_INET;sin.sin_addr.S_un.S_addr = INADDR_ANY;/初始化 WSADATA 结构体if(WSAStartup(sockVersion,&wsaData) != 0)cout Initlization failed!