VC开发小技巧(1)

发表于:2007-06-11来源:作者:点击数: 标签:
一、打开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.dw

一、打开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);


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

原文转自:http://www.ltesting.net

...