自己写了一个CMyButton类 可是用的时候CPU却占用90%以上
主窗口原来不调用它的时候CPU占用为0,只要调用它就到90%以上了,找不出原因,因为只剩AfxRegisterWndClass 和Create这两个必要的创建窗口函数都会跳到90%。。为什么啊,VC里面自带的按钮却不会。。。
CMyButton类:
- C/C++ code
CMyButton::CMyButton(CWnd *parewnd,UINT buttonID,UINT nmapID1,UINT nmapID2,UINT x,UINT y,UINT nwidth,UINT nhigh){// m_nwidth=nwidth;// m_nhigh=nhigh;// m_nmapID1=nmapID1;// m_nmapID2=nmapID2; RECT rect; rect.left=x; rect.top=y; rect.right=x+nwidth; rect.bottom=y+nhigh; LPCTSTR lpszClassName=AfxRegisterWndClass(0,0,(HBRUSH)(COLOR_BTNFACE+1),AfxGetApp()->LoadStandardCursor(IDC_ARROW)); Create(lpszClassName,0,WS_CHILD|WS_VISIBLE,rect,parewnd,buttonID); //::CreateWindow(lpszClassName,"mybutton",WS_CHILD|WS_VISIBLE,x,y,nwidth,nhigh,hparewnd,0,AfxGetInstanceHandle(),0);}主窗口的调用:
- C# code
BOOL CBabyDlg::OnInitDialog(){ CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != NULL) { CString strAboutMenu; strAboutMenu.LoadString(IDS_ABOUTBOX); if (!strAboutMenu.IsEmpty()) { pSysMenu->AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); } } CMyButton *m_mybutton=new CMyButton(this,11,IDB_BITMAP2,IDB_BITMAP2,52,21,22,18);//在这里调用 CDC *pDC; //CRect wndrect; //CDC memdc; CRgn deletergn; CBitmap membitmp; BITMAP bitmap; COLORREF cl; POINT point; pDC=GetDC(); m_memdc.CreateCompatibleDC(pDC); membitmp.LoadBitmap(IDB_BITMAP1); m_memdc.SelectObject(&membitmp); membitmp.GetBitmap(&bitmap); ::SetWindowPos(m_hWnd,HWND_TOP,0,0,bitmap.bmWidth,bitmap.bmHeight,SWP_NOMOVE); GetWindowRect(&m_wndrect); m_wndrgn.CreateRectRgn(0,0,m_wndrect.Width(),m_wndrect.Height()); //ShowWindow(1); for(int x=0;x<m_wndrect.Width();x++){ for(int y=0;y<m_wndrect.Height();y++){ point.x=x; point.y=y; cl=m_memdc.GetPixel(point); if(cl==0){ deletergn.CreateRectRgn(x,y,x+1,y+1); m_wndrgn.CombineRgn(&m_wndrgn,&deletergn,RGN_XOR); deletergn.DeleteObject(); } } } x=1; SetWindowLong(m_hWnd,GWL_STYLE,GetWindowLong(m_hWnd,GWL_STYLE)|WS_SYSMENU); SetWindowRgn((HRGN)m_wndrgn,1); // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon SetWindowText("baby"); m_closebutton.ModifyStyle(0,BS_BITMAP); m_buttonmap.LoadBitmap(IDB_BITMAP2); m_closebutton.SetBitmap(HBITMAP(m_buttonmap)); // TODO: Add extra initialization here return TRUE; // return TRUE unless you set the focus to a control}[解决办法]