First, open CD-ROM MCISENDSTRING ("SET CDAUDIO DOOR Open Wait", NULL, 0, NULL); Second, close CD_ROM McISendstring ("Set CDAUDIO DOOR CLOSED WAIT", NULL, 0, NULL); 3, turn off computer OsversionInfo OsversionInfo ; OsVersionInfo.dwOSVersionInfoSize // data structure contains the operating system version information = sizeof (OSVERSIONINFO); GetVersionEx (& OsVersionInfo); // Get OS version information if (OsVersionInfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) {// Windows98, call the ExitWindowsEx () The function restarts the computer DWORD DWRESERVED; EXITWINDOWSEX (EWX_REBOOT, DWRESERVED); / / You can change the first parameter, implement some of the processing prior to logout user, //, turn off the power, etc. Operation, some processing prior to exit} four, restart the computer TypedEf Int (Callback * shutdowndlg) (int); // Shows the pointer of the shutdown dialog function Hinstance hinst = loadLibrary ("shell32.dll"); // Load shell32.dll shutdowndlg shutdowndialog; // Point to Shout in the shell32.dll library Pointer IF (Hinst! = NULL) {// Get the address of the function and call Shutdowndialog = (* shutdowndialog) (0);} 5, enumeration All fonts 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); // Enumeration function 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;} wherein a is m_ctlFontList List control variable six, only run a program instance at a time, if you have run, exit if (FindWindow (NULL, "Program Title")) EXIT (0); 7. Get the current mouse in location CPoint Pt; getCursorpos (& PT); / / Get position eight, context menu event trigger event:
OnContextMenu event nine, display and hidden program menus CWND * PWND = AFXGETMAINWND (); if (b_m) // Hide menu {PWND-> setMenu (null); PWND-> DrawMenuBar (); b_m = false;} else {cmenu menu Menu.LoadMenu (idR_mainframe); Display menu can also change the menu item PWND-> setMenu (& menu); pWnd-> DrawMenuBar (); b_m = true; menu.detach ();} 10, get the executable icon HICON Hicon = :: Extracticon (AFXGETINSTANCEHANDLE (), _ T ("NOTEPAD.EXE"), 0); IF (HiCon && HiCon! = (HICON) -1) {PDC-> Drawicon (10, 10, hicon);} destroyicon the hIcon); XI, automatic window aside program demonstrates BOOL AdjustPos (CRect * lpRect) {// automatically aside 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) {// If the call is unsuccessful, use GetSystemMetrics to get the screen area RCWA = CRECT (0, ISX, ISY);} else rcwa = rworkarea; INT IX = LPRECT-> LEFT; int = lprect-> top; if (ix
SetWindowPos (NULL, IX, RCWA.BOTTOM-RCW.HEIGHT (), 0, 0, SWP_NOSize; LPRECT-> OffsetRect (0, rcwa.bottom-lprect-> bottom); return true;} Return false;} // Then use the procedure in the onmoveing event to call CRECT R = * prect; AdjustPos (& R); * prect = (RECT) R; 12, add a menu item to the system menu to add a menu item to the system menu requires the following Three steps: First, use the Resource Symbols dialog (select Resource Symbols ... You can display the dialog in the View menu) Define the menu item ID, the ID should be greater than 0x0F and less than 0xF000; second, call CWnd :: getSystemMenu Get System Menu pointer and call CWnd :: Appendmenu Add menu items to the menu. The following example adds two new int CMainFrame :: OnCreate (LPCREATESTRUCT lpCreateStruct) {... // Make sure the system menu system menu item is in the right range ASSERT (IDM_MYSYSITEM <0xF000);. // Get pointer to system menu CMenu. * pSysMenu = GetSystemMenu (FALSE); ASSERT_VALID (pSysMenu);. // Add a separator and our menu item to system menu CString StrMenuItem (_T ( "New menu item")); pSysMenu-> AppendMenu (MF_SEPARATOR); pSysMenu-> Appendmenu (MF_String, IDM_MYSISISITEM, STRMENUITEM); ...} Thirteen, run other programs // 1, run Email or URL Char SzmailAddress [80]; STRCPY (Szmailaddress, "Mailto: Netvc@21cn.com"); Shellexecute (Null, "open", szmailaddress, null, null, sw_shownormal; // 2, run executable program WINEXEC ("notepad.exe", sw_show); // Run count of fourteen, dynamically increase or delete menu 1, add menu // Add cmenu * mainmenu; mainmenu = AFXGETMAINWND () -> getMenu (); // Get the main menu (MainMenu-> getSubmenu (0)) -> appendmenu (mf_separator); // Add Division (MainMenu-> GetSubmenu) 0) -> appendmenu (mf_string, id_app_about, _t ("always on & top")); // Add new menu item DrawMenubar (); // Heavy painting menu 2, delete menu // Delete cmenu * mainmenu; mainmenu = AFXGETMAINWND () -> getMenu (); // Get the main menu CSTRING STR; for (INT i = (MainMenu-> GetSubMenu (0)) -> getMenuItemCount () - 1; I> = 0; I -) // Take the number of items in the menu.
{(MAINMENU-> GetSubMenu (0)) -> getMenustring (i, str, mf_byposition); // copy the label of the specified menu item to the specified buffer. Explanation of MF_BYPosition. IF (str == "always on & top") // If we have just increased menu items, then delete. {(MAINMENU-> GetSubMenu (0)) -> DeleteMenu (i, mf_byposition); Break;} fifteen, changing the icon static changes to the application: Modify the icon resource IDR_MAINFRAME. It has two icons, one is 16 * 16, the other is 3 2 * 32, pay attention to modify together. Dynamic changes: Send WM_SETICON messages to the main window. The code is as follows: hicon hicon = AFXGetApp () -> loading (idi_icon); Assert (Hicon); AFXGETMAINWND () -> SendMessage (wm_seticon, true, (lparam) Hicon; 16 Another method of changing the window title uses statement CWnd * m_pcWnd = AFXGETMAINWND (), then call the setWindowTe XT () function in the following form: setWindowText (* m_pcwnd, (lpctstr) m_windowtext); // m_windowtext can be a CST Ring class variable. 17. Copying image data by enhancement panels on the clipboard to copy image data to any application through the metafile, which can be placed in the CVIEW derived function.
Cmetafiledc * m_pmetadc = new cmetafiled (); m_pmetadc-> createenhacesd (getdc (), null, null, "whatver"); // Draw meta file // do what Ever You Want to do: Bitmaps, Lines, Text ... // close meta file dc and prepare for clipboard; HENHMETAFILE hMF = m_pMetaDC-> CloseEnhanced (); // copy to clipboard OpenClipboard (); EmptyClipboard (); :: SetClipboardData (CF_ENHMETAFILE, hMF); CloseClipboard (); // DeleteMetaFile (HMF); DELETE M_PMETADC; Eighteen, the transfer of text data on the clipboard puts text onto the splic panel: cstring source; // put your text in Source if (OpenClipBoard ()) {Hglobal Clipbuffer; Char * Buffer; EmptyClipboard (); clipbuffer = GlobalAlloc (GMEM_DDESHARE, source.GetLength () 1); buffer = (char *) GlobalLock (clipbuffer); strcpy (buffer, LPCSTR (source)); GlobalUnlock (clipbuffer); SetClipboardData (CF_TEXT, clipbuffer ); CloseClipboard ();} Get text from the splic panel: char * buffer; if (OpenClipboard ()) {buffer = (char *) getclipboardData (cf_text); // do sometying with buffer here // before IT Goes out of scope}; 19th, capture screen images to cutting version void cshowbmpindlgdlg :: oncutscreen () {showwindow (sw_hide); Rect r_bmp = {0, 0, :: getSystemmetrics (SM_CXSCREEN),: : GetSystemMetrics (SM_CYSCREEN)}; HBITMAP hBitmap; hBitmap = CopyScreenToBitmap (& r_bmp); // hWnd is the window handle if (OpenClipboard ()) {EmptyClipboard (); SetClipboardData (CF_BITMAP, hBitmap); CloseClipboard ();} ShowWindow (SW_SHOW );} Hbitmap cshowbmpindlgdlg :: CopyScreenTOBTMAP (LPRECT LPRECT) {// lpRect Represents Selected Area {HDC HSCRDC, HMEMDC; // Screen and Memory Device Description Table Hbitmap Hbitmap, Holdbitmap; // Bit, NY, NX2 , NY2; // Select area coordinate int NWIDTH, NHEIGHT;
// bitmap width and height int xscrn, yscrn; // screen resolution // Make sure the selected area is not empty rectangular IF (isRectempty (LPRECT)) Return Null; / / Create a device description table hscrdc = createdc (" Display ", NULL, NULL, NULL); // Create a compatible memory device description table hmemdc = createcompatibledc (HSCRDC); // Get selected area coordinate Nx = lpRect-> Left; NY = lpRect-> Top; nx2 = lprect-> Right; NY2 = LPRECT-> BOTTOM; // Get screen resolution xscrn = getDeviceCaps (HSCRDC, Horzres); YSCRN = getDeviceCaps (HSCRDC, Vertres); / / Make sure the selected area is visible if IF (NX <0) Nx = 0; IF (NY <0) NY = 0; IF (Nx2> XSCRN) NX2 = Xscrn; IF (NY2> YSCRN) NY2 = YSCRN; NWIDTH = Nx2 - NX; NHEight = NY2 - NY (/) Creating a bitmap hbitmap = createcompatiblebitmap (HSCRDC, NWIDTH, NHEIGHT), selection of new bitmap = (hbitmap) SelectObject (HBitmap) SelectObject (HbitMap) in the memory device descriptor table. / / Copy the screen device description table to the memory device description table Bitblt (HMEMDC, 0, 0, NWIDTH, NHEIGHT, HSCRDC, NX, NY, SRCCOPY); // Get the handle of the screen bitmap hbitmap = (hbitmap) SelectObject HMEMDC, HoldbitMap; // Clear DeleteDC (HSCRDC); deletedc (hmemdc); // Return bitmaphe Return HbitMap;}}} 20, how to display bitmap scaling in the Static control // Display bit in STAIC control Figure void cshowbmpindlgdlg :: showbmpinstaic () {cbitma p hbmp; hbitmap hbitmap; // Point PSTATIC to the place to display CSTATIC * PSTAIC; PSTAIC = (cstatic *) getdlgitem (IDC_IMAGE); // Loading resource mm.bmp is my file name, with your replacement hbitmap = (Hbitmap) :: loadimage (:: AfxGetInstanceHandle (), "mm.bmp", image_bitmap, 0, 0, lr_loadfromfile | lr_createdibsection; hbmp.attach (hbitmap); // Get image format Bitmap BM; HBMP.GETBITMAP (& BM ); CDC DCMEM; DCMEM.CREATECMOMPALEDC (GETDC ()); cbitmap * Poldbitmap = (cbitmap *) DcMem.selectObject (HBMP); CRECT LRECT; PSTAIC-> getClientRect (& LRECT); // Display bitmap PSTAIC-> Getdc ) -> stretchblt (LRECT.EFT, LRECT.TOP, LRECT.WIDTH (), LRECT.HEIGH T (), & DCMEM, 0, 0, BM.BMWIDTH, BM.BMHEIGHT, SRCCPY;