資源描述:
《vc++常用函數(shù)》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫(kù)。
1、VC++常用的函數(shù)VC++編程技術(shù)連載---VC++常用的函數(shù)VC++編程技術(shù)連載---VC++常用的函數(shù)一、打開(kāi)CD-ROMmciSendString("SetcdAudiodooropenwait",NULL,0,NULL);二、關(guān)閉CD_ROMmciSendString("SetcdAudiodoorclosedwait",NULL,0,NULL);三、關(guān)閉計(jì)算機(jī)OSVERSIONINFOOsVersionInfo;//包含操作系統(tǒng)版本信息的數(shù)據(jù)結(jié)構(gòu)OsVersionInfo.dwOSVersionInfoSize=sizeof(OSVERSIONINFO);GetVersionE
2、x(&OsVersionInfo);//獲取操作系統(tǒng)版本信息if(OsVersionInfo.dwPlatformId==VER_PLATFORM_WIN32_Windows){//Windows98,調(diào)用ExitWindowsEx()函數(shù)重新啟動(dòng)計(jì)算機(jī)DWORDdwReserved;ExitWindowsEx(EWX_REBOOT,dwReserved);//可以改變第一個(gè)參數(shù),實(shí)現(xiàn)注銷用戶、//關(guān)機(jī)、關(guān)閉電源等操作//退出前的一些處理程序}四、重啟計(jì)算機(jī)typedefint(CALLBACK*SHUTDOWNDLG)(int);//顯示關(guān)機(jī)對(duì)話框函數(shù)的指針HINSTANCEhInst
3、=LoadLibrary("shell32.dll");//裝入shell32.dllSHUTDOWNDLGShutDownDialog;//指向shell32.dll庫(kù)中顯示關(guān)機(jī)對(duì)話框函數(shù)的指針if(hInst!=NULL){//獲得函數(shù)的地址并調(diào)用之ShutDownDialog=(SHUTDOWNDLG)GetProcAddress(hInst,(LPSTR)60);(*ShutDownDialog)(0);}五、枚舉所有字體LOGFONTlf;lf.lfCharSet=DEFAULT_CHARSET;//InitializetheLOGFONTstructurestrcpy(lf.
4、lfFaceName,"");CClientDCdc(this);//Enumeratethefontfamilies::EnumFontFamiliesEx((HDC)dc,&lf,(FONTENUMPROC)EnumFontFamProc,(LPARAM)this,0);//枚舉函數(shù)intCALLBACKEnumFontFamProc(LPENUMLOGFONTlpelf,LPNEWTEXTMETRIClpntm,DWORDnFontType,longlparam){//CreateapointertothedialogwindowCDay7Dlg*pWnd=(CDay7Dlg*)l
5、param;//addthefontnametothelistboxpWnd->m_ctlFontList.AddString(lpelf->elfLogFont.lfFaceName);//Return1tocontinuefontenumerationreturn1;}//其中m_ctlFontList是一個(gè)列表控件變量六、一次只運(yùn)行一個(gè)程序?qū)嵗?,如果已運(yùn)行則退出if(FindWindow(NULL,"程序標(biāo)題"))exit(0);七、得到當(dāng)前鼠標(biāo)所在位置CPointpt;GetCursorPos(&pt);//得到位置八、上下文菜單事件觸發(fā)事件OnContextMenu事件九、顯示
6、和隱藏程序菜單CWnd*pWnd=AfxGetMainWnd();if(b_m)//隱藏菜單{pWnd->SetMenu(NULL);pWnd->DrawMenuBar();b_m=false;}else{CMenumenu;menu.LoadMenu(IDR_MAINFRAME);////顯示菜單也可改變菜單項(xiàng)pWnd->SetMenu(&menu);pWnd->DrawMenuBar();b_m=true;menu.Detach();}十、獲取可執(zhí)行文件的圖標(biāo)HICONhIcon=::ExtractIcon(AfxGetInstanceHandle(),_T("NotePad.exe
7、"),0);if(hIcon&&hIcon!=(HICON)-1){pDC->DrawIcon(10,10,hIcon);}DestroyIcon(hIcon);十一、窗口自動(dòng)靠邊程序演示BOOLAdjustPos(CRect*lpRect){//自動(dòng)靠邊intiSX=GetSystemMetrics(SM_CXFULLSCREEN);intiSY=GetSystemMetrics(SM_CYFULLSCREEN);RECTrWor