VC Common Skills Highlights (1)

zhaozj2021-02-16  59

One. How to limit the graphics in the edit box and modify the input character using the ClassWizard to process the WM_CHAR message, calculate the nchar parameter and determine the operation performed, and the user can determine whether to modify, transmit characters. The following example shows how to display alphanumeric characters. If the character is alphabetical character, call CWnd; onchar, otherwise I don't call onchar. Void CMyedit:: onchar (uint nchar, uint nrepcnt, UITN NFLAGS) {file: // determine if nchar IS An alphabetic character. if (: ischaralpha ((tchar) nchar) CEDIT:: onchar (nchar, nrepcnt, nflags);} If you want to modify the character, you cannot simply call the Cedit:: onchar, Then CEDIT:: OnChar calls CWnd:: Default Gets the value of the original WPARAM and LPARAM, which is not. To modify a character, you need to modify NCHAR first, then call CWnd:: DefWindowProc with modified NCHAR. The following example shows how to transform characters to uppercase: file: // make all characters Uppercase void CMYEDIT:: OnChar (uint nchar, uint nrepcnt, uint nflags) {file: // make sure character is uppercase. Imp (: ischaralpha) (. (TCHAR) nChar) nChar =:: CharUpper (nChar); file: // Bypass default OnChar processing and directly call file:. // default window proc DefWindProc (WM_CHAR, nChar, MAKELPARAM (nRepCnt, nFlags));}

two. During the operation, how to prohibit the closing button at the top right of the window CMenu * pmenu = AFXGETMAINWND () -> getSystemMenu (false); if (pmenu) pmenu-> EnableMenuItem (sc_close, mf_bycommand | mf_grayed);

// By non-disabled state cmenu * pmenu = AFXGETMAINWND () -> getSystemMenu (false); if (pmenu) pmenu-> EnableMenuItem (sc_close, mf_bycommand | mf_enable);

three. Method of drawing screen does not flash When a certain area of ​​the window is invalid, the system will send a WM_UPDATE message to trigger a heavy blow to the view. If all graphic objects are simply drawn in the onDraw () function, it will cause significant flashing. Therefore, it is necessary to do corresponding processing. This system uses a graphic drawing in memory, and then copy the drawn graphic from the memory to the window customer. Void CDrawview :: OnDraw (CDC * PDC) {CDRAWDOC * PDOC = getDocument (); assert_valid (pdoc);

CDC DC; cBitmap Bitmap;

Cbitmap * PoldbitMap; CRECT Client; CRECT Client; CRECT Client; PDC-> getClipbox (client); // Check the invalid area getClientRect (RECT); // Check the entire client area IF (DC.CREATECOMPALEDC (PDC)) // creation one with PDC compatible memory device enumeration {if (bitmap.createcompatiblebitmap (PDC, Rect.Width (), Rect.Height ())) // Create a bitmap with PDC compatible, size is the entire client area {onpreparedc (& DC, NULL ); // Make DC and PDCs with the same mapping relationship PoldbitMap = Dc.selectObject (& Bitmap); // Select bitmap to memory environment dc.selectclipRgn (null); // Make DC's entire customer area into invalid zone DC. InterSectClipRect (client); // "and" with "the invalid area for detecting the File: // memory environment and PDC, etc.}} CBRUSH Brush; if (! brush.createsolidbrush (RGB (255, 255, 255) ))); brush.unRealizeObject (); dc.FillRect (Client, & Brush); // Refresh the DC's pattern area into background color IF (m_drawobjs.getcount ()! = 0) DRAW (& DC); // Put all the drawings in memory

PDC-> Bitblt (Client.wid, Client.top, Client.width (), Client.Height (), & DC, Client.Left, Client.top, Srccopy; // Pits the bitmap of the plug-in zone. File: / / Copy to window clipping zones dc.selectObject (PoldbitMap);

}

转载请注明原文地址:https://www.9cbs.com/read-22424.html

New Post(0)