Novel Design of Visual C ++ Medium Chart button

zhaozj2021-02-11  193

In numerous Windows software, bitmapbutton is indeed a considerable role. Compared with the normal button, it replaces the text, the image is intuitive, making the screen more friendly. When using the software in Visual C , the author often uses the bitmap button. However, in the process of preparing, it is found that it also has a place where the beauty is inadequate.

First, the question is proposed

When we are in the Internet, we often use various browsers, such as IE or Netscape, which cannot be impressed with the user on the toolbar. When the mouse does not come into time, the bitmap button in the normal state is only a flat graph; once it is touched, it immediately "appears" out, on the one hand, on the other hand, its color and the three-dimensional contrast also give people a new feeling. In the software written in Visual C , the bitmap button does not change before and after contact, although it has great progress than ordinary buttons, but still inevitably looks a little, lacks "dynamic". This article is solved using the "Focused) of the bitmap button to solve the mouse operation.

Second, the method of solving and related functions

Microsoft Basic Class Bank (MFC) provides CBITMAPBUTTON classes, and its common member functions are AutoLoad and LoadBitmaps. The following is a brief introduction: 1. Bool AutoAd (uint nid, cwnd * pparent); This function linked a normal button with a CBITMAPB / class object.

BOOL LoadBitmaps (LPCSTR lpszBitmapResource, LPCSTR lpszBitmapResourceSel = NULL, LPCSTR lpszBitmapResourceFocus = NULL, LPCSTR lpszBitmapResourceDisabled = NULL); button bitmap has four states: a normal (U), press (D) state, obtains an input (F) state, Disable (X) status. Where F state is not commonly used. This function corresponds to the four states of the CBitmapButton class object with four bitmap files, with parameters: lpszbitmapResource is a bitmap file name under normal status (U) of bitmap buttons. LPSZBITMAPRESOURESEL is a bitmap file name under the bitmap button. LPSZBITMAPRESOURCEFOCUS is a bitmap button to get the bitmap file name under the input status (f). LPSZBITMAPRESOURCEDISABED is a bitmap file name under the bitmap button disabled status (x).

SetCapture () and ReleaseCapture ()

SetCapture () "Captures" for the mouse, even if the mouse cursor has removed the window, the window is still able to accept all messages related to the mouse. ReleaseCapture () is used to release capture of the mouse.

When the mouse is touched but has not been pressed, it does not correspond to any of these states, and VC does not provide the corresponding mechanism to solve the problems raised by this article. This program uses the mouse to move when the mouse is located, set it to obtain an input state, and the third resource file "F" bitmap file is transferred. When the mouse touches this bitmap, "emerges" out and turn the mouse cursor into a small hand shape, and then ringing to remind reminders. At the same time, due to the use of the setCapture () function, you need to design a variety of operations of the mouse. The main program is as follows. Third, the main program section

The author wrote a small demo, simple analog electrical switch function. It has two bitmap buttons and an editing control box used as a status display. When the mouse is above the bitmap button, the status display shows the "cursor of the mouse on the bitmap button". When the power switch opens, press the "Speaker" bitmap button will vocal; otherwise the "speaker" bitmap button is as gray, and does not work. void CBmpDlg :: OnMouseMove (UINT nFlags, CPoint point) {CWnd * pWnd; HCURSOR MyCursor; CRgn m_regionPower; // Region of POWER Button CRgn m_regionPlay; // Region of PLAY Button // build the rectangular area of ​​the button bitmap m_regionPower.CreateEllipticRgnIndirect (CRECT (27, 56, 72, 92); M_RegionPlay.createelllipticRGNIndirect (CRECT (78, 56, 120, 92)); cstring showstring0 = "The cursor of the mouse is on the bitmap button !!!";

... ...

m_bplay = false; m_bpower = false; if (m_regionpower.ptinregion (point) // mouse falls above the bitmap button {m_bpower = true; // Set the bitmap button to get the input state PWnd = getdlgitem (IDC_Button_Power); PWnd-> setfocus (); setcapture (); INPUTEDIT (). setwindowtext (showstring0); infutedit (). Showwindow (true); // Mouse cursor becomes a small hand shape mycursor = AFXGETAPP () -> loadingcursor (IDC_MYCURSOR); :: setCursor (MyCursor); Verify (M_Play.LoadBitmaps ("Playu", "Playd", "Playf", "Playx")); m_bpressedplay = false; return;} if (m_regionplay.ptinregion (point)) // mouse Falling above the bitmap button {if (m_bpoweron) {// If the power has been turned on m_bplay = true; pWnd = getdlgitem (iDC_Button_Play); PWND-> setfocus (); setcapture (); infuteit (). SetWindowText (Showstring0) InputEdit (). ShowWindow (True); Mycursor = AFXGetApp () -> loadcursor ;: setCursor (MyCursor); Verify (M_Power.LoadBitmaps ("Poweronu", "Powerond", "Poweronf");} else {// if the power has been turned off ReleaseCapture ();. InputEdit () SetWindowText (ShowString0 ShowString2); InputEdit () ShowWindow (TRUE);. VERIFY (m_Power.LoadBitmaps ( "POWEROFU", "POWEROFD", "POWEROFF" ) );} m_bpressedpower = false; return;} // mouse falls outside all bitmap buttons (); infuteit (). setWindowText (Showstring1); INPUTEDIT (). ShowWindow (TRUE); PWND = getdlgitem (IDOK) PWND-> setfocus (); verify (M_Play.LoadBitmaps ("Playu", "Playd", "Playf", "Playx"); if (m_bpoweron) Verify (M_Power.LoadBitmaps ("Poweronu", "Powerond", "Poweronf")); Else Verify ("PowerOfu", "PowerOfd", "Poweroff")); m_bpressedplay = false; m_bpressedpower = false; cdialog :: ONMOUSEMOVE (NFLAGS, POINT);

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

New Post(0)