📄 dlgpreparent.cpp
字号:
// DlgPreparent.cpp : implementation file
//
#include "stdafx.h"
#include "Manage_WH.h"
#include "DlgPreparent.h"
#include "DlgPregoto.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDlgPreparent dialog
CDlgPreparent::CDlgPreparent(CWnd* pParent /*=NULL*/)
: CDialog(CDlgPreparent::IDD, pParent)
{
//{{AFX_DATA_INIT(CDlgPreparent)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
pPreView = NULL;
m_OneCount = A4_ONELINE;
m_NextCount = A4_OTHERLINE;
m_nCount = 0;
m_PosPage = 1;
memset(&PrnInfo, 0, sizeof(PRNINFO));
}
void CDlgPreparent::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDlgPreparent)
DDX_Control(pDX, IDC_LIST, m_list);
DDX_Control(pDX, IDC_SDOWN, m_down);
DDX_Control(pDX, IDC_SUP, m_up);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDlgPreparent, CDialog)
//{{AFX_MSG_MAP(CDlgPreparent)
ON_WM_PAINT()
ON_WM_SIZE()
ON_WM_SYSCOMMAND()
ON_COMMAND(TBTN_EXIT, OnExit)
ON_COMMAND(TBTN_GOTO, OnGoto)
ON_COMMAND(TBTN_LAST, OnLast)
ON_COMMAND(TBTN_NEXT, OnNext)
ON_COMMAND(TBTN_PREVIOUS, OnPrevious)
ON_COMMAND(TBTN_PRINT, OnPrint)
ON_COMMAND(TBTN_TOP, OnTop)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDlgPreparent message handlers
WNDPROC CDlgPreparent::wpListProc = NULL;
HWND CDlgPreparent::hPrvWnd = NULL;
void CDlgPreparent::SetCallBackFun(PRINTPREVIEW pFun, PRNINFO sPrnInfo)
{
memcpy(&PrnInfo, &sPrnInfo, sizeof(PRNINFO));
pDrawInfo = pFun;
m_nCount = PrnInfo.nMaxLine;
m_nCountPage = 1;
int m = m_nCount-m_OneCount;
int n = m/m_NextCount;
m_nCountPage += n;
n = m%m_NextCount;
if(n>0)
m_nCountPage++;
PrnInfo.nCountPage = m_nCountPage;
}
BOOL CDlgPreparent::OnCommand(WPARAM wParam, LPARAM lParam)
{
int nID = LOWORD(wParam);
switch(nID)
{
case IDOK:
return FALSE;
case IDCANCEL:
return FALSE;
}
return CDialog::OnCommand(wParam, lParam);
}
BOOL CDlgPreparent::DestroyWindow()
{
if(IsWindow(m_wndtoolbar.m_hWnd))
m_wndtoolbar.DestroyWindow();
if(pPreView != NULL)
{
pPreView->DestroyWindow();
delete pPreView;
}
return CDialog::DestroyWindow();
}
BOOL CDlgPreparent::OnInitDialog()
{
CDialog::OnInitDialog();
if(m_nCount<=0)
{
EndDialog(FALSE);
return FALSE;
}
CDialog::OnInitDialog();
wpListProc = (WNDPROC)::SetWindowLong(m_list.m_hWnd, GWL_WNDPROC, (LONG)ListProc);
m_list.MoveWindow(-1000, -1000, 10, 10, TRUE);
m_hIcon = ::LoadIcon(AfxGetApp()->m_hInstance, (LPCTSTR)ICON_PREVIEW);
::SetClassLong(this->m_hWnd, GCL_HICON, (LONG)m_hIcon);
ShowWindow(SW_MAXIMIZE);
//添加工具条
if (!m_wndtoolbar.CreateEx(this,TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_ALIGN_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS ,
CRect(4,4,0,0)) || !m_wndtoolbar.LoadToolBar(IDR_TOOLBAR))
{
MessageBox("创建工具栏失败!", "错误", MB_ICONSTOP);
return FALSE;
}
m_wndtoolbar.ShowWindow(SW_SHOW);
RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);
m_wndtoolbar.GetWindowRect(&m_TbRect);
GetWindowRect(&rcClient);
SendMessage(WM_SIZE, 0, 0);
pPreView = new CDlgPreview;
pPreView->Create(IDD_PREVIEW, this);
pPreView->ShowWindow(SW_SHOW);
CRect rcTemp;
rcTemp.SetRect(rcClient.left, m_TbRect.Height()+2, rcClient.right, rcClient.bottom);
pPreView->SetCallBackFun(pDrawInfo, PrnInfo);
pPreView->MoveWindow(&rcTemp);
hPrvWnd = pPreView->m_hWnd;
m_wndtoolbar.SendMessage(TB_ENABLEBUTTON, TBTN_TOP, FALSE);
m_wndtoolbar.SendMessage(TB_ENABLEBUTTON, TBTN_PREVIOUS, FALSE);
if(m_nCount <= m_OneCount)
{
m_wndtoolbar.SendMessage(TB_ENABLEBUTTON, TBTN_GOTO, FALSE);
m_wndtoolbar.SendMessage(TB_ENABLEBUTTON, TBTN_NEXT, FALSE);
m_wndtoolbar.SendMessage(TB_ENABLEBUTTON, TBTN_LAST, FALSE);
}
else
{
m_wndtoolbar.SendMessage(TB_ENABLEBUTTON, TBTN_GOTO, TRUE);
m_wndtoolbar.SendMessage(TB_ENABLEBUTTON, TBTN_NEXT, TRUE);
m_wndtoolbar.SendMessage(TB_ENABLEBUTTON, TBTN_LAST, TRUE);
}
return TRUE;
}
void CDlgPreparent::OnPaint()
{
CPaintDC dc(this);
if (IsIconic())
{
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
{
CRect rect;
GetClientRect(rect);
dc.FillSolidRect(rect, RGB(60,70,120));
CDialog::OnPaint();
}
}
void CDlgPreparent::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
GetClientRect(&rcClient);
CRect rup;
rup.left = 0;
rup.top = 0;
rup.bottom = 2;
rup.right = rcClient.right;
if(IsWindow(m_up.m_hWnd))
m_up.MoveWindow(&rup);
if(IsWindow(m_down.m_hWnd))
{
rup.top = m_TbRect.Height();
rup.bottom = rup.top+2;
m_down.MoveWindow(&rup);
}
if(pPreView != NULL)
{
if(IsWindow(pPreView->m_hWnd))
{
CRect rcTemp;
rcTemp.SetRect(rcClient.left, m_TbRect.Height()+2, rcClient.right, rcClient.bottom);
pPreView->MoveWindow(&rcTemp);
}
}
}
void CDlgPreparent::OnSysCommand(UINT nID, LPARAM lParam)
{
if(nID == SC_CLOSE)
EndDialog(FALSE);
CDialog::OnSysCommand(nID, lParam);
}
//退出
void CDlgPreparent::OnExit()
{
SendMessage(WM_SYSCOMMAND, SC_CLOSE, NULL);
}
//转到
void CDlgPreparent::OnGoto()
{
int nPage = 1;
int m = m_nCount-m_OneCount;
int n = m/m_NextCount;
nPage += n;
n = m%m_NextCount;
if(n>0)
nPage++;
CDlgPregoto cpg;
cpg.nMax = nPage;
cpg.nCurPage = m_PosPage;
if(cpg.DoModal())
{
m_PosPage = cpg.nGoto;
pPreView->SetCurrentPage(m_nCountPage, m_PosPage);
if(m_PosPage > 1 && m_PosPage< m_nCountPage)
{
m_wndtoolbar.SendMessage(TB_ENABLEBUTTON, TBTN_TOP, TRUE);
m_wndtoolbar.SendMessage(TB_ENABLEBUTTON, TBTN_PREVIOUS, TRUE);
m_wndtoolbar.SendMessage(TB_ENABLEBUTTON, TBTN_NEXT, TRUE);
m_wndtoolbar.SendMessage(TB_ENABLEBUTTON, TBTN_LAST, TRUE);
}
if(m_PosPage == 1)
OnTop();
if(m_PosPage == m_nCountPage)
OnLast();
}
UpdatePreViewWnd();
}
//最后页
void CDlgPreparent::OnLast()
{
m_PosPage = m_nCountPage;
pPreView->SetCurrentPage(m_nCountPage, m_PosPage);
m_wndtoolbar.SendMessage(TB_ENABLEBUTTON, TBTN_TOP, TRUE);
m_wndtoolbar.SendMessage(TB_ENABLEBUTTON, TBTN_PREVIOUS, TRUE);
m_wndtoolbar.SendMessage(TB_ENABLEBUTTON, TBTN_NEXT, FALSE);
m_wndtoolbar.SendMessage(TB_ENABLEBUTTON, TBTN_LAST, FALSE);
UpdatePreViewWnd();
}
//下一页
void CDlgPreparent::OnNext()
{
m_PosPage++;
pPreView->SetCurrentPage(m_nCountPage, m_PosPage);
int nSpare = 0;
nSpare = m_nCount - m_PosPage*m_NextCount;
if(m_PosPage <= 2)
nSpare +=(m_NextCount - m_OneCount);
m_wndtoolbar.SendMessage(TB_ENABLEBUTTON, TBTN_TOP, TRUE);
m_wndtoolbar.SendMessage(TB_ENABLEBUTTON, TBTN_PREVIOUS, TRUE);
if(nSpare>0)
{
m_wndtoolbar.SendMessage(TB_ENABLEBUTTON, TBTN_NEXT, TRUE);
m_wndtoolbar.SendMessage(TB_ENABLEBUTTON, TBTN_LAST, TRUE);
}
else
{
m_wndtoolbar.SendMessage(TB_ENABLEBUTTON, TBTN_NEXT, FALSE);
m_wndtoolbar.SendMessage(TB_ENABLEBUTTON, TBTN_LAST, FALSE);
}
UpdatePreViewWnd();
}
//上一页
void CDlgPreparent::OnPrevious()
{
m_PosPage--;
pPreView->SetCurrentPage(m_nCountPage, m_PosPage);
if(m_PosPage<=1)
{
m_wndtoolbar.SendMessage(TB_ENABLEBUTTON, TBTN_TOP, FALSE);
m_wndtoolbar.SendMessage(TB_ENABLEBUTTON, TBTN_PREVIOUS, FALSE);
m_wndtoolbar.SendMessage(TB_ENABLEBUTTON, TBTN_NEXT, TRUE);
m_wndtoolbar.SendMessage(TB_ENABLEBUTTON, TBTN_LAST, TRUE);
}
else
{
m_wndtoolbar.SendMessage(TB_ENABLEBUTTON, TBTN_TOP, TRUE);
m_wndtoolbar.SendMessage(TB_ENABLEBUTTON, TBTN_PREVIOUS, TRUE);
m_wndtoolbar.SendMessage(TB_ENABLEBUTTON, TBTN_NEXT, TRUE);
m_wndtoolbar.SendMessage(TB_ENABLEBUTTON, TBTN_LAST, TRUE);
}
UpdatePreViewWnd();
}
//打印
void CDlgPreparent::OnPrint()
{
pPreView->PrintDoc();
}
//首页
void CDlgPreparent::OnTop()
{
m_PosPage = 1;
pPreView->SetCurrentPage(m_nCountPage, m_PosPage);
m_wndtoolbar.SendMessage(TB_ENABLEBUTTON, TBTN_TOP, FALSE);
m_wndtoolbar.SendMessage(TB_ENABLEBUTTON, TBTN_PREVIOUS, FALSE);
m_wndtoolbar.SendMessage(TB_ENABLEBUTTON, TBTN_NEXT, TRUE);
m_wndtoolbar.SendMessage(TB_ENABLEBUTTON, TBTN_LAST, TRUE);
UpdatePreViewWnd();
}
void CDlgPreparent::UpdatePreViewWnd()
{
pPreView->SendMessage(WM_PAINT, NULL, NULL);
}
LRESULT CALLBACK CDlgPreparent::ListProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
POINT pt;
RECT rc;
switch(uMsg)
{
case WM_MOUSEWHEEL:
::GetCursorPos(&pt);
if(!IsWindow(hPrvWnd))
break;
::GetWindowRect(hPrvWnd, &rc);
if(::PtInRect(&rc, pt))
{
::SendMessage(hPrvWnd, WM_MOUSEWHEEL, wParam, lParam);
return 0;
}
break;
}
return CallWindowProc(wpListProc, hwnd, uMsg, wParam, lParam);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -