// Wndex2dlg. CPP: implementation file <br/> // <br/> # include "stdafx. H "<br/> # include" wndex2.h "<br/> # include" wndex2dlg. H "<br/> # ifdef _ debug <br/> # define new debug_new <br/> # UNDEF this_file <br/> static char this_file [] = _ file __; <br/> # endif <br/> ////////////////////////////// //////////////////////////////////////// ////// <br/> // caboutdlg Dialog used for app about <br/> class caboutdlg: publi C cdialog <br/>{< br/> Public: <br/> caboutdlg (); <br/> // dialog data <br/> // {afx_data (caboutdlg) <br/> Enum {IDD = idd_aboutbox }; <br/> //} afx_data <br/> // classwizard generated virtual function overrides <br/> // {afx_virtual (caboutdlg) <br/> protected: <br/> virtual void dodataexchange (cdataexchange * PDX ); // DDX/DDV support <br/> //} afx_virtual <br/> // implementation <br/> protected: <br/> // {afx _ MSG (caboutdlg) <br/> //} afx_msg <br/> declare_message_map () <br/>}; <br/> caboutdlg: caboutdlg (): cdialog (caboutdlg: IDD) <br/>{< br/> // {afx_data_init (caboutdlg) <br/> //} afx_data_init <br/>}< br/> void caboutdlg: dodataexchange (cdataexchange * PDX) <br/>{< br/> cdialog :: dodataexchange (PDX); <br/> // {afx_data_map (caboutdlg) <br/> //} afx_data_map <br/>}< br/> begin_message_map (caboutdlg, cdialog) <br/> // {Afx_msg_map (caboutdlg) <br/> // No message handlers <br/> //} afx_msg_map <br/> end_message_map () <br/> //////////////////////////////////// //////////////////////////////////////// /<br/> // cwndex2dlg dialog <br/> cwndex2dlg:: cwndex2dlg (cwnd * pparent/* = NULL */) <br/>: cdialog (cwndex2dlg: IDD, pparent) <br/> {<br/> // {afx_data_init (cwndex2dlg) <br/> // Note: The classwizard will add member initializa Tion here <br/> //} afx_data_init <br/> // note that loadicon does not require a subsequent destroyicon in Win32 <br/> m_hicon = afxgetapp () -> loadicon (idr_mainframe); <br/>}< br/> void cwndex2dlg: dodataexchange (cdataexchange * PDX) <br/>{< br/> cdicon :: dodataexchange (PDX); <br/> // {afx_data_map (cwndex2dlg) <br/> // note: the classwizard will add DDX and DDV callhere <br/>//}} afx_data_map <br/>}< br/> Export (cwndex2dlg, cdialog) <br/> // {afx_msg_map (cwndex2dlg) <br/> on_wm_syscommand () <br/> on_wm_paint () <br/> on_wm_querydragicon () <br/> on_bn_clicked (response, onbtnrect) <br/> on_bn_clicked (response, onbtnell) <br/> response (response, onbtnpolyg) <br/> on_bn_clicked) <br/> on_bn_clicked (idc_btn_trans, onbtntrans) <br/> on_bn_clicked (idc_btn_trans2, Onbtntrans2) <br/> upload (idc_btn_flash, onbtnflash) <br/> on_bn_clicked (bytes, onbtnstopf) <br/> upload () <br/> on_bn_clicked (bytes, onbtnpicture) <br/> on_bn_clicked (idc_btn_animate, onbtnanimate) <br/> on_wm_erasebkgnd () <br/>/}} afx_msg_map <br/> end_message_map () <br/> //////////////////////////////////// //////////////////////////////////////// /<br/> // cwndex2dlg Messa GE handlers <br/> bool cwndex2dlg: oninitdialog () <br/>{< br/> cdialog: oninitdialog (); <br/> // Add "about... "menu item to system menu. <br/> // idm_aboutbox must be in the system command range. <br/> assert (idm_aboutbox & 0xfff0) = idm_aboutbox); <br/> assert (idm_aboutbox <0xf000); <br/> cmenu * psysmenu = getsystemmenu (false ); <br/> If (psysmenu! = NULL) <br/>{< br/> cstring straboutmenu; <br/> straboutmenu. loadstring (ids_aboutbox); <br/> If (! Straboutmenu. isempty () <br/>{< br/> psysmenu-> appendmenu (mf_separator); <br/> psysmenu-> appendmenu (mf_string, idm_aboutbox, straboutmenu ); <br/>}< br/> // set the icon for this dialog. the framework does this automatically <br/> // when the application's main window is not a dialog <br/> seticon (m_hicon, true ); // set big icon <br/> seticon (m_hicon, false); // set small icon </P> <p> // todo: Add extr A Initialization here <br/> centerwindow (); <br/> animatewindow (getsafehwnd (), 500, aw_blend); // fade in </P> <p> return true; // return true unless you set the focus to a control <br/>}< br/> void cwndex2dlg: onsyscommand (uint NID, lparam) <br/>{< br/> If (NID & 0xfff0) = idm_aboutbox) <br/>{< br/> caboutdlg dlgabout; <br/> dlgabout. domodal (); <br/>}< br/> else <br/>{< br/> cdialog: onsyscommand (NID, lpara M); <br/>}< br/> // if you add a Minimize button to your dialog, you will need the code below <br/> // to draw the icon. for MFC applications using the document/view model, <br/> // This is automatically done for you by the framework. <br/> void cwndex2dlg: onpaint () <br/>{< br/> If (isiconic ()) <br/> {<br/> cpaintdc (this); // device context for painting <br/> sendmessage (wm_iconerasebkgnd, (WP Aram) DC. getsafehdc (), 0); <br/> // center icon in client rectangle <br/> int cxicon = getsystemmetrics (sm_cxicon ); <br/> int cyicon = getsystemmetrics (sm_cyicon); <br/> crect rect; <br/> getclientrect (& rect); <br/> int x = (rect. width ()-cxicon + 1)/2; <br/> int y = (rect. height ()-cyicon + 1)/2; <br/> // draw the icon <br/> DC. drawicon (X, Y, m_hicon); <br/>}< br/> else <br/>{< br/> cdialog: onpaint (); <Br/>}< br/> // The system callthis to obtain the cursor to display while the user drags <br/> // The minimized window. <br/> hcursor cwndex2dlg: onquerydragicon () <br/>{< br/> return (hcursor) m_hicon; <br/>}< br/> void cwndex2dlg :: onbtnrect () <br/>{< br/> crect rect; <br/> getclientrect (& rect ); <br/> // create a rectangular area <br/> crgn RGN; <br/> RGN. createrectrgn (rect. left, rect. top, rect. right, rect. bottom); <br />// Set the window area <br/> set1_wrgn (hrgn) RGN, true); </P> <p >}< br/> void cwndex2dlg :: onbtnell () <br/>{< br/> crect rect; <br/> getclientrect (& rect ); <br/> // create an elliptical area <br/> crgn RGN; <br/> RGN. createellipticrgn (0, 0, rect. width (), rect. height (); <br/> // set the region <br/> set1_wrgn (hrgn) RGN, true ); </P> <p >}< br/> void cwndex2dlg: onbtnpolyg () <br/>{< br/> crect rect; <br/> getclientrect (rect ); <br/> // common Polygon Area <br/> cpoint poi NT [6]; // six points of the hexagonal structure <br/> point [0]. X = 0; <br/> point [0]. y = rect. height ()/2; <br/> point [1]. X = rect. width ()/3; <br/> point [1]. y = 0; <br/> point [2]. X = 2 * rect. width ()/3; <br/> point [2]. y = 0; <br/> point [3]. X = rect. width (); <br/> point [3]. y = rect. height ()/2; <br/> point [4]. X = 2 * rect. width ()/3; <br/> point [4]. y = rect. height (); <br/> point [5]. X = rect. width ()/3; <br/> point [5]. y = rect. height (); <br/> crgn RGN; <br/> RGN. createpolygo Nrgn (point, 6, alternate); <br/> // set the area of the window <br/> set1_wrgn (hrgn) RGN, true ); </P> <p >}< br/> void cwndex2dlg: onbtnround () <br/>{< br/> crect rect; <br/> getclientrect (rect ); <br/> // create a circular area <br/> crgn RGN; <br/> RGN. createroundrectrgn (0, 0, rect. width (), rect. height (), rect. width ()/2, rect. height ()/2); <br/> // set the window area <br/> set1_wrgn (hrgn) RGN, true ); <br/>}< br/> void cwndex2dlg: onbtntrans () <br/>{< br/> crect R Ect1; <br/> getwindowrect (rect1); <br/> crect rect2; <br/> getwindowrect (rect2); <br/> clienttoscreen (rect2 ); </P> <p> crgn rgn1; <br/> rgn1.createrectrgn (rect1.left, rect2.top, rect1.right, rect1.bottom); </P> <p> crgn rgn2; <br/> rgn2.createrectrgn (rect2.left, rect2.top, rect2.right, rect2.bottom); </P> <p> crgn RGN; <br/> RGN. createrectrgn (0, 0, 1, 1); <br/> RGN. combinergn (& rgn1, & rgn2, rgn_diff); <br/> // set the window area <br/> setwi Ndowrgn (hrgn) RGN, true); </P> <p >}< br/> void cwndex2dlg: onbtntrans2 () <br/>{< br/> // Add ws_ex_layered (0x80000) extended style <br/> modifystyleex (80000 X ); <br/> // load the dynamic link library of user32.dll <br/> hmodule = loadlibrary ("user32.dll"); <br/> If (hmodule! = NULL) <br/>{< br/> typedef bool (winapi * func) (hwnd, colorref, byte, DWORD ); <br/> // get the setlayeredwindowattributes function pointer <br/> func = (func) getprocaddress (hmodule, "setlayeredwindowattributes"); <br/> If (func! = NULL) <br/>{< br/> func (getsafehwnd (), 0, 50, 2 ); // For details, see setlayeredwindowattributes function <br/>}< br/> freelibrary (hmodule); <br/>}</P> <p >}< br/> void cwndex2dlg:: onbtnflash () <br/>{< br/> // set the timer <br/> settimer (1,100, null ); </P> <p >}< br/> void cwndex2dlg: onbtnstopf () <br/> {<br/> // disable the timer <br/> killtimer (1 ); <br/> // The Window returns the original status <br/> flashwindow (false); </P> <p >}< br/> void cwndex2dlg :: ontimer (uint nidevent) <br/>{< br/> If (nidevent = 1) <br/> {<br/> // The Window flashes from one State to another <br/> flashwindow (true ); <br/>}< br/> cdialog: ontimer (nidevent); <br/>}< br/> void cwndex2dlg: onbtnpicture () <br/>{ <br/> crect rect; <br/> getwindowrect (& rect); <br/> // load the bitmap <br/> cbitmap BMP; <br/> BMP. loadbitmap (idb_bitmap); <br/> // select the bitmap into the device environment <br/> cdc dc; <br/> CDC * PDC = getdc (); <br/> DC. createcompatibledc (PDC); <br/> DC. selectObject (& BMP); <br/> // turns the black area in the bitmap into transparent <br/> crgn RGN; <br/> RGN. createrectrgn (0, 0, rect. width (), rect. height (); <br/> for (INT x = 0; x <rect. height (); X ++) <br/>{< br/> for (INT y = 0; y <rect. width (); y ++) <br/>{< br/> colorref Cr = dc. getpixel (x, y); <br/> If (Cr = RGB (0, 0) <br/>{< br/> crgn rgn2; <br/> rgn2.createrectrgn (X, Y, x + 1, Y + 1); <br/> RGN. combinergn (& RGN, & rgn2, rgn_xor); // XOR combines the two regions, remove overlapping parts <br/>}< br/> // set the window area <br/> set1_wrgn (hrgn) RGN, true); <br/> releasedc (PDC); </P> <p >}< br/> void cwndex2dlg: onbtnanimate () <br/>{< br/> // centerwindow (); <br/> // animatewindow (getsafehwnd (), 100, aw_blend ); </P> <p >}< br/> bool cwndex2dlg: onerasebkgnd (CDC * PDC) <br/>{< br/> crect rect; <br/> getwindowrect (& rect); <br/> cbitmap BMP; <br/> BMP. loadbitmap (idb_bitmap); <br/> cdc dc; <br/> DC. createcompatibledc (PDC); <br/> DC. selectObject (& BMP); <br/> PDC-> bitblt (0, 0, rect. width (), rect. height (), & DC, 0, 0, srccopy); <br/> return true; <br/>}
In the image window operation, you must add a message response.
Afx_msg bool onerasebkgnd (CDC * PDC );
On_wm_erasebkgnd ()
: Http://ishare.iask.sina.com.cn/f/14464563.html