posts - 131, comments - 12, trackbacks - 0, articles - 0
  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

DWORD GetModuleFileName(
   HMODULE hModule,     // handle to module。将要得到的模块的句柄。如果是当前模块,NULL
   LPTSTR lpFilename,   // path buffer   得到的文件名。
   DWORD nSize          // size of buffer   一般MAX_PATH就可以了
); 
得到全路径
TCHAR exeFullPath[MAX_PATH]; // MAX_PATH
GetModuleFileName(NULL,exeFullPath,MAX_PATH);//得到程序模块名称,全路径
也就是当前运行程序的全路径 
例子:
GetModuleFileName(NULL,strFullPath.GetBuffer(MAX_PATH),MAX_PATH); // 使用全路径 避免因当前目录改变而找不到文件

posted @ 2012-09-26 10:04 盛胜 阅读(556) | 评论 (0)编辑 收藏

FillRect(&fillrect,&colorbrush) 
colorbrush 是画刷 的 id.  它是 CBrush  类(class)的 一个 对象,实际上它定义了 用什么颜色 和 “花纹”来 “涂”一个 区域。它自身 并无 几何形状和大小的限制。 fillrect 定义 了一个 矩形区域范围 的 坐标。 FillRect  就是 “用colorbrush 规定的颜色和花纹来 涂 满 fillrect 定义的矩形区域”。

posted @ 2012-09-26 09:44 盛胜 阅读(355) | 评论 (0)编辑 收藏

Create

Creates a tool tip control and attaches it to a CToolTipCtrl object.

CreateEx

Creates a tool tip control with the specified Windows extended styles and attaches it to a CToolTipCtrl object.

CToolTipCtrl

Constructs a CToolTipCtrl object.

GetBubbleSize

Retrieves the size of the tool tip.

GetCurrentTool

Retrieves information, such as the size, position, and text, of the tooltip window that the current tooltip control displays.

GetDelayTime

Retrieves the initial, pop-up, and reshow durations that are currently set for a tool tip control.

GetMargin

Retrieves the top, left, bottom, and right margins that are set for a tool tip window.

GetMaxTipWidth

Retrieves the maximum width for a tool tip window.

GetText

Retrieves the text that a tool tip control maintains for a tool.

GetTipBkColor

Retrieves the background color in a tool tip window.

GetTipTextColor

Retrieves the text color in a tool tip window.

GetTitle

Retrieves the title of the current tooltip control.

GetToolCount

Retrieves a count of the tools maintained by a tool tip control.

GetToolInfo

Retrieves the information that a tool tip control maintains about a tool.

SetDelayTime

Sets the initial, pop-up, and reshow durations for a tool tip control.

SetMargin

Sets the top, left, bottom, and right margins for a tool tip window.

SetMaxTipWidth

Sets the maximum width for a tool tip window.

SetTipBkColor

Sets the background color in a tool tip window.

SetTipTextColor

Sets the text color in a tool tip window.

SetToolInfo

Sets the information that a tool tip maintains for a tool.

SetWindowTheme

Sets the visual style of the tool tip window.

Activate

Activates and deactivates the tool tip control.

AddTool

Registers a tool with the tool tip control.

AdjustRect

Converts between a tool tip control's text display rectangle and its window rectangle.

DelTool

Removes a tool from the tool tip control.

HitTest

Tests a point to determine whether it is within the bounding rectangle of the given tool. If so, retrieves information about the tool.

Pop

Removes a displayed tool tip window from view.

Popup

Causes the current ToolTip control to display at the coordinates of the last mouse message.

RelayEvent

Passes a mouse message to a tool tip control for processing.

SetTitle

Adds a standard icon and title string to a tool tip.

SetToolRect

Sets a new bounding rectangle for a tool.

Update

Forces the current tool to be redrawn.

UpdateTipText

Sets the tool tip text for a tool.

posted @ 2012-09-25 10:25 盛胜 阅读(354) | 评论 (0)编辑 收藏

为了避免同一个文件被include多次
1   #ifndef方式
2   #pragma once方式
在能够支持这两种方式的编译器上,二者并没有太大的区别,但是两者仍然还是有一些细微的区别。
    方式一:
    #ifndef __SOMEFILE_H__
    #define __SOMEFILE_H__
    ... ... // 一些声明语句
    #endif
    方式二:
    #pragma once
    ... ... // 一些声明语句
    #ifndef的方式依赖于宏名字不能冲突,这不光可以保证同一个文件不会被包含多次,也能保证内容完全相同的两个文件不会被不小心同时包含。当然,缺点就是如果不同头文件的宏名不小心“撞车”,可能就会导致头文件明明存在,编译器却硬说找不到声明的状况
    #pragma once则由编译器提供保证:同一个文件不会被包含多次。注意这里所说的“同一个文件”是指物理上的一个文件,而不是指内容相同的两个文件。带来的好处是,你不必再费劲想个宏名了,当然也就不会出现宏名碰撞引发的奇怪问题。对应的缺点就是如果某个头文件有多份拷贝,本方法不能保证他们不被重复包含。当然,相比宏名碰撞引发的“找不到声明”的问题,重复包含更容易被发现并修正。
   方式一由语言支持所以移植性好,方式二 可以避免名字冲突

posted @ 2012-09-25 08:47 盛胜 阅读(218) | 评论 (0)编辑 收藏

#include<iostream.h>
class point
{
   public:
      int x;
      int y;
   point()
   {
      x=0;
      y=0;
   }
   point(int a,int b)
   {
      x=a;
      y=b;
   }
   void output()
   {
      cout<<x<<endl<<y<<endl;
   }
   void input(int x,int y)
   {
      this->x=x;
      this->y=y;
   }

}

void main()
{
   point pt(5,5);
   pt.input(10,10);
   pt.output();

}
输出结果为10 
10

如果把this指针去掉则为5
5

在使用构造函数时注意是否需要释放内存。~构造函数名()利用析构函数解决内存泄漏问题。

posted @ 2012-09-24 10:47 盛胜 阅读(269) | 评论 (0)编辑 收藏


MessageBox(hwnd,szChar,"char",0);

MessageBox 在2008中定义为 MessageBoxW W指的是宽字节(也叫UNICODE),有3种方法可解决 
①用函数MessageBoxA 
②在内容前加上TEXT(对变量无效),如MessageBox(hwnd,szChar,TEXT("char"),0);

③在项目属性->常规中,把Uicode改成多字符段。

PS:在2008中,很多函数的返回值都是宽字节的,所以不一定要用MessageBoxA 
在MSDN上可以查到用宽字节的函数和同样功能普通函数的名称。 
在6.0中没用宽字节

posted @ 2012-09-21 15:41 盛胜 阅读(435) | 评论 (0)编辑 收藏

TCHAR字符串操作函数:
_tcslen(str) 获得字符串长度
_tcsrchr(str, L'\\') 反向搜索获得最后一个TCHAR的位置
_stprintf(TCHAR *buffer,const TCHAR *format [,argument] ... )获得一个格式化字符串
_tcsdup 给一个指针分配源字符串大小的内存并从源字符串copy值
_tcstok 按标记将字符串拆分
tcscpy 拷贝字符串

posted @ 2012-09-21 09:27 盛胜 阅读(7020) | 评论 (0)编辑 收藏

CString的构造函数
CString( );
例:CString csStr;

CString( const CString& stringSrc );
例:CString csStr("ABCDEF中文123456");
    CString csStr2(csStr);

CString( TCHAR ch, int nRepeat = 1 );
例:CString csStr('a',5);
//csStr="aaaaa"

CString( LPCTSTR lpch, int nLength );
例:CString csStr("abcdef",3);
//csStr="abc"

CString( LPCWSTR lpsz );
例:wchar_t s[]=L"abcdef";
    CString csStr(s);
//csStr=L"abcdef"

CString( const unsigned char* psz );
例:const unsigned char s[]="abcdef";
    const unsigned char* sp=s;
    CString csStr(sp);
//csStr="abcdef"

CString( LPCSTR lpsz );
例:CString csStr("abcdef");
//csStr="abcdef"

int GetLength( ) const;
返回字符串的长度,不包含结尾的空字符。
例:csStr="ABCDEF中文123456";
    printf("%d",csStr.GetLength());       //16

void MakeReverse( );
颠倒字符串的顺序
例:csStr="ABCDEF中文123456";
    csStr.MakeReverse();
    cout<<csStr;                  //654321文中FEDCBA

void MakeUpper( );
将小写字母转换为大写字母
例:csStr="abcdef中文123456";
    csStr.MakeUpper();
    cout<<csStr;                  //ABCDEF中文123456

void MakeLower( );
将大写字母转换为小写字母
例:csStr="ABCDEF中文123456";
    csStr.MakeLower();
    cout<<csStr;                  //abcdef中文123456

int Compare( LPCTSTR lpsz ) const;
区分大小写比较两个字符串,相等时返回0,大于时返回1,小于时返回-1
例:csStr="abcdef中文123456";
    csStr2="ABCDEF中文123456";
    cout<<csStr.CompareNoCase(csStr2);             //0

int CompareNoCase( LPCTSTR lpsz ) const;
不区分大小写比较两个字符串,相等时返回0,大于时返回1,小于时返回-1
例:csStr="abcdef中文123456";
    csStr2="ABCDEF中文123456";
    cout<<csStr.CompareNoCase(csStr2);             //-1

int Delete( int nIndex, int nCount = 1 )
删除字符,删除从下标nIndex开始的nCount个字符
例:csStr="ABCDEF";
    csStr.Delete(2,3);
    cout<<csStr;              // ABF
//当nIndex过大,超出对像所在内存区域时,函数没有任何操作。
//当nIndex为负数时,从第一个字符开始删除。
//当nCount过大,导致删除字符超出对像所在内存区域时,会发生无法预料的结果。
//当nCount为负数时,函数没有任何操作。

int Insert( int nIndex, TCHAR ch )
int Insert( int nIndex, LPCTSTR pstr )

在下标为nIndex的位置,插入字符或字符串。返回插入后对象的长度
例:csStr="abc";
    csStr.Insert(2,'x');
    cout<<csStr;                     //abxc
    csStr="abc";
    csStr.Insert(2,"xyz");
    cout<<csStr;                     //abxyzc
//当nIndex为负数时,插入在对象开头
//当nIndex超出对象末尾时,插入在对象末尾

int Remove( TCHAR ch );
移除对象内的指定字符。返回移除的数目
例:csStr="aabbaacc";
    csStr.Remove('a');
    cout<<csStr;                     //bbcc

int Replace( TCHAR chOld, TCHAR chNew );
int Replace( LPCTSTR lpszOld, LPCTSTR lpszNew );

替换字串
例:csStr="abcdef";
    csStr.Replace('a','x');
    cout<<csStr;                    //xbcdef
    csStr="abcdef";
    csStr.Replace("abc","xyz");
    cout<<csStr;                    //xyzdef

void TrimLeft( );
void TrimLeft( TCHAR chTarget );
void TrimLeft( LPCTSTR lpszTargets );

从左删除字符,被删的字符与chTarget或lpszTargets匹配,一直删到第一个不匹配的字符为止
例:csStr="aaabaacdef";
    csStr.TrimLeft('a');
    cout<<csStr;                //baacdef
    csStr="aaabaacdef";
    csStr.TrimLeft("ab");
    cout<<csStr;                //cdef
//无参数时删除空格

void TrimRight( );
void TrimRight( TCHAR chTarget );
void TrimRight( LPCTSTR lpszTargets );

从右删除字符,被删的字符与chTarget或lpszTargets匹配,一直删到第一个不匹配的字符为止
例:csStr="abcdeaafaaa";
    csStr.TrimRight('a');
    cout<<csStr;               //abcdeaaf
    csStr="abcdeaafaaa";
    csStr.TrimRight("fa");
    cout<<csStr;                //abcde
//无参数时删除空格

void Empty( );
清空
例:csStr="abcdef";
    csStr.Empty();
    printf("%d",csStr.GetLength());    //0

BOOL IsEmpty( ) const;
测试对象是否为空,为空时返回零,不为空时返回非零
例:csStr="abc";
    cout<<csStr.IsEmpty();         //0;
    csStr.Empty();
    cout<<csStr.IsEmpty();         //1;

int Find( TCHAR ch ) const;
int Find( LPCTSTR lpszSub ) const;
int Find( TCHAR ch, int nStart ) const;
int Find( LPCTSTR pstr, int nStart ) const;

查找字串,nStart为开始查找的位置。未找到匹配时返回-1,否则返回字串的开始位置
例:csStr="abcdef";
    cout<<csStr.Find('b');       //1
    cout<<csStr.Find("de");      //3
    cout<<csStr.Find('b',3);     //-1
    cout<<csStr.Find('b',0);     //1
    cout<<csStr.Find("de",4);    //-1
    cout<<csStr.Find("de",0);    //3
//当nStart超出对象末尾时,返回-1。
//当nStart为负数时,返回-1。

int FindOneOf( LPCTSTR lpszCharSet ) const;
查找lpszCharSet中任意一个字符在CString对象中的匹配位置。未找到时返回-1,否则返回字串的开始位置
例:csStr="abcdef";
    cout<<csStr.FindOneOf("cxy");       //2

CString SpanExcluding( LPCTSTR lpszCharSet ) const;
返回对象中与lpszCharSet中任意匹配的第一个字符之前的子串
例:csStr="abcdef";
    cout<<csStr.SpanExcluding("cf");    //ab

CString SpanIncluding( LPCTSTR lpszCharSet ) const;
从对象中查找与lpszCharSe中任意字符不匹配的字符,并返回第一个不匹配字符之前的字串
例:csStr="abcdef";
    cout<<csStr.SpanIncluding("fdcba");    //abcd

int ReverseFind( TCHAR ch ) const;
从后向前查找第一个匹配,找到时返回下标。没找到时返回-1
例:csStr="abba";
    cout<<csStr.ReverseFind('a');        //3

void Format( LPCTSTR lpszFormat, ... );
void Format( UINT nFormatID, ... );

格式化对象,与C语言的sprintf函数用法相同
例:csStr.Format("%d",13);
    cout<<csStr;                       //13

TCHAR GetAt( int nIndex ) const;
返回下标为nIndex的字符,与字符串的[]用法相同
例:csStr="abcdef";
    cout<<csStr.GetAt(2);             //c
//当nIndex为负数或超出对象末尾时,会发生无法预料的结果。

void SetAt( int nIndex, TCHAR ch );
给下标为nIndex的字符重新赋值
例:csStr="abcdef";
    csStr.SetAt(2,'x');
    cout<<csStr;                      //abxdef
//当nIndex为负数或超出对象末尾时,会发生无法预料的结果。

CString Left( int nCount ) const;
从左取字串
例:csStr="abcdef";
    cout<<csStr.Left(3);           //abc
//当nCount等于0时,返回空。
//当nCount为负数时,返回空。
//当nCount大于对象长度时,返回值与对象相同。

CString Right( int nCount ) const;
从右取字串
例:csStr="abcdef";
    cout<<csStr.Right(3);           //def
//当nCount等于0时,返回空。
//当nCount为负数时,返回空。
//当nCount大于对象长度时,返回值与对象相同。

CString Mid( int nFirst ) const;
CString Mid( int nFirst, int nCount ) const;

从中间开始取字串
例:csStr="abcdef";
    cout<<csStr.Mid(2);           //cdef
    csStr="abcdef";
    cout<<csStr.Mid(2,3);         //cde
//当nFirst为0和为负数时,从第一个字符开始取。
//当nFirst等于对象末尾时,返回空字串。
//当nFirst超出对象末尾时,会发生无法预料的结果。
//当nCount超出对象末尾时,返回从nFirst开始一直到对象末尾的字串
//当nCount为0和为负数时,返回空字串。

LPTSTR GetBuffer( int nMinBufLength );
申请新的空间,并返回指针
例:csStr="abcde";
    LPTSTR pStr=csStr.GetBuffer(10);
    strcpy(pStr,"12345");
    csStr.ReleaseBuffer();
    pStr=NULL;
    cout<<csStr                 //12345
//使用完GetBuffer后,必须使用ReleaseBuffer以更新对象内部数据,否则会发生无法预料的结果。

void ReleaseBuffer( int nNewLength = -1 );
使用GetBuffer后,必须使用ReleaseBuffer以更新对象内部数据
例:csStr="abc";
    LPTSTR pStr=csStr.GetBuffer(10);
    strcpy(pStr,"12345");
    cout<<csStr.GetLength();       //3(错误的用法)
    csStr.ReleaseBuffer();
    cout<<csStr.GetLength();       //5(正确)
    pStr=NULL;
//CString对象的任何方法都应在ReleaseBuffer之后调用

LPTSTR GetBufferSetLength( int nNewLength );
申请新的空间,并返回指针
例:csStr="abc";
    csStr.GetBufferSetLength(20);
    cout<<csStr;                  //abc
    count<<csStr.GetLength();     //20;
    csStr.ReleaseBuffer();
    count<<csStr.GetLength();     //3;
//使用GetBufferSetLength后可以不必使用ReleaseBuffer。



CString ImagePath = "d:/abc/dd.avi";
int i = ImagePath.ReverseFind(_T('/'));
CString strtest = ImagePath.Left(i+1);


pasting

posted @ 2012-09-21 09:01 盛胜 阅读(304) | 评论 (0)编辑 收藏


int _stricmp( const char *string1, const char *string2 ); strcmp 用来比较ANSI字符串,而_tcscmp用 来比较UNICODE(宽字符)的字符串。ANSI字符串中,1个英文字母为1个字节,1个中文字符为2个字节,遇到0字符表示字符串结束。而在 UNICODE(宽字符)中,所有的字符都为2个字节,此时字符串中间的字节,可能含有0字符,此时就不能用strcmp比较了。

strcmp(char *s1, char *s2) : 按照各个字符(ascii)比较s1和s2,相等则返回0,否则返回ascii相减的结果。
int _stricmp(
   const char *string1,
   const char *string2 
);

Return value

Description

< 0

string1 less than string2

0

string1 identical to string2

> 0

string1 greater than string2



posted @ 2012-09-20 15:15 盛胜 阅读(4856) | 评论 (0)编辑 收藏

CFileDialog
文件选择对话框的使用:首先构造一个对象并提供相应的参数,构造函数原型如下:
CFileDialog::CFileDialog( BOOL bOpenFileDialog, LPCTSTR lpszDefExt = NULL, LPCTSTR lpszFileName = NULL, DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, LPCTSTR lpszFilter = NULL, CWnd* pParentWnd = NULL );

例子:CFileDialog mFileDlg(FALSE, NULL, NULL, OFN_ALLOWMULTISELECT, _T("所有文件 (*.*)|*.*||"), this); 


参数意义如下:

bOpenFileDialog 为TRUE则显示打开对话框,为FALSE则显示保存对话文件对话框。
lpszDefExt 指定默认的文件扩展名。
lpszFileName 指定默认的文件名。
dwFlags 指明一些特定风格。
lpszFilter 是最重要的一个参数,它指明可供选择的文件类型和相应的扩展名。参数格式如:
"Chart Files (*.xlc)|*.xlc|Worksheet Files (*.xls)|*.xls|Data Files (*.xlc;*.xls)|*.xlc; *.xls|All Files (*.*)|*.*||";文件类型说明和扩展名间用 | 分隔,同种类型文件的扩展名间可以用 ; 分割,每种文件类型间用 | 分隔,末尾用 || 指明。
pParentWnd 为父窗口指针。
创建文件对话框可以使用DoModal(),在返回后可以利用下面的函数得到用户选择:
CString CFileDialog::GetPathName( ) 得到完整的文件名,包括目录名和扩展名如:c: est est1.txt
CString CFileDialog::GetFileName( ) 得到完整的文件名,包括扩展名如:test1.txt
CString CFileDialog::GetExtName( ) 得到完整的文件扩展名,如:txt
CString CFileDialog::GetFileTitle ( ) 得到完整的文件名,不包括目录名和扩展名如:test1
POSITION CFileDialog::GetStartPosition( ) 对于选择了多个文件的情况得到第一个文件位置。
CString CFileDialog::GetNextPathName( POSITION& pos ) 对于选择了多个文件的情况得到下一个文件位置,并同时返回当前文件名。但必须已经调用过POSITION CFileDialog::GetStartPosition( )来得到最初的POSITION变量。

posted @ 2012-09-20 09:55 盛胜 阅读(438) | 评论 (0)编辑 收藏

仅列出标题
共14页: First 6 7 8 9 10 11 12 13 14