?? dialogtest7dlg.cpp
字號:
// DialogTest7Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "DialogTest7.h"
#include "DialogTest7Dlg.h"
#include "winuser.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()
/////////////////////////////////////////////////////////////////////////////
// CDialogTest7Dlg dialog
CDialogTest7Dlg::CDialogTest7Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CDialogTest7Dlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CDialogTest7Dlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_bMouseOnButton = FALSE;
}
void CDialogTest7Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDialogTest7Dlg)
DDX_Control(pDX, IDC_BUTTON_ALLKV, m_btnAllKV);
DDX_Control(pDX, IDC_BUTTON_UPDATE, m_btnUpdate);
DDX_Control(pDX, IDC_BUTTON_MYKV, m_btnMyKV);
DDX_Control(pDX, IDC_BUTTON_FLASHKV, m_btnFlashKV);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDialogTest7Dlg, CDialog)
//{{AFX_MSG_MAP(CDialogTest7Dlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_ERASEBKGND()
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_SETCURSOR()
//}}AFX_MSG_MAP
ON_MESSAGE(WM_MOUSEONBUTTON, OnMouseOnButton)
ON_MESSAGE(WM_MOUSEOFFBUTTON, OnMouseOffButton)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDialogTest7Dlg message handlers
BOOL CDialogTest7Dlg::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
CenterWindow();
m_bmMainBk.LoadBitmap(IDB_BITMAP_MAINBK);
BITMAP bm;
m_bmMainBk.GetObject(sizeof(BITMAP), &bm);
MoveWindow(0, 0, bm.bmWidth, bm.bmHeight);
m_rcMyComputer = CRect(140, 134, 357, 154);
m_rcMyDocument = CRect(140, 160, 357, 180);
m_rcMyDownload = CRect(140, 186, 357, 206);
m_rcMyHarddisk = CRect(140, 212, 357, 232);
m_rcMyCompactdisk = CRect(140, 238, 357, 258);
m_rcMyFloppydisk = CRect(140, 264, 357, 284);
m_rcMyStorage = CRect(140, 290, 357, 310);
m_rcMySelfDocument = CRect(140, 316, 357, 336);
m_rcSelected = m_rcMyComputer;
m_strSelected = "我的電腦";
//m_btnMyKV.MoveWindow(CRect(0, 26, 123, 26+26));
m_rcBtnMyKV = CRect(0, 26, 123, 26+26);
m_btnMyKV.MoveWindow(m_rcBtnMyKV);
m_btnMyKV.SetBitmaps(IDB_BITMAP_MYKVNORMAL,
IDB_BITMAP_MYKVDOWN,
IDB_BITMAP_MYKVDOWN);
// m_btnFlashKV.MoveWindow(CRect(409, 145, 409+138, 145+34));
m_rcBtnFlashKV = CRect(409, 145, 409+138, 145+34);
m_btnFlashKV.MoveWindow(m_rcBtnFlashKV);
m_btnFlashKV.SetBitmaps(IDB_BITMAP_FLASHKVNORMAL,
IDB_BITMAP_FLASHKVDOWN,
IDB_BITMAP_FLASHKVSELECT);
// m_btnAllKV.MoveWindow(CRect(409, 187, 409+138, 187+34));
m_rcBtnAllKV = CRect(409, 187, 409+138, 187+34);
m_btnAllKV.MoveWindow(m_rcBtnAllKV);
m_btnAllKV.SetBitmaps(IDB_BITMAP_ALLKVNORMAL,
IDB_BITMAP_ALLKVDOWN,
IDB_BITMAP_ALLKVSELECT);
// m_btnUpdate.MoveWindow(CRect(409, 230, 409+138, 230+34));
m_rcBtnUpdate = CRect(409, 230, 409+138, 230+34);
m_btnUpdate.MoveWindow(m_rcBtnUpdate);
m_btnUpdate.SetBitmaps(IDB_BITMAP_UPDATENORMAL,
IDB_BITMAP_UPDATEDOWN,
IDB_BITMAP_UPDATESELECT);
return TRUE; // return TRUE unless you set the focus to a control
}
void CDialogTest7Dlg::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 CDialogTest7Dlg::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
{
CPaintDC dc(this);
dc.SetBkMode(TRANSPARENT);
if (!m_bMouseOnButton)
{
CBrush cbSel;
cbSel.CreateSolidBrush(RGB(223, 233, 243));
dc.FillRect(&m_rcSelected, &cbSel);
}
else
{
CBrush cbSel;
cbSel.CreateSolidBrush(RGB(255, 230, 60));
dc.FillRect(&m_rcSelected, &cbSel);
}
LOGFONT lf;
ZeroMemory(&lf, sizeof(LOGFONT));
lf.lfHeight = -11;
lf.lfWeight = FW_NORMAL;
CFont font;
font.CreateFontIndirect(&lf);
CFont *pOldFont = dc.SelectObject(&font);
//dc.DrawText("我的電腦", 8, &m_rcSelected, DT_LEFT);
//dc.TextOut( 149, 138, "我的電腦");
dc.TextOut(149, m_rcSelected.top + 3, m_strSelected);
dc.SelectObject(pOldFont);
font.DeleteObject();
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CDialogTest7Dlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
BOOL CDialogTest7Dlg::OnEraseBkgnd(CDC* pDC)
{
CDC dcMem;
dcMem.CreateCompatibleDC(pDC);
CBitmap *pOldBitmap = dcMem.SelectObject(&m_bmMainBk);
CRect rcClient;
GetClientRect(&rcClient);
//pDC->GetClipBox(&rcClient);
pDC->BitBlt(rcClient.left, rcClient.top, rcClient.Width(), rcClient.Height(),
&dcMem, 0, 0, SRCCOPY);
dcMem.SelectObject(pOldBitmap);
dcMem.DeleteDC();
return TRUE;
// return FALSE;
}
void CDialogTest7Dlg::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if (PtInRect(&m_rcSelected, point))
{
// SetClassLong(GetSafeHwnd(), GCL_HCURSOR,
// (LONG)LoadCursor(NULL, IDC_ICON));
SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(32649)));
}
if (PtInRect(&m_rcBtnAllKV, point))
{
// CClientDC dc(this);
// dc.TextOut(1, 1 ,"Hello");
}
CDialog::OnMouseMove(nFlags, point);
}
void CDialogTest7Dlg::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if (PtInRect(&m_rcMyComputer, point))
{
m_rcSelected = m_rcMyComputer;
m_strSelected = "我的電腦";
}
if (PtInRect(&m_rcMyDocument, point))
{
m_rcSelected = m_rcMyDocument;
m_strSelected = "我的文檔";
}
if (PtInRect(&m_rcMyDownload, point))
{
m_rcSelected = m_rcMyDownload;
m_strSelected = "我的下載";
}
if (PtInRect(&m_rcMyHarddisk, point))
{
m_rcSelected = m_rcMyHarddisk;
m_strSelected = "我的硬盤";
}
if (PtInRect(&m_rcMyCompactdisk, point))
{
m_rcSelected = m_rcMyCompactdisk;
m_strSelected = "我的光盤";
}
if (PtInRect(&m_rcMyFloppydisk, point))
{
m_rcSelected = m_rcMyFloppydisk;
m_strSelected = "我的軟盤";
}
if (PtInRect(&m_rcMyStorage, point))
{
m_rcSelected = m_rcMyStorage;
m_strSelected = "移動存儲設備";
}
if (PtInRect(&m_rcMySelfDocument, point))
{
m_rcSelected = m_rcMySelfDocument;
m_strSelected = "自定義文件夾";
}
// Invalidate();
CRect rc(140, 134, 357, 336);
InvalidateRect(&rc);
CDialog::OnLButtonDown(nFlags, point);
}
void CDialogTest7Dlg::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(32649)));
CDialog::OnLButtonUp(nFlags, point);
}
void CDialogTest7Dlg::ChangeCursor(HCURSOR hCursor)
{
}
BOOL CDialogTest7Dlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
// TODO: Add your message handler code here and/or call default
return CDialog::OnSetCursor(pWnd, nHitTest, message);
}
void CDialogTest7Dlg::OnMouseOnButton()
{
m_bMouseOnButton = TRUE;
InvalidateRect(m_rcSelected);
}
void CDialogTest7Dlg::OnMouseOffButton()
{
m_bMouseOnButton = FALSE;
InvalidateRect(m_rcSelected);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -