📄 maindlg.h
字号:
// MainDlg.h : interface of the CMainDlg class
//
/////////////////////////////////////////////////////////////////////////////
#pragma once
#include "GIFShow.h"
CGIFShow *pGIFInst;
class CMainDlg : public CDialogImpl<CMainDlg>, public CUpdateUI<CMainDlg>,
public CMessageFilter, public CIdleHandler
{
public:
enum { IDD = IDD_MAINDLG };
virtual BOOL PreTranslateMessage(MSG* pMsg)
{
return CWindow::IsDialogMessage(pMsg);
}
virtual BOOL OnIdle()
{
return FALSE;
}
BEGIN_UPDATE_UI_MAP(CMainDlg)
END_UPDATE_UI_MAP()
BEGIN_MSG_MAP(CMainDlg)
MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
MESSAGE_HANDLER(WM_PAINT, OnPaint)
COMMAND_ID_HANDLER(ID_APP_ABOUT, OnAppAbout)
COMMAND_ID_HANDLER(IDOK, OnOK)
COMMAND_ID_HANDLER(IDCANCEL, OnCancel)
COMMAND_ID_HANDLER(ID_EXIT, OnCancel)
COMMAND_ID_HANDLER(ID_OPTION_SHOWGIF, OnShoweGif)
COMMAND_ID_HANDLER(ID_OPTION_HIDEGIF, OnHideGif)
COMMAND_ID_HANDLER(ID_OPTION_DESTROYGIF, OnDestroyGif)
END_MSG_MAP()
// Handler prototypes (uncomment arguments if needed):
// LRESULT MessageHandler(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
// LRESULT CommandHandler(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
// LRESULT NotifyHandler(int /*idCtrl*/, LPNMHDR /*pnmh*/, BOOL& /*bHandled*/)
LRESULT OnPaint(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
CPaintDC dc(m_hWnd);
RECT rc;
GetClientRect(&rc);
dc.FillSolidRect(&rc, COLORREF(RGB(100, 0, 0)));
return 0;
}
LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
pGIFInst = new CGIFShow(GetDC());
// center the dialog on the screen
CenterWindow();
SHINITDLGINFO sid;
sid.dwMask = SHIDIM_FLAGS; // This is the only allowed value
sid.dwFlags = SHIDIF_SIZEDLGFULLSCREEN; // Make the DB full screan
sid.hDlg = m_hWnd; // Handle to the main dialog
SHInitDialog(&sid);
SHMENUBARINFO mbi = { sizeof(mbi), 0 };
mbi.hwndParent = m_hWnd;
mbi.nToolBarId = IDR_MENU1; // ID of toolbar resource
mbi.hInstRes = _AtlBaseModule.GetResourceInstance();
mbi.dwFlags = SHCMBF_HMENU;
VERIFY(SHCreateMenuBar(&mbi));
// set icons
HICON hIcon = (HICON)::LoadImage(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDR_MAINFRAME),
IMAGE_ICON, ::GetSystemMetrics(SM_CXICON), ::GetSystemMetrics(SM_CYICON), LR_DEFAULTCOLOR);
SetIcon(hIcon, TRUE);
HICON hIconSmall = (HICON)::LoadImage(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDR_MAINFRAME),
IMAGE_ICON, ::GetSystemMetrics(SM_CXSMICON), ::GetSystemMetrics(SM_CYSMICON), LR_DEFAULTCOLOR);
SetIcon(hIconSmall, FALSE);
// register object for message filtering and idle updates
CMessageLoop* pLoop = _Module.GetMessageLoop();
ATLASSERT(pLoop != NULL);
pLoop->AddMessageFilter(this);
pLoop->AddIdleHandler(this);
UIAddChildWindowContainer(m_hWnd);
return TRUE;
}
LRESULT OnAppAbout(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{/*
CAboutDlg dlg;
dlg.DoModal();*/
static bool bSwitch = true;
if (bSwitch)
{
//if(pGIFInst->Load(TEXT("\\200751752722625778052.gif")))
//if(pGIFInst->Load(TEXT("\\earth.gif")))
if(pGIFInst == NULL)
pGIFInst = new CGIFShow(GetDC());
if(pGIFInst->Load(TEXT("\\earth.gif")))
{
RECT rcClient;
GetClientRect(&rcClient);
pGIFInst->SetPosition(96,130);
pGIFInst->Play();
}
bSwitch = false;
}
else
{
bSwitch = true;
pGIFInst->Stop();
}
return 0;
}
LRESULT OnOK(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
// TODO: Add validation code
CloseDialog(wID);
return 0;
}
LRESULT OnCancel(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
CloseDialog(wID);
return 0;
}
LRESULT OnShoweGif(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
if(pGIFInst == NULL)
pGIFInst = new CGIFShow(GetDC());
if(pGIFInst->Load(TEXT("\\earth.gif")))
{
RECT rcClient;
GetClientRect(&rcClient);
pGIFInst->SetPosition(96,130);
pGIFInst->Play();
}
return 0;
}
LRESULT OnHideGif(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
if(pGIFInst)
pGIFInst->Stop();
return 0;
}
LRESULT OnDestroyGif(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
delete pGIFInst;
pGIFInst = NULL;
RECT invalideRect;
SetRect(&invalideRect , 96,130 , 96+120 , 130+120);
InvalidateRect(&invalideRect , TRUE);
//UpdateWindow();
return 0;
}
void CloseDialog(int nVal)
{
if(NULL != pGIFInst)
delete pGIFInst;
DestroyWindow();
::PostQuitMessage(nVal);
}
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -