📄 combinetooldlg.cpp
字号:
// CombineToolDlg.cpp : implementation file
//
#include "stdafx.h"
#include "CombineTool.h"
#include "CombineToolDlg.h"
#include "mmsystem.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:
HINSTANCE hUserDll;
CRect rctMain;
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
CStatic m_picSta;
CBitmap m_bmpSmile;
CBitmap m_bmpGlass;
//}}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 void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnTimer(UINT nIDEvent);
virtual BOOL OnInitDialog();
afx_msg void OnPaint();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
private:
BOOL m_bIsFirst;
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
DDX_Control(pDX, IDC_STA_PIC, m_picSta);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
ON_WM_LBUTTONDOWN()
ON_WM_TIMER()
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCombineToolDlg dialog
CCombineToolDlg::CCombineToolDlg(CWnd* pParent /*=NULL*/)
: CDialog(CCombineToolDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CCombineToolDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_szSoundPath = "";
m_szShowIdealSoundPath = "";
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CCombineToolDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCombineToolDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCombineToolDlg, CDialog)
//{{AFX_MSG_MAP(CCombineToolDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_STA_QUIT, OnStaQuit)
ON_WM_MOUSEMOVE()
ON_BN_CLICKED(IDC_STA_TOOL, OnStaTool)
ON_BN_CLICKED(IDC_STA_PLAY, OnStaPlay)
ON_BN_CLICKED(IDC_STA_LOG, OnStaLog)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCombineToolDlg message handlers
BOOL SetTransparent(HWND hWnd, HINSTANCE hUserDll, COLORREF crKey, BYTE bAlpha, DWORD dwFlags)
{
BOOL bRet = TRUE;
typedef BOOL (WINAPI* lpfnSetTransparent)(HWND hWnd, COLORREF crKey, BYTE bAlpha, DWORD dwFlags);
// Check that "USER32.dll" library has been loaded successfully...
if ( hUserDll )
{
lpfnSetTransparent pFnSetTransparent = NULL;
pFnSetTransparent = (lpfnSetTransparent)GetProcAddress(hUserDll, "SetLayeredWindowAttributes");
if (pFnSetTransparent )
bRet = pFnSetTransparent(hWnd, crKey, bAlpha, dwFlags);
else
bRet = FALSE;
} //if( hUserDll )
return bRet;
}
void InitTran(HWND hWnd, HINSTANCE& hUserDll)
{
hUserDll = ::LoadLibrary(_T("USER32.dll"));
::SetWindowLong(hWnd, GWL_EXSTYLE, ::GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_LAYERED );
SetTransparent(hWnd, hUserDll, 0, 255 * 100/100 , LWA_ALPHA );
}
void CloseSmoothly(HWND hWnd, HINSTANCE hUserDll)
{
for(int nPercent=100; nPercent >= 0 ;nPercent--)
{
Sleep(30);
SetTransparent(hWnd, hUserDll, 0, 255 * nPercent/100, LWA_ALPHA);
}
if (hUserDll)
::FreeLibrary( hUserDll );
}
BOOL CCombineToolDlg::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
SetWindowText("WZJ欢迎您使用小小工具合集!");
CString szExePath = AfxGetApp()->m_pszHelpFilePath;
CString szExeName = AfxGetApp()->m_pszExeName;
szExePath = szExePath.Left(szExePath.GetLength() - szExeName.GetLength() - 4);
m_szSoundPath = szExePath + "\\sound\\menuMove.wav";
m_szShowIdealSoundPath = szExePath + "\\sound\\showIdeal.wav";
return TRUE; // return TRUE unless you set the focus to a control
}
void CCombineToolDlg::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 CCombineToolDlg::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 CCombineToolDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CCombineToolDlg::OnStaQuit()
{
// TODO: Add your control notification handler code here
CAboutDlg dlg;
MSG* pMsg = (MSG*)GetCurrentMessage();
POINT pt = pMsg->pt;
CPoint p(pt);
ScreenToClient(&p);
if (p.y < 135)
{
dlg.DoModal();
}
else
{
if (IDOK == MessageBox("真的要退出?", "WZJ小秘书提示", MB_OKCANCEL | MB_ICONQUESTION))
{
OnOK();
}
}
}
void CCombineToolDlg::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CRect rctTool(CRect(10, 80, 60, 120));
CRect rctPlay(CRect(75, 80, 125, 120));
CRect rctLog(CRect(140, 80, 190, 120));
CRect rctQuit(CRect(205, 80, 255, 120));
if (rctPlay.PtInRect(point))
{
if (m_nPlay != 1)
{
PlaySound(m_szSoundPath, NULL, SND_ASYNC|SND_NODEFAULT);
m_nPlay = 1;
}
ShowSubMenu(0, 1, 0, 0);
SetWindowText("休闲娱乐,我的地盘我做主!");
}
else if (rctLog.PtInRect(point))
{
if (m_nPlay != 2)
{
PlaySound(m_szSoundPath, NULL, SND_ASYNC|SND_NODEFAULT);
m_nPlay = 2;
}
ShowSubMenu(0, 0, 1, 0);
SetWindowText("日志帐目,给自己一片宁静的空间!");
}
else if (rctTool.PtInRect(point))
{
if (m_nPlay != 3)
{
PlaySound(m_szSoundPath, NULL, SND_ASYNC|SND_NODEFAULT);
m_nPlay = 3;
}
SetWindowText("快捷工具,使用这些工具从此再也不用到处苦找!");
ShowSubMenu(1, 0, 0, 0);
}
else if (rctQuit.PtInRect(point))
{
if (m_nPlay != 4)
{
PlaySound(m_szSoundPath, NULL, SND_ASYNC|SND_NODEFAULT);
m_nPlay = 4;
}
SetWindowText("看看作者,作者开发得好累啊,看看他的信息给个面子吧!");
ShowSubMenu(0, 0, 0, 1);
}
else
{
m_nPlay = 0;
SetWindowText("WZJ欢迎您使用小小工具合集!");
ShowSubMenu(0,0,0,0);
}
CDialog::OnMouseMove(nFlags, point);
}
void CCombineToolDlg::ShowSubMenu(BOOL bIsToolShow, BOOL bIsPlayShow, BOOL bIsLogShow, BOOL bIsQuitShow)
{
((CStatic*)GetDlgItem(IDC_STA_PLAY))->ShowWindow(bIsPlayShow);
((CStatic*)GetDlgItem(IDC_STA_LOG))->ShowWindow(bIsLogShow);
((CStatic*)GetDlgItem(IDC_STA_TOOL))->ShowWindow(bIsToolShow);
((CStatic*)GetDlgItem(IDC_STA_QUIT))->ShowWindow(bIsQuitShow);
}
void CAboutDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CString szExePath = AfxGetApp()->m_pszHelpFilePath;
CString szExeName = AfxGetApp()->m_pszExeName;
szExePath = szExePath.Left(szExePath.GetLength() - szExeName.GetLength() - 4);
CString szAboutSoundPath = szExePath + "\\sound\\About.wav";
PlaySound(szAboutSoundPath, NULL, SND_ASYNC|SND_NODEFAULT);
CloseSmoothly(m_hWnd, hUserDll);
OnOK();
CDialog::OnLButtonDown(nFlags, point);
}
#include "CustTool.h"
#include "MyTool.h"
void CCombineToolDlg::OnStaTool()
{
// TODO: Add your control notification handler code here
MSG* pMsg = (MSG*)GetCurrentMessage();
POINT pt = pMsg->pt;
CPoint p(pt);
ScreenToClient(&p);
CCustTool custTool;
CMyTool myTool;
if (p.y < 135)
{
custTool.ShowDlg();
}
else
{
myTool.ShowDlg();
}
}
void CAboutDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
m_bIsFirst = !m_bIsFirst;
if (m_bIsFirst)
m_picSta.SetBitmap(m_bmpGlass);
else
m_picSta.SetBitmap(m_bmpSmile);
CDialog::OnTimer(nIDEvent);
}
BOOL CAboutDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
m_bmpSmile.LoadBitmap(IDB_BMP_SMILE);
m_bmpGlass.LoadBitmap(IDB_BMP_GLASS);
SetTimer(0, 2000, NULL);
GetClientRect(&rctMain);
InitTran(m_hWnd, hUserDll);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
#include "Ideal.h"
#include "Test.h"
void CCombineToolDlg::OnStaPlay()
{
// TODO: Add your control notification handler code here
MSG* pMsg = (MSG*)GetCurrentMessage();
POINT pt = pMsg->pt;
CPoint p(pt);
ScreenToClient(&p);
CIdeal ideal;
CTest test;
if (p.y < 135)
{
ideal.m_lpSoundFile = m_szShowIdealSoundPath;
ideal.ShowDlg();
}
else
{
test.ShowDlg();
}
}
void CAboutDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
CBrush bru(RGB(210, 230, 250));
dc.FillRect(&rctMain, &bru);
// Do not call CDialog::OnPaint() for painting messages
}
#include "Log.h"
#include "Account.h"
void CCombineToolDlg::OnStaLog()
{
// TODO: Add your control notification handler code here
MSG* pMsg = (MSG*)GetCurrentMessage();
POINT pt = pMsg->pt;
CPoint p(pt);
ScreenToClient(&p);
CLog log;
CAccount account;
if (p.y < 135)
{
log.ShowDlg();
}
else
{
account.ShowDlg();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -