如何操作控件的DDX方法

No9 2000-05-28 05:58:00
我最近写了一个程序,需要直接得到编辑框中的浮点数的数值,却发现原来的DDX方法不行,当用户输入未完成时,(比如要输入‘2.0’,已经输入‘2.’时,更新后自动变成了‘2’),于是我想要自行控制控件的DDX方法,我想派生一个新类,去重载DDX方法,不知道该如何处理,请指教?
...全文
195 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
No9 2000-06-28
  • 打赏
  • 举报
回复
谢谢 jiangsheng 的指点,您的意思我明白了!
蒋晟 2000-06-20
  • 打赏
  • 举报
回复
See TN026 in MSDN.
No9 2000-06-19
  • 打赏
  • 举报
回复
本人愚钝,直到目前还没有 jiangsheng 的意思,不知道是不是少了一部分文字/代码,再次烦请你解释一下,好吗?
谢谢!
蒋晟 2000-06-17
  • 打赏
  • 举报
回复
// 必须已经设置好10位的长度限制和number风格
void extern AFXAPI DDX_Text_DWORD(CDataExchange* pDX, UINT nIDC,DWORD& rDWord)
{
CString string,MaxString,ErrMsg;

pDX->m_pDlgWnd->GetDlgItem(nIDC)->GetWindowText(string);
while (string.GetLength() > 0) {
if (string.GetAt(0) == '0')
string=string.Right(string.GetLength() - 1);
else
break;
}
if (string.GetLength() > 10) {
string.Format("错误:输入的数字太长!\n长度不能大于%d!",10);
AfxMessageBox(string);
pDX->Fail();
return; // fail
}
if (string.GetLength() == 10) {
MaxString.Format("%u",ULONG_MAX);
if (string > MaxString) {
ErrMsg.Format("错误:输入的数字太大:%s!\n输入的数字不能大于%u!",string,ULONG_MAX);
AfxMessageBox(ErrMsg);
pDX->Fail();
return; // fail
}
}

// call the system's DDX_Text
DDX_Text(pDX,nIDC,rDWord);
}

void AFXAPI DDX_DateTimeCtrl(CDataExchange* pDX, UINT nIDC,COleDateTimeSpan& tmspn)
{
HWND hWndCtrl = pDX->PrepareCtrl(nIDC);
CDateTimeCtrl* pWnd = (CDateTimeCtrl*) CWnd::FromHandle(hWndCtrl);
if(!pWnd) return;
COleDateTime tmTemp,tmBase;

if(pDX->m_bSaveAndValidate){
pWnd->GetTime(tmTemp);
tmspn=tmTemp-tmBase;
}
else{
tmTemp=tmspn+tmBase;

if(::IsWindow(pWnd->m_hWnd))
pWnd->SetTime(tmTemp);
}
}
No9 2000-06-17
  • 打赏
  • 举报
回复
为什么还是没有人回答我呀,我好急呀......
No9 2000-06-07
  • 打赏
  • 举报
回复
噢!我还不知道该如何加分呢?
No9 2000-06-07
  • 打赏
  • 举报
回复
为什么我发表了多日,至今还是没人回应,我好伤心呀,好着急呀!
难道是太难吗?高手那么多,这么可能!
难道是分数太少吗?我现在加分求解!
还可能是......
词法分析// TranslationDlg.cpp : 实现文件 // #include "stdafx.h" #include "Translation.h" #include "TranslationDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #endif // 用于应用程序“关于”菜单项的 CAboutDlg 对话框 class CAboutDlg : public CDialog { public: CAboutDlg(); // 对话框数据 enum { IDD = IDD_ABOUTBOX }; protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 // 实现 protected: DECLARE_MESSAGE_MAP() }; CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) { } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); } BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) END_MESSAGE_MAP() // CTranslationDlg 对话框 CTranslationDlg::CTranslationDlg(CWnd* pParent /*=NULL*/) : CDialog(CTranslationDlg::IDD, pParent) { m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CTranslationDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); DDX_Control(pDX, IDC_EDIT2, content); DDX_Control(pDX, IDC_EDIT1, result); } BEGIN_MESSAGE_MAP(CTranslationDlg, CDialog) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() //}}AFX_MSG_MAP ON_BN_CLICKED(IDC_BUTTON1, &CTranslationDlg::OnBnClickedButton1) END_MESSAGE_MAP() // CTranslationDlg 消息处理程序 BOOL CTranslationDlg::OnInitDialog() { CDialog::OnInitDialog(); // 将“关于...”菜单项添加到系统菜单中。 // IDM_ABOUTBOX 必须在系统命令范围内。 ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != NULL) { CString strAboutMenu; strAboutMenu.LoadString(IDS_ABOUTBOX); if (!strAboutMenu.IsEmpty()) { pSysMenu->AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); } } // 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动 // 执行此操作 SetIcon(m_hIcon, TRUE); // 设置大图标 SetIcon(m_hIcon, FALSE); // 设置小图标 // TODO: 在此添加额外的初始化代码 CAboutDlg dlgAbout; dlgAbout.DoModal(); return TRUE; // 除非将焦点设置到控件,否则返回 TRUE } void CTranslationDlg::OnSysCommand(UINT nID, LPARAM lParam) { if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } else { CDialog::OnSysCommand(nID, lParam); } } // 如果向对话框添加最小化按钮,则需要下面的代码 // 来绘制该图标。对于使用文档/视图模型的 MFC 应用程序, // 这将由框架自动完成。 void CTranslationDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // 用于绘制的设备上下文 SendMessage(WM_ICONERASEBKGND, reinterpret_cast(dc.GetSafeHdc()), 0); // 使图标在工作区矩形中居中 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; // 绘制图标 dc.DrawIcon(x, y, m_hIcon); } else { CDialog::OnPaint(); } } //当用户拖动最小化窗口时系统调用此函数取得光标 //显示。 HCURSOR CTranslationDlg::OnQueryDragIcon() { return static_cast(m_hIcon); } void CTranslationDlg::SplideFrontSpc (CString &str) { int i = 0; for(i;str[i]==' ';) {str.Delete (0);}//MessageBox (_T("ok")); } void CTranslationDlg::OnBnClickedButton1() { // TODO: 在此添加控件通知处理程序代码 CString code ,temp ,output; //CString word[8] = ; CString flag[3][10] = {{_T("if"),_T("int"),_T("for"),_T("while"),_T("do"),_T("return"),_T("break"),_T("continue")}, {_T("+"),_T("-"),_T("*"),_T("/"),_T("="),_T(">"),_T("<"),_T("<="),_T(">="),_T("!=")}, { _T(","),_T(";"),_T("{"),_T("}"),_T("("),_T(")")}}; content.GetWindowTextW (code); code.Replace (_T("\r\n"),_T("")); code.Append (_T(" ")); while(!code.IsEmpty ()) { temp.Empty (); int i,j; int isfind = 0;//是否找到,找到了代表其类型 SplideFrontSpc(code); //temp = code.Left (code.Find (_T(","))); //code.Delete (0,2);//temp = code[0]; //截取下一个单词 temp = code.Left (code.Find (_T(" "))); code.Delete (0,code.Find (_T(" "))); //对比单词类型 for(i=0;!isfind&&i<3;i++) for(j=0;j<10;j++) if(temp == flag[i][j]) { if(i==0) isfind = 1; else if(i==1) isfind = 4; else isfind = 5; break; } if(isfind==0) { int isnum = temp[0]-'0'; if(isnum>-1||isnum<10) isfind = 3; else isfind = 2; } CString cnum; cnum.Format (_T("%d"),isfind); if(!temp.IsEmpty ()) temp = _T("(") + cnum + _T(", \"") + temp + _T("\")"); else temp = _T("词法分析完毕!\r\n"); output = output + temp + _T("\r\n"); } //output = _T("asdjfk\r\naksdjfl\nasldkfj\n"); result.SetWindowTextW (output); } BOOL CTranslationDlg::PreTranslateMessage(MSG* pMsg) { // TODO: 在此添加专用代码和/或调用基类 return CDialog::PreTranslateMessage(pMsg); } void CTranslationDlg::OnOK() { // TODO: 在此添加专用代码和/或调用基类 CDialog::OnOK(); }
1,01.zipMFC Extension LibraryMFC扩展界面库, 使用Visual C++ 6.0(15KB)2,02.zipVisual Studio style UIVisual Studio风格的界面效果(15KB)3,03.zipInternet Explorer 4 style UIIE4.0风格的界面效果(29KB)4,04.zipOutlook Style UIOutlook风格的界面效果(16KB)5,05.zipDynamic child window repositioning动态改变对话框的大小, 对话框中的控件相应改变(15KB)6,06.zipEnhanced list control增强的List控件(43KB)7,07.zipCDialog using animated control在CDialog中使用动画(12KB)8,08.zipOpen Dialog with Bitmap Preview位图预览的打开文件对话框(43KB)9,09.zipStandard file open dialog with preview标准位图预览的打开文件对话框(24KB)10,10.zipBitmap Dialog Class位图对话框类(13KB)11,11.zipClass for Browsing shell namespace with your own dialog显示目录的树型结构, 可用于目录的选择(31KB)12,12.zipUsing ON_UPDATE_COMMAND_UI with dialogs在对话框中使用ON_UPDATE_COMMAND_UI(13KB)13,13.zipUsing ON_UPDATE_COMMAND_UI with dialogs (2)使用ON_UPDATE_COMMAND_UI(11KB)14,14.zipModeless child dialog in a Main Dialog with corrected tab order非模式对话框在主对话框中的TAB顺序(21KB)15,15.zipCostumizing CFileDialog定制的CFileDialog(22KB)16,16.zipAttaching Elements to Borders一个可以在对话框中改变按纽位置、大小的容器(26KB)17,17.zipScrolling credits dialog滚动信用对话框(12KB)18,18.zipColor Dialog with Persistent Custom Colors对话框继承了上一次的颜色风格(12KB)19,19.zipA Base Dialog Class for Modal/Modeless Dialog with Custom Background Color自定义背景的对话框(13KB)20,20.zipParse IP addresses解析IP地址(12KB)21,21.zipParse phone fields解析电话区域(11KB)22,22.zipChanging the default file open/save dialogs in an MFC doc/view application初始化对话框和支持动态数据交换(DDX)(15KB)23,23.zipDialog with Splash Screen Example Code...Splash对话框的例子(18KB)24,24.zipClass to select directory选择目录的类(13KB)25,25.zipClass to select directory (Enhancements)增强的选择目录的类(12KB)26,26.zipDirectory Picker Dialog目录采集对话框(42KB)27,27.zipSimple way to change dialog's background and text colors改变对话框背景颜色和文字颜色的简单途径(11KB)28,28.zipA Simple Dialog Layout Manager一个简单的对话框设计管理器(19KB)29,29.zipUsing Buttons on a Dialog Bar with CCmdUI通过CCmdUI在对话框条中使用按纽(19KB)30,30.zipDisplay help for dialog controls on the status bar在状态条中显示对话框中控件的帮助信息(12KB)31,31.zipDragging a dialog by clicking anywhere on it点击任何地方拖动对话框(11KB)32,32.zipSplash screen with text on it that uses its own thread通过自己的线程在Splash对话框中显示文字(136KB)33,33.zipCreating an expanding dialog创建一个可扩展的对话框(15KB)34,34.zipExpanding/Contracting Dialog Box扩展/缩小对话框(24KB)35,35.zipCFileDialog class that only displays folders让CFileDialog只显示目录(很有用)(2KB)36,36.zipFolder Browsing Dialog目录浏览对话框(3KB)37,37.zipFont dialog with custom text preview & color字体对话框中增加字体和颜色的预览(12KB)38,38.zipEmbedding an HTML Help window into a dialog嵌入一个超文本(HTML)的帮助窗口到对话框中(22KB)39,39.zipDialog which can be used as MDI child window使用MDI子窗口的对话框(13KB)40,40.zipConvert modal dialogs to modeless将模式对话框转换成非模式对话框(12KB)41,41.zipNetscape 4.x Preferences Dialog类似Netscape 4.x参数选择的对话框(7KB)42,42.zipHandling OnUpdate() processing for menu itemsOnUpdate()处理菜单项(5KB)43,43.zipOptions Tree Dialog树状的配置对话框(25KB)44,44.zipCustomizing the font dialog定制的字体对话框(4KB)45,45.zipSizable dialogs at its easiest轻松改变对话框的大小(5KB)46,46.zipA Snap Size Dialog Class一个捕获对话框大小的类(5KB)47,47.zipCSplitterWnd in a Dialog based Application一个基于对话框的应用(6KB)48,48.zipSplash Screen with 256 color support支持256色的Splash对话框(7KB)49,49.zipSubselection Dialog 子项选择的对话框(5KB)50,50.zipSwitching dialog boxes in a dialog-based application在基于对话框应用中切换对话框(5KB)51,51.zipBetter Tip of the Day dialog典型的Did you konw...对话框(26KB)52,52.zipToolbars and Statusbars on Dialogs在对话框中增加工具条和状态条(7KB)53,53.zipTooltips in modal dialog boxes在模式对话框中实现工具提示(6KB)54,54.zipTooltips for dialog controls实现对话框控件的工具提示(4KB)55,55.zipTransparent Dialog透明的对话框(5KB)56,56.zipViewing Dialog Template Resources at Runtime运行时看对话框模板资源(5KB)57,57.zipAlternative Wizard Dialog一个Wizard对话框, 在安装程序中也有用(5KB)58,58.zipAVLTree实现AVL(Addison-Velski and Landis)树结构(5KB)59,59.zipTemplate class to manipulate bits of undefined type一个操作未知类型的模板库(5KB)60,60.zipBlowfish EncryptionBlowfish加密算法加密(4KB)61,61.zipBlowfish encryption classBlowfish加密类(5KB)62,62.zipExpression Evaluation数学公式识别类(5KB)63,63.zipA Y2.038K-Safe Replacement for CTimeCTime的替换类(5KB)64,64.zipIterating through List Containers关于List容器的话题(5KB)65,65.zipLexical Analyser词汇分析(8KB)66,66.zipLocales and Facets in Visual C++VC++的许多细节话题(10KB)67,67.zipA Generalized Parsing Class for MFC一个普通的MFC解析类(5KB)68,69.zipCreating Singleton Objects using Visual C++使用VC++创建一个单独的对象(9KB)69,69.zipSmart Pointers and other Pointer classes指针类(5KB)70,70.zipSortable CObArray class对CObArray类排序(5KB)71,71.zipSortable CObList class对CObList类排序(6KB)72,72.zipExtension to the STL find_if and for_each扩充STL库(5KB)73,73.zipChange from child window to popup window (and back) 将一个子窗口改成弹出式窗口(5KB)74,74.zipRestoring Window Position With Multiple Monitors在多层监视器中恢复窗口的位置(5KB)75,75.zipTransparent Window透明的窗口(6KB)76,CenterMDIWnd_demo.zipCenter CMDIChildWnds in the client area of the main frame window(151KB)77,TabbedMDI.zipA variation on the MDI that indicates the open child windows in a tab control. (400KB)78,AdvancedPrev.zipA simple class that helps provide faster Print Preview within MFC Doc/View applications(38KB)79,mditab.zipA dockable bar containing a tabbed list of open windows(91KB)80,CloseUnusedDocs_src.zipClosing unused MDI documents with 1 line of code(2KB)81,graphfx_demo.zipA Doc/View framework for displaying graphical data(192KB)82,WindowsManager.zipImplementing "Windows..." dialog(39KB)83,MultiMRUList_src.zipThis article describes how to maintain the separate MRU list for each document type that is needed in some applications(26KB)84,MultiTop.zipAllows an application to have multiple top-level windows. (22KB)85,PersistFrames.zipA collection of classes that allows MFC SDI and MDI applications to remember the positions and sizes of their main frame and child frame windows. (71KB)86,step0.zipA series of articles that resulted from experimenting with adding Drag and Drop features to my existing application. (16KB)87,undo.zipEasily add Undo/Redo to your CDocument/CView Based Applciation(2KB)88,PropertyView.zipA "Property Sheet"-like view class for MFC (108KB)89,DocViewWTL.zipA library that provides the easiest way to get loosely coupled components. (156KB)90,Dialog2.zipA step by step tutorial showing how to create your first windows program using MFC(112KB)91,MyMDIApp.zipA brief step-by-step tutorial that demonstrates creating an SDI and MDI based applications using the MFC Doc/View architecture.(54KB)92,sditutorial_demo.zipA brief step-by-step tutorial that demonstrates creating an SDI based application that does not use the MFC Doc/View architecture.(15KB)93,QuickWin.zipRedirect stdin, stdout and stderr into a window(125KB)94,GradientTitleBar.zipThis article shows you how to give your Win95/NT4 modeless dialogs a Win98/W2K like gradient title bar.(42KB)95,MsgBoxDemo.zipThe system Message Box that is closed atuomatically after some time(21KB)96,step1.zipSimple step by step article explaining how to create a modeless dialog box as child window.(21KB)97,step2.zipSimple step by step article explaining how to create a modeless dialog box as sibling of the app's main window.(22KB)98,ResizableDialog.zipA CDialog derived class to implement resizable dialogs with MFC (98KB)99,CenterAnywhere_demo.zipThis is a good replacement for CWnd::CenterWindow() that works. (43KB)100,CardDialog.zipA auto-sizing dialog used to store and display smaller child dialogs(22KB)101,scrolling_credits.zipA Scrolling Credits Dialog(209KB)102,snapdialog.zipDialog class that implement a snap-to-screen-border feature like Winamp(16KB)103,messagebox.zipA class which encapsulates MessageBoxIndirect.(18KB)104,rfldlg.zipThis article demonstrates how to add a recent file list to a dialog based application(25KB)105,dialogspl_demo.zipSplash screens are not only for Doc/View based applications(142KB)106,CClockCtrl_src.zipA Freeware MFC class to display an analog clock.(17KB)107,ChildDlg.zipChild Dialog (Sub Forms)(29KB)108,CIconDialog_src.zipA Freeware MFC dialog class to select an icon.(12KB)109,CPushPinFrame_src.zipA Freeware MFC PushPin property page dialog class.(19KB)110,showhide.zipA neat way to show/hide groups of related controls(13KB)111,ResizeCtrl.zipA resize control to implement resizable dialogs with MFC(38KB)112,DDXFile_src.zipA Freeware DDX routine for selecting a filename.(29KB)113,DynWindow_src.zipDescribes a method to implement resizable child windows.(108KB)114,DynamicDialog.zipCreate dialogs dynamically, and easily, without the need for a dialog resource script.(40KB)115,DlgExpand.zipThis article shows gives you the ability to make your dialogs expand or contract, depending on how much information the user wishes to view(15KB)116,TipDemo.zipImproved Tip-of-the-Day Dialog(149KB)117,layoutmgr.zipA framework to provide automatic layout control for dialogs and forms(101KB)118,MainWndPlacement.zipSave/restore the main window size at application exit/startup with a single function call in MDI, SDI and dialog based applications.(29KB)119,sizer_demo.zipAn article on extendable layout management classes(27KB)120,Splasher_src.zipAn improved splash screen component for MFC.(62KB)121,StackDialog.zipCreating a stacked dialog such as Netscape's 'Preferences' dialog(22KB)122,bitmappreviewdialog_src.zipThis article describes a completely object oriented standard file open dialog with preview.(12KB)123,subselect_dialog.zipSubselection Dialog(123KB)124,TabDialog.zipA docking dialog that auto-expands when the mouse passes over it(35KB)125,TcxMsgBox.zipTCX Message Box (derived from CWnd)(35KB)126,ToolTips.zipA demonstration of how to show tooltips in modal dialog bozes(23KB)127,UpdateModalDlg_demo.zipHow to update a modal dialog contents using a callback function(17KB)128,WinampWnd_demo.zipAn article discussing a Plugin for Nullsoft Winamp which looks and behaves like the Winamp UI.(43KB)129,Skins.zipA mini library to build Bitmap based skinnable apps.(174KB)130,FaderWnd_demo.zipAn MFC class to fade any window with only one line of code.(28KB)131,Win2kFileDlg.zipEver wanted to use the new Office 2000 file dialogs on Win 95/98/NT/Me, including the file previewing? Well now you can.(76KB)132,win2000fd.zipHow to show the new Common File Dialog in MFC Apps in Windows 2000(36KB)133,Wizard2000.zipCreate Windows 2000 style Wizards with white backgrounds(109KB)134,FileExportDialog.zipAdding filters to the Open File dialog(24KB)135,customize_dialog.zipCustomizing the Windows Common File Open Dialog(15KB)136,SelectFolder.zipThe windows 'Select Folder' dialog with some extra functionality(41KB)137,animate_dlg.zipAnimated Icon on Titlebar of a Dialog based Application(34KB)138,BmpDlg.zipBitmap Dialog Class(52KB)139,namespace.zipClass for Browsing shell namespace with your own dialog(78KB)140,OnUpdate_demo.zipHandling OnUpdate() processing for menu items(10KB)141,DialogUpdates.zipUsing ON_UPDATE_COMMAND_UI with all controls in a Dialog(18KB)142,override.zipCustomizing the font dialog(4KB)143,cmdlg.zipCostumizing CFileDialog(31KB)144,custom_open.zipCustom Open File or Save as Dialog(25KB)145,ColorFormView.zipCFormView Class with Custom Background Color(33KB)146,Banner.zipAnimated Background Banner(88KB)147,MDIClient.zipA Custom MDI Client Class(42KB)148,html_help_view.zipHTML Help In CView Window(5KB)149,MDIPreview_demo.zipPrint Preview in MDI Frame(20KB)150,zoom_scale.zipAdd Zoom and Scale Capabilities to CScrollView(338KB)151,autopan.zipAuto-Panning Windows(44KB)152,autopan2.zipMicrosoft Internet Explorer like Intellimouse AutoScroll(42KB)153,intellipan.zipIntellimouse panning (improved Auto-Panning Windows)(5KB)154,intellipan2.zipIntellimouse panning 2 (A universal Auto-Panning solution)(12KB)155,bigscroll.zipBreaking the CScrollView 32768 size limitation with CBigScrollView(90KB)156,variable_splitter.zipVariable splitter views(58KB)157,TabbedViews_src.zipTabbed Views(78KB)158,animate_icon_src.zipAnimated Icon on Titlebar of a window(48KB)159,msdi1632.zipMultiSingle (MSDI) Document interface(77KB)160,msdidao.zipMultiSingle (MSDI) Document interface with DAO doc(508KB)161,ScreenSwitch_demo.zipMultiple Views Using SDI(26KB)162,multiview.zipMultiple views for a single document (MDI) 3(86KB)163,WinMenu_demo.zipHome made MDI windows list in Window menu(21KB)164,SdiMulti.zipSDI Interface with Multi-Views and Multi-Splitters(88KB)165,DocViewInDll_demo.zipSeparating the views of an MDI application into different DLLs(60KB)166,MultiFrame_demo.zipMultiple frame windows in SDI application(76KB)167,mrcext.zipResizable Docking Window(862KB)168,sizing.zipSizing TabControlBar(46KB)169,devstudio.zipAnother DevStudio-alike DialogBar(43KB)170,docking.zipResizable Docking Window 2(98KB)171,simple_splitter.zipGeneral Purpose Splitter Class(43KB)172,cxysplitter.zipA pair of splitter classes used in dialogbox(21KB)173,dynamic_splitter.zipSplitter Window - "True" dynamic splitter window(52KB)174,outlook_style.zipOutook Style Splitter Bar(59KB)175,minsplit.zipMinimum size splitter(36KB)176,scrbsplt.zipRemoving and reapplying splitter windows on-the-fly in Scribble with a custom splitter window class(157KB)177,switchviews_in_splitter.zipSwitching views in splitter panes (SDI)(44KB)178,rulers_src.zipImplementing Rulers inside of Splitter Panes(5KB)179,dynamic1.zipDifferent Views In Dynamic Splitter(202KB)180,dialogstartupanimation.zipThis sample shows you how to create dialog startup animation like that of Window 98'menu(18KB)181,yqeditgridcontrol.zipa grid control that enable keyboard input. That is to say, you can write data in it. (31KB)182,switchmdiviews.zipThis sample shows you how to switch from one view to the other in a MDI splitter window application(31KB) 183,yqmdireplaceview.zipThis sample shows you how to replace different views in a MDI splitter window application(36KB) 184,switchview.zipThis sample shows you how to switch from one MDI window to another by using the "Ctrl Tab" key.(29KB) 185,filterreturnkey.zipThis sample shows you how to trap, filter the ENTER and ESCAPE key of a dialog box (17KB)186,filterkey.zipThis sample shows you how to filter a certain key and mask that key(18KB)187,editenter.zipThis sample shows you how to use RETURN key to switch among edit controls of a dialog box(18KB)188,dialoghook.zipThis sample shows you how to set keyboard hook function of a dialog box to trap RETURN ,ESCAPE key.(17KB) 189,contexthelp.zipThis sample shows you how to create context sensitive help of a control of a dialog box(26KB) 190,traparrokey.zipThis sample describes how to trap arrow keys in an control of a dialog box (18KB)191,yqadvancedbtn.zipOwner draw hot button support both bitmap and icon, with flat, gripper property. (108KB)192,drawlistbo.zipOwner draw CTabCtrl with flat gripper property (40KB)193,startupanimation.zipCreate Window startup animation, including several kind of animation style, very interesting(23KB) 194,flatlistbox.zipusing a unique way to implement flat attribute( other than those published on the codegurn), as well as hot ,gripper attribute.(21KB) 195,yqhoteditctrl.zipCreate edit control with Hot , flat, gripper. separator attributes (21KB)196,3dmdishadow.zipCreate 3D shadow of a MDI frame windows(32KB) 197,3dsdishadow.zipCreate 3D shadow of a SDI frame windows(29KB)198,getfile.zipA DDX routine for MFC to retrieve filenames(29KB)199,splasher.zipAn improved splash screen component for MFC(62KB)200,pushpin.zipA pushpin button MFC class(12KB)201,getfolder.zipA DDX routine for MFC to retrieve folders(30KB)202,ntray.zipAn MFC class to manipulate tray icons(17KB)203,hlinkctrl.zipAn MFC class to support hyperlinks on windows and dialogs(16KB)204,icondialog.zipAn icon selection dialog class for MFC(12KB)205,pushpinframe.zipAn MFC class to provide property dialogs ala Developer Studio(16KB)206,mappin.zipAn MFC class to implement map pins(286KB)207,iconcombobox.zip2 MFC classes to implement icon selection combo boxes(19KB)208,menuex_demo.zipImplementing an Ownerdrawn menu (35KB)209,bcmenu261.zipCool Owner Drawn Menus with BitmapsVersion 2.61(70KB)210,dynmenu.zipSome handy functions for adding and deleting submenus and menuitems in runtime (16KB)211,gradientmenu.zipCreate Popup menus in MFC with a gradient and text on the left side (89KB)212,menuicon_demo.zipGive your apps a unique look by adding a logo to your menu(48KB)213,bcgbappwizard.zipBCGControlBar library version 4.6(2121KB)214,mpcstatusbar.zipAn enhanced CStatusBar to easily and dynamically add/remove controls on a status bar (48KB)215,textonlystatusbar.zipAn easy to use and implement Text Only Status Bar with Tool tip text extracted from the status bar panes. (39KB)216,progressbar.zipShowing progress bar in a status bar pane(33KB)217,sizecbar_src.zipDevStudio-like docking window (64KB)218,sizing_tabct1_demo.zipCreates a dockable and resizable control bar. (46KB)219,dockview.zipA fairly simple way to incoporate views into sizing control bars(69KB)220,spin_slide_toolbar.zipHow to create toolbars with spinners and/or sliders(48KB)221,tearoffrebars_prj.zipThis article Implements the functionality similar to the Office 2000 toolbars(26KB)222,flatbar.zipA flat toolbar implementation that does not require the updated common controls library from Internet Explorer. (197KB)223,toolbar_droparrow_demo.zipDemonstrates how to use the new toolbar styles to add dropdown arrows to toolbar buttons (28KB)224,dynamictb.zipA simple tutorial that shows how to dynamically replace toolbars at runtime (35KB)225,toolbar_docking_demo.zipDemonstrates how to dock toolbars side-by-side (29KB)226,tapetoolbar.zipA spectacular variation on toolbars (35KB)227,chevions.zipAn introduction to using the cool new toolbar chevrons (18KB)228,toolgroupmanager.zipA reusable template class for managing multiple toolbars, only one of which is displayed at a time(30KB)229,toolbar_hotbuttons_demo.zipDemonstrates how to add rollover buttons to your toolbar(30KB)230,toolbar.zipWTL Tool Bar Drop-Down Extension(64KB)231,win95asm.zipIntroduction to Menus(113KB)232,outbar.zipCGfxOutBarCtrl, an Outlook98 bar-like control(163KB)233,tabstatus.zipAdvanced UI - MDI list in the status bar (and a custom Window List dialog)(62KB)234,gfxlist.zipList Control - Enhanced list control(1544KB)235,maillook.zipInternet Mail Look(42KB)236,cdxcdynamic.zipDynamic child window repositioning for dialogs, property sheets, form views and any other CWnd derived classes. (227KB)237,voicecmd.zipVoice Command Enabling Your Software (27KB)238,cj60lib.zipMFC Extension Library - CJ60 Version 6.07(1100KB)239,infobar.zipInformation Bar (62KB)240,switcher.zipA Switcher Control (like the Windows Task Bar) (40KB)
MFC计算器课程设计报告 地信091 指导老师: 2010.11.15 一.题目:利用MFC框架编写简易计算器 要求使用MFC框架在Visual Studio 6.0环境下编写一个简易的计算器,支持任意位数的加减乘数,正负转换,并且实现BackSpace CE C功能。 二.设计过程 1. Windows消息处理机制的理解 首先编写程序需要对Windows程序的消息处理机制(Message Handle)有个比较清晰的了解。Windows的程序都是通过消息来传送数据,有不需要用户参与的系统消息,比如异常处理等。还有用户消息,比如鼠标的单击,双击,键盘的键入等。 2. 界面的设计 仿照Windows附件里面的计算器,在资源视图中画好界面,如图: 主要使用到Layout菜单中的Align功能对各个按钮进行对其,使界面更加整洁。拖出的控件有上面的一个Edit控件用于显示数字,Button控件用于处理鼠标的消息。 3. 建立的变量,控件的命名,对应的消息处理函数对应表 ID CAPTION Message Handler IDD_CALC_DIALOG 简易计算器 1.0 Beta1版 N/A IDC_NUM0 0 OnNum0 IDC_NUM1 1 OnNum1 IDC_NUM2 2 OnNum2 IDC_NUM3 3 OnNum3 IDC_NUM4 4 OnNum4 IDC_NUM5 5 OnNum5 IDC_NUM6 6 OnNum6 IDC_NUM7 7 OnNum7 IDC_NUM8 8 OnNum8 IDC_NUM9 9 OnNum9 IDC_NEG +/- OnNeg IDC_PT . OnPt IDC_DIV / OnDiv IDC_MUL * OnMul IDC_MIN - OnMin IDC_ADD + OnAdd IDC_BACKSPACE BACK OnBackspace IDC_CE CE OnCe IDC_CLEAR C OnClear IDC_EQU = OnEqu IDC_DIS N/A N/A OnCal(double num) 变量定义: double poz; //保存小数点的位置,初始化为1,表示poz-1个小数点。 double m_Dis; //Edit控件上需要显示的数字 BOOL point_flag; //小数点表示位,判定是否是小数,是小数为1,不是小数为0。 double numfirst; //保存计算过程中的前一个数字, double numsecond;//保存计算过程中的第二个数字 char op;//记录当前的计算符号,可以为’+’,’-’,’*’,’/’,’=’,’c’,’n’ 变量初始化: poz=1; m_Dis = 0.0; numfirst=0; numsecond=0; op=0; 4. 设计思路 a) 首先考虑对所有按键分为两类,数字类和符号类,0,1,2,3,4,5,6,7,8,9为数字类,+,-,*,/,=为符号类。数字在计算的过程中最多需要保存两个,所以定义了两个double型变量numfirst和numsecond来进行存储。符号需要一个char op来存储。 b) 然后考虑在计算的过程中,numfirst和numsecond的存储状态有三种,一种是numfirst==0 && numsecond==0 也就是程序刚开始运行还没有开始录入数字的状态。二种是numfirst!=0 && numsecond==0 也就是第一个数字已经录入,符号也已经录入时候把m_Dis的值直接赋值给numfirst,第三种是numfirst!=0 &&numsecond!=0,表示可以通过op来把两数合并为一个数。 c) 考虑到该计算器支持连续的计算,比如3.33+1.33*88/96= ?。所以必须在点符号Button也要计算出之前的结果,通过判断op,来计算,把两个数字合并为一个数字,方便下一次运算,功能近似于点=,所以把=也划分到符号类。 d) 因为数字全部使用的是double,键入的数字必须通过一定的处理达到累加的效果,加上小数和整数的处理差异性大,所以分别用point_flag来判断,分别出来小数和整数。 5. 成员函数及其释义 因为对OnNum0()到OnNum9()的处理函数差异仅在一个数字上,可以通过调用一个共同的函数OnCal(double num)来简化源代码长度,增加模块性。 void CCalcDlg::OnCal(double num) { //分三种状态来处理 if(numfirst!=0 && numsecond!=0) { if(point_flag==TRUE) //判定为小数 { poz*=0.1; //小数进位 m_Dis=m_Dis+poz*num;//递增 UpdateData(false); //把结果从内存传递到屏幕 } else { m_Dis=m_Dis*10+num; UpdateData(false); } } if(numfirst!=0 && numsecond==0) { if(point_flag==TRUE) { poz*=0.1; m_Dis=m_Dis+poz*num; UpdateData(false); } else//判定为整数 { m_Dis=m_Dis*10+num;//递增 UpdateData(false); } } if(numfirst==0 && numsecond==0) { if(point_flag==TRUE) { poz*=0.1; m_Dis=m_Dis+poz*num; UpdateData(false); } else { m_Dis=m_Dis*10+num; UpdateData(false); } } } 以OnAdd()为例子讲解符号的处理函数,函数的功能是先判定之前按下字符时op的值,更具op的值来进行相应的运算。 void CCalcDlg::OnAdd() { //根据numfirst和numsecond和op的值分为5种状态。 if(numfirst!=0 && numsecond==0&&op=='+') { numsecond=m_Dis; numfirst=numfirst+numsecond; //之前按的是加把两个数赋值到前一个数 m_Dis=numfirst;//赋值给屏幕 numsecond=0; //从新赋值为0,清空,不影响下一次判断 UpdateData(FALSE); m_Dis=0; //屏幕的值同时清空 } if(numfirst!=0 && numsecond==0&&op=='-') { numsecond=m_Dis; numfirst=numfirst-numsecond; m_Dis=numfirst; numsecond=0; UpdateData(FALSE); m_Dis=0; } if(numfirst!=0 && numsecond==0&&op=='*') { numsecond=m_Dis; numfirst=numfirst*numsecond; m_Dis=numfirst; numsecond=0; UpdateData(FALSE); m_Dis=0; } if(numfirst!=0 && numsecond==0&&op=='/') { numsecond=m_Dis; numfirst=numfirst/numsecond; m_Dis=numfirst; numsecond=0; UpdateData(FALSE); m_Dis=0; } if(numfirst==0 && numsecond==0) { //该状态为程序启动还没有开始录入输入的状态 numfirst=m_Dis; //屏幕的值赋值到numfirst UpdateData(FALSE); m_Dis=0; } op='+'; //最后记录最后一个操作是+ poz=1;//小数点位置归位 point_flag=FALSE;//默认小数点标志为整数,也就是0,也就是FALSE } “+/-“按钮的处理函数 void CCalcDlg::OnNeg() { m_Dis=-m_Dis;//换个符号,其他都一样 UpdateData(FALSE); poz=1; point_flag=FALSE; } ‘.’按钮的处理函数 void CCalcDlg::OnPt() { point_flag=TRUE; //把标志位改为“小数点”状态 } “Backspace”按钮的处理 void CCalcDlg::OnBackspace() { //主要通过_gcvt()和strtod()函数进行字符串和浮点数之间的转换 char buffer[30]; //定义个装字符的数组 _gcvt(m_Dis,sizeof(m_Dis),buffer); //把m_Dis存的数字转换为string for(int i=0;i<30;i++) { if(buffer[i]=='.'&& buffer[i+1]==0)//判断是否为整数 { point_flag=FALSE; //标志位设置为“整数位” break; } } if(point_flag==TRUE) //如果是小数 { for(int j=0;jmessage,pMsg->wParam,pMsg->lParam); return CDialog::PreTranslateMessage(pMsg); } // CalculatorDlg.cpp : implementation file // #include "stdafx.h" #include "Calculator.h" #include "CalculatorDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CAboutDlg dialog used for App About class CAboutDlg : public CDialog { public: CAboutDlg(); // Dialog Data //{{AFX_DATA(CAboutDlg) enum { IDD = IDD_ABOUTBOX }; //}}AFX_DATA // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CAboutDlg) protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL // Implementation protected: //{{AFX_MSG(CAboutDlg) //}}AFX_MSG DECLARE_MESSAGE_MAP() }; CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) { //{{AFX_DATA_INIT(CAboutDlg) //}}AFX_DATA_INIT } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CAboutDlg) //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) //{{AFX_MSG_MAP(CAboutDlg) // No message handlers //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CCalculatorDlg dialog CCalculatorDlg::CCalculatorDlg(CWnd* pParent /*=NULL*/) : CDialog(CCalculatorDlg::IDD, pParent) { //{{AFX_DATA_INIT(CCalculatorDlg) poz=1; numfirst=0; numsecond=0; op=0; m_Dis = 0.0; // num=0; //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CCalculatorDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CCalculatorDlg) DDX_Text(pDX, IDC_EDIT, m_Dis); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CCalculatorDlg, CDialog) //{{AFX_MSG_MAP(CCalculatorDlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(IDC_NUM0, OnNum0) ON_BN_CLICKED(IDC_NUM1, OnNum1) ON_BN_CLICKED(IDC_NUM2, OnNum2) ON_BN_CLICKED(IDC_NUM3, OnNum3) ON_BN_CLICKED(IDC_NUM4, OnNum4) ON_BN_CLICKED(IDC_NUM5, OnNum5) ON_BN_CLICKED(IDC_NUM6, OnNum6) ON_BN_CLICKED(IDC_NUM7, OnNum7) ON_BN_CLICKED(IDC_NUM8, OnNum8) ON_BN_CLICKED(IDC_NUM9, OnNum9) ON_BN_CLICKED(IDC_ADD, OnAdd) ON_BN_CLICKED(IDC_NEG, OnNeg) ON_BN_CLICKED(IDC_PT, OnPt) ON_BN_CLICKED(IDC_BACKSPACE, OnBackspace) ON_BN_CLICKED(IDC_CE, OnCe) ON_BN_CLICKED(IDC_CLEAR, OnClear) ON_BN_CLICKED(IDC_MIN, OnMin) ON_BN_CLICKED(IDC_MUL, OnMul) ON_BN_CLICKED(IDC_DIV, OnDiv) ON_BN_CLICKED(IDC_EOU, OnEou) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CCalculatorDlg message handlers BOOL CCalculatorDlg::OnInitDialog() { CDialog::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 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 return TRUE; // return TRUE unless you set the focus to a control } void CCalculatorDlg::OnSysCommand(UINT nID, LPARAM lParam) { if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } else { CDialog::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 CCalculatorDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (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 { CDialog::OnPaint(); } } // The system calls this to obtain the cursor to display while the user drags // the minimized window. HCURSOR CCalculatorDlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; } void CCalculatorDlg::OnCal(double num) {//分三种状态来处理 if(numfirst!=0 && numsecond!=0) { if(point_flag==TRUE) //判定为小数 { poz*=0.1; //小数进位 m_Dis=m_Dis+poz*num;//递增 UpdateData(false); //把结果从内存传递到屏幕 } else { m_Dis=m_Dis*10+num; UpdateData(false); } } if(numfirst!=0 && numsecond==0) { if(point_flag==TRUE) { poz*=0.1; m_Dis=m_Dis+poz*num; UpdateData(false); } else//判定为整数 { m_Dis=m_Dis*10+num;//递增 UpdateData(false); } } if(numfirst==0 && numsecond==0) { if(point_flag==TRUE) { poz*=0.1; m_Dis=m_Dis+poz*num; UpdateData(false); } else { m_Dis=m_Dis*10+num; UpdateData(false); } } } void CCalculatorDlg::OnNum0() { // TODO: Add your control notification handler code here OnCal(0); } void CCalculatorDlg::OnNum1() { // TODO: Add your control notification handler code here OnCal(1); } void CCalculatorDlg::OnNum2() { // TODO: Add your control notification handler code here OnCal(2); } void CCalculatorDlg::OnNum3() { // TODO: Add your control notification handler code here OnCal(3); } void CCalculatorDlg::OnNum4() { // TODO: Add your control notification handler code here OnCal(4); } void CCalculatorDlg::OnNum5() { // TODO: Add your control notification handler code here OnCal(5); } void CCalculatorDlg::OnNum6() { // TODO: Add your control notification handler code here OnCal(6); } void CCalculatorDlg::OnNum7() { // TODO: Add your control notification handler code here OnCal(7); } void CCalculatorDlg::OnNum8() { // TODO: Add your control notification handler code here OnCal(8); } void CCalculatorDlg::OnNum9() { // TODO: Add your control notification handler code here OnCal(9); } void CCalculatorDlg::OnAdd() { // TODO: Add your control notification handler code here { //根据numfirst和numsecond和op的值分为5种状态。 if(numfirst!=0 && numsecond==0&&op=='+') { numsecond=m_Dis; numfirst=numfirst+numsecond; //之前按的是加把两个数赋值到前一个数 m_Dis=numfirst;//赋值给屏幕 numsecond=0; //从新赋值为0,清空,不影响下一次判断 UpdateData(FALSE); m_Dis=0; //屏幕的值同时清空 } if(numfirst!=0 && numsecond==0&&op=='-') { numsecond=m_Dis; numfirst=numfirst-numsecond; m_Dis=numfirst; numsecond=0; UpdateData(FALSE); m_Dis=0; } if(numfirst!=0 && numsecond==0&&op=='*') { numsecond=m_Dis; numfirst=numfirst*numsecond; m_Dis=numfirst; numsecond=0; UpdateData(FALSE); m_Dis=0; } if(numfirst!=0 && numsecond==0&&op=='/') { numsecond=m_Dis; numfirst=numfirst/numsecond; m_Dis=numfirst; numsecond=0; UpdateData(FALSE); m_Dis=0; } if(numfirst==0 && numsecond==0) { //该状态为程序启动还没有开始录入输入的状态 numfirst=m_Dis; //屏幕的值赋值到numfirst UpdateData(FALSE); m_Dis=0; } op='+'; //最后记录最后一个操作是+ poz=1;//小数点位置归位 point_flag=FALSE;//默认小数点标志为整数,也就是0,也就是FALSE } } void CCalculatorDlg::OnNeg() { // TODO: Add your control notification handler code here m_Dis=-m_Dis;//换个符号,其他都一样 UpdateData(FALSE); poz=1; point_flag=FALSE; } void CCalculatorDlg::OnPt() { // TODO: Add your control notification handler code here point_flag=TRUE; //把标志位改为"小数点"状态 } void CCalculatorDlg::OnBackspace() { // TODO: Add your control notification handler code here //主要通过_gcvt()和strtod()函数进行字符串和浮点数之间的转换 char buffer[30]; //定义个装字符的数组 _gcvt(m_Dis,sizeof(m_Dis),buffer); //把m_Dis存的数字转换为string for(int i=0;i<30;i++) { if(buffer[i]=='.'&& buffer[i+1]==0)//判断是否为整数 { point_flag=FALSE; //标志位设置为"整数位" break; } } if(point_flag==TRUE) //如果是小数 { for(int j=0;j<30;j++) { if(buffer[j]==0) { buffer[j-1]=0; //把'\0'之前的字符赋值为'\0',就相当于剪掉最后一位 break; } } } else //如果是整数 { buffer[i-1]=0; //剪掉'.'之前那位 } m_Dis=strtod(buffer,NULL);//再用strtod弄成浮点数 UpdateData(FALSE); poz=1; } void CCalculatorDlg::OnCe() { // TODO: Add your control notification handler code here if(numfirst!=0 && numsecond==0)//CE只能修改第二个数字 { m_Dis=0; //把屏幕的值赋值为0 UpdateData(FALSE);//并显示出来 } } void CCalculatorDlg::OnClear() { // TODO: Add your control notification handler code here op=NULL; //清空符号 numfirst=0;//清空第一个数字 numsecond=0;//清空第二个数字 point_flag=FALSE;//改为默认整数位 poz=1;//小数点归位 m_Dis=0; UpdateData(FALSE); //屏幕显示归0 } void CCalculatorDlg::OnMin() { // TODO: Add your control notification handler code here { //根据numfirst和numsecond和op的值分为5种状态。 if(numfirst!=0 && numsecond==0&&op=='+') { numsecond=m_Dis; numfirst=numfirst+numsecond; //之前按的是加把两个数赋值到前一个数 m_Dis=numfirst;//赋值给屏幕 numsecond=0; //从新赋值为0,清空,不影响下一次判断 UpdateData(FALSE); m_Dis=0; //屏幕的值同时清空 } if(numfirst!=0 && numsecond==0&&op=='-') { numsecond=m_Dis; numfirst=numfirst-numsecond; m_Dis=numfirst; numsecond=0; UpdateData(FALSE); m_Dis=0; } if(numfirst!=0 && numsecond==0&&op=='*') { numsecond=m_Dis; numfirst=numfirst*numsecond; m_Dis=numfirst; numsecond=0; UpdateData(FALSE); m_Dis=0; } if(numfirst!=0 && numsecond==0&&op=='/') { numsecond=m_Dis; numfirst=numfirst/numsecond; m_Dis=numfirst; numsecond=0; UpdateData(FALSE); m_Dis=0; } if(numfirst==0 && numsecond==0) { //该状态为程序启动还没有开始录入输入的状态 numfirst=m_Dis; //屏幕的值赋值到numfirst UpdateData(FALSE); m_Dis=0; } op='-'; //最后记录最后一个操作是+ poz=1;//小数点位置归位 point_flag=FALSE;//默认小数点标志为整数,也就是0,也就是FALSE } } void CCalculatorDlg::OnMul() { // TODO: Add your control notification handler code here { //根据numfirst和numsecond和op的值分为5种状态。 if(numfirst!=0 && numsecond==0&&op=='+') { numsecond=m_Dis; numfirst=numfirst+numsecond; //之前按的是加把两个数赋值到前一个数 m_Dis=numfirst;//赋值给屏幕 numsecond=0; //从新赋值为0,清空,不影响下一次判断 UpdateData(FALSE); m_Dis=0; //屏幕的值同时清空 } if(numfirst!=0 && numsecond==0&&op=='-') { numsecond=m_Dis; numfirst=numfirst-numsecond; m_Dis=numfirst; numsecond=0; UpdateData(FALSE); m_Dis=0; } if(numfirst!=0 && numsecond==0&&op=='*') { numsecond=m_Dis; numfirst=numfirst*numsecond; m_Dis=numfirst; numsecond=0; UpdateData(FALSE); m_Dis=0; } if(numfirst!=0 && numsecond==0&&op=='/') { numsecond=m_Dis; numfirst=numfirst/numsecond; m_Dis=numfirst; numsecond=0; UpdateData(FALSE); m_Dis=0; } if(numfirst==0 && numsecond==0) { //该状态为程序启动还没有开始录入输入的状态 numfirst=m_Dis; //屏幕的值赋值到numfirst UpdateData(FALSE); m_Dis=0; } op='*'; //最后记录最后一个操作是+ poz=1;//小数点位置归位 point_flag=FALSE;//默认小数点标志为整数,也就是0,也就是FALSE } } void CCalculatorDlg::OnDiv() { // TODO: Add your control notification handler code here { //根据numfirst和numsecond和op的值分为5种状态。 if(numfirst!=0 && numsecond==0&&op=='+') { numsecond=m_Dis; numfirst=numfirst+numsecond; //之前按的是加把两个数赋值到前一个数 m_Dis=numfirst;//赋值给屏幕 numsecond=0; //从新赋值为0,清空,不影响下一次判断 UpdateData(FALSE); m_Dis=0; //屏幕的值同时清空 } if(numfirst!=0 && numsecond==0&&op=='-') { numsecond=m_Dis; numfirst=numfirst-numsecond; m_Dis=numfirst; numsecond=0; UpdateData(FALSE); m_Dis=0; } if(numfirst!=0 && numsecond==0&&op=='*') { numsecond=m_Dis; numfirst=numfirst*numsecond; m_Dis=numfirst; numsecond=0; UpdateData(FALSE); m_Dis=0; } if(numfirst!=0 && numsecond==0&&op=='/') { numsecond=m_Dis; numfirst=numfirst/numsecond; m_Dis=numfirst; numsecond=0; UpdateData(FALSE); m_Dis=0; } if(numfirst==0 && numsecond==0) { //该状态为程序启动还没有开始录入输入的状态 numfirst=m_Dis; //屏幕的值赋值到numfirst UpdateData(FALSE); m_Dis=0; } op='/'; //最后记录最后一个操作是+ poz=1;//小数点位置归位 point_flag=FALSE;//默认小数点标志为整数,也就是0,也就是FALSE } } void CCalculatorDlg::OnEou() { // TODO: Add your control notification handler code here { //根据numfirst和numsecond和op的值分为5种状态。 if(numfirst!=0 && numsecond==0&&op=='+') { numsecond=m_Dis; numfirst=numfirst+numsecond; //之前按的是加把两个数赋值到前一个数 m_Dis=numfirst;//赋值给屏幕 numsecond=0; //从新赋值为0,清空,不影响下一次判断 UpdateData(FALSE); m_Dis=0; //屏幕的值同时清空 } if(numfirst!=0 && numsecond==0&&op=='-') { numsecond=m_Dis; numfirst=numfirst-numsecond; m_Dis=numfirst; numsecond=0; UpdateData(FALSE); m_Dis=0; } if(numfirst!=0 && numsecond==0&&op=='*') { numsecond=m_Dis; numfirst=numfirst*numsecond; m_Dis=numfirst; numsecond=0; UpdateData(FALSE); m_Dis=0; } if(numfirst!=0 && numsecond==0&&op=='/') { numsecond=m_Dis; numfirst=numfirst/numsecond; m_Dis=numfirst; numsecond=0; UpdateData(FALSE); m_Dis=0; } if(numfirst==0 && numsecond==0) { //该状态为程序启动还没有开始录入输入的状态 numfirst=m_Dis; //屏幕的值赋值到numfirst UpdateData(FALSE); m_Dis=0; } op='='; //最后记录最后一个操作是+ poz=1;//小数点位置归位 point_flag=FALSE;//默认小数点标志为整数,也就是0,也就是FALSE } } 总结: 本次MFC计算器的制作,学习到了MFC基本的编程方法,增加了小组开发的团结协作能力。对OOP编程的理解进一步加深。但是程序仍然没存在一定的问题,比如除数不能为0的Exception handle,符号键多次点击结果混乱。由于时间仓促,如果有更多的时间,必定这些问题会迎刃而解。通过这次课程设计,以后Windows 应用程序势必会轻车熟路。
1,01.zipDisplaying a 256 color bitmap在程序中显示256色的位图(6KB)2,02.zipCreating a bitmap object from a BMP file从位图文件中创建位图对象(6KB)3,03.zipAn auto-sizing bitmap picture control一个自适应大小的位图控件(16KB)4,04.zipWriting a bitmap to a BMP file将一个位图写到BMP文件中(11KB)5,05.zipBitmap background in MDI Client在多文档客户程序中增加位图底图(4KB)6,06.zipConverting a bitmap to a region将一个位图转换成一个区域(7KB)7,07.zipConverting a bitmap to a region - memory leak fix 将一个位图转换成一个区域--内存泄露的修正(4KB)8,08.zipTransparent Bitmap实现透明的位图(7KB)9,09.zipCopying a bitmap to clipboard拷贝一个位图到剪贴板(5KB)10,10.zipConverting DDB to DIB将一个设备相关的位图转换成设备无关的位图(6KB)11,11.zipConverting DIB to DDB将一个设备无关的位图转换成设备相关的位图(5KB)12,12.zipCreating a DIB section from a BMP file 从BMP文件中创建一个设备无关的位图(5KB)13,13.zipGetting the dimensions of a bitmap得到一个位图的尺寸(4KB)14,14.zipDraw bitmap with grayed 3D effect画一副3维灰边的位图(6KB)15,15.zipDrawing a bitmap显示位图(7KB)16,16.zipDrawing a bitmap from a BMP file从BMP文件中装入位图并显示(6KB)17,17.zipEBGFX Library 推荐一个强大的EBGFX图形库(15KB)18,18.zipEmboss text and other shape on your bitmap 将文字以浮雕方式嵌入你的位图(7KB)19,19.zipApply a 3D bitmap pattern on text or other shapes将文字上色(3维的位图模板)(6KB)20,20.zipEncapsulated Dib API压缩设备无关位图的API(5KB)21,21.zipAn enhanced DIBLOOK sample 一个增强的DIBLOOK例子(5KB)22,22.zipFade in / Fade out Images using Palette animation使用生动的调色板淡入/淡出位图(8KB)23,23.zipPainting the background for a CFormView derived class在CFromView中画背景图(7KB)24,24.zipGradient Fill 有坡度的填充(5KB)25,25.zipPaint a Gradient Color Background显示渐变的背景(6KB)26,26.zipDrawing an image in grayscale画位图到一个灰色刻度中(5KB)27,27.zipFading from color to grayscale a

16,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧