计算一段程序进行的时间、 控制台下用Win32 API打开文件对话框
2013-09-26 14:16
483 查看
#include "stdafx.h" #include <time.h> #include <iostream> #include <windows.h> using namespace std; #include <fstream> float aaa; void main() { clock_t start,finish; int i=0; int ss=0; float avg; start=clock(); while(1) { i++; if (i==10000000) { finish=clock(); avg=(finish-start)/*/8.0*/; aaa=avg; cout<<finish<<" "<<start<<endl; printf("%f",avg); break; } } }
二、
控制台下用Win32 API打开文件对话框
#include "stdafx.h" #include <Windows.h> #include <CommDlg.h> #include <iostream> using namespace std; static OPENFILENAME ofn ; void PopFileInitialize (HWND hwnd) { static TCHAR szFilter[] = TEXT ("所有图片文件\0*.bmp;*.dib;*.jpg;*.jpeg;*.jpe;*.gif;*.tiff;*.png;*.ico\0") \ TEXT ("JPEG文件 (*.jpg;*.jpeg;*.jpe)\0*.jpg;*.jpeg;*.jpe\0") \ TEXT ("位图文件 (*.bmp;*.dib)\0*.bmp;*.dib\0") \ TEXT ("GIF (*.gif)\0*.gif\0") \ TEXT ("TIFF (*.tiff)\0*.tiff") \ TEXT ("PNG (*.png)\0*.png") \ TEXT ("ICO (*.ico)\0*.ico\0\0"); ofn.lStructSize = sizeof (OPENFILENAME) ; ofn.hwndOwner = hwnd ; ofn.hInstance = NULL ; ofn.lpstrFilter = szFilter ; ofn.lpstrCustomFilter = NULL ; ofn.nMaxCustFilter = 0 ; ofn.nFilterIndex = 0 ; ofn.lpstrFile = NULL ; // Set in Open and Close functions ofn.nMaxFile = MAX_PATH ; ofn.lpstrFileTitle = NULL ; // Set in Open and Close functions ofn.nMaxFileTitle = MAX_PATH ; ofn.lpstrInitialDir = NULL ; ofn.lpstrTitle = NULL ; ofn.Flags = 0 ; // Set in Open and Close functions ofn.nFileOffset = 0 ; ofn.nFileExtension = 0 ; ofn.lpstrDefExt = TEXT ("jpg") ; ofn.lCustData = 0L ; ofn.lpfnHook = NULL ; ofn.lpTemplateName = NULL ; } BOOL PopFileOpenDlg (HWND hwnd, PTSTR pstrFileName, PTSTR pstrTitleName) { ofn.hwndOwner = hwnd ; ofn.lpstrFile = pstrFileName ; ofn.lpstrFileTitle = pstrTitleName ; ofn.Flags = OFN_HIDEREADONLY | OFN_CREATEPROMPT ; return GetOpenFileName (&ofn) ; } int main() { static TCHAR szFileName[MAX_PATH], szTitleName[MAX_PATH] ; HWND hwnd; hwnd=GetForegroundWindow(); //获取前台窗口句柄。本程序中的前台窗口就是控制台窗口。 PopFileInitialize (hwnd); //初始化ofn PopFileOpenDlg(hwnd, szFileName, szTitleName);//打开文件对话框 cout<<szFileName<<endl; //在控制台中显示选中文件的路径 return 0; }
记得把你的工程属性中得字符集改成多字节字符集,因为在Unicode字符集下路径显示出的是一串数字。
相关文章推荐
- 控制台下用Win32 API打开文件对话框
- 控制台下用Win32 API打开文件对话框
- vba使用win32 API(GetOpenFileName )实现打开文件对话框
- vba使用win32 API(GetOpenFileName )实现打开文件对话框
- vba使用win32 API(GetOpenFileName )实现打开文件对话框
- vba使用win32 API(GetOpenFileName )实现打开文件对话框
- vba使用win32 API(GetOpenFileName )实现打开文件对话框
- vba使用win32 API(GetOpenFileName )实现打开文件对话框
- vba使用win32 API(GetOpenFileName )实现打开文件对话框
- vba使用win32 API(GetOpenFileName )实现打开文件对话框
- vba使用win32 API(GetOpenFileName )实现打开文件对话框
- Win32 api使用中调用GetOpenFileName打开文件对话框无响应的解决方法
- 基于控制台或Win32 API程序生成文件版本信息
- vba使用win32 API(GetOpenFileName )实现打开文件对话框
- vba使用win32 API(GetOpenFileName )实现打开文件对话框
- vba使用win32 API(GetOpenFileName )实现打开文件对话框
- vba使用win32 API(GetOpenFileName )实现打开文件对话框
- win32控制台程序使用CfileDialog进行文件读取
- vba使用win32 API(GetOpenFileName )实现打开文件对话框
- vba使用win32 API(GetOpenFileName )实现打开文件对话框