📄 hotelinfoshow.cpp
字号:
// HotelInfoShow.cpp : implementation file
//
#include "stdafx.h"
#include "qq.h"
#include "HotelInfoShow.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define AW_CENTER 0x00000010
#include "QQView.h"
#include "Page3.h"
/////////////////////////////////////////////////////////////////////////////
// CHotelInfoShow dialog
//CString CHotelInfoShow::lpszShowText="";
CHotelInfoShow::CHotelInfoShow(CWnd* pParent /*=NULL*/)
: CDialog(CHotelInfoShow::IDD,pParent)
{
//{{AFX_DATA_INIT(CHotelInfoShow)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
lpszShowText="";//构造赋值
// pntCenter.x=0;
// pntCenter.y=0;
}
void CHotelInfoShow::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CHotelInfoShow)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CHotelInfoShow, CDialog)
//{{AFX_MSG_MAP(CHotelInfoShow)
ON_WM_LBUTTONDOWN()
ON_WM_PAINT()
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CHotelInfoShow message handlers
BOOL CHotelInfoShow::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
//文本何时显示的问题:
//在初始化函数OnInitDialog()中先调用animateWindow()形成动画效果
//在窗口完成动画效果后,如果从其他地方调用CDC::DrawText()函数的话
//没有效果,在窗口中根本就不会显示你要显示的文本
//解决方法是:
//在直接调用AnimateWindow()后,立即调用CDC::DrawText()函数显示的文本
//是正确的文本
//若想通过OnPaint()函数来达到这个目的不行
//初始化函数中调用AnimateWindow()后不会再调用OnPaint(),达不到预期的效果
// [6/7/2003-20:08]
//当鼠标点击视图区时,以鼠标点击的点为中心点逐渐显示对话框
//但是显示的开始点总是视图区域的原点CPoint(0,0);
//需要修改
// [6/7/2003-22:52]
// CRect rect;
// this->GetClientRect(&rect);
// CQQView* pView=CQQView::GetView();
// CPoint pntCenter=pView->pnt;
// ClientToScreen(&pntCenter);//pntCenter.x-rect.Width()/2,pntCenter.y-rect.Height()/2
// this->SetWindowPos(&CWnd::wndTop,pntCenter.x-rect.Width()/2,pntCenter.y-rect.Height()/2,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE);
this->CenterWindow();
HINSTANCE m_hInst=LoadLibrary("user32.dll");
typedef BOOL(WINAPI* LPANIMATEWND)(HWND,DWORD,DWORD);
LPANIMATEWND m_aniwnd=(LPANIMATEWND)GetProcAddress(m_hInst,"AnimateWindow");
m_aniwnd(this->GetSafeHwnd(),650,AW_CENTER);
this->ShowText(lpszShowText);//显示文本
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CHotelInfoShow::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CDialog::OnLButtonDown(nFlags, point);
CDialog::EndDialog(IDOK);
CQQView* pView=CQQView::GetView();
CDC* pDC=pView->GetDC();
CRect rect;
pView->GetClientRect(&rect);
CPage3 page3;
if(pView->nImgTypeInView==13)
{
// pView->Invalidate(TRUE);
//there is a bug!!
//重画有问题!!仍然需要解决!!!!!!!
// [6/7/2003-21:46]
pDC->FillSolidRect(rect,pDC->GetBkColor());
page3.DrawFrameImg(pDC,CRect(page3.xStart,page3.yStart,page3.xStart+350,page3.yStart+200));
}
}
void CHotelInfoShow::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
// CRect rect;
// this->GetClientRect(&rect);
// CSize size=dc.GetTextExtent(lpszShowText);
// long xStart=rect.left+(rect.Width()-size.cx)/2;
// long yStart=rect.top+(rect.Height()-size.cy)/2;
// // dc.TextOut(xStart,yStart,lpszShowText);
// CRect rectText(xStart,yStart,xStart+size.cx,yStart+size.cy);
// dc.SetBkMode(TRANSPARENT);
// //打印文本的时候不能自动换行
// if( size.cx < rect.Width())
// dc.DrawText(lpszShowText ,rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
// else
// dc.DrawText(lpszShowText, rectText, DT_CENTER | DT_WORDBREAK);
// dc.DrawText(lpszShowText,&rectText,DT_CENTER | DT_WORDBREAK);
// bFinish=false;
// Do not call CDialog::OnPaint() for painting messages
}
void CHotelInfoShow::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
// 通过时间器来形成动画的效果很不好,屏幕总是在闪动 [5/25/2003-13:28]
// this->ShowWindow(SW_HIDE);
// CRect rect;
// this->GetClientRect(&rect);
// long xCenter=(rect.left+rect.right)/2;
// long yCenter=(rect.top+rect.bottom)/2;
//
// CRgn testrgn;
//
// // int m=GetSystemMetrics(SM_CYSIZEFRAME);
//
// //以下代码实现对话框的动态弹出
// static int i=10;
// if(i<rect.Width()/2)
// {
// testrgn.CreateRectRgn(xCenter-i,yCenter-i,xCenter+i,yCenter+i);
//
// SetWindowRgn((HRGN) testrgn,TRUE);
//
// ShowWindow(SW_SHOW);
//
// CenterWindow();
//
// testrgn.DeleteObject();
// i+=5;
// }
//
// else
// {
// this->ShowWindow(SW_SHOW);//动态显示完成后要显示原来的对话框
// this->KillTimer(0);
// }
CDialog::OnTimer(nIDEvent);
}
/************************************************************************/
/* 函数功能:将位图拷贝道指定的Rect内
// 参数说明:
// pDC:设备上下文,用来拷贝位图
// rect:用来拷贝位图的区域 */
/************************************************************************/
void CHotelInfoShow::FillRectUseBMP(CDC *pDC, CRect rect)
{
CDC MemDC;
MemDC.CreateCompatibleDC(pDC);//创建与pDC兼容的设备上下文
CBitmap m_bitmap;
m_bitmap.LoadBitmap(IDB_TEXTBK);
MemDC.SelectObject(&m_bitmap);//将位图对象选入设备上下文
BITMAP bitamp;
m_bitmap.GetBitmap(&bitamp);//获取位图属性
pDC->StretchBlt(rect.left,rect.top,rect.Width(),rect.Height(),&MemDC,0,0,bitamp.bmWidth,bitamp.bmHeight,SRCCOPY);
m_bitmap.DeleteObject();
}
void CHotelInfoShow::ShowText(CString strShowText)
{
CDC* pDC=this->GetDC();
CRect rect,strTextRect;
GetClientRect(&rect);
// int nMaxLength=0;
CRect rectTextShw(rect.Width()/10,rect.Height()/10,rect.Width()*9/10,rect.Height()*9/10);
CSize sizeText=pDC->GetTextExtent(strShowText);
FillRectUseBMP(pDC,rect);
pDC->SetBkMode(TRANSPARENT);
if(sizeText.cx<rectTextShw.Width())
{
pDC->DrawText(strShowText,&rectTextShw,DT_CENTER | DT_VCENTER | DT_SINGLELINE);
}
else
{
pDC->DrawText(strShowText,&rectTextShw,DT_CENTER | DT_WORDBREAK);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -