光标:
int ShowCursor(BOOL bShow); //显示隐藏光标
BOOL SwapMouseButton(BOOL fSwap); //鼠标左右键交换
UINT GetDoubleClickTime(void); //取得鼠标双击时间
BOOL SetDoubleClickTime(UINT uInterval); //设置鼠标双击时间
BOOL ClipCursor(CONST RECT* lpRect); //锁定鼠标在某个范围
BOOL ClipCursor(CONST RECT* lpRect); //解除鼠标锁定
CDC设备环境:
HDC hDC=::GetDC(NULL); //屏幕绘图
::MoveToEx(hDC,0,0,NULL);
LineTo(hDC,200,20);
::ReleaseDC(NULL,hDC);
HDC hDC=::GetDC(m_hWnd); //客户区绘图
::MoveToEx(hDC,0,0,NULL);
LineTo(hDC,200,50);
::ReleaseDC(m_hWnd,hDC);
CDC *pDC=GetDC();
pDC->MoveTo(0,0);
pDC->LineTo(200,100);
ReleaseDC(pDC);
CClientDC dc(this); //客户区绘图
CBrush brush(RGB(255,0,0));
dc.FillRect(CRect(0,0,100,100),&brush);
CWindowDC dc(this); //窗体绘图
CPen pen(PS_SOLID,3,RGB(0,255,0));
CPen *pOldPen=dc.SelectObject(&pen);
dc.MoveTo(0,0);
dc.LineTo(200,200);
dc.SelectObject(pOldPen);
CWindowDC *pDC; //堆中DC绘图
pDC=new CWindowDC(this);
pDC->MoveTo(0,0);
pDC->LineTo(200,250);
delete pDC;
RGB颜色收集:
RGB(255,255,207) //淡黄色
系统应用:
1.设定系统自动登录
HKEY hkey;
TCHAR g_pcszValue[] = _T("1");
CMimaDlg dlg;
if(dlg.DoModal() != IDOK)
{
return;
}
TCHAR* g_pcszMima =(TCHAR *) new char[dlg.m_strMima.GetLength()];
g_pcszMima = _T(dlg.m_strMima.GetBuffer(dlg.m_strMima.GetLength()));
if(RegOpenKey( HKEY_LOCAL_MACHINE, _T("Software\\Microsoft\\Windows NT\\CurrentVersion\\WinLogon"), &hkey ) == ERROR_SUCCESS )
{
if(!RegSetValueEx(hkey, _T("AutoAdminLogon"), 0, REG_SZ, reinterpret_cast<CONST BYTE *>(g_pcszValue), sizeof( g_pcszValue ) / sizeof( g_pcszValue[0] ) ) == ERROR_SUCCESS )
{
AfxMessageBox("设定失败!");
return;
}
if(!RegSetValueEx(hkey, _T("DefaultPassword"), 0, REG_SZ, reinterpret_cast<CONST BYTE *>(g_pcszMima), sizeof( g_pcszMima ) / sizeof( g_pcszMima[0] ) ) == ERROR_SUCCESS )
{
AfxMessageBox("设定失败!");
TCHAR pcszValue[] = _T("0");
RegSetValueEx( hkey, _T("AutoAdminLogon"), 0, REG_SZ, reinterpret_cast<CONST BYTE *>(pcszValue), sizeof( pcszValue ) / sizeof( pcszValue[0] ) );
}
else
AfxMessageBox("设定成功!重新启动即可生效!\r\n 请注意系统安全!");
}
else
{
AfxMessageBox("设定失败!");
}
取消系统自动登陆:
HKEY hkey;
TCHAR g_pcszValue[] = _T("0");
if(RegOpenKey(HKEY_LOCAL_MACHINE, _T("Software\\Microsoft\\Windows NT\\CurrentVersion\\WinLogon"), &hkey ) == ERROR_SUCCESS )
{
if(!RegSetValueEx( hkey, _T("AutoAdminLogon"), 0, REG_SZ, reinterpret_cast<CONST BYTE *>(g_pcszValue), sizeof( g_pcszValue ) / sizeof( g_pcszValue[0] ) ) == ERROR_SUCCESS )
{
AfxMessageBox("设定失败!");
}
else
AfxMessageBox("设定成功!重新启动即可生效!\r\n 请注意系统安全!");
}
else
{
AfxMessageBox("设定失败!");
}
2.热键HotKey
注册热键:
UpdateData(TRUE);
m_Wap.MakeUpper();
m_Dlg.MakeUpper();
if(::RegisterHotKey(this->m_hWnd,0Xa002,MOD_CONTROL,(UINT)m_Wap[0])
&&::RegisterHotKey(this->m_hWnd,0Xa001,MOD_CONTROL,(UINT)m_Dlg[0]))
AfxMessageBox("*^_^* 热键已经注册了 *^_^*");
热键消息拦截:
void CHotDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
if (nID==SC_MINIMIZE)
{
ShowWindow(SW_HIDE);
}
else
CDialog::OnSysCommand(nID, lParam);
}
BOOL CHotDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if (pMsg->message==WM_HOTKEY && pMsg->wParam==0Xa002)
{
HWND handle=FindWindowEx(NULL,NULL,NULL,"Winamp 播放清单编辑器");
HWND handle2=FindWindowEx(NULL,NULL,NULL,"Winamp Playlist Editor");
if(handle)
{
::ShowWindow(handle,SW_SHOWNORMAL);
::SetForegroundWindow(handle);
}
if(handle2)
{
::ShowWindow(handle2,SW_SHOWNORMAL);
::SetForegroundWindow(handle2);
}
}
if (pMsg->message==WM_HOTKEY && pMsg->wParam==0Xa001)
{
::ShowWindow(this->m_hWnd,SW_SHOWNORMAL);
::SetForegroundWindow(this->m_hWnd);
}
return CDialog::PreTranslateMessage(pMsg);
}
热键取消:
void CHotDlg::OnClose()
{
// TODO: Add your message handler code here and/or call default
UnregisterHotKey(this->m_hWnd,0Xa001);
UnregisterHotKey(this->m_hWnd,0Xa002);
CDialog::OnClose();
}
3.静态连接库:
生成静态连接库文件
//头文件,定义外部调用函数 Lib.h
#ifndef __LIB_H__
#define __LIB_H__
#ifdef __cplusplus
extern "C"
{
#endif
int sum(int num1,int num2);
int mult(int num1,int num2);
#ifdef __cplusplus
}
#endif
#endif //__LIB_H__
cpp文件
#include "Lib.h"
int sum(int num1,int num2)
{
return num1+num2;
}
int mult(int num1,int num2)
{
return num1*num2;
}
测试静态链接库
#include "Lib.h" //包含静态库的头文件
#pragma comment(lib,"Lib") //引入静态库
int a = 5, b = 7;
int c = sum (a, b);
int d = mult (a, b);
CString str;
str.Format ("和:%d积:%d", c, d);
MessageBox (str);