重启、关闭计算机 打开/关闭CD-ROM获取本机已安装的字体修改执行文件图标

来源:互联网 发布:k 线数据 编辑:程序博客网 时间:2024/06/06 04:25

一、重启计算机

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);
}

二、关闭计算机

OSVERSIONINFO OsVersionInfo; //包含操作系统版本信息的数据结构
OsVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx(&OsVersionInfo); //获取操作系统版本信息
if(OsVersionInfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
{
    //Windows98,调用ExitWindowsEx()函数重新启动计算机
    DWORD dwReserved;
    ExitWindowsEx(EWX_REBOOT,dwReserved); //可以改变第一个参数,实现注销用户、
    //关机、关闭电源等操作
    // 退出前的一些处理程序
}

三、打开CD-ROM

mciSendString("Set cdAudio door open wait",NULL,0,NULL);

四、关闭CD_ROM

mciSendString("Set cdAudio door closed wait",NULL,0,NULL);

五、枚举所有字体

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是一个列表控件变量

 

/// 方法二:使用GDIPlus获取系统已经安装的字体,

/// 与方法一的结果有一些区别,其字体类型数量可能较少
InstalledFontCollection InstalledFont; 
int iFontCount = InstalledFont.GetFamilyCount();
FontFamily* pInstalledFontFamilies = new FontFamily[iFontCount];
int numFamilies = 0;
InstalledFont.GetFamilies(iFontCount, pInstalledFontFamilies, &numFamilies);
ASSERT(iFontCount == numFamilies);
FontFamily* pFontFamilies = pInstalledFontFamilies;

for(int i = 0;i < iFontCount; ++i) 
{
   TCHAR wcsFontName[ARRAY_MAX] = {0};
   if(pFontFamilies != NULL)
   {
    pFontFamilies->GetFamilyName(wcsFontName);
   }
   if(wcsFontName[0] != NULL)
   {
     //添加字体到控件 
     m_ctlFontList.AddString(wcsFontName);
   }
   ++pFontFamilies;


delete []pInstalledFontFamilies;

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

CPoint pt;
GetCursorPos(&pt); //得到位置

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

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

 

九、改变应用程序图标的方法:

    静态更改:修改图标资源IDR_MAINFRAME。它有两个图标,一个是16*16的,另一个是32*32的,注意要一起修改。

  动态更改: 向主窗口发送WM_SETICON消息.代码如下:

    HICON hIcon=AfxGetApp()->LoadIcon(IDI_ICON);
    ASSERT(hIcon);
    AfxGetMainWnd()->SendMessage(WM_SETICON,TRUE,(LPARAM)hIcon);

十、一种改变窗口标题的方法

  使用语句 CWnd* m_pCWnd = AfxGetMainWnd( ),然后,再以如下形式调用SetWindowText()函数:

//m_WindowText可以是一个CString类的变量。

SetWindowText( *m_pCWnd,(LPCTSTR)m_WindowText);

原创粉丝点击