?? easysysdlg.cpp
字號:
// EasySYSDlg.cpp : implementation file
//
#include "stdafx.h"
#include "EasySYS.h"
#include "EasySYSDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CEasySYSDlg dialog
CEasySYSDlg::CEasySYSDlg(CWnd* pParent /*=NULL*/)
: CDialog(CEasySYSDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CEasySYSDlg)
m_strPrjName = _T("");
m_strPrjPath = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
ReadPathFromReg();
}
void CEasySYSDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CEasySYSDlg)
DDX_Text(pDX, IDC_PRJ_NAME, m_strPrjName);
DDX_Text(pDX, IDC_LOCATION, m_strPrjPath);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CEasySYSDlg, CDialog)
//{{AFX_MSG_MAP(CEasySYSDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BROWSE_FOLDER, OnBrowseFolder)
ON_BN_CLICKED(IDOK, OnCreate)
ON_CBN_SELCHANGE(IDC_DDK_VERSION, OnSelchangeDdkVersion)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CEasySYSDlg message handlers
BOOL CEasySYSDlg::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);
}
}
// 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
// TODO: Add extra initialization here
//initialize location
//initialize ddk
for (int i=0; i<OPTION_NUM; i++)
{
if (g_options[i].nClass == DDK_VERSION)
{
int iIndex = ((CComboBox *)GetDlgItem(IDC_DDK_VERSION))->AddString(g_options[i].szDisp);
((CComboBox *)GetDlgItem(IDC_DDK_VERSION))->SetItemData(iIndex,g_options[i].nID);
if (g_options[i].bChecked)
{
((CComboBox *)GetDlgItem(IDC_DDK_VERSION))->SetCurSel(iIndex);
}
}
}
//initialize target os
//nothing
return TRUE; // return TRUE unless you set the focus to a control
}
void CEasySYSDlg::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 CEasySYSDlg::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 CEasySYSDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
//call back for browse folder, direct into the folder of last selected
int CALLBACK BrowseCallbackProc(HWND hwnd,UINT uMsg,LPARAM lParam,LPARAM lpData)
{
if (BFFM_INITIALIZED == uMsg)
{
::SendMessage(hwnd,BFFM_SETSELECTION,TRUE,lpData);
}
return 0;
}
void CEasySYSDlg::OnBrowseFolder()
{
// TODO: Add your control notification handler code here
BROWSEINFO bi;
TCHAR szFolder[MAX_PATH];
memset(&bi,0,sizeof(bi));
bi.hwndOwner = this->GetSafeHwnd();
bi.lpszTitle = _T("Select a folder...");
bi.pidlRoot = NULL;
bi.pszDisplayName = (LPTSTR)&szFolder;
bi.lpfn = BrowseCallbackProc;
bi.lParam = (LPARAM)m_strPrjPath.GetBuffer(0);
LPITEMIDLIST pidl;
pidl = SHBrowseForFolder(&bi);
if (pidl == NULL)
{
return;
}
else
{
SHGetPathFromIDList(pidl, (LPTSTR)&szFolder);
GetDlgItem(IDC_LOCATION)->SetWindowText(szFolder);
m_strPrjPath = szFolder;
}
}
void CEasySYSDlg::OnCreate()
{
// TODO: Add your control notification handler code here
UpdateData();
//check project name
if (m_strPrjName.IsEmpty())
{
MessageBox(_T("Please input project name."), DIALOG_CAPTION, MB_ICONSTOP);
return;
}
//check location
if (m_strPrjPath.IsEmpty())
{
MessageBox(_T("Please input project location."), DIALOG_CAPTION, MB_ICONSTOP);
return;
}
SavePathToReg();
//check ddk
if (!CheckDDK())
{
//do nothing;
//return;
}
//check target os
if (!CheckTargetOS())
{
return;
}
//create project
if (CreateProject() == 0)
{
MessageBox(_T("Create successful."), DIALOG_CAPTION, MB_OK);
}
}
BOOL CEasySYSDlg::CheckTargetOS()
{
//get target os option, and check it
//get
m_nTosNum = 0;
if( ((CButton *)GetDlgItem(IDC_TOS_W2K))->GetCheck()
&& GetDlgItem(IDC_TOS_W2K)->IsWindowEnabled() )
{
SetCheckItem(TARGET_OS, TOS_W2K);
m_nTosNum++;
}
if( ((CButton *)GetDlgItem(IDC_TOS_WXP))->GetCheck()
&& GetDlgItem(IDC_TOS_WXP)->IsWindowEnabled() )
{
SetCheckItem(TARGET_OS, TOS_WXP);
m_nTosNum++;
}
if( ((CButton *)GetDlgItem(IDC_TOS_W2K3))->GetCheck()
&& GetDlgItem(IDC_TOS_W2K3)->IsWindowEnabled() )
{
SetCheckItem(TARGET_OS, TOS_W2K3);
m_nTosNum++;
}
//check
if (m_nTosNum <= 0)
{
MessageBox(_T("Please select more than one target operation system."), DIALOG_CAPTION, MB_ICONSTOP);
return FALSE;
}
return TRUE;
}
BOOL CEasySYSDlg::CheckDDK()
{
int nIndex = ((CComboBox *)GetDlgItem(IDC_DDK_VERSION))->GetCurSel();
int nOptionID = ((CComboBox *)GetDlgItem(IDC_DDK_VERSION))->GetItemData(nIndex);
nIndex = SetCurOption(DDK_VERSION,nOptionID);
m_strDDKVer = g_options[nIndex].szInter;
return CheckDDKEnvironment();
}
BOOL CEasySYSDlg::CheckDDKEnvironment()
{
TCHAR bufDDKPath[MAX_PATH];
CString strDDKEnvironmentName = m_strDDKVer + _T("BASE");
DWORD dwBufLen = MAX_PATH;
DWORD dwType = REG_SZ;
BOOL bRet = FALSE;
HKEY hKeyEnvironment;
//check system Environment
if(ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, ENVIRONMENT_PATH_SYSTEM, 0, KEY_READ, &hKeyEnvironment))
{
if ( ERROR_SUCCESS == RegQueryValueEx(hKeyEnvironment,(LPCTSTR)strDDKEnvironmentName,NULL,&dwType,(LPBYTE)bufDDKPath,&dwBufLen) )
{
bRet = TRUE;
}
RegCloseKey(hKeyEnvironment);
}
if (bRet)
{
return bRet;
}
//check user's Environment
dwBufLen = MAX_PATH;
if(ERROR_SUCCESS == RegOpenKeyEx(HKEY_CURRENT_USER, ENVIRONMENT_PATH_USER, 0, KEY_READ, &hKeyEnvironment))
{
if ( ERROR_SUCCESS != RegQueryValueEx(hKeyEnvironment,(LPCTSTR)strDDKEnvironmentName,NULL,&dwType,(LPBYTE)bufDDKPath,&dwBufLen) )
{
//check ddk install
CString strDDKLocation;
int nRet = GetDDKLoaction(strDDKLocation);
if (nRet == 0)
{
CString strTemp;
strTemp.Format(_T("You have not installed DDK!"));
MessageBox(strTemp, DIALOG_CAPTION);
return FALSE;
}
else if (nRet > 1 )
{
CString strTemp;
strTemp.Format(_T("You have installed more than one DDK. \nWe Use the \"%s\" as default DDK."), strDDKLocation);
MessageBox(strTemp, DIALOG_CAPTION);
}
//set ddk
CString strTXT;
strTXT.Format(_T("DDKBuild need environment named %s.\nDo you want to let me set it now?"), strDDKEnvironmentName);
int iRet = MessageBox(strTXT, DIALOG_CAPTION ,MB_YESNO);
if (iRet == IDYES)
{
bRet = SetDDKEnvironment(strDDKLocation);
if (!bRet)
{
MessageBox(_T("Set DDK Environment Error!"), DIALOG_CAPTION ,MB_YESNO);
}
}
}
else
{
bRet = TRUE;
}
RegCloseKey(hKeyEnvironment);
}
return bRet;
}
BOOL CEasySYSDlg::SetDDKEnvironment(CString &strDDKEnvironmentValue)
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -