// MainFrm.cpp : implementation of the CMainFrame class // #include "stdafx.h" #include "ScrDemo.h" #include "MainFrm.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif extern CScrDemoApp theApp; enum { SCRCAP_NONE, SCRCAP_FROM_EXE, SCRCAP_ACTIVE_WINDOW, SCRCAP_ACTIVE_CLIENT, SCRCAP_FULL_SCREEN, SCRCAP_SELECTED_OBJECT, SCRCAP_MENU_UNDERCURSOR, SCRCAP_AREA_RECT, SCRCAP_AREA_ROUNDRECT, SCRCAP_AREA_ELLIPSE, SCRCAP_AREA_POLYGON, SCRCAP_AREA_FREEHAND, SCRCAP_AREA_TRIANGLE, SCRCAP_MOUSE_CURSOR, SCRCAP_WINDOW_UNDER_CURSOR, SCRCAP_WALLPAPER, }; ///////////////////////////////////////////////////////////////////////////// // CMainFrame IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd) BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd) //{{AFX_MSG_MAP(CMainFrame) ON_WM_PALETTECHANGED() ON_WM_QUERYNEWPALETTE() ON_COMMAND(IDM_CAPTURE_ACTIVECLIENT, OnCaptureActiveclient) ON_COMMAND(IDM_CAPTURE_ACTIVEWINDOW, OnCaptureActivewindow) ON_COMMAND(IDM_CAPTURE_FROMEXEDLGTABBEDVIEW, OnCaptureFromexedlgtabbedview) ON_COMMAND(IDM_CAPTURE_FROMEXEDLGTREE, OnCaptureFromexedlgtree) ON_COMMAND(IDM_CAPTURE_FULLSCREEN, OnCaptureFullscreen) ON_COMMAND(IDM_CAPTURE_MENUUNDERCURSOR, OnCaptureMenuundercursor) ON_COMMAND(IDM_CAPTURE_MOUSECURSOR, OnCaptureMousecursor) ON_COMMAND(IDM_CAPTURE_SELECTEDAREA, OnCaptureSelectedarea) ON_COMMAND(IDM_CAPTURE_SELECTEDOBJECT, OnCaptureSelectedobject) ON_COMMAND(IDM_CAPTURE_STOP, OnCaptureStop) ON_COMMAND(IDM_CAPTURE_WALLPAPER, OnCaptureWallpaper) ON_COMMAND(IDM_CAPTURE_WINDOWUNDERCURSOR, OnCaptureWindowundercursor) ON_COMMAND(IDM_OPTIONS_AREA, OnOptionsArea) ON_COMMAND(IDM_OPTIONS_OBJECT, OnOptionsObject) ON_COMMAND(IDM_OPTIONS_OPTIONS, OnOptionsOptions) ON_UPDATE_COMMAND_UI(IDM_CAPTURE_ACTIVECLIENT, OnUpdateCaptureActiveclient) ON_UPDATE_COMMAND_UI(IDM_CAPTURE_ACTIVEWINDOW, OnUpdateCaptureActivewindow) ON_UPDATE_COMMAND_UI(IDM_CAPTURE_FROMEXEDLGTABBEDVIEW, OnUpdateCaptureFromexedlgtabbedview) ON_UPDATE_COMMAND_UI(IDM_CAPTURE_FROMEXEDLGTREE, OnUpdateCaptureFromexedlgtree) ON_UPDATE_COMMAND_UI(IDM_CAPTURE_FULLSCREEN, OnUpdateCaptureFullscreen) ON_UPDATE_COMMAND_UI(IDM_CAPTURE_MENUUNDERCURSOR, OnUpdateCaptureMenuundercursor) ON_UPDATE_COMMAND_UI(IDM_CAPTURE_MOUSECURSOR, OnUpdateCaptureMousecursor) ON_UPDATE_COMMAND_UI(IDM_CAPTURE_SELECTEDAREA, OnUpdateCaptureSelectedarea) ON_UPDATE_COMMAND_UI(IDM_CAPTURE_SELECTEDOBJECT, OnUpdateCaptureSelectedobject) ON_UPDATE_COMMAND_UI(IDM_CAPTURE_WALLPAPER, OnUpdateCaptureWallpaper) ON_UPDATE_COMMAND_UI(IDM_CAPTURE_WINDOWUNDERCURSOR, OnUpdateCaptureWindowundercursor) ON_UPDATE_COMMAND_UI(IDM_CAPTURE_STOP, OnUpdateCaptureStop) ON_WM_CLOSE() ON_WM_SYSCOLORCHANGE() ON_WM_PALETTEISCHANGING() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CMainFrame construction/destruction CMainFrame::CMainFrame() { m_nCapture = SCRCAP_NONE; } CMainFrame::~CMainFrame() { } BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return CMDIFrameWnd::PreCreateWindow(cs); } ///////////////////////////////////////////////////////////////////////////// // CMainFrame diagnostics #ifdef _DEBUG void CMainFrame::AssertValid() const { CMDIFrameWnd::AssertValid(); } void CMainFrame::Dump(CDumpContext& dc) const { CMDIFrameWnd::Dump(dc); } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CMainFrame message handlers void CMainFrame::OnPaletteChanged(CWnd* pFocusWnd) { CMDIFrameWnd::OnPaletteChanged(pFocusWnd); CMDIChildWnd* pMDIChildWnd = MDIGetActive(); if (pMDIChildWnd == NULL) return; // no active MDI child frame SendMessageToDescendants(WM_DOREALIZE, (WPARAM)pFocusWnd->m_hWnd, (LPARAM) TRUE); } BOOL CMainFrame::OnQueryNewPalette() { // always realize the palette for the active view CMDIChildWnd* pMDIChildWnd = MDIGetActive(); if (pMDIChildWnd == NULL) return FALSE; // no active MDI child frame (no new palette) CView* pView = pMDIChildWnd->GetActiveView(); ASSERT(pView != NULL); // just notify the target view return((BOOL) pView->SendMessage(WM_DOREALIZE, (WPARAM)m_hWnd, (LPARAM) FALSE)); } void CMainFrame::OnSysColorChange() { OnQueryNewPalette(); } void CMainFrame::OnPaletteIsChanging(CWnd* pRealizeWnd) { OnPaletteChanged(pRealizeWnd); } void CMainFrame::OnCaptureActiveclient() { int nResult, nType=SCRCAP_ACTIVE_CLIENT; if(theApp.m_pRasterScr->GetCaptureHotKey()!=0) if (m_nCapture == nType) { return; } m_nCapture = nType; theApp.m_pRasterScr->StopCapture(); if(theApp.m_pRasterScr->GetCaptureHotKey()!=0) { while (m_nCapture == nType) { nResult = theApp.m_pRasterScr->CaptureActiveClient(); if (nResult != 0) { m_nCapture = SCRCAP_NONE; } } } else nResult = theApp.m_pRasterScr->CaptureActiveClient(); } void CMainFrame::OnCaptureActivewindow() { int nResult, nType=SCRCAP_ACTIVE_WINDOW; if(theApp.m_pRasterScr->GetCaptureHotKey()!=0) if (m_nCapture == nType) { return; } m_nCapture = nType; theApp.m_pRasterScr->StopCapture(); if(theApp.m_pRasterScr->GetCaptureHotKey()!=0) { while (m_nCapture == nType) { nResult = theApp.m_pRasterScr->CaptureActiveWindow(); if (nResult != 0) { m_nCapture = SCRCAP_NONE; } } } else nResult = theApp.m_pRasterScr->CaptureActiveWindow(); } void CMainFrame::OnCaptureFromexedlgtabbedview() { _bstr_t Dummy; m_nCapture = SCRCAP_NONE; theApp.m_pRasterScr->StopCapture(); theApp.m_pRasterScr->CaptureEXEDlg ((long)m_hWnd,0, Dummy, SCR_CAP_ALL, SCR_CAP_EXEDLG_TABVIEW); } void CMainFrame::OnCaptureFromexedlgtree() { _bstr_t Dummy; m_nCapture = SCRCAP_NONE; theApp.m_pRasterScr->StopCapture(); theApp.m_pRasterScr->CaptureEXEDlg((long)m_hWnd,0, Dummy, SCR_CAP_ALL, SCR_CAP_EXEDLG_TREEVIEW); } void CMainFrame::OnCaptureFullscreen() { int nResult, nType=SCRCAP_FULL_SCREEN; if(theApp.m_pRasterScr->GetCaptureHotKey()!=0) if (m_nCapture == nType) { return; } m_nCapture = nType; theApp.m_pRasterScr->StopCapture(); if(theApp.m_pRasterScr->GetCaptureHotKey()!=0) { while (m_nCapture == nType) { nResult = theApp.m_pRasterScr->CaptureFullScreen(); if (nResult != 0) { m_nCapture = SCRCAP_NONE; } } } else nResult = theApp.m_pRasterScr->CaptureFullScreen(); } void CMainFrame::OnCaptureMenuundercursor() { int nResult, nType=SCRCAP_MENU_UNDERCURSOR; if(theApp.m_pRasterScr->GetCaptureHotKey()!=0) if (m_nCapture == nType) { return; } m_nCapture = nType; theApp.m_pRasterScr->StopCapture(); if(theApp.m_pRasterScr->GetCaptureHotKey()!=0) { while (m_nCapture == nType) { nResult = theApp.m_pRasterScr->CaptureMenuUnderCursor(); if (nResult != 0) { m_nCapture = SCRCAP_NONE; } } } else nResult = theApp.m_pRasterScr->CaptureMenuUnderCursor(); } void CMainFrame::OnCaptureMousecursor() { int nResult, nType=SCRCAP_MOUSE_CURSOR; if(theApp.m_pRasterScr->GetCaptureHotKey()!=0) if (m_nCapture == nType) { return; } m_nCapture = nType; theApp.m_pRasterScr->StopCapture(); if(theApp.m_pRasterScr->GetCaptureHotKey()!=0) { while (m_nCapture == nType) { nResult = theApp.m_pRasterScr->CaptureMouseCursor(); if (nResult != 0) { m_nCapture = SCRCAP_NONE; } } } else nResult = theApp.m_pRasterScr->CaptureMouseCursor(); } void CMainFrame::OnCaptureSelectedarea() { int nResult, nType=SCRCAP_AREA_TRIANGLE; if(theApp.m_pRasterScr->GetCaptureHotKey()!=0) if (m_nCapture == nType) { return; } m_nCapture = nType; theApp.m_pRasterScr->StopCapture(); if(theApp.m_pRasterScr->GetCaptureHotKey()!=0) { while (m_nCapture == nType) { nResult = theApp.m_pRasterScr->CaptureArea((ScreenCaptureAreaTypes)0); if (nResult != 0) { m_nCapture = SCRCAP_NONE; } } } else nResult = theApp.m_pRasterScr->CaptureArea((ScreenCaptureAreaTypes)0); } void CMainFrame::OnCaptureSelectedobject() { int nResult, nType=SCRCAP_SELECTED_OBJECT; if(theApp.m_pRasterScr->GetCaptureHotKey()!=0) if (m_nCapture == nType) { return; } m_nCapture = nType; theApp.m_pRasterScr->StopCapture(); if(theApp.m_pRasterScr->GetCaptureHotKey()!=0) { while (m_nCapture == nType) { nResult = theApp.m_pRasterScr->CaptureSelectedObject(); if (nResult != 0) { m_nCapture = SCRCAP_NONE; } } } else nResult = theApp.m_pRasterScr->CaptureSelectedObject(); } void CMainFrame::OnCaptureStop() { if (m_nCapture == SCRCAP_NONE) { return; } m_nCapture = SCRCAP_NONE; theApp.m_pRasterScr->StopCapture(); } void CMainFrame::OnCaptureWallpaper() { int nResult, nType=SCRCAP_WALLPAPER; if(theApp.m_pRasterScr->GetCaptureHotKey()!=0) if (m_nCapture == nType) { return; } m_nCapture = nType; theApp.m_pRasterScr->StopCapture(); if(theApp.m_pRasterScr->GetCaptureHotKey()!=0) { while (m_nCapture == nType) { nResult = theApp.m_pRasterScr->CaptureWallPaper(); if (nResult != 0) { m_nCapture = SCRCAP_NONE; } } } else nResult = theApp.m_pRasterScr->CaptureWallPaper(); } void CMainFrame::OnCaptureWindowundercursor() { int nResult, nType=SCRCAP_WINDOW_UNDER_CURSOR; if(theApp.m_pRasterScr->GetCaptureHotKey()!=0) if (m_nCapture == nType) { return; } m_nCapture = nType; theApp.m_pRasterScr->StopCapture(); if(theApp.m_pRasterScr->GetCaptureHotKey()!=0) { while (m_nCapture == nType) { nResult = theApp.m_pRasterScr->CaptureWindowUnderCursor(); if (nResult != 0) { m_nCapture = SCRCAP_NONE; } } } else nResult = theApp.m_pRasterScr->CaptureWindowUnderCursor(); } void CMainFrame::OnOptionsArea() { m_nCapture = SCRCAP_NONE; theApp.m_pRasterScr->StopCapture(); theApp.m_pRasterScr->CaptureAreaOptionDlg ((long)m_hWnd,0); } void CMainFrame::OnOptionsObject() { m_nCapture = SCRCAP_NONE; theApp.m_pRasterScr->StopCapture(); theApp.m_pRasterScr->CaptureObjectOptionDlg ((long)m_hWnd,0); } void CMainFrame::OnOptionsOptions() { m_nCapture = SCRCAP_NONE; theApp.m_pRasterScr->StopCapture(); theApp.m_pRasterScr->CaptureOptionDlg((long)m_hWnd,0); } void CMainFrame::OnUpdateCaptureActiveclient(CCmdUI* pCmdUI) { pCmdUI->SetCheck(m_nCapture == SCRCAP_ACTIVE_CLIENT); } void CMainFrame::OnUpdateCaptureActivewindow(CCmdUI* pCmdUI) { pCmdUI->SetCheck(m_nCapture == SCRCAP_ACTIVE_WINDOW); } void CMainFrame::OnUpdateCaptureFromexedlgtabbedview(CCmdUI* pCmdUI) { pCmdUI->SetCheck(m_nCapture == SCRCAP_FROM_EXE); } void CMainFrame::OnUpdateCaptureFromexedlgtree(CCmdUI* pCmdUI) { pCmdUI->SetCheck(m_nCapture == SCRCAP_FROM_EXE); } void CMainFrame::OnUpdateCaptureFullscreen(CCmdUI* pCmdUI) { pCmdUI->SetCheck(m_nCapture == SCRCAP_FULL_SCREEN); } void CMainFrame::OnUpdateCaptureMenuundercursor(CCmdUI* pCmdUI) { pCmdUI->SetCheck(m_nCapture == SCRCAP_MENU_UNDERCURSOR); } void CMainFrame::OnUpdateCaptureMousecursor(CCmdUI* pCmdUI) { pCmdUI->SetCheck(m_nCapture == SCRCAP_MOUSE_CURSOR); } void CMainFrame::OnUpdateCaptureSelectedarea(CCmdUI* pCmdUI) { pCmdUI->SetCheck(m_nCapture == SCRCAP_AREA_TRIANGLE); } void CMainFrame::OnUpdateCaptureSelectedobject(CCmdUI* pCmdUI) { pCmdUI->SetCheck(m_nCapture == SCRCAP_SELECTED_OBJECT); } void CMainFrame::OnUpdateCaptureWallpaper(CCmdUI* pCmdUI) { pCmdUI->SetCheck(m_nCapture == SCRCAP_WALLPAPER); } void CMainFrame::OnUpdateCaptureWindowundercursor(CCmdUI* pCmdUI) { pCmdUI->SetCheck(m_nCapture == SCRCAP_WINDOW_UNDER_CURSOR); } void CMainFrame::OnUpdateCaptureStop(CCmdUI* pCmdUI) { pCmdUI->Enable(m_nCapture != SCRCAP_NONE); } void CMainFrame::OnClose() { if (m_nCapture != SCRCAP_NONE) { MessageBox(TEXT("Capturing must be stopped first!"), TEXT("Warning"), MB_ICONWARNING); return; } CMDIFrameWnd::OnClose(); }