wxWidgets 不规则透明WinForm窗体(通过透明图片实现)
文章转自王牌软件
站长推荐:NSetup一键部署软件
一键式完成美化安装包制作,自动增量升级,数据统计,数字签名。应对各种复杂场景,脚本模块化拆分,常规复杂的脚本代码,图形化设置。无需专业的研发经验,轻松完成项目部署。(www.nsetup.cn)
只回答业务咨询
站长推荐:NSetup一键部署软件
一键式完成美化安装包制作,自动增量升级,数据统计,数字签名。应对各种复杂场景,脚本模块化拆分,常规复杂的脚本代码,图形化设置。无需专业的研发经验,轻松完成项目部署。(www.nsetup.cn)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
#include "wx/wxprec.h" class MyFrame; class MyApp : public wxApp { public: virtual bool OnInit(); private: MyFrame *frame; }; class MyFrame : public wxFrame { private: wxBitmap *bit; wxPoint *point; public: MyFrame(); void OnPaint(wxPaintEvent& event); void OnWindowCreate(wxWindowCreateEvent& event); void OnRightClick(wxMouseEvent& event); void OnMouseClickDown(wxMouseEvent& event); void OnMouseMotion(wxMouseEvent& event); void OnMouseClickUp(wxMouseEvent& event); }; bool MyApp::OnInit(){ this->frame = new MyFrame(); this->frame->Show(TRUE); this->SetTopWindow(this->frame); return TRUE; }; MyFrame::MyFrame() : wxFrame(NULL,-1,wxT("不规则窗体")){ this->SetWindowStyle(wxFRAME_SHAPED|wxSIMPLE_BORDER|wxSTAY_ON_TOP); ::wxInitAllImageHandlers(); wxImage *img = new wxImage(wxT("d:\\bg.png"),wxBITMAP_TYPE_ANY); this->SetSize(img->GetWidth(),img->GetHeight()); img->SetMask(TRUE); img->SetMaskColour(255,255,255); bit = new wxBitmap(*img); this->Bind(wxEVT_PAINT,&MyFrame::OnPaint,this); wxRegion *r = new wxRegion(*bit); this->SetShape(*r); this->Bind(wxEVT_RIGHT_UP,&MyFrame::OnRightClick,this); this->point = new wxPoint(0,0); this->Bind(wxEVT_LEFT_DOWN,&MyFrame::OnMouseClickDown,this); this->Bind(wxEVT_LEFT_UP,&MyFrame::OnMouseClickUp,this); this->Bind(wxEVT_MOTION,&MyFrame::OnMouseMotion,this); }; void MyFrame::OnPaint(wxPaintEvent& event){ wxPaintDC *dc = new wxPaintDC(this); if(bit->IsOk()){ dc->DrawBitmap(*bit,0,0,TRUE); } }; void MyFrame::OnWindowCreate(wxWindowCreateEvent& event){ wxRegion *r = new wxRegion(*bit); this->SetShape(*r); } void MyFrame::OnRightClick(wxMouseEvent& event){ if(wxMessageBox(wxT("是否退出程序?"),wxT("退出"),wxYES_NO,this) == 2){ wxExit(); } }; void MyFrame::OnMouseClickDown(wxMouseEvent& event){ this->CaptureMouse(); event.GetPosition(&this->point->x,&this->point->y); }; void MyFrame::OnMouseClickUp(wxMouseEvent& event){ if(this->HasCapture()){ this->ReleaseMouse(); } }; void MyFrame::OnMouseMotion(wxMouseEvent& event){ if(event.Dragging() && event.LeftIsDown()){ int x,y; event.GetPosition(&x,&y); this->ClientToScreen(&x,&y); this->Move(x-this->point->x,y-this->point->y); } }; IMPLEMENT_APP(MyApp); |
wxWidgets 不规则透明窗体(通过透明图片实现)
采用VS2010开发,使用wxWidgets2.9.4框架
学习日记,兼职软件设计,软件修改,毕业设计。
本文出自 学习日记,转载时请注明出处及相应链接。
本文永久链接: https://www.softwareace.cn/?p=439