Visual C++上的二十个常用方法

分类: VC.NET   出处:iocblog整理  更新时间:2009-05-17   添加到收藏  

一、打开cd-rom

mcisendstring("set cdaudio door open wait",null,0,null); 

二、关闭cd_rom

mcisendstring("set cdaudio door closed wait",null,0,null);  

三、关闭计算机

osversioninfo osversioninfo; //包含操作系统版本信息的数据结构
osversioninfo.dwosversioninfosize = sizeof(osversioninfo);
getversionex(&osversioninfo); //获取操作系统版本信息
if(osversioninfo.dwplatformid == ver_platform_win32_windows)
{
//windows98,调用exitwindowsex()函数重新启动计算机

dword dwreserved;
exitwindowsex(ewx_reboot,dwreserved); //可以改变第一个参数,实现注销用户、
//关机、关闭电源等操作
// 退出前的一些处理程序
}  

四、重启计算机

typedef int (callback *shutdowndlg)(int); //显示关机对话框函数的指针
hinstance hinst = loadlibrary("shell32.dll"); //装入shell32.dll
shutdowndlg shutdowndialog; //指向shell32.dll库中显示关机对话框函数的指针
if(hinst != null)
{
//获得函数的地址并调用之
shutdowndialog = (shutdowndlg)getprocaddress(hinst,(lpstr)60);

(*shutdowndialog)(0);

五、枚举所有字体

logfont lf;
lf.lfcharset = default_charset; // initialize the logfont structure
strcpy(lf.lffacename,"");
cclientdc dc (this);
// enumerate the font families
::enumfontfamiliesex((hdc) dc,&lf,                                                                                      
(fontenumproc) enumfontfamproc,(lparam) this,0);
//枚举函数
int callback enumfontfamproc(lpenumlogfont lpelf,
lpnewtextmetric lpntm,dword nfonttype,long lparam)

{
// create a pointer to the dialog window
cday7dlg* pwnd = (cday7dlg*) lparam;
// add the font name to the list box
pwnd ->m_ctlfontlist.addstring(lpelf ->elflogfont.lffacename);
// return 1 to continue font enumeration
return 1;

 其中m_ctlfontlist是一个列表控件变量

六、一次只运行一个程序实例,如果已运行则退出

 if( findwindow(null,"程序标题")) exit(0);

七、得到当前鼠标所在位置

cpoint pt;
getcursorpos(&pt); //得到位置 

八、上下文菜单事件触发事件:OnContextMenu事件

九、显示和隐藏程序菜单


 

 

CWnd *pWnd=AfxGetMainWnd();
if(b_m) //隐藏菜单
{
pWnd->SetMenu(NULL);
pWnd->DrawMenuBar();
b_m=false;
}
else
{
CMenu menu;
menu.LoadMenu(IDR_MAINFRAME); ////显示菜单 也可改变菜单项
pWnd->SetMenu(&menu);
pWnd->DrawMenuBar();
b_m=true;
menu.Detach();

十、获取可执行文件的图标

 

HICON hIcon=::ExtractIcon(AfxGetInstanceHandle(),_T("NotePad.exe"),0);
if (hIcon &&hIcon!=(HICON)-1)
{
pDC->DrawIcon(10,10,hIcon);
}
DestroyIcon(hIcon); 

[1] [2] [3] 下一页



文章整理:iocblog
版权申明:本站文章均来自网络,如有侵权,请联系我们,我们收到后立即删除,谢谢!
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有。