📄 gdialog.cpp
字号:
// GDialog.cpp: implementation of the GDialog class.
//
//////////////////////////////////////////////////////////////////////
#include "..\stdafx.h"
#include "GDialog.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
GDialog::GDialog()
{
m_pOldFocus=NULL;
m_nBackColor=RGB(192,192,192)|EdgeRGB(255,255,255);
m_nForeColor=RGB(0,0,0);
m_nStyle=WS_CAPTION|WS_SYSMENU;
m_pFont=&GUI_DEFAULTFONT;
m_nState=0;
}
GDialog::~GDialog()
{
}
//消息处理函数
void GDialog::WndProc(int nMessage, int wParam, int lParam)
{
switch(nMessage)
{
case WM_PAINT:
if(wParam & ~ODA_CLIENT)OnNcPaint();
if(wParam & ODA_CLIENT){OnPaint();DrawControls();}
break;
case WM_MOVE:
OnMove();
break;
case WM_CREATE:
OnCreate();
case WM_COMMAND:
m_nDlgResult=wParam;
break;
case WM_LBUTTONDOWN:
case WM_LBUTTONUP:
{
RECT r;
r.top=m_rectWnd.top;
r.bottom=m_Rect.top;
r.right=m_rectWnd.right;
r.left=r.right-(r.bottom-r.top)-4;
if(nMessage==WM_LBUTTONDOWN)
{
if(PtInRect(wParam,lParam,r))
{
m_nState |= ODS_GRAYED;
PostMessage(WM_PAINT,ODA_FOCUS,-1);
}
}
else
{
if(m_nState & ODS_GRAYED)
{
m_nState &= ~ODS_GRAYED;
PostMessage(WM_PAINT,ODA_FOCUS,-1);
if(PtInRect(wParam,lParam,r))
{
if(m_nStyle & WS_SYSMENU)m_nDlgResult=-1;
}
}
}
break;
}
default:
break;
}
}
void GDialog::Create()
{
if(!m_pOldFocus)
{
GWnd* pWnd;
//处理GUI
if(m_nWndCount>0)
{
pWnd=m_aWnd[m_nWndCount-1];
if(pWnd->m_pParent)pWnd=pWnd->m_pParent;
pWnd->m_nState &= ~ODS_FOCUS;
pWnd->PostMessage(WM_PAINT,ODA_FOCUS,-1);
}
if(m_pFocus)
{
m_pFocus->m_nState &= ~ODS_FOCUS;
m_pFocus->PostMessage(WM_PAINT,ODA_FOCUS,-1);
m_pOldFocus=m_pFocus;
m_pFocus=NULL;
}
else m_pOldFocus=this;
m_pParent=NULL;
m_nWndIndex=m_nWndCount;
m_aWnd[m_nWndCount++]=this;
m_nStyle|=WS_VISIBLE;
m_nState|=ODS_FOCUS;
WndProc(WM_CREATE,0,0);
m_nDlgResult=0;
PostMessage(WM_PAINT,ODA_ALL,-1);
}
}
void GDialog::Close()
{
if(m_pOldFocus)
{
GWnd* pWnd;
if(m_pOldFocus==this)m_pFocus=NULL;
else
{
m_pFocus=m_pOldFocus;
m_pFocus->m_nState |= ODS_FOCUS;
}
m_pOldFocus=NULL;
while(m_nWndCount)
{
m_nWndCount--;
pWnd=m_aWnd[m_nWndCount];
pWnd->WndProc(WM_CLOSE,0,0);
if(pWnd==this)break;
}
m_nStyle&=~WS_VISIBLE;
m_nState&=~ODS_FOCUS;
if(m_nWndCount>0)
{
pWnd=m_aWnd[m_nWndCount-1];
if(pWnd->m_pParent)pWnd=pWnd->m_pParent;
pWnd->m_nState |=ODS_FOCUS;
pWnd->PostMessage(WM_PAINT,ODA_ALL,-1);
}
}
}
int GDialog::DoModal()
{
Create();
do
{
DoEvents();
if(m_nDlgResult)WndProc(WM_CLOSE,1,0);
else WndProc(WM_KICKIDLE,0,0);
}while(!m_nDlgResult);
Close();
return m_nDlgResult;
}
void GDialog::AddControl(GWnd *pChild,LPCTSTR szText,int nStyle)
{
if(szText)pChild->m_strText=szText;
if(nStyle)pChild->m_nStyle=nStyle;
pChild->m_nStyle|=WS_CHILD;
pChild->m_pParent=this;
pChild->m_pFont=m_pFont;
pChild->m_nBackColor=m_nBackColor;
pChild->m_nForeColor=m_nForeColor;
pChild->m_nWndIndex=m_nWndCount;
m_aWnd[m_nWndCount++]=pChild;
pChild->WndProc(WM_CREATE,0,0);
}
void GDialog::OnNcPaint()
{
int nBorder;
int c=m_nForeColor;
RECT r0=m_rectClip;
RECT r=m_rectWnd;
const FONT* pFont=m_pFont;
m_pFont=&GUI_DEFAULTFONT;
m_rectClip=m_rectWndClip;
if(m_nStyle & WS_MAXIMIZE)nBorder=0;
else if(m_nStyle & WS_FLAT)
{
if(m_nStyle & WS_CAPTION)
{
m_nForeColor=EdgeRGB(255);
Rectangle(r);
nBorder=1;
}
}
else if(m_nStyle & WS_DLGFRAME)
{
DrawEdge(r,EDGE_RAISED);
nBorder=2;
}
else if(m_nStyle & WS_BORDER)
{
Draw3dRect(r,EdgeRGB(255),EdgeRGB(64));
nBorder=1;
}
if((m_nStyle & WS_CAPTION)==WS_CAPTION)
{
r.left=m_rectWnd.left+nBorder;
r.right=m_rectWnd.right-nBorder;
r.top=m_rectWnd.top+nBorder;
r.bottom=r.top+m_pFont->nHeight+1;
m_nForeColor=(m_nState & ODS_FOCUS)?RGB(0,0,128):RGB(128,128,128);
FillRect(r,m_nForeColor);
r.left+=2;
m_nForeColor=RGB(255,255,255);
DrawText(m_strText,r,DT_LEFT|DT_VCENTER);
r.top+=2;r.bottom-=2;
r.right-=2;
r.left=r.right-(r.bottom-r.top);
if(!(m_nStyle & WS_SYSMENU) || !(m_nState & ODS_GRAYED))Draw3dRect(r,RGB(255,255,255),RGB(64,64,64));
else Draw3dRect(r,RGB(64,64,64),RGB(255,255,255));
r.left+=1;r.top+=1;r.right-=1;r.bottom-=1;
if(!(m_nStyle & WS_SYSMENU)|| !(m_nState & ODS_GRAYED))Draw3dRect(r,RGB(192,192,192),RGB(128,128,128));
else Draw3dRect(r,RGB(128,128,128),RGB(192,192,192));
r.left+=1;r.top+=1;r.right-=1;r.bottom-=1;
FillRect(r,RGB(192,192,192));
if(m_nStyle & WS_SYSMENU)
{
m_nForeColor=RGB(0,0,0);
if(m_nState & ODS_GRAYED)
{
r.top+=1;r.left+=1;
}
else
{
r.bottom-=1;r.right-=1;
}
Line(r.left,r.top,r.right,r.bottom);
Line(r.left,r.bottom,r.right,r.top);
}
else
{
m_nForeColor=RGB(128,128,128);
Line(r.left,r.top,r.right,r.bottom);
Line(r.left,r.bottom,r.right,r.top);
}
}
if(m_nStyle& WS_CLIENT)
{
r=m_Rect;
r.left-=2;r.top-=2;
r.right+=2;r.bottom+=2;
DrawEdge(r,EDGE_SUNKEN);
}
m_pFont=pFont;
m_rectClip=r0;
m_nForeColor=c;
}
void GDialog::OnPaint()
{
if(m_nBackColor!=CLR_NONE)FillRect(m_Rect,m_nBackColor);
}
void GDialog::DrawControls()
{
int i;
for(i=m_nWndIndex+1;i<m_nWndCount;i++)
{
m_aWnd[i]->WndProc(WM_PAINT,ODA_ALL,-1);
}
}
void GDialog::OnMove()
{
int nBorder;
if(m_nStyle & WS_MAXIMIZE)nBorder=0;
else if(m_nStyle & WS_FLAT)nBorder=(m_nStyle & WS_CAPTION)?1:0;
else if(m_nStyle & WS_DLGFRAME)nBorder=2;
else if(m_nStyle & WS_BORDER)nBorder=1;
else nBorder=0;
m_Rect=m_rectWnd;
if(m_nStyle & WS_CLIENT)nBorder+=2;
m_Rect.left+=nBorder;
m_Rect.right-=nBorder;
m_Rect.top+=nBorder;
m_Rect.bottom-=nBorder;
if((m_nStyle & WS_CAPTION)==WS_CAPTION)m_Rect.top+=GUI_DEFAULTFONT.nHeight+2;
}
void GDialog::OnCreate()
{
if(m_nStyle & WS_MAXIMIZE)
{
MoveWindow(0,0,GUI_CXSCREEN,GUI_CYSCREEN);
}
else if(m_nStyle & DS_CENTER)
{
RECT r;
int w=m_rectWnd.right-m_rectWnd.left+1;
int h=m_rectWnd.bottom-m_rectWnd.top+1;
r.left=(GUI_CXSCREEN-w)/2;
r.right=r.left+w-1;
r.top=(GUI_CYSCREEN-h)/2;
r.bottom=r.top+h-1;
MoveWindow(r);
}
else MoveWindow(m_rectWnd);
}
int GDialog::MessageBox(LPCTSTR szText, LPCTSTR szCaption, int nType)
{
GMsgBox dlg;
if(nType & MB_FACELIKE)
{
dlg.m_nForeColor=m_nForeColor;
dlg.m_nBackColor=m_nBackColor;
dlg.m_pFont=m_pFont;
}
if(!szCaption)szCaption=m_strText;
dlg.Create(szText,szCaption,nType);
do{DoEvents();}while(!dlg.PeakButton());
dlg.Close();
return dlg.m_nDlgResult;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -