子级分类:
C++/MFC基础
Windows界面
网络与通信
图形图象处理
系统通信
数据库
文件系统
硬件/系统调用
组件技术
其它技术
 |
Faq:如何遍历整个目录
|
|
| |
|
提问用户
主题
提问状态
yugiant(小鱼儿)
如何遍历整个目录
已解决
问题解答归纳:
BOOL DeleteCurFolder(CString folder)
/*****************************************************************
作用:清空文件夹,预防可能产生的bug %
返回值:bool true-success,false-fail %
关键函数:CFildFind::FindFile %
关键变量:folder 对应文件夹 %
作者:张奇 %
修改时间:2002-10-10 ...
|
|
| 作者:不祥 xler张贴于2004-05-21 10:19:39.0,共阅读2598次,回复0次 |
|
|
 |
解高斯方程组算法(自己写的和清华教材上的比较)
|
|
| |
| 重点是方程组类Linequ的方法 Solve(),解法一是清华教材《C++语言程序设计》郑莉等编的算法,好像有错(反正测试计算出来试错的main()为测试码),且不怎么明白!于是自己写了个,自己命名为逐行消去法!请大家看看!呵呵写得不好请帮忙改进!// Linqu.h
//Begin of file Linequ.h
#ifndef LINQU_H
#define LINQU_H
#include <iostream.h>
#include <math.h>
class Matrix //The definition of basic class
{
public: //Interface for outside
Matrix(int dim=2); //Constructor
~Matrix(); //Destructor
void setMatrix(double* rmatr); //Initialize Matrix
void printM(); //Display Matrix
protected:
int index; ...
|
|
| 作者:不祥 barco张贴于2004-05-17 23:36:27.0,共阅读2509次,回复3次 |
|
|
 |
实现Dialog的Menu中最近使用文件机制
|
|
| |
| l 如何启动Dialog的Command Update机制?
重载Cdialog的WM_INITMENUPOPUP, 修改使用 void CFrameWnd::OnInitMenuPopup (CMenu* pMenu, UINT, BOOL bSysMenu)
中的source code,启动Command Update机制
l 如何实现Dialog的Menu中最近使用文件机制?
最近使用文件机制是用CWinApp的Command Update机制和以下两个消息处理的:
ON_UPDATE_COMMAND_UI(ID_FILE_MRU_FILE1, OnUpdateRecentFileMenu)
ON_COMMAND_EX_RANGE(ID_FILE_MRU_FILE1,ID_FILE_MRU_FILE16, OnOpenRecentFile)
void CWinApp::OnUpdateRecentFileMenu(CCmdUI* pCmdUI)
{
ASSERT_VALID(this);
if (m_pRecentFileList == NULL) // no MRU files
pCmdUI->Enable(FALSE);
...
|
|
| 作者:不祥 jerry张贴于2004-05-11 20:37:18.0,共阅读2180次,回复0次 |
|
|
 |
两种关机代码的比较
|
|
| |
| InitiateSystemShutdown(NULL,"关机",10,TRUE,FALSE) //这个函数不能直接掐断电源,但是可以cancel掉关机指令
ExitWindowsEx(EWX_POWEROFF | EWX_FORCE ,0) //直接强制关机,掐断电源
|
|
| 作者:不祥 xler张贴于2004-05-11 18:03:37.0,共阅读1703次,回复0次 |
|
|
 |
系统关机代码
|
|
| |
| BOOL ShutDown()
{
OSVERSIONINFO osVI;
HANDLE hToken=NULL;
osVI.dwOSVersionInfoSize=sizeof(OSVERSIONINFO);
if(GetVersionEx(&osVI))
{
switch(osVI.dwPlatformId)
{
case VER_PLATFORM_WIN32s:
case VER_PLATFORM_WIN32_WINDOWS:
ExitWindowsEx(EWX_POWEROFF,0);
break;
case VER_PLATFORM_WIN32_NT:
if(OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES, &hToken))
{
SetPrivilege(hToken,SE_SHUTDOWN_NAME,TRUE);
if(!ExitWindowsEx(EWX_ ...
|
|
| 作者:不祥 xler张贴于2004-05-11 18:01:29.0,共阅读2016次,回复0次 |
|
|
 |
系统重起代码
|
|
| |
| HINSTANCE hShell32 = ::LoadLibrary("shell32.dll");
if(hShell32)
{
typedef int (WINAPI *RestartDialog)(HWND hwndOwner,LPCSTR lpstrReason,UINT uFlags);
RestartDialog SHRestartWindowsDialog =(RestartDialog)GetProcAddress(hShell32, MAKEINTRESOURCE(59));
if(SHRestartWindowsDialog)
{
(SHRestartWindowsDialog)(GetDesktopWindow(),NULL,EWX_REBOOT);
}
}
|
|
| 作者:不祥 xler张贴于2004-05-11 17:47:30.0,共阅读1928次,回复0次 |
|
|
 |
win2000锁定屏幕调用代码
|
|
| |
| 对于其他os,不知道有没有用WinExec("rundll32.exe user32.dll,LockWorkStation",SW_HIDE);
|
|
| 作者:不祥 xler张贴于2004-05-11 17:37:05.0,共阅读1926次,回复0次 |
|
|
 |
如何实现双击程序托盘图标弹出或者弹入动画效果
|
|
| |
| 使用API:
BOOL WINAPI DrawAnimatedRects(HWND hwnd, int idAni, CONST RECT * lprcFrom, CONST RECT * lprcTo);
Eg:
Bool m_bShow = false; //区分弹出还是弹入
BOOL WinAnimation()
{
CWnd * pWnd=FindWindow("Shell_TrayWnd",NULL); //windows底部信息提示窗口
if(!pWnd)return FALSE;
CRect rectSur,rectDst;
GetWindowRect(&rectSur); //本窗口大小,用户自己处理
EnumChildWindows(pWnd->GetSafeHwnd(),My_Find,(LPARAM)&rectDst); //寻找托盘
if(m_bShow)DrawAnimatedRects(GetSafeHwnd(),IDANI_CAPTION,&rectSur,&rectDst); //弹入
else DrawAnimatedRects(GetSafeHwnd(),IDANI_CAPTION,&rectDst,&rectSur); //弹出
re ...
|
|
| 作者:不祥 xler张贴于2004-05-11 14:47:50.0,共阅读2062次,回复0次 |
|
|
 |
分割“品”字型的视图
|
|
| |
| BOOL CBrowserFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
m_Splitter1.CreateStatic(this,1,2);
m_Splitter2.CreateStatic(&m_Splitter1,2,1,WS_CHILD|WS_VISIBLE,m_Splitter1.IdFromRowCol(0,1));
m_Splitter1.CreateView(0,0,RUNTIME_CLASS(CBrowserFolder),CSize(200,0),pContext);
m_Splitter2.CreateView(0,0,RUNTIME_CLASS(CLogoBar),CSize(0,80),pContext);
m_Splitter2.CreateView(1,0,RUNTIME_CLASS(CBrowserList),CSize(0,0),pContext);
return CFrameWnd::OnCreateClient(lpcs,pContext);
}
|
|
| 作者:不祥 bluejoe张贴于2004-04-30 10:16:05.0,共阅读1639次,回复0次 |
|
|
 |
GetLastError()对应的原因
|
|
| |
| void DisplayError(DWORD dwError)
{
LPVOID pv;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|
FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
dwError,
MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),
(LPTSTR)&pv,
0,
NULL);
MessageBox(NULL, (LPTSTR)pv, "Error", MB_ICONHAND);
LocalFree(pv);
}
这样用:
DisplayError(WSAGetLastError());
可以看到错误的原因!
|
|
| 作者:不祥 jerry张贴于2004-04-24 22:31:46.0,共阅读2060次,回复0次 |
|
|
 |
使用QueryPerformanceCount的小例子
|
|
| |
| LARGE_INTEGER liCount1;
LARGE_INTEGER liCount2;
LARGE_INTEGER liFrequency;
double fSeconds;
//你的其他代码...
//时间点1(例如按某个button的时间)
QueryPerformanceCounter(&liCount1);
//你的其他代码...
//时间点2(例如某事件完成的时间)
QueryPerformanceCounter(&liCount2);
QueryPerformanceFrequency(&liFrequency);//每秒记数
fSeconds=(double)(liCount2.QuadPart -liCount1.QuadPart )/(double)liFrequency.QuadPart; //时间点2和时间点1之间的精确秒数
|
|
| 作者:不祥 ycr40张贴于2004-04-20 17:21:50.0,共阅读2037次,回复1次 |
|
|
 |
如何在对话框中加入状态栏[1]
|
|
| |
| 1.ID_INDICATOR_NISH and ID_INDICATOR_TIME这个两个加到 symbol 里去,同样的加到 string table 里去
2.在你的 Dialog 类里面加个 CStatusBar m_bar;
3.在实现文件开头加上
static UINT BASED_CODE indicators[] =
{
ID_INDICATOR_NISH,
ID_INDICATOR_TIME
};
4.OnInitDialog 里面加上
m_bar.Create(this); //We create the status bar
m_bar.SetIndicators(indicators,2); //Set the number of panes
CRect rect;
GetClientRect(&rect);
//Size the two panes
m_bar.SetPaneInfo(0,ID_INDICATOR_NISH,
SBPS_NORMAL,rect.Width()-100);
m_bar.SetPaneInfo(1,ID_INDICATOR_TIME,SBPS_STRETCH ,0);
//This is where we actually draw ...
|
|
| 作者:不祥 Bccv张贴于2004-04-20 11:46:50.0,共阅读2018次,回复0次 |
|
|
 |
异步读写的简单串口类
|
|
| |
| // Serial.h
#ifndef __SERIAL_H__
#define __SERIAL_H__
#define FC_DTRDSR 0x01
#define FC_RTSCTS 0x02
#define FC_XONXOFF 0x04
#define ASCII_BEL 0x07
#define ASCII_BS 0x08
#define ASCII_LF 0x0A
#define ASCII_CR 0x0D
#define ASCII_XON 0x11
#define ASCII_XOFF 0x13
class CSerial
{
public:
CSerial();
~CSerial();
BOOL Open( int nPort = 2, int nBaud = 9600 );
BOOL Close( void );
int ReadData( void *, int );
int SendData( const char *, int );
int ReadDataWaiting( void );
BOOL IsOpened( void ){ return( m_b ...
|
|
| 作者:不祥 bruticus张贴于2004-04-19 12:51:38.0,共阅读2506次,回复1次 |
|
|
 |
用默认浏览器打开 URL
|
|
| |
| HKEY hkRoot,hSubKey; //定义注册表根关键字及子关键字
char ValueName[256];
unsigned char DataValue[256];
unsigned long cbValueName=256;
unsigned long cbDataValue=256;
char ShellChar[256]; //定义命令行
DWORD dwType;
//打开注册表根关键字
if(RegOpenKey(HKEY_CLASSES_ROOT,NULL,&hkRoot)==ERROR_SUCCESS)
{
//打开子关键字
if(RegOpenKeyEx(hkRoot,
"htmlfile\\shell\\open\\command",
0,
KEY_ALL_ACCESS,
&hSubKey)==ERROR_SUCCESS)
{
//读取注册表,获取默认浏览器的命令行
RegEnumValue(hSubKey,
0,
ValueName,
&cbValueName,
NULL,
&dwType,
DataValue,
&cb ...
|
|
| 作者:不祥 Bccv张贴于2004-03-30 16:44:19.0,共阅读2385次,回复1次 |
|
|
 |
将普通字符串转化为Unicode编码
|
|
| |
| 该函数在偶的手机程序里面用过,字符串的长度就是sEncodes.GetLength() / 2(支持中英文混排)。CString CMobile::String2HEX(CString sSource)
{
_bstr_t bstrSMS(sSource);
int nSMSLength = bstrSMS.length();
wchar_t * pwc = (wchar_t *)bstrSMS;
CString sEncode;
for(int i = 0; i < nSMSLength; i++)
{
CString sHex;
sHex.Format(_T("%04X"), pwc[i]);
sEncode += sHex;
}
return sEncode;
}
|
|
| 作者:不祥 bluejoe张贴于2004-04-18 10:40:12.0,共阅读1977次,回复0次 |
|
|
 |
统计中英文字符混合片断的字符数
|
|
| |
| CString strTxt; //需要统计的片断
int Lenth = strTxt.GetLength();
int nELenth = 0; //英文
int nCLenth = 0; //中文
int nTotalLenth = 0;////总共字数
for(int i=0;i<Lenth;i++)
{
char c = strTxt.GetAt(i);
//中文字符
if(c<0||c>255)
continue;
//英文字符
else
nELenth ++;
}
//计算中文字符数
nCLenth = (Lenth-nELenth)/2;
|
|
| 作者:不祥 Bccv张贴于2004-03-30 09:59:44.0,共阅读1608次,回复1次 |
|
|
 |
在工具条中加入组合框控件
|
|
| |
| 昨天在 smth 有人问,说下.大家多指教
首先打开VC的工具条资源编辑器,如图一所示,在要加入组合框的地方加一个空按纽,如图一所示的第四个按纽,分配一个ID号,在本文的实例中为IDC_COMBOX。
工具条应该封装为一个类,组合框控件应该作为这个类的一个成员变量。生成一个以CToolBar为基类的的新类CComboToolBar,这可以用VC的类向导(ClassWizard)来实现,先生成一个以CToolBarCtrl为基类的新类CComboToolBar,然后在文件编辑器中打开ComboToolBar.h和ComboToolBar.cpp文件,把CComboToolBar基类改为CToolBar。新类生成后,加入成员变量CComboBox m_combobox。
然后把CMainFrame类中的工具条成员变量m_wndToolBar的类型由CToolBar改为CComboToolBar。编辑应用程序向导已经生成好的函数int CMainFrame::OnCreate (LPCREATESTRUCT lpCreateStruct),这个函数通常用来产生工具条和状态条,在创建工具条的函数后加入以下代码:
CRect rect;
//设置组合框的宽度,四个参数依次为控件在工具条中的索引号、ID号、风格、宽度
m_wndToolBar.SetButtonInfo ...
|
|
| 作者:不祥 Bccv张贴于2004-04-16 09:10:08.0,共阅读2168次,回复1次 |
|
|
 |
如何改变控件的字体 (老问题,好解决)
|
|
| |
| 由于控件是也是窗口,用户可以调用CWnd: : SetFont指定新字体。
//Declare font object in class declaration (.H file ).
private :
Cfont m_font ;
// Set font in class implementation (.Cpp file ). Note m_wndButton is a
//member variable added by ClassWizard.DDX routines hook the member
//variable to a dialog button contrlo.
BOOL CSampleDialog : : OnInitDialog ( )
¡­
//Create an 8-point Arial font
m_font . CreateFont (MulDiv (8 , -pDC-> GetDeviceCaps (LOGPIXELSY) , 72).
0 , 0 , 0 , FW_NORMAL , 0 , 0, 0, ANSI_CHARSER, OUT_STROKE_PRECIS ,
CLIP_STROKE _PRECIS , DRA ...
|
|
| 作者:不祥 Bccv张贴于2004-04-16 09:00:25.0,共阅读2120次,回复1次 |
|
|
 |
也贴一个显示选择目录文件夹的片断
|
|
| |
| 和 bluejoe 一样的差不多..BROWSEINFO browseInfo;
browseInfo.hwndOwner = this->m_hWnd;
// set root at Desktop
browseInfo.pidlRoot = NULL;
browseInfo.pszDisplayName = "hehe";
browseInfo.lpszTitle = "Paht";
browseInfo.ulFlags = BIF_RETURNFSANCESTORS|BIF_RETURNONLYFSDIRS;
browseInfo.lpfn = NULL;
browseInfo.lParam = 0;
LPITEMIDLIST lpItemIDList;
if ((lpItemIDList = ::SHBrowseForFolder(&browseInfo))
!= NULL)
{
// Get the path of the selected folder from the item ID list.
if (::SHGetPathFromIDList(lpItemIDList, szBuffer))
{
// At this point, szBuffer contains the path the user chose. ...
|
|
| 作者:不祥 Bccv张贴于2004-04-16 08:38:18.0,共阅读1688次,回复0次 |
|
|
 |
十进制/十六进制/二进制字串转化
|
|
| |
| //十进制->二进制
CString DecimalToBinary(CString strDecimal)
{
int nDecimal = atoi(strDecimal.GetBuffer(0));
int nYushu; //ÓàÊý
int nShang; //ÉÌ
CString strBinary = "";
char buff[2];
CString str = "";
BOOL bContinue = TRUE;
while(bContinue)
{
nYushu = nDecimal%2;
nShang = nDecimal/2;
sprintf(buff,"%d",nYushu);
str = strBinary;
strBinary.Format("%s%s",buff,str);
nDecimal = nShang;
if(nShang==0)
bContinue = FALSE;
}
return strBinary;
}
//十六进制到二进制
CString HexToBinary(CString strHex)
{
int nLen ...
|
|
| 作者:不祥 Bccv张贴于2004-03-30 10:02:56.0,共阅读2988次,回复1次 |
|
|
|