tory(szFilename);
_chdir("..");
}
}
else
{
if(!stricmp(filestruct.name,szFilename))
{
_getcwd(path_search,_MAX_PATH);
strcat(path_search,"\\");
strcat(path_search,filestruct.name);
MessageBox(path_search);
}
}
}
_findclose(handle);
// 最后结束整个查找工作
} 这样我们就可以对整个目录进行遍历搜索,查找某一特定的文件,并输出显示其完整的文件路径。以上的程序在Visual C++ 6.0中已调试通过。27、两种方法实现MFC 对话框最大化时控件也随比例最大化或者还原 方法一:单个控件ID操作第一步、在对话框类中(.h文件)定义如下变量和函数定义如下几个变量:[cpp] view plaincopy
1. void ReSize(int nID);
2. BOOL change_flag;
3. float m_Multiple_height;
4. float m_Multiple_width;
[cpp] view plaincopy
1. afx_msg void OnSize(UINT nType, int cx, int cy); 第二步、在OnInitDialog()中 计算出当前对话框的大小与最大化后大小[cpp] view plaincopy
1. CRect rect;
2. ::GetWindowRect(m_hWnd,rect);//这里m_hWnd为窗口句柄,如果不存在此变量则在该行代码前加一句:HWND h_Wnd=GetSafeHwnd( );
3. ScreenToClient(rect);
4. LONG m_nDlgWidth = rect.right - rect.left;
5. LONG m_nDlgHeight = rect.bottom - rect.top;
6. //Calc 分辨率
7. LONG m_nWidth = GetSystemMetrics(SM_CXSCREEN);
8. LONG m_nHeight = GetSystemMetrics(SM_CYSCREEN);
9. //计算放大倍数(要用float值,否则误差很大)
10. m_Multiple_width = float(m_nWidth)/float(m_nDlgWidth);
11. m_Multiple_height = float(m_nHeight)/float(m_nDlgHeight);
12. change_flag = TRUE;//用来判断OnSize执行时,OninitDialg是否已经执行了 第三步、给对话框添加 WM_SIZE消息[cpp] view plaincopy
1. //给对话框添加 VM_SIZE消息
2. void CStuDemoDlg::OnSize(UINT nType, int cx, int cy)
3. {
4. CDialog::OnSize(nType, cx, cy);
5.
6. // TODO: Add your message handler code here
7. if (change_flag)//如果OninitDlg已经调用完毕
8. {
9. ReSize(IDC_STATIC_1);
10. ReSize(IDC_STATIC_2);
11. ReSize(IDC_EDIT11);//
12. ReSize(IDC_EDIT12);//
13. ReSize(IDC_LIST_SHOW);//LIST
14. ReSize(IDC_BUTTON_ADD);
15. ReSize(IDC_BUTTON_DEL);
16. ReSize(IDOK);
17. ReSize(IDCANCEL);
18. //恢复放大倍数,并保存 (确保还原时候能够还原到原来的大小)
19. m_Multiple_width = float(1)/m_Multiple_width;
20. m_Multiple_height = float(1)/m_Multiple_height;
21. }
22. } 第四步、刷新控件:根据比例计算控件缩放的大小,然后movewindow 到新矩形上[cpp] view plaincopy
1. void CStuDemoDlg::ReSize(int nID)
2. {
3. CRect Rect;
4. GetDlgItem(nID)->GetWindowRect(Rect);
5. ScreenToClient(Rect);
6. //计算控件左上角点
7. CPoint OldTLPoint,TLPoint;
8. OldTLPoint = Rect.TopLeft();
9. TLPoint.x = long(OldTLPoint.x *m_Multiple_width);
10. TLPoint.y = long(OldTLPoint.y * m_Multiple_height );
11. //计算控件右下角点
12. CPoint OldBRPoint,BRPoint; OldBRPoint = Rect.BottomRight();
13. BRPoint.x = long(OldBRPoint.x *m_Multiple_width);
14. BRPoint.y = long(OldBRPoint.y * m_Multiple_height );
15. //移动控件到新矩形
16. Rect.SetRect(TLPoint,BRPoint);
17. GetDlgItem(nID)->MoveWindow(Rect,TRUE);
18. } 方法二:集体控件操作第一步、在对话框类中(.h文件)定义如下变量和函数[cpp] view plaincopy
1. void ReSize();
2. POINT old;
[cpp] view plaincopy
1. afx_msg void OnSize(UINT nType, int cx, int cy); 第二步、在OnInitDialog()中 计算出原始对话框的大小[cpp] view plaincopy
1. CRect rect;
2. GetClientRect(&rect); //取客户区大小
3. old.x=rect.right-rect.left;
4. old.y=rect.bottom-rect.top; 第三步、添加 WM_SIZE消息[cpp] view plaincopy
1. void CStuDemoDlg::OnSize(UINT nType, int cx, int cy)
2. {
3. CDialog::OnSize(nType, cx, cy);
4. // TODO: Add your message handler code here
5. if (nType==SIZE_RESTORED||nType==SIZE_MAXIMIZED)
6. {
7. ReSize();
8. }
9. } 第四步、刷新控件函数[cpp] view plaincopy
1. void CStuDemoDlg::ReSize()
2. {
3. float fsp[2];
4. POINT Newp; //获取现在对话框的大小
5. CRect recta;
6. GetClientRect(&recta