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

📄 dialogstatusdlg.cpp

📁 Visual_C++[1].NET_Bible1 Visual_C++宝典书中的全部源码
💻 CPP
字号:
// DialogStatusDlg.cpp : implementation file
//

#include "stdafx.h"
#include "DialogStatus.h"
#include "DialogStatusDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

HBITMAP hBmp;

// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	enum { IDD = IDD_ABOUTBOX };

	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support

// Implementation
protected:
	DECLARE_MESSAGE_MAP()
public:
  afx_msg void OnBnClickedOk();
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}

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

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  ON_BN_CLICKED(IDOK, OnBnClickedOk)
END_MESSAGE_MAP()


// CDialogStatusDlg dialog



CDialogStatusDlg::CDialogStatusDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CDialogStatusDlg::IDD, pParent)
{
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

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

BEGIN_MESSAGE_MAP(CDialogStatusDlg, CDialog)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	//}}AFX_MSG_MAP
  ON_BN_CLICKED(IDD_ABOUTBOX, OnBnClickedAboutbox)
END_MESSAGE_MAP()


// CDialogStatusDlg message handlers

BOOL CDialogStatusDlg::OnInitDialog()
{
  CDialog::OnInitDialog();

  CreateStatusBar();

	return TRUE;  // return TRUE  unless you set the focus to a control

}

void CDialogStatusDlg::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 CDialogStatusDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, reinterpret_cast<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 function to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CDialogStatusDlg::OnQueryDragIcon()
{
	return static_cast<HCURSOR>(m_hIcon);
}

void CDialogStatusDlg::CreateStatusBar()
{
  // Hard-coded value to represent the status 
  // bar's height. 
  const int STATUSBAR_HEIGHT = 30;

  // Static structure used to hold each pane's
  // text value and pane style. I simply did it
  // like this so that I could use a for loop
  // when creating the panes.  
  static struct 
  {
    char szText[25];
    DWORD dwStyle;
  } Panes[] = {
    "Border", 0,
    "No border", SBT_NOBORDERS,
    "Popup", SBT_POPOUT,
  };
  
  // Set the rect of the status bar based on
  // the dialog. I simply take the dialog's 
  // coordinates and only change the top value
  // since the left, right and bottom values
  // are what I need to align the status bar
  // to the bottom of the dialog.
  CRect rect;
  GetWindowRect(&rect);
  rect.top = rect.bottom - STATUSBAR_HEIGHT;

  // Create the status bar using the rect that 
  // I've defined.
  if (!m_wndStatusBar.Create(WS_CHILD | WS_BORDER | WS_VISIBLE ,
                        rect,
                        this,
                        IDC_STATUSBAR))
  {
    AfxMessageBox ("Error in creating status bar");
  }
  else
  {
	  // Set the status bar's minimum height to be
	  // equal to the value I used to size it
	  // earlier.
	  m_wndStatusBar.SetMinHeight(STATUSBAR_HEIGHT);
  	
    // Get the size of the window as we're going to have
    // manually do all sizing of the status bar panes.
    CRect rectDialog;
    GetWindowRect(&rectDialog);
    int iDialogWidth = rectDialog.right - rectDialog.left;
  	
    // We'll simply make each pane of equal size. Obviously,
    // a more advanced usage would have these panes 
    // sized according to their data and usage.
    int nPanes = sizeof (Panes) / sizeof (Panes[0]);
    int iPaneWidths[sizeof (Panes) / sizeof (Panes[0])];

    for (int i = 0; i < (nPanes-1); i++)
      iPaneWidths[i] = (i + 1) * (iDialogWidth / nPanes);
    iPaneWidths[(nPanes-1)] = -1;

	  m_wndStatusBar.SetParts(nPanes, iPaneWidths); 
  	
	  // Sample pane data
	  for (int i = 0; i < nPanes; i++)
	    m_wndStatusBar.SetText(Panes[i].szText, i, Panes[i].dwStyle);
  }	    
}

void CAboutDlg::OnBnClickedOk()
{
	CWaitCursor wait;

  CString strUrl = "http://www.thecodechannel.com/redirect.asp?u=/&s=vcnb";
  if (32 >= (int)ShellExecute(NULL, "open", strUrl, NULL, NULL, SW_SHOWNORMAL))
	{
		AfxMessageBox("::ShellExecute failed to open this link!");
	}
}

void CDialogStatusDlg::OnBnClickedAboutbox()
{
  CAboutDlg().DoModal();
}

⌨️ 快捷键说明

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