一、 加载图标ICO资源
HICON m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); // 加载图标
二、 程序运行过程中设置图标
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
三、 获取屏幕像素
int nWidth=GetSystemMetrics(SM_CXSCREEN); //屏幕宽度
int nHeight=GetSystemMetrics(SM_CYSCREEN); //屏幕高度
四、 设置窗口形状
在初始化函数OnInitDialog()
CRect rct;
GetClientRect(&rct);
CRgn hRgn;
hRgn.CreateRoundRectRgn(20,20,rct.Width()-10,rct.Height()-10,20,20);
SetWindowRgn(hRgn,true);//设置窗口形状
五、 创建自定义字体并输出文字
CDC *pDC =GetDC();
CFont m_font;
//m_font.CreateFont(60,40,0,900, 4,
///0,0,0,0,0,0,0,0,"Times New Roman");
VERIFY(m_font.CreateFont(
48, // nHeight
36, // nWidth
3300, // nEscapement,倾角为330°
0, // nOrientation
FW_HEAVY, // nWeight
FALSE, // bItalic
FALSE, // bUnderline
0, // cStrikeOut
ANSI_CHARSET, // nCharSet
OUT_DEFAULT_PRECIS, // nOutPrecision
CLIP_DEFAULT_PRECIS, // nClipPrecision
DEFAULT_QUALITY, // nQuality
DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily
_T("Times New Roman"))); // lpszFacename
CFont* def_font = pDC->SelectObject(&m_font);
//pDC->SetBkMode(TRANSPARENT);
pDC->SetTextColor(RGB(0,161,255));//设置文本颜色
pDC->SetBkMode(TRANSPARENT);//设置文本背景为透明
pDC->TextOut(223,223,"扭矩nm");//输出文字
六、 设置窗口背景颜色
BOOL CYuApp::InitInstance()
{
AfxEnableControlContainer();
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
else
Enable3dControlsStatic(); // Call this when linking to MFC statically
endif
SetDialogBkColor(RGB(0,0,0),RGB(0,161,234));//设置背景颜色
CYuDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
}
七、 字节对齐
在操作系统中存在字节对齐现象,比如32为操作系统的单位为32位,即四字节。
对于一个数据到底占据了多少内存空间可以用以下函数
####define _INTSIZEOF(n) ( (sizeof(n) + sizeof(int) - 1) & ~(sizeof(int) - 1) )
_INTSIZEOF(char) =4;
_INTSIZEOF(unsigned char) =4;
_INTSIZEOF(short) =4;
_INTSIZEOF(unsigned short) =4;
_INTSIZEOF(int) =4;
_INTSIZEOF(unsigned int) =4;
_INTSIZEOF(long) =4;
_INTSIZEOF(unsigned long) =4;
_INTSIZEOF(__int64) =8;
_INTSIZEOF(unsigned __int64) =8;
_INTSIZEOF(float) =4;
_INTSIZEOF(double) =8;
八、 如何获取当前应用程序完整路径名字
char exeFullPath[128]; // MAX_PATH在API中定义了吧,好象是 128
GetModuleFileName(NULL,exeFullPath,MAX_PATH);
printf("\r\n[%s]\r\n",exeFullPath);//
printf("\r\n[%s]\r\n",argv[0]);//main函数传入的第一个参数,应用程序的名称