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

📄 mainfrm.cpp

📁 计算机管理系统可以实现开机时自动运行
💻 CPP
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//

#include "stdafx.h"
#include "System.h"

#include "MainFrm.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMainFrame

IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)

BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
	//{{AFX_MSG_MAP(CMainFrame)
	ON_WM_CREATE()
	ON_WM_CLOSE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

static UINT indicators[] =
{
	ID_SEPARATOR,           // status line indicator
	ID_INDICATOR_CAPS,
	ID_INDICATOR_NUM,
	ID_INDICATOR_SCRL,
};

/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction

CMainFrame::CMainFrame()
{
//	flag=false;
	// TODO: add member initialization code here
	
}

CMainFrame::~CMainFrame()
{
}

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
		return -1;
	
/*	if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
		| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
		!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
	{
		TRACE0("Failed to create toolbar\n");
		return -1;      // fail to create
	}

	if (!m_wndStatusBar.Create(this) ||
		!m_wndStatusBar.SetIndicators(indicators,
		  sizeof(indicators)/sizeof(UINT)))
	{
		TRACE0("Failed to create status bar\n");
		return -1;      // fail to create
	}

	m_wndToolBar.SetWindowText("Standdard");

	// TODO: Delete these three lines if you don't want the toolbar to
	//  be dockable
	m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
	EnableDocking(CBRS_ALIGN_ANY);
	DockControlBar(&m_wndToolBar);


/*	  NOTIFYICONDATA tnd; 
      tnd.cbSize=sizeof(NOTIFYICONDATA);
      tnd.hWnd=this->m_hWnd;
      tnd.uID=IDR_MAINFRAME;
      tnd.uFlags=NIF_MESSAGE|NIF_ICON|NIF_TIP;
      tnd.uCallbackMessage=WM_LIBEN;
      tnd.hIcon=LoadIcon(AfxGetInstanceHandle(),
      MAKEINTRESOURCE(IDR_MAINFRAME)); 
      strcpy(tnd.szTip,"提示信息");
      Shell_NotifyIcon(NIM_ADD,&tnd);
*/ 
    //AfxGetApp()->m_nCmdShow = SW_HIDE;
    AnimateWindow(GetSafeHwnd(),5000,AW_CENTER);///淡入淡出

	//BOOL AnimateWindow(HWND hWnd,DWORD dwTime,DWORD dwFlags)。 
/*hWnd:指定产生动画的窗口的句柄。 
dwTime:指明动画持续的时间(以微秒计),完成一个动画的标准时间为200微秒。 
dwFags:指定动画类型。这个参数可以是一个或多个下列标志的组合。标志描述: 
AW_SLIDE:使用滑动类型。缺省则为滚动动画类型。当使用AW_CENTER标志时,这个标志就被忽略。 
AW_ACTIVATE:激活窗口。在使用了AW_HIDE标志后不能使用这个标志。 
AW_BLEND:实现淡出效果。只有当hWnd为顶层窗口的时候才可以使用此标志。 
AW_HIDE:隐藏窗口,缺省则显示窗口。 
AW_CENTER:若使用了AW_HIDE标志,则使窗口向内重叠,即收缩窗口;若未使用AW_HIDE标志,则使窗口向外扩展,即展开窗口。 
AW_HOR_POSITIVE:自左向右显示窗口。该标志可以在滚动动画和滑动动画中使用。当使用AW_CENTER标志时,该标志将被忽略。 
AW_VER_POSITIVE:自顶向下显示窗口。该标志可以在滚动动画和滑动动画中使用。当使用AW_CENTER标志时,该标志将被忽略。 
AW_VER_NEGATIVE:自下向上显示窗口。该标志可以在滚动动画和滑动动画中使用。当使用AW_CENTER标志时,该标志将被忽略
*/
	//该函数能在显示与隐藏窗口时产生两种特殊类型的动画效果:滚动动画和滑动动画。
	 
     CenterWindow(GetDesktopWindow());//窗口置于屏幕正中

   	EnableAutoStart();//设置程序自动开机运行
	return 0;
}

BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
	
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs


	   CSystemApp *app = (CSystemApp *)AfxGetApp();/////
         if(!app->m_flag)
	  { 
		  if( !CFrameWnd::PreCreateWindow(cs) )
		  return FALSE;
		  cs.x=5;
          cs.y=5;
          cs.cx=900;
          cs.cy=900;//设置主窗口大小
          cs.style=WS_POPUP|WS_BORDER|WS_BORDER|SS_GRAYFRAME;//WS_BORDER指明边界,大小不可调,该窗口不具有WS_CAPTION,应此不可移动
	      //SetWindowPos(&this->wndTopMost,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);
		 }
		 else
	  { 
	  cs.style =WS_POPUP;//使主窗口不可见
      cs.dwExStyle |=WS_EX_TOOLWINDOW;//不显示任务按钮
	  //SetWindowPos(&this->wndTopMost,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);
      return CFrameWnd::PreCreateWindow(cs);
	  }


 

return TRUE;
}


void CMainFrame::EnableAutoStart()//设置程序自动开机运行
{
	CString sPath;	
	int nPos;
	HKEY RegKey;
	GetModuleFileName(NULL,sPath.GetBufferSetLength(MAX_PATH+1),MAX_PATH);
	sPath.ReleaseBuffer();
	nPos=sPath.ReverseFind('\\');
	sPath=sPath.Left(nPos);
	CString lpszFile=sPath+"\\System.exe";
	CFileFind fFind;
	BOOL bSuccess;
	bSuccess=fFind.FindFile(lpszFile);
	fFind.Close();
	if(bSuccess)
	{
		CString fullName;
		fullName=lpszFile;
		RegKey=NULL;
		RegOpenKey(HKEY_LOCAL_MACHINE,"Software\\Microsoft\\Windows\\CurrentVersion\\Run",&RegKey);
		RegSetValueEx(RegKey,"计算机登录管理系统",0,REG_SZ,(const unsigned char*)(LPCTSTR)fullName,fullName.GetLength());
		this->UpdateData(FALSE);
	}
	else
	{ 
		::AfxMessageBox("没找到执行程序,自动运行失败");
		exit(0);
	}
}

/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics

#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
	CFrameWnd::AssertValid();
}

void CMainFrame::Dump(CDumpContext& dc) const
{
	CFrameWnd::Dump(dc);
}

#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers


void CMainFrame::OnClose() 
{
	// TODO: Add your message handler code here and/or call default
	AnimateWindow(GetSafeHwnd(),1000,AW_HIDE|AW_CENTER);

	CFrameWnd::OnClose();
}

⌨️ 快捷键说明

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