Skip to content

Commit

Permalink
添加托盘图标和菜单
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangxiaogang committed Mar 28, 2020
1 parent 25815db commit 227878a
Show file tree
Hide file tree
Showing 19 changed files with 218 additions and 158 deletions.
9 changes: 4 additions & 5 deletions ReadMe.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
Hosts�ļ���������
��ɫ����
���С�ɣ
���谲װ��
HostsMan
�����л�hosts�ļ���С����
��ɫ����,���谲װ�
�����,����1MB��
��дע������������þ��ڳ���Ŀ¼�¡�


�������ԣ�C++(MFC)
�������ߣ�VS2005

Binary file removed res/app.ico
Binary file not shown.
16 changes: 15 additions & 1 deletion DialogUtil.cpp → src/DialogHelper.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
#include "StdAfx.h"
#include "DialogUtil.h"
#include "DialogHelper.h"

void EnableDlgItem(HWND hWnd, int nItem, BOOL enable)
{
HWND hItem;
hItem = GetDlgItem(hWnd,nItem);
EnableWindow(hItem, enable);
}

void ShowDlgItem(HWND hWnd, int nItem, BOOL show)
{
HWND hItem;
hItem = GetDlgItem(hWnd,nItem);
ShowWindow(hItem, show ? SW_SHOW : SW_HIDE);
}

void MoveDlgItem(HWND hWnd,int nItem, int dx, int dy, UINT nFlag)
{
Expand Down
4 changes: 3 additions & 1 deletion DialogUtil.h → src/DialogHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@
#define MDIF_OFFSET_X 0x04 //水平移动
#define MDIF_OFFSET_Y 0x08 //垂直移动

void MoveDlgItem(HWND hWnd,int nItem, int dx, int dy, UINT nFlag);
void MoveDlgItem(HWND hWnd,int nItem, int dx, int dy, UINT nFlag);
void ShowDlgItem(HWND hWnd, int nItem, BOOL show);
void EnableDlgItem(HWND hWnd, int nItem, BOOL enable);
File renamed without changes.
File renamed without changes.
25 changes: 7 additions & 18 deletions HostsMan.rc → src/HostsMan.rc
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ EXSTYLE WS_EX_APPWINDOW
CAPTION "HostsMan"
FONT 9, "����", 0, 0, 0x1
BEGIN
CONTROL "",IDC_LIST1,"SysListView32",LVS_REPORT | LVS_SINGLESEL | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | LVS_NOCOLUMNHEADER | WS_BORDER | WS_TABSTOP,0,0,142,311
CONTROL "",IDC_LIST1,"SysListView32",LVS_REPORT | LVS_SINGLESEL | LVS_SHOWSELALWAYS | LVS_SORTASCENDING | LVS_ALIGNLEFT | LVS_NOCOLUMNHEADER | WS_BORDER | WS_TABSTOP,0,0,142,311
EDITTEXT IDC_EDIT1,143,0,316,311,ES_MULTILINE | ES_WANTRETURN | WS_VSCROLL | WS_HSCROLL
CONTROL "״̬��",IDC_STATUS,"msctls_statusbar32",WS_TABSTOP,0,313,459,12
END
Expand All @@ -90,15 +90,6 @@ BEGIN
EDITTEXT IDC_EDIT1,7,7,224,14,ES_AUTOHSCROLL
END

IDD_ABOUT DIALOGEX 0, 0, 186, 95
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Dialog"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
DEFPUSHBUTTON "ȷ��",IDOK,129,74,50,14
ICON IDR_MAINFRAME,IDC_STATIC,7,7,20,20
END


/////////////////////////////////////////////////////////////////////////////
//
Expand Down Expand Up @@ -162,14 +153,6 @@ BEGIN
TOPMARGIN, 7
BOTTOMMARGIN, 21
END

IDD_ABOUT, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 179
TOPMARGIN, 7
BOTTOMMARGIN, 88
END
END
#endif // APSTUDIO_INVOKED

Expand All @@ -188,6 +171,12 @@ BEGIN
MENUITEM "������(&R)", IDM_RENAME
MENUITEM "ɾ��(&D)", IDM_DELETE
END
POPUP "����"
BEGIN
MENUITEM "��ʾ", IDM_SHOW
MENUITEM "����", IDM_HELP
MENUITEM "�˳�", IDM_EXIT
END
END

#endif // ����(�л����񹲺͹�) resources
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions HostsMan.vcproj → src/HostsMan.vcproj
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath=".\DialogUtil.cpp"
RelativePath=".\DialogHelper.cpp"
>
</File>
<File
Expand Down Expand Up @@ -236,7 +236,7 @@
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
RelativePath=".\DialogUtil.h"
RelativePath=".\DialogHelper.h"
>
</File>
<File
Expand Down
25 changes: 6 additions & 19 deletions InputDlg.cpp → src/InputDlg.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
// NewDialog.cpp : 实现文件
#include "stdafx.h"
#include "MainApp.h"
#include "InputDlg.h"

// CNewDialog 对话框
IMPLEMENT_DYNAMIC(CInputDlg, CDialog)

CInputDlg::CInputDlg(CWnd* pParent /*=NULL*/)
Expand All @@ -12,42 +10,31 @@ CInputDlg::CInputDlg(CWnd* pParent /*=NULL*/)

}

CInputDlg::~CInputDlg()
{
}

void CInputDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}

void CInputDlg::SetTitle(LPCTSTR text)
{
m_title = text;
}

void CInputDlg::SetInput(LPCTSTR text)
{
m_input = text;
}

BEGIN_MESSAGE_MAP(CInputDlg, CDialog)
END_MESSAGE_MAP()

void CInputDlg::OnOK()
{
int ret;
LPCH exclude="\\/:*?\"<>|";
GetDlgItemText(IDC_EDIT1, m_input);
ret = m_input.FindOneOf("/*^=\\");
ret = m_input.FindOneOf(exclude);
if(ret >= 0)
{
MessageBox(_T("名称内不能包含特殊符号!"), _T("名称无效"));
CString text;
text.Format("不能包含下列特殊符号!\r\n\\/:*?\"<>|");
MessageBox(text, "无效输入", MB_ICONINFORMATION);
return;
}
ret = m_input.GetLength();
if(ret == 0)
{
MessageBox(_T("请输入配置名称!"), _T("名称无效"));
MessageBox("请输入配置名称!", "无效输入", MB_ICONINFORMATION);
return;
}
CDialog::OnOK();
Expand Down
12 changes: 3 additions & 9 deletions InputDlg.h → src/InputDlg.h
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
#pragma once


// CNewDialog 对话框

class CInputDlg : public CDialog
{
DECLARE_DYNAMIC(CInputDlg)
DECLARE_MESSAGE_MAP()

public:
CInputDlg(CWnd* pParent = NULL); // 标准构造函数
virtual ~CInputDlg();
void SetInput(LPCTSTR text);
void SetTitle(LPCTSTR text);
enum { IDD = IDD_NEW };
CInputDlg(CWnd* pParent = NULL);
enum { IDD = IDD_INPUT };

public:
CString m_title;
CString m_input;

protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV Ö§³Ö
DECLARE_MESSAGE_MAP()
virtual void OnOK();
virtual BOOL OnInitDialog();
};
15 changes: 2 additions & 13 deletions MainApp.cpp → src/MainApp.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// EasyHost.cpp : 定义应用程序的类行为。
//

#include "stdafx.h"
#include "MainApp.h"
#include "MainDlg.h"
Expand All @@ -9,25 +6,17 @@
#define new DEBUG_NEW
#endif


// CEasyHostApp
BEGIN_MESSAGE_MAP(CMainApp, CWinApp)
ON_COMMAND(ID_HELP, OnHelp)
END_MESSAGE_MAP()


// CEasyHostApp 构造
CMainApp::CMainApp()
{
// TODO: 在此处添加构造代码,
// 将所有重要的初始化放置在 InitInstance 中

}

// 唯一的一个 CEasyHostApp 对象
CMainApp theApp;


// CEasyHostApp 初始化
BOOL CMainApp::InitInstance()
{
CWinApp::InitInstance();
Expand All @@ -54,5 +43,5 @@ void CMainApp::InitContex()

void CMainApp::OnHelp()
{

ShellExecute(NULL, "open", "https://gitee.com/kerndev/HostsMan", NULL, NULL, SW_NORMAL);
}
6 changes: 2 additions & 4 deletions MainApp.h → src/MainApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@ class CMainApp : public CWinApp
{
public:
CMainApp();

private:
void InitContex();
virtual BOOL InitInstance();
DECLARE_MESSAGE_MAP()
afx_msg void OnHelp();
DECLARE_MESSAGE_MAP()
};

extern CMainApp theApp;
extern CMainApp theApp;
Loading

0 comments on commit 227878a

Please sign in to comment.