⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 setwindlg.cpp

📁 一个类似卡巴斯基界面的设计!其按钮和别的一些控件都是封装了各种优秀的自绘类!
💻 CPP
📖 第 1 页 / 共 2 页
字号:

	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CSetWinDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CSetWinDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CSetWinDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

//void CSetWinDlg::Onchange() 
//{
	// TODO: Add your control notification handler code here
	
//}

void CSetWinDlg::OnSeting() 
{
	// TODO: Add your control notification handler code here
	CAboutDlg *st;
	st=new CAboutDlg;
	st->Create(IDD_ABOUTBOX,NULL);
	st->ShowWindow(SW_SHOW);

}

void CSetWinDlg::OnCancel() 
{
	// TODO: Add extra cleanup here

	::Shell_NotifyIcon(NIM_DELETE,m_ptnid);//删除系统托盘图标
//	m_menu.DestroyMenu();//销毁菜单	
	CDialog::OnCancel();
}

void CSetWinDlg::OnBtn3() //点击按钮后调整控件位置
{
	// TODO: Add your control notification handler code here
	m_Container.MoveWindow(10,140,225,120);
	m_Btn1.MoveWindow(7,70,227,25);
	m_Btn2.MoveWindow(7,105,227,25);
	m_Btn3.MoveWindow(7,140,227,25);
	m_USBKEY1.MoveWindow(60,180,80,15);

	m_com1.ShowWindow(SW_HIDE);
	m_com2.ShowWindow(SW_HIDE);
	m_USBKEY1.ShowWindow(SW_SHOW);

	com->ShowWindow(SW_HIDE);
	man->ShowWindow(SW_HIDE);
	usb->ShowWindow(SW_SHOW);


//	Invalidate();


	
}
///////////点击按钮2时的界面///////////////
void CSetWinDlg::OnBtn2() 
{
	// TODO: Add your control notification handler code here

	m_Container.MoveWindow(10,105,225,100);
	m_Btn1.MoveWindow(7,70,227,25);
	m_Btn2.MoveWindow(7,105,227,25);
	m_Btn3.MoveWindow(7,210,227,25);
//	m_USBKEY1.MoveWindow(60,180,80,15);

	m_com1.ShowWindow(SW_HIDE);
	m_com2.ShowWindow(SW_HIDE);
	m_USBKEY1.ShowWindow(SW_HIDE);

	com->ShowWindow(SW_HIDE);
	man->ShowWindow(SW_HIDE);
	usb->ShowWindow(SW_SHOW);


}


void CSetWinDlg::OnBtn1() 
{
	// TODO: Add your control notification handler code here
	m_Container.MoveWindow(10,70,225,120);
	m_Btn1.MoveWindow(7,70,227,25);
	m_Btn2.MoveWindow(7,195,227,25);
	m_Btn3.MoveWindow(7,230,227,25);

	m_com1.ShowWindow(SW_SHOW);
	m_com2.ShowWindow(SW_SHOW);
	m_USBKEY1.ShowWindow(SW_HIDE);

	com->ShowWindow(SW_SHOW);
	man->ShowWindow(SW_HIDE);
	usb->ShowWindow(SW_HIDE);

	//Invalidate(FALSE);
	UpdateData();
}

void CSetWinDlg::Oncom1() 
{
	// TODO: Add your control notification handler code here
    com->ShowWindow(SW_SHOW);
	man->ShowWindow(SW_HIDE);
	usb->ShowWindow(SW_HIDE);
	
}

void CSetWinDlg::Oncom2() 
{
	// TODO: Add your control notification handler code here
//	Manage *man;

	com->ShowWindow(SW_HIDE);
    man->ShowWindow(SW_SHOW);
	usb->ShowWindow(SW_HIDE);

	
}


/////////////////改变背景颜色////////////////////////////////
HBRUSH CSetWinDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
	
	// TODO: Change any attributes of the DC here
	if(pWnd->GetDlgCtrlID()==IDD_Protect)//CTLCOLOR_STATIC)//||nCtlColor==CTLCOLOR_DLG)
	{
		pDC->SetBkColor(RGB(255,255,255));
	}	
	// TODO: Return a different brush if the default is not desired
	return hbr;
}
//////////////////反调函数,关闭启动菜单和托盘/////////////
LRESULT CSetWinDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) 
{
	// TODO: Add your specialized code here and/or call the base class
		switch(message)
	{
        case MYWM_NOTIFYICON:
    //如果是用户定义的消息
        if(lParam==WM_LBUTTONDBLCLK)
		{
        //鼠标双击时主窗口出现
		    AfxGetApp()->m_pMainWnd->ShowWindow(SW_SHOW);
		}
        else if(lParam==WM_RBUTTONDOWN)    //鼠标右键单击弹出选单
		{ 
            BCMenu menu;
		//	CBitmap bit;
			
		//	bit.LoadBitmap(IDB_BITMAP5);

            menu.LoadMenu(IDR_MENU1); //载入事先定义的选单
			
			menu.ModifyODMenuA(NULL,IDC_Stop,IDB_BITMAP5);
            BCMenu *pMenu=(BCMenu*)menu.GetSubMenu(0);//获取第一个主菜单的子菜单项
		//	pMenu->AppendMenuA(MF_OWNERDRAW,ID_Image,"",&bit);
            CPoint pos;
	        GetCursorPos(&pos);
            pMenu->TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON,pos.x,pos.y,AfxGetMainWnd());
		}
        break;
        case WM_SYSCOMMAND:
        //如果是系统消息
        if(wParam==SC_CLOSE)//wParam==SC_MINIMIZE||
		{
            //接收到最小化消息时主窗口隐藏
            AfxGetApp()->m_pMainWnd->ShowWindow(SW_HIDE);
            return 0;
		}
        break;
	}
	return CDialog::WindowProc(message, wParam, lParam);
}

void CSetWinDlg::OnDestroy() 
{
	// TODO: Add your command handler code here
		::Shell_NotifyIcon(NIM_DELETE,m_ptnid);//删除系统托盘图标
		//m_menu.DestroyMenu();//销毁菜单	
		PostQuitMessage(0);


}
//////////////菜单//////////////////////////////////////
LRESULT CSetWinDlg::OnMenuChar(UINT nChar, UINT nFlags, CMenu* pMenu) 
{
	LRESULT lresult;
	if(BCMenu::IsMenu(pMenu))
		lresult=BCMenu::FindKeyboardShortcut(nChar, nFlags, pMenu);
	else
		lresult=CDialog::OnMenuChar(nChar, nFlags, pMenu);
	return(lresult);
}

////////////////菜单初始化///////////////////////
void CSetWinDlg::OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu) 
{
	CDialog::OnInitMenuPopup(pPopupMenu, nIndex, bSysMenu);
	OnUpdateFlush(pPopupMenu);
	
	if(!bSysMenu){
		if(BCMenu::IsMenu(pPopupMenu)) BCMenu::UpdateMenu(pPopupMenu);
	}
	
}

/////////////////////菜单的设置////////////////////////
void CSetWinDlg::OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct) 
{
	BOOL setflag=FALSE;
	if(lpMeasureItemStruct->CtlType==ODT_MENU){
		if(IsMenu((HMENU)lpMeasureItemStruct->itemID)&&BCMenu::IsMenu((HMENU)lpMeasureItemStruct->itemID)){
			m_menu.MeasureItem(lpMeasureItemStruct);
			setflag=TRUE;
		}
	}
	if(!setflag)CDialog::OnMeasureItem(nIDCtl, lpMeasureItemStruct);
}

void CSetWinDlg::OnUpdateEditCut(CCmdUI* pCmdUI) 
{
	pCmdUI->SetCheck(editcheck);
}
///////////////////////菜单//////////////////////////
void CSetWinDlg::OnUpdateFlush(CMenu *pMenu)
{
	ASSERT(pMenu != NULL);
	// check the enabled state of various menu items

	CCmdUI state;
	state.m_pMenu = pMenu;
	ASSERT(state.m_pOther == NULL);
	ASSERT(state.m_pParentMenu == NULL);

	// determine if menu is popup in top-level menu and set m_pOther to
	//  it if so (m_pParentMenu == NULL indicates that it is secondary popup)
	HMENU hParentMenu;
	if (AfxGetThreadState()->m_hTrackingMenu == pMenu->m_hMenu)
		state.m_pParentMenu = pMenu;    // parent == child for tracking popup
	else if ((hParentMenu = ::GetMenu(m_hWnd)) != NULL)
	{
		CWnd* pParent = GetTopLevelParent();
			// child windows don't have menus -- need to go to the top!
		if (pParent != NULL &&
			(hParentMenu = ::GetMenu(pParent->m_hWnd)) != NULL)
		{
			int nIndexMax = ::GetMenuItemCount(hParentMenu);
			for (int nIndex = 0; nIndex < nIndexMax; nIndex++)
			{
				if (::GetSubMenu(hParentMenu, nIndex) == pMenu->m_hMenu)
				{
					// when popup is found, m_pParentMenu is containing menu
					state.m_pParentMenu = CMenu::FromHandle(hParentMenu);
					break;
				}
			}
		}
	}

	state.m_nIndexMax = pMenu->GetMenuItemCount();
	for (state.m_nIndex = 0; state.m_nIndex < state.m_nIndexMax;
	  state.m_nIndex++)
	{
		state.m_nID = pMenu->GetMenuItemID(state.m_nIndex);
		if (state.m_nID == 0)
			continue; // menu separator or invalid cmd - ignore it

		ASSERT(state.m_pOther == NULL);
		ASSERT(state.m_pMenu != NULL);
		if (state.m_nID == (UINT)-1)
		{
			// possibly a popup menu, route to first item of that popup
			state.m_pSubMenu = pMenu->GetSubMenu(state.m_nIndex);
			if (state.m_pSubMenu == NULL ||
				(state.m_nID = state.m_pSubMenu->GetMenuItemID(0)) == 0 ||
				state.m_nID == (UINT)-1)
			{
				continue;       // first item of popup can't be routed to
			}
			state.DoUpdate(this, FALSE);    // popups are never auto disabled
		}
		else
		{
			// normal menu item
			// Auto enable/disable if frame window has 'm_bAutoMenuEnable'
			//    set and command is _not_ a system command.
			state.m_pSubMenu = NULL;
			state.DoUpdate(this, state.m_nID < 0xF000);
		}

		// adjust for menu deletions and additions
		UINT nCount = pMenu->GetMenuItemCount();
		if (nCount < state.m_nIndexMax)
		{
			state.m_nIndex -= (state.m_nIndexMax - nCount);
			while (state.m_nIndex < nCount &&
				pMenu->GetMenuItemID(state.m_nIndex) == state.m_nID)
			{
				state.m_nIndex++;
			}
		}
		state.m_nIndexMax = nCount;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -