代码改变世界

Visual C++ 2011-4-6

2011-04-08 09:01  Clingingboy  阅读(609)  评论(0编辑  收藏  举报

 

一.RGB的用法

用宏RGB定义,是COLORREF是DWORD,用GetRValue,GetGValue,GetBValue取相关值

COLORREF color=RGB(0xFF,0X00,0X00);
BYTE redValue=GetRValue(color);

二.SubclassDlgItem的用法

    Call this member function to "dynamically subclass" a control created from a dialog template and attach it to this CWnd object.

参考:http://blog.163.com/rb_shen/blog/static/62422647200812510286393/

三.strcpy_s与strcpy, StringCchCopy的区别

参考:

http://zhouruijun163.blog.163.com/blog/static/1077156201091553626847/
http://blog.csdn.net/baodi_z/archive/2007/07/17/1694640.aspx
http://www.microsoft.com/china/msdn/library/security/secure03102004.mspx?mfr=true

四.sizeof与strlen的区别

sizeof返回字节大小,strlen返回字符串长度,不同概念,sizeof与字符串长度无关

五.MFC的ICON使用方法

先用LoadIcon载入ICON资源,然后调用SetIcon方法设置

m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
SetIcon(m_hIcon, FALSE);

六.CloseHandle的用法

http://www.cnblogs.com/bloodofhero/archive/2010/06/13/1757726.html

七.LogonUser验证Windows用户

用c#的实现p/invoke
参考:http://www.cnblogs.com/scottwong/archive/2009/02/09/1386832.html?login=1

class Program
{
public const int LOGON32_LOGON_INTERACTIVE = 2;
public const int LOGON32_PROVIDER_DEFAULT = 0;
[DllImport("advapi32.dll", CharSet = CharSet.Auto)]
public static extern int LogonUser(string lpszUserName, string lpszDomain, string lpszPassword, int dwLogonType, int dwLogonProvider, ref IntPtr phToken);
static bool Authenticate(string username, string password)
{
IntPtr token = IntPtr.Zero;
bool isAuthenticated = (LogonUser(username, ".", password, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, ref token) != 0);
return isAuthenticated;
}
static void Main(string[] args)
{
string username = "administrator";
string password = "123456";
if (Authenticate(username, password))
{
Console.WriteLine(string.Format("用户 {0} 已经通过身份验证。", username));
}
else
{
Console.WriteLine(string.Format("用户 {0} 未能通过身份验证。", username));
}
Console.Read();
}
}

 

八.__super关键字

调用基类方法的关键字(只能是基类)