//一、打開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);
//十一、窗口自動靠邊程序演示
BOOL AdjustPos(CRect* lpRect)
{//自動靠邊
int iSX=GetSystemMetrics(SM_CXFULLSCREEN);
int iSY=GetSystemMetrics(SM_CYFULLSCREEN);
RECT rWorkArea;
BOOL bResult = SystemParametersInfo(SPI_GETWORKAREA, sizeof(RECT), &rWorkAre
a, 0);
CRect rcWA;
if(!bResult)
{//如果調用不成功就利用GetSystemMetrics獲取屏幕面積
rcWA=CRect(0,0,iSX,iSY);
}
else
rcWA=rWorkArea;
int iX=lpRect->left;
int iY=lpRect->top;
if(iX < rcWA.left + DETASTEP && iX!=rcWA.left)
{//調整左
//pWnd->SetWindowPos(NULL,rcWA.left,iY,0,0,SWP_NOSIZE);
lpRect->OffsetRect(rcWA.left-iX,0);
AdjustPos(lpRect);
return TRUE;
}
if(iY < rcWA.top + DETASTEP && iY!=rcWA.top)
{//調整上
//pWnd->SetWindowPos(NULL ,iX,rcWA.top,0,0,SWP_NOSIZE);
lpRect->OffsetRect(0,rcWA.top-iY);
AdjustPos(lpRect);
return TRUE;
}
if(iX + lpRect->Width() > rcWA.right - DETASTEP && iX !=rcWA.right-lpRect->Width())
{//調整右
//pWnd->SetWindowPos(NULL ,rcWA.right-rcW.Width(),i ..
訪客只能看到部份內容,免費 加入會員 或由臉書 Google 可以看到全部內容