VC FAQ

xiaoxiao2021-03-17  199

1. When the mouse changes the shape of the mouse in the window: HCURSOR HCURSOR = LoadCursor (AFXGetInstanceHandle (), makeintresource (IDC_CURSOR1)); :: setClasslong (M_HWND, GCL_HCURSOR, (long) hcursor;

2, let the window always display on other windows: setWindowPos (& Wndtopmost, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);

3, change the Static control background color: Processing WM_CTLCOLOR: IF (PWND-> getsafehwnd () == getdlgitem (idc_static1) -> getsafehwnd () && ctlcolor_static == nctlcolor) {m_bkbrush.createsolidbrush (RGB (255, 0, 0)) PDC-> setBkmode (Transparent); return m_brbrush;} return Hbr;

4, change the title bar icon: HICON hLargeIcon = AfxGetApp () -> LoadIcon (IDI_NEW_ICON); HICON hSmallIcon = (HICON) :: LoadImage (AfxGetResourceHandle (), MAKEINTRESOURCE (IDI_NEW_ICON), IMAGE_ICON, 16,16, LR_DEFAULTCOLOR); SetIcon ( Hlargeicon, True; Seticon (HSMallicon, False);

5, the window size limit in a specific size range: Processing WM_GETMINMAXINFO: LRESULT OnGetMinMaxInfo lParam (WPARAM wParam, LPARAM lParam) {MINMAXINFO * pmmi = (MINMAXINFO *); pmmi-> ptMinTrackSize.x = 100; pmmi-> ptMinTrackSize.y = 150; PMMi-> ptmaxtracksize.x = 600; pmmi-> ptmaxtracksize.y = 400;}

6, a plus button image: HBITMAP m_hBitmap defined as member variables CTestDlgDlg; void CXXXDlg :: OnButton () {m_hBitmap = :: LoadBitmap (:: AfxGetInstanceHandle (), MAKEINTRESOURCE (IDB_BMP_MYBMP)); m_cBtnBmp.SetBitmap (m_hBitmap);}

7, set the initial size of the program window

Add code in cxxxapp :: initInstance ():

m_pmainwnd-> setWindowPos (NULL, 0, 0, 750, 500, SWP_NOMOVE);); // Setting the initial size of 750 * 500

8, how to maximize and minimize the window and the MDI window?

Let's talk about the window first. Set the value of m_ncmdshow in the initstance function. M_ncmdshow = sw_showmaxmizeD // Maximize m_ncmdshow = sw_showminmized // minimize m_ncmdshow = sw_shownormal // normal way

MDI window: If you create a new application, you can use the MFC AppWizard's Advanced button and detect the maximum or minimize the MDI Window's PrecreateWindow function in the MDI sub-window style group. Set WS_MAXMIZE or WS_MINMIZE if you are derived from cmdichildwnd Call CWnd :: Show Window in the OnInitialUpdate function to specify the style of the MDI Child Window.

Maximize the documentation actions: If you are VC4.0, then just select MDI-> maximized in Advance when CREATE. If VC5, then in the OnInitUpdate member function of the view class, add:

CMDICHILDWND * PWND = (cmdichildwnd *) getParentFrame (); PWND-> mdimaximize ();

9. How to dynamically obtain the toolbar pointer and give the toolbar Total I don't want to dynamically change the title of the toolbar in cmainframe :: oncreate (): int CMAINFRAME :: OnCreate (lpcreatestruct lpCreateStruct) {... m_wndtoolbar.SetWindowText (_T ("standdard"));

Return 0;} If you want to dynamically change the title of the toolbar, as follows: Declare a menu, and respond to events, such as response: onmytoolbar () function void cmainframe :: ONMYTOOLBAR () {// Todo: add Your Command Handler Code Here CToolbar * Ptoolbar = (ctoolbar *) AFXGETMAINWND () -> getDescendantWindow; ptoolbar-> setWindowText (_t ("st (" st ("st (" st ("standdard"));} Do not do onMytoolbar () when TOOBAR is suspended, you get the pointer: cstatusbar * pstatusbar = (cstatusbar *) AFXGETMAINWND () -> getDescendantWindow (AFX_IDW_STATUS_BAR);

10. How to hide the toolbar to add the following two functions Hide: Void cmainframe :: onhide () {if (m_wndtoolbar.IswindowVisible ()) m_wndtoolbar.ModifyStyle (ws_visible, 0); sendMessage (wm_size);}

Display: void CMainFrame :: OnShow () {if m_wndToolBar.ModifyStyle (0, WS_VISIBLE); SendMessage (WM_SIZE); (m_wndToolBar.IsWindowVisible ()!)}, Or: m_wndToolBar.ShowWindow (SW_HIDE); or ShowControlBar (& m_wndToolBar, FALSE, FALSE);

11, take the screen color:

HDC HDC; HDC = CREATEDC ("Display", 0, 0); // The device is a display cpoint point; getCursorpos (& Point); ColorRef color; color = getpixel (hdc, point.x, point.y); int. Int R, g, b; r = getrvalue (color); g = getgvalue (color); b = getBValue (color); CSTRING STRR, STRG, STRB; strr.format ("% d", r); strg.Format "% d", g); strb.format ("% d", b); getdlgitem (idc_edit_r) -> setWindowText (strr); getdlgitem (idc_edit_g) -> setWindowText (STRG); getdlgitem (idc_edit_b) -> setWindowText STRB); deletedc (HDC);

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

New Post(0)