📄 windowlistdlg.cpp
字号:
// WindowListDlg.cpp : implementation file
//
#include "stdafx.h"
#include "IE6mdi.h"
#include "WindowListDlg.h"
#include "ViewManager.h"
#include <stdlib.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CWindowListDlg dialog
CWindowListDlg::CWindowListDlg(CWnd* pParent /*=NULL*/)
: CDialog(CWindowListDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CWindowListDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CWindowListDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CWindowListDlg)
DDX_Control(pDX, IDC_WINDOWLIST, wndList);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CWindowListDlg, CDialog)
//{{AFX_MSG_MAP(CWindowListDlg)
ON_BN_CLICKED(IDC_SELECT_ALL, OnSelectAll)
ON_BN_CLICKED(IDC_INVERT_SELECT, OnInvertSel)
ON_BN_CLICKED(IDC_CASCADE, OnCascade)
ON_BN_CLICKED(IDC_TILE, OnTile)
ON_BN_CLICKED(IDC_TILEVERT, OnTileVert)
ON_BN_CLICKED(IDC_ACTIVATE, OnActivate)
ON_BN_CLICKED(IDC_MINIMIZE, OnMini)
ON_BN_CLICKED(IDC_RESTORE, OnResto)
ON_BN_CLICKED(IDC_CLOSE, OnClose)
ON_LBN_SELCHANGE(IDC_WINDOWLIST, OnSelchangeWindowlist)
ON_LBN_DBLCLK(IDC_WINDOWLIST, OnDblclkWindowlist)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CWindowListDlg message handlers
BOOL CWindowListDlg::OnInitDialog()
{
CDialog::OnInitDialog();
CPtrArray arViews;
CStringArray arViewTitles;
CView * pActiveView = ((CFrameWnd *)AfxGetMainWnd())->GetActiveView();
int t, iSel = -1;
for (t = 0; t < theViewManager.arViewTitles.GetSize(); t++)
{
int idx = wndList.AddString(theViewManager.arViewTitles.GetAt(t));
wndList.SetItemData(idx, t);
if (pActiveView == ((CView *) (theViewManager.arViews.GetAt(t))) ) iSel = t;
}
wndList.SetCurSel(iSel);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CWindowListDlg::OnActivate()
{
int idx = wndList.GetCurSel();
if (idx >= 0)
{
CDialog::OnOK();
int item = wndList.GetItemData(idx);
// error when no more windows and not detected:
// item == -1
if (item != -1) {
CView * pView = ((CView *) theViewManager.arViews.GetAt(item));
if ((pView != NULL)&&(pView->GetSafeHwnd() != 0))
((CMDIFrameWnd *)AfxGetMainWnd())->MDIActivate(pView->GetParent());
}
}
}
int SortInt(const void *arg1, const void *arg2 )
{
if (*((INT *)arg1)>*((INT *)arg2)) return 1;
if (*((INT *)arg1)<*((INT *)arg2)) return -1;
return 0;
}
void CWindowListDlg::OnResto()
{
int iCount = wndList.GetSelCount();
if (iCount > 0)
{
INT * pi = new INT[iCount];
ASSERT(pi);
VERIFY(wndList.GetSelItems(iCount, pi) == iCount);
qsort((void *) pi, (size_t) iCount, sizeof(int), SortInt);
for (int t = 0; t < iCount; t++)
{
int item = wndList.GetItemData(pi[t]);
CView * v = ((CView *) theViewManager.arViews.GetAt(item));
if ((v != NULL)&&(v->GetSafeHwnd() != 0))
v->GetParent()->ShowWindow(SW_RESTORE);
}
delete [] pi;
}
}
void CWindowListDlg::OnMini()
{
int iCount = wndList.GetSelCount();
if (iCount > 0)
{
INT * pi = new INT[iCount];
ASSERT(pi);
VERIFY(wndList.GetSelItems(iCount, pi) == iCount);
qsort((void *) pi, (size_t) iCount, sizeof(int), SortInt);
for (int t = 0; t < iCount; t++)
{
int item = wndList.GetItemData(pi[t]);
CView * v = ((CView *) theViewManager.arViews.GetAt(item));
if ((v != NULL)&&(v->GetSafeHwnd() != 0))
v->GetParent()->ShowWindow(SW_MINIMIZE);
}
delete [] pi;
}
}
void CWindowListDlg::OnCascade()
{
int iCount = wndList.GetSelCount();
int n = wndList.GetCount(); // nb total
if (iCount > 0)
{
INT * pi = new INT[iCount];
ASSERT(pi);
VERIFY(wndList.GetSelItems(iCount, pi) == iCount);
qsort((void *) pi, (size_t) iCount, sizeof(int), SortInt);
OnInvertSel();
OnMini();
// now, we SW_SHOWNORMAL all in the list
for (int t = 0; t < iCount; t++)
{
int item = wndList.GetItemData(pi[t]);
CView * v = ((CView *) theViewManager.arViews.GetAt(item));
if ((v != NULL)&&(v->GetSafeHwnd() != 0))
v->GetParent()->ShowWindow(SW_SHOWNORMAL);
}
// update the selection in the list
// deselect ALL
if (n ==1)
wndList.SetSel(0,FALSE);
else
wndList.SelItemRange(FALSE,0,n-1);
// select only the good ones !
for(t = 0; t < iCount; t++)
wndList.SetSel(pi[t],TRUE);
delete [] pi;
OnSelchangeWindowlist();
// set the cascade mode
AfxGetApp()->m_pMainWnd->SendMessage(WM_COMMAND,(WPARAM)ID_WINDOW_CASCADE,(LPARAM)NULL);
}
}
void CWindowListDlg::OnTile()
{
// minimize everybody and tile the selected view !
// ID_WINDOW_TILE_HORZ
int iCount = wndList.GetSelCount();
int n = wndList.GetCount(); // nb total
if (iCount > 0)
{
INT * pi = new INT[iCount];
ASSERT(pi);
VERIFY(wndList.GetSelItems(iCount, pi) == iCount);
qsort((void *) pi, (size_t) iCount, sizeof(int), SortInt);
OnInvertSel();
OnMini();
// now, we SW_SHOWNORMAL all in the list
for (int t = 0; t < iCount; t++)
{
int item = wndList.GetItemData(pi[t]);
CView * v = ((CView *) theViewManager.arViews.GetAt(item));
if ((v != NULL)&&(v->GetSafeHwnd() != 0))
v->GetParent()->ShowWindow(SW_SHOWNORMAL);
}
// update the selection in the list
// deselect ALL
if (n ==1)
wndList.SetSel(0,FALSE);
else
wndList.SelItemRange(FALSE,0,n-1);
// select only the good ones !
for(t = 0; t < iCount; t++)
wndList.SetSel(pi[t],TRUE);
delete [] pi;
OnSelchangeWindowlist();
AfxGetApp()->m_pMainWnd->SendMessage(WM_COMMAND,(WPARAM)ID_WINDOW_TILE_HORZ,(LPARAM)NULL);
}
}
void CWindowListDlg::OnTileVert()
{
// minimize everybody and tile the selected view !
// ID_WINDOW_TILE_HORZ
int iCount = wndList.GetSelCount();
int n = wndList.GetCount(); // nb total
if (iCount > 0)
{
INT * pi = new INT[iCount];
ASSERT(pi);
VERIFY(wndList.GetSelItems(iCount, pi) == iCount);
qsort((void *) pi, (size_t) iCount, sizeof(int), SortInt);
OnInvertSel();
OnMini();
// now, we SW_SHOWNORMAL all in the list
for (int t = 0; t < iCount; t++)
{
int item = wndList.GetItemData(pi[t]);
CView * v = ((CView *) theViewManager.arViews.GetAt(item));
if ((v != NULL)&&(v->GetSafeHwnd() != 0))
v->GetParent()->ShowWindow(SW_SHOWNORMAL);
}
// update the selection in the list
// deselect ALL
if (n ==1)
wndList.SetSel(0,FALSE);
else
wndList.SelItemRange(FALSE,0,n-1);
// select only the good ones !
for(t = 0; t < iCount; t++)
wndList.SetSel(pi[t],TRUE);
delete [] pi;
OnSelchangeWindowlist();
AfxGetApp()->m_pMainWnd->SendMessage(WM_COMMAND,(WPARAM)ID_WINDOW_TILE_VERT,(LPARAM)NULL);
}
}
void CWindowListDlg::OnClose()
{
int iCount = wndList.GetSelCount();
CView** lView;
lView = (CView**)malloc(iCount*sizeof(CView*));
if (iCount > 0)
{
INT * pi = new INT[iCount];
ASSERT(pi);
VERIFY(wndList.GetSelItems(iCount, pi) == iCount);
qsort((void *) pi, (size_t) iCount, sizeof(int), SortInt);
for (int t = 0; t < iCount; t++)
{
int item = wndList.GetItemData(pi[t]);
lView[t] = ((CView *) theViewManager.arViews.GetAt(item));
}
delete [] pi;
for(t = 0; t < iCount; t++)
{
CView * v = lView[t];
if ((v != NULL)&&(v->GetSafeHwnd() != 0)) // security, should not be !!!
v->GetParent()->SendMessage(WM_CLOSE);
}
CView * pActiveView = ((CFrameWnd *)AfxGetMainWnd())->GetActiveView();
wndList.ResetContent();
int iSel = -1;
for (t = 0; t < theViewManager.arViewTitles.GetSize(); t++)
{
int idx = wndList.AddString(theViewManager.arViewTitles.GetAt(t));
wndList.SetItemData(idx, t);
if (pActiveView == ((CView *) (theViewManager.arViews.GetAt(t))) ) iSel = t;
}
wndList.SetCurSel(iSel);
OnSelchangeWindowlist();
// CDialog::OnOK();
}
free(lView);
}
void CWindowListDlg::OnSelchangeWindowlist()
{
int iCount = wndList.GetSelCount();
if (iCount <= 0)
{
GetDlgItem(IDC_MINIMIZE)->EnableWindow(false);
GetDlgItem(IDC_RESTORE)->EnableWindow(false);
GetDlgItem(IDC_CLOSE)->EnableWindow(false);
GetDlgItem(IDC_ACTIVATE)->EnableWindow(false);
GetDlgItem(IDC_CASCADE)->EnableWindow(false);
GetDlgItem(IDC_TILE)->EnableWindow(false);
GetDlgItem(IDC_INVERT_SELECT)->EnableWindow(false);
GetDlgItem(IDC_TILEVERT)->EnableWindow(false);
}
else
{
if (iCount == 1)
GetDlgItem(IDC_ACTIVATE)->EnableWindow(true);
else
GetDlgItem(IDC_ACTIVATE)->EnableWindow(false);
GetDlgItem(IDC_CASCADE)->EnableWindow(true);
GetDlgItem(IDC_TILE)->EnableWindow(true);
GetDlgItem(IDC_TILEVERT)->EnableWindow(true);
GetDlgItem(IDC_CLOSE)->EnableWindow(true);
GetDlgItem(IDC_MINIMIZE)->EnableWindow(true);
GetDlgItem(IDC_INVERT_SELECT)->EnableWindow(true);
GetDlgItem(IDC_RESTORE)->EnableWindow(true);
}
}
void CWindowListDlg::OnDblclkWindowlist()
{
OnActivate();
}
void CWindowListDlg::OnSelectAll()
{
int iCount = wndList.GetCount();
if (iCount > 0) {
if (iCount ==1)
wndList.SetSel(0);
else
wndList.SelItemRange(TRUE,0,iCount-1);
OnSelchangeWindowlist();
}
else
return;
}
//IDC_INVERT_SELECT
void CWindowListDlg::OnInvertSel ()
{
int iCount = wndList.GetCount();
if (iCount > 0) {
int i;
for (i=0;i<iCount;i++) {
if (wndList.GetSel(i) != 0) { // selected
wndList.SetSel(i,FALSE);
}
else {
wndList.SetSel(i,TRUE);
}
}
OnSelchangeWindowlist();
}
else
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -