Derive a cbuttonex class
Reload oncreate to use the GDI + texture to the button
-
- IntCbuttonex: oncreate (maid)
-
- {
-
- If(Cbutton: oncreate (lpcreatestruct) =-1)
-
- Return-1;
-
-
- Crect RC;
- Getclientrect (& rc );
-
- Cdc dc;
-
- Using NamespaceGdiplus;// Required before using GDI +
-
- Graphics graph (getdc ()-> m_hdc );
- Image image (L"E: \ image related \ my work \ gdi?button.png");
-
- Graph. drawimage (& image, RC. right-rc.left, RC. bottom-rc.top );
-
-
- Return0;
-
- }
-
Processing mousemove and mouseleave for better results
- VoidCbuttonex: onmousemove (UintNflags, cpoint point)
-
- {
-
- Crect RC;
-
- Getclientrect (& rc );
-
- Cdc dc;
- Using NamespaceGdiplus;// Required before using GDI +
-
- Graphics graph (getdc ()-> m_hdc );
-
- Image image (L"E: \ image related \ my work \ gdi?button2.png");
-
- Graph. drawimage (& image, RC. right-rc.left, RC. bottom-rc.top );
-
- Trackmouseevent event;
-
- Event. cbsize =Sizeof(Event );
-
- Event. dwflags = tme_leave;
-
- Event. dwhovertime = 0;
-
- Event. hwndtrack = getsafehwnd ();
-
- Verify (_ trackmouseevent (& event ));
- Cbutton: onmousemove (nflags, point );
-
- }
-
- IntCbuttonex: oncreate (maid)
-
- {
-
- If(Cbutton: oncreate (lpcreatestruct) =-1)
-
- Return-1;
-
- Crect RC;
-
- Getclientrect (& rc );
-
- Cdc dc;
-
- Using NamespaceGdiplus;// Required before using GDI +
-
- Graphics graph (getdc ()-> m_hdc );
- Image image (L"E: \ image related \ my work \ gdi?button.png");
-
- Graph. drawimage (& image, RC. right-rc.left, RC. bottom-rc.top );
-
-
- Return0;
-
- }
- LresultCbuttonex: onmouseleave (WparamWparam,LparamLparam)
-
- {
-
- Crect RC;
-
- Getclientrect (& rc );
-
- Cdc dc;
- Using NamespaceGdiplus;// Required before using GDI +
-
- Graphics graph (getdc ()-> m_hdc );
-
- Image image (L"E: \ image related \ my work \ gdi?button.png");
-
- Graph. drawimage (& image, RC. right-rc.left, RC. bottom-rc.top );
- Return1;
-
- }
The mouseleave function must manually add a message response.
- Afx_msgLresultOnmouseleave (WparamWparam,LparamLparam );
- On_message (wm_mouseleave, onmouseleave)
If you want to use the buttons directly added by VC to set the style as the owner
The bs_ownerdraw type must be added for dynamic creation.
Reload the drawitem Function
-
- VoidCbuttonex: drawitem (lpdrawitemstruct)
-
- {
-
- // Todo: add your code to draw the specified item
-
- Crect RC;
-
- Getclientrect (& rc );
- Cdc dc;
-
- Using NamespaceGdiplus;// Required before using GDI +
-
- Graphics graph (getdc ()-> m_hdc );
-
- Uses_conversion;// Added # include "atlbase. H" to the complicated definition header file"
-
- Wchar_t* Tempboardpath = a2w (m_resoucepath );// Convert cstring to wchar_t
-
- If(M_resoucepath.isempty ())
-
- {
- Image image (L"E: \ image related \ my work \ GDI + button crystal 1.png");
-
- Graph. drawimage (& image, RC. right-rc.left, RC. bottom-rc.top );
-
- }
-
- Else
-
- {
-
- Image image (tempboardpath );
-
- Graph. drawimage (& image, RC. right-rc.left, RC. bottom-rc.top );
-
- }
-
- }
Add a function to receive external resources.
- VoidCbuttonex: setresoucepath (cstring path)
- {
- M_resoucepath = path;
- }
Initialize the DLG class
Use
-
- M_btnex.setresoucepath ("E: \ image related \ my work \ recycle_bin_blue2.ico");
- M_btnex2.setresoucepath ("E: \ image related \ my work \ recycle_bin_full.ico");
-
-
- M_btnex.create ("", Bs_ownerdraw | ws_visible | ws_child, crect (0, 50, 50 ),This, 11111 );
-
- M_btnex2.create ("", Bs_ownerdraw | ws_visible | ws_child, crect (50,100 ),This, 11112 );
-
OK. Create one. Try it ~~
The one in the upper left corner is dynamically created during initialization.
In the middle is the control added with VC
1
After hovering over the mouse, you can switch to an image display.