📄 abwin.cpp
字号:
// AbWin.cpp: implementation of the CAbWin class.
//
//////////////////////////////////////////////////////////////////////
#ifdef _DEBUG
#include <sstream>
#endif
#include "mixer.h"
#include "MiXoException.h"
#include "AbWinException.h"
#include "AbWin.h"
#include "Font.h"
#include "ClassContainer.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
WNDPROC *CAbWin::GetWinProc() const
{
return reinterpret_cast<WNDPROC*>(&::g_WindowProcCaller);
}
CAbWin::CAbWin(const char *szModName)
: CAbProcClient(),
m_hMenu(0),m_hWnd(0),m_atmClass(0),m_rRect(),m_hParWnd(0),m_strModName(),
m_hMod(0),m_rClient(-1,-1,-1,-1),m_hFont(0),m_pFont(NULL),
m_hBgBrush(0)
// m_sWndClass(),
{
if(szModName)
m_strModName=szModName;
else
m_strModName="";
}
CAbWin::CAbWin(const CAbWin &c)
: CAbProcClient(),
m_hMenu(c.m_hMenu),m_hWnd(c.m_hWnd),m_atmClass(c.m_atmClass),
m_rRect(c.m_rRect),m_hParWnd(c.m_hParWnd),m_strModName(c.m_strModName),
m_hMod(c.m_hMod),m_rClient(c.m_rClient),m_hFont(c.m_hFont),
m_hBgBrush(0),
m_pFont(NULL)
// m_sWndClass(c.m_sWndClass),
{ if(c.m_pFont)
m_pFont=new CAbFont(*c.m_pFont);
}
CAbWin::~CAbWin()
{
DeInit(); //as far as I know calls always CAbWin::DeInit
}
HWND CAbWin::SetParHandle(HWND h,bool bInWinToo)
{
HWND hOld=m_hParWnd;
m_hParWnd=h;
if(bInWinToo)
hOld=::SetParent(hOld,h);
return hOld;
}
void CAbWin::Init(HWND hParWnd)
{
if(m_hWnd || m_atmClass)
throw CAbException(::GetLastError(),__FILE__,__LINE__);
WNDCLASSEX sWndClass;
m_hParWnd=hParWnd;
m_hMod=::GetModuleHandle(GetModName());
if(::g_GetClassContainer()->IsSystemClass(GetClassName()))
return;
// if(::GetClassInfoEx(m_hMod,GetClassName(),&sWndClass)) //already registered
// return;
sWndClass.cbSize=sizeof(WNDCLASSEX);
sWndClass.style=GetClassStyle();
sWndClass.lpfnWndProc=&g_WindowProcCaller;
sWndClass.cbClsExtra=0;
sWndClass.cbWndExtra=DLGWINDOWEXTRA;
sWndClass.hInstance=m_hMod;
sWndClass.hIcon=GetIcon();
sWndClass.hCursor=GetCursor();
if(m_hBgBrush)
sWndClass.hbrBackground=m_hBgBrush;
else
sWndClass.hbrBackground=GetBgBrush();
sWndClass.lpszMenuName=GetMenuNameString();
sWndClass.lpszClassName=GetClassName();
sWndClass.hIconSm=GetSmallIcon();
m_atmClass=::g_GetClassContainer()->RegisterClass(sWndClass);
// m_atmClass=::RegisterClassEx(&sWndClass);
// if(m_atmClass == 0)
// throw CAbWinException(::GetLastError(),__FILE__,__LINE__,sWndClass);
}
void CAbWin::DeInit()
{
if(m_hWnd) {
::g_GetWinContainer()->UnregisterWindow(m_hWnd);
::DestroyWindow(m_hWnd);
m_hWnd=0;
if(m_hBgBrush)
m_hBgBrush=0;
}
if(m_atmClass) {
::g_GetClassContainer()->UnRegisterClass(m_atmClass);
// ::UnregisterClass((const char*)(m_atmClass|NULL),NULL); //m$ stupid
m_atmClass=0;
}
if(m_hMenu) {
::DestroyMenu(m_hMenu);
m_hMenu=0;
}
if(m_pFont) {
delete m_pFont;
m_pFont=NULL;
}
m_rClient=CWinRect(-1,-1,-1,-1);
}
void CAbWin::LoadMenu()
{
if(m_hMenu) {
::DestroyMenu(m_hMenu);
m_hMenu=0;
}
if(m_hMod == NULL)
m_hMod=::GetModuleHandle(GetModName());
if(GetMenuNameString()) {
m_hMenu=::LoadMenu(m_hMod,GetMenuNameString());
if(!m_hMenu)
throw CAbException(::GetLastError(),__FILE__,__LINE__);
}
}
void CAbWin::CalcWindowRectSize()
{
if(m_rClient == CWinRect(-1,-1,-1,-1) )
return;
RECT r={m_rClient.X(),m_rClient.Y(),m_rClient.X1(),m_rClient.Y1()};
::AdjustWindowRectEx(&r,GetWinStyle(),(GetMenuNameString())?true:false,GetExWinStyle());
SetWindowRect(CWinRect(r.left,r.top,r.right,r.bottom));
}
void CAbWin::Create()
{
if(m_hWnd)
throw CAbException(::GetLastError(),__FILE__,__LINE__);
if(m_hMod == NULL)
m_hMod=::GetModuleHandle(GetModName());
if(!m_hMenu && GetMenuNameString()) //???
LoadMenu();
CalcWindowRectSize();
m_hWnd=::CreateWindowEx(
GetExWinStyle(),
GetClassName(),GetTitle(),
GetWinStyle(),
GetRect().X(),GetRect().Y(),GetRect().Wd(),GetRect().Ht(),
m_hParWnd,
m_hMenu,
m_hMod,
NULL);
PostCreate();
}
void CAbWin::PostCreate()
{
if(!m_hWnd)
throw CAbException(::GetLastError(),__FILE__,__LINE__);
::g_GetWinContainer()->RegisterWindow(new CWindowProc(this,m_hWnd));
if(m_pFont) {
string str=m_pFont->GetFontName();
SetWindowFont(str.c_str(),m_pFont->GetHt());
} else {
if(m_hFont)
SendMessage(m_hWnd,WM_SETFONT,(WPARAM)m_hFont,MAKELPARAM(TRUE,0));
}
if(m_rClient == CWinRect(-1,-1,-1,-1) )
{
RECT r;
::GetClientRect(m_hWnd,&r);
SetWindowClientRect(CWinRect(r.left,r.top,r.right,r.bottom));
}
}
void CAbWin::Refresh()
{
if(m_hWnd)
InvalidateRect(GetWndHandle(),NULL,TRUE);
}
bool CAbWin::OnWMClose()
{
DeInit();
return true;
}
bool CAbWin::OnWMDestroy()
{
DeInit(); //if clipboard add some stuff here
return true;
}
LRESULT CAbWin::WindowProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
switch(uMsg){
case WM_CLOSE:
if(OnWMClose())
return 0;
break;
case WM_DESTROY:
if(OnWMDestroy())
return 0;
break;
case WM_PAINT:
if(OnWMPaint((HDC)wParam))
return 0;
break;
}
return ::DefWindowProc(hWnd,uMsg,wParam,lParam);
}
void CAbWin::SetWindowFont(const char *sz,int iHt)
{
CAbFont *pOldFont=m_pFont;
m_pFont=new CAbFont();
m_pFont->SetFontName(sz);
if(m_hWnd) {
HDC hDC=::GetDC(m_hWnd);
m_pFont->SetHt(iHt,hDC);
::ReleaseDC(m_hWnd,hDC);
m_pFont->Create();
m_hFont=m_pFont->GetHandle();
SendMessage(m_hWnd,WM_SETFONT,(WPARAM)m_hFont,MAKELPARAM(TRUE,0));
}else{
m_pFont->SetHt(iHt,NULL);
}
if(pOldFont)
delete pOldFont;
}
void CAbWin::SetBgBrush(HBRUSH h)
{
WNDCLASSEX sWndClass;
m_hBgBrush=h;
if(m_hMod == NULL)
m_hMod=::GetModuleHandle(GetModName());
if(m_hWnd && ::GetClassInfoEx(m_hMod,GetClassName(),&sWndClass)) //already registered
{
::SetClassLong(m_hWnd,GCL_HBRBACKGROUND,(LONG)h);
return;
}
}
void CAbWin::SetExWinStyle(DWORD s)
{
if(m_hWnd) {
::SetWindowLong(m_hWnd,GWL_EXSTYLE,(LONG)s);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -