#include "stdafx.h"
#include "NBtq2.h"
#include "NBtq2Dlg.h"
#include ".\NBtq2Dlg.h"
#include "DlgProxy.h"
#include "SourceDeclaration.h"
#include "afxwin.h"
#include "WinDef.h"
#include "LVCustDraw.h"
#include "Wizar.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
enum { IDD = IDD_ABOUTBOX };
protected:
virtual void DoDataExchange(CDataExchange* pDX);
protected:
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()
IMPLEMENT_DYNAMIC(CNBtq2Dlg, CDialog);
CNBtq2Dlg::CNBtq2Dlg(CWnd* pParent )
: CDialog(CNBtq2Dlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_pAutoProxy = NULL;
}
CNBtq2Dlg::~CNBtq2Dlg()
{
if (m_pAutoProxy != NULL)
m_pAutoProxy->m_pDialog = NULL;
}
void CNBtq2Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_LIST1, m_ctlListView);
}
BEGIN_MESSAGE_MAP(CNBtq2Dlg, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_CLOSE()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST1, &CNBtq2Dlg::OnLvnItemchangedList1)
ON_BN_CLICKED(IDCANCEL, &CNBtq2Dlg::OnBnClickedCancel)
ON_BN_CLICKED(IDOK, &CNBtq2Dlg::OnBnClickedOk)
ON_BN_CLICKED(IDC_BUTTON3, &CNBtq2Dlg::OnBnClickedButton3)
END_MESSAGE_MAP()
BOOL CNBtq2Dlg::OnInitDialog()
{
CDialog::OnInitDialog();
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
BOOL bNameValid;
CString strAboutMenu;
bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
ASSERT(bNameValid);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
SetIcon(m_hIcon, TRUE); SetIcon(m_hIcon, FALSE);
COLORREF a=100,b=175;
m_ctlListView.InsertColumn(0, _T(" PART NO "), LVCFMT_LEFT, 100);
m_ctlListView.InsertColumn(1, _T(" DESCRIPTION "), LVCFMT_LEFT, 140);
m_ctlListView.InsertColumn(2, _T(" "), LVCFMT_RIGHT, 0);
static CString text[6][3]= {
_T ("P1"), _T ("D1"), _T("G1"),
_T ("P2"), _T ("D2"), _T("G1"),
_T ("P3"), _T ("D3"), _T("G2"),
_T ("P4"), _T ("D4"), _T("G2"),
_T ("P5"), _T ("D5"), _T("G3"),
_T ("P6"), _T ("D6"), _T("G3")
};
bool TurnOn =1;
m_ctlListView.SetExtendedStyle(LVS_EX_FULLROWSELECT);
for (int i=0; i<6; i++)
{
m_ctlListView.InsertItem (i, text[i][0]);
m_ctlListView.SetItemText (i, 1, text[i][1]);
m_ctlListView.SetItemText (i, 2, text[i][2]);
}
m_ctlListView.GroupByColumn(2);
m_ctlListView.CollapseAllGroups();
return TRUE; }
void CNBtq2Dlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
void CNBtq2Dlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this);
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<wparam>(dc.GetSafeHdc()), 0);
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
HCURSOR CNBtq2Dlg::OnQueryDragIcon()
{
return static_cast<hcursor>(m_hIcon);
}
void CNBtq2Dlg::OnClose()
{
if (CanExit())
CDialog::OnClose();
}
void CNBtq2Dlg::OnOK()
{
if (CanExit())
CDialog::OnOK();
}
void CNBtq2Dlg::OnCancel()
{
if (CanExit())
CDialog::OnCancel();
}
BOOL CNBtq2Dlg::CanExit()
{
if (m_pAutoProxy != NULL)
{
ShowWindow(SW_HIDE);
return FALSE;
}
return TRUE;
}
void CNBtq2Dlg::OnLvnItemchangedList1(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMLISTVIEW pNMLV = reinterpret_cast<lpnmlistview>(pNMHDR);
*pResult = 0;
}
BEGIN_MESSAGE_MAP(CLVCustomDrawApp, CWinApp)
ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()
CLVCustomDrawApp::CLVCustomDrawApp()
{
}
BOOL CLVCustomDrawApp::InitInstance()
{
CWizard dlg ( _T("") );
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
}
else if (nResponse == IDCANCEL)
{
}
return FALSE;
}
void CNBtq2Dlg::OnBnClickedCancel()
{
OnCancel();
}
void CNBtq2Dlg::OnBnClickedOk()
{
OnOK();
}
void CNBtq2Dlg::OnBnClickedButton3()
{
CNBtq2Dlg dlg;
dlg.DoModal();
}
#include "stdafx.h"
#include "SourceDeclaration.h"
#include <shlwapi.h>
#include <stdio.h>
#include "resource.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
BEGIN_MESSAGE_MAP(CnList, CListCtrl)
#if _WIN32_WINNT >= 0x0600
#endif
END_MESSAGE_MAP()
namespace {
LRESULT EnableWindowTheme(HWND hwnd, LPCWSTR classList, LPCWSTR subApp, LPCWSTR idlist)
{
LRESULT lResult = S_FALSE;
HRESULT (__stdcall *pSetWindowTheme)(HWND hwnd, LPCWSTR pszSubAppName, LPCWSTR pszSubIdList);
HANDLE (__stdcall *pOpenThemeData)(HWND hwnd, LPCWSTR pszClassList);
HRESULT (__stdcall *pCloseThemeData)(HANDLE hTheme);
HMODULE hinstDll = ::LoadLibrary(_T("UxTheme.dll"));
if (hinstDll)
{
(FARPROC&)pOpenThemeData = ::GetProcAddress(hinstDll, "OpenThemeData");
(FARPROC&)pCloseThemeData = ::GetProcAddress(hinstDll, "CloseThemeData");
(FARPROC&)pSetWindowTheme = ::GetProcAddress(hinstDll, "SetWindowTheme");
if (pSetWindowTheme && pOpenThemeData && pCloseThemeData)
{
HANDLE theme = pOpenThemeData(hwnd,classList);
if (theme!=NULL)
{
VERIFY(pCloseThemeData(theme)==S_OK);
lResult = pSetWindowTheme(hwnd, subApp, idlist);
}
}
::FreeLibrary(hinstDll);
}
return lResult;
}
bool IsCommonControlsEnabled()
{
bool commoncontrols = false;
HMODULE hinstDll = ::LoadLibrary(_T("comctl32.dll"));
if (hinstDll)
{
DLLGETVERSIONPROC pDllGetVersion = (DLLGETVERSIONPROC)::GetProcAddress(hinstDll, "DllGetVersion");
if (pDllGetVersion != NULL)
{
DLLVERSIONINFO dvi = {0};
dvi.cbSize = sizeof(dvi);
HRESULT hRes = pDllGetVersion ((DLLVERSIONINFO *) &dvi);
if (SUCCEEDED(hRes))
commoncontrols = dvi.dwMajorVersion >= 6;
}
::FreeLibrary(hinstDll);
}
return commoncontrols;
}
bool IsThemeEnabled()
{
bool XPStyle = false;
bool (__stdcall *pIsAppThemed)();
bool (__stdcall *pIsThemeActive)();
HMODULE hinstDll = ::LoadLibrary(_T("UxTheme.dll"));
if (hinstDll)
{
(FARPROC&)pIsAppThemed = ::GetProcAddress(hinstDll, "IsAppThemed");
(FARPROC&)pIsThemeActive = ::GetProcAddress(hinstDll,"IsThemeActive");
if (pIsAppThemed != NULL && pIsThemeActive != NULL)
{
if (pIsAppThemed() && pIsThemeActive())
{
XPStyle = IsCommonControlsEnabled();
}
}
::FreeLibrary(hinstDll);
}
return XPStyle;
}
}
LRESULT CnList::InsertGroupHeader(int nIndex, int nGroupId, const CString& strHeader, DWORD dwState , DWORD dwAlign )
{
LVGROUP lg = {0};
lg.cbSize = sizeof(lg);
lg.iGroupId = nGroupId;
lg.state = dwState;
lg.mask = LVGF_GROUPID | LVGF_HEADER | LVGF_STATE | LVGF_ALIGN;
lg.uAlign = dwAlign;
#ifdef UNICODE
lg.pszHeader = (LPWSTR)(LPCTSTR)strHeader;
lg.cchHeader = strHeader.GetLength();
#else
CComBSTR header = strHeader;
lg.pszHeader = header;
lg.cchHeader = header.Length();
#endif
return InsertGroup(nIndex, (PLVGROUP)&lg );
}
BOOL CnList::SetRowGroupId(int nRow, int nGroupId)
{
LVITEM lvItem = {0};
lvItem.mask = LVIF_GROUPID;
lvItem.iItem = nRow;
lvItem.iSubItem = 0;
lvItem.iGroupId = nGroupId;
return SetItem( &lvItem );
}
int CnList::GetRowGroupId(int nRow)
{
LVITEM lvi = {0};
lvi.mask = LVIF_GROUPID;
lvi.iItem = nRow;
VERIFY( GetItem(&lvi) );
return lvi.iGroupId;
}
BOOL CnList::GroupByColumn(int nCol)
{
if (!IsCommonControlsEnabled())
return FALSE;
CWaitCursor waitCursor;
SetRedraw(FALSE);
RemoveAllGroups();
EnableGroupView( GetItemCount() > 0 );
if (IsGroupViewEnabled())
{
CSimpleMap<cstring,csimplearray><int> > groups;
for(int nRow=0; nRow<getitemcount();> {
CString cellText = GetItemText(nRow, nCol);
int nGroupId = groups.FindKey(cellText);
if (nGroupId==-1)
{
CSimpleArray<int> rows;
groups.Add(cellText, rows);
nGroupId = groups.FindKey(cellText);
}
groups.GetValueAt(nGroupId).Add(nRow);
}
for(int nGroupId = 0; nGroupId < groups.GetSize(); ++nGroupId)
{
const CSimpleArray<int>& groupRows = groups.GetValueAt(nGroupId);
DWORD dwState = LVGS_NORMAL;
#ifdef LVGS_COLLAPSIBLE
if (IsGroupStateEnabled())
dwState = LVGS_COLLAPSIBLE;
#endif
VERIFY( InsertGroupHeader(nGroupId, nGroupId, groups.GetKeyAt(nGroupId), dwState) != -1);
for(int groupRow = 0; groupRow < groupRows.GetSize(); ++groupRow)
{
VERIFY( SetRowGroupId(groupRows[groupRow], nGroupId) );
}
}
SetRedraw(TRUE);
Invalidate(FALSE);
return TRUE;
}
SetRedraw(TRUE);
Invalidate(FALSE);
return FALSE;
}
namespace {
struct PARAMSORT
{
PARAMSORT(HWND hWnd, int nCol, bool bAscending)
:m_hWnd(hWnd)
,m_ColumnIndex(nCol)
,m_Ascending(bAscending)
{}
HWND m_hWnd;
int m_ColumnIndex;
bool m_Ascending;
CSimpleMap<int,cstring> m_GroupNames;
const CString& LookupGroupName(int nGroupId)
{
int groupIdx = m_GroupNames.FindKey(nGroupId);
if (groupIdx==-1)
{
static const CString emptyStr;
return emptyStr;
}
return m_GroupNames.GetValueAt(groupIdx);
}
};
int CALLBACK SortFuncGroup(int nLeftId, int nRightId, void* lParamSort)
{
PARAMSORT& ps = *(PARAMSORT*)lParamSort;
const CString& left = ps.LookupGroupName(nLeftId);
const CString& right = ps.LookupGroupName(nRightId);
if (ps.m_Ascending)
return _tcscmp( left, right );
else
return _tcscmp( right, left );
}
}
void CnList::PreSubclassWindow()
{
CListCtrl::PreSubclassWindow();
#if (_WIN32_WINNT >= 0x501)
SetExtendedStyle(LVS_EX_DOUBLEBUFFER | GetExtendedStyle());
#endif
SetExtendedStyle(GetExtendedStyle() | LVS_EX_FULLROWSELECT);
SetExtendedStyle(GetExtendedStyle() | LVS_EX_HEADERDRAGDROP);
SetExtendedStyle(GetExtendedStyle() | LVS_EX_GRIDLINES);
EnableWindowTheme(GetSafeHwnd(), L"ListView", L"Explorer", NULL);
}
BOOL CnList::IsGroupStateEnabled()
{
if (!IsGroupViewEnabled())
return FALSE;
OSVERSIONINFO osver = {0};
osver.dwOSVersionInfoSize = sizeof(osver);
GetVersionEx(&osver);
WORD fullver = MAKEWORD(osver.dwMinorVersion, osver.dwMajorVersion);
if (fullver < 0x0600)
return FALSE;
return TRUE;
}
BOOL CnList::SetGroupTitleImage(int nGroupID, int nImage, const CString& topDesc, const CString& bottomDesc)
{
if (!IsGroupStateEnabled())
return FALSE;
#if _WIN32_WINNT >= 0x0600
LVGROUP lg = {0};
lg.cbSize = sizeof(lg);
lg.mask = LVGF_TITLEIMAGE;
lg.iTitleImage = nImage;
#ifdef UNICODE
if (!topDesc.IsEmpty())
{
lg.mask |= LVGF_DESCRIPTIONTOP;
lg.cchDescriptionTop = topDesc.GetLength();
}
if (!bottomDesc.IsEmpty())
{
lg.mask |= LVGF_DESCRIPTIONBOTTOM;
lg.pszDescriptionBottom = (LPWSTR)(LPCTSTR)bottomDesc;
lg.cchDescriptionBottom = bottomDesc.GetLength();
}
#else
CComBSTR bstrTopDesc = topDesc;
CComBSTR bstrBottomDesc = bottomDesc;
if (!topDesc.IsEmpty())
{
lg.mask |= LVGF_DESCRIPTIONTOP;
lg.pszDescriptionTop = bstrTopDesc;
lg.cchDescriptionTop = bstrTopDesc.Length();
}
if (!bottomDesc.IsEmpty())
{
lg.mask |= LVGF_DESCRIPTIONBOTTOM;
lg.pszDescriptionBottom = bstrBottomDesc;
lg.cchDescriptionBottom = bstrBottomDesc.Length();
}
#endif
if (SetGroupInfo(nGroupID, (PLVGROUP)&lg)==-1)
return FALSE;
return TRUE;
#else
return FALSE;
#endif
}
BOOL CnList::OnEraseBkgnd(CDC* pDC)
{
CRect rect;
CnList::GetClientRect(rect);
POINT mypoint;
CBrush brush0(m_colRow1);
CBrush brush1(m_colRow2);
int chunk_height=GetCountPerPage();
pDC->FillRect(&rect,&brush1);
for (int i=0;i<=chunk_height;i++)
{
GetItemPosition(i,&mypoint);
rect.top=mypoint.y ;
GetItemPosition(i+1,&mypoint);
rect.bottom =mypoint.y;
pDC->FillRect(&rect,i %2 ? &brush1 : &brush0);
}
brush0.DeleteObject();
brush1.DeleteObject();
return FALSE;
}
void CnList::CollapseAllGroups()
{
if (!IsGroupStateEnabled())
return;
for(int nRow=0; nRow<getitemcount();> {
int nGroupId = GetRowGroupId(nRow);
if (nGroupId!=-1)
{
if (!HasGroupState(nGroupId,LVGS_COLLAPSED))
{
SetGroupState(nGroupId,LVGS_COLLAPSED);
}
}
}
}
BOOL CnList::SetGroupState(int nGroupId, DWORD dwState)
{
if (!IsGroupStateEnabled())
return FALSE;
LVGROUP lg = {0};
lg.cbSize = sizeof(lg);
lg.mask = LVGF_STATE;
lg.state = dwState;
lg.stateMask = dwState;
#ifdef LVGS_COLLAPSIBLE
if (HasGroupState(nGroupId, LVGS_COLLAPSIBLE))
lg.state |= LVGS_COLLAPSIBLE;
#endif
if (SetGroupInfo(nGroupId, (PLVGROUP)&lg)==-1)
return FALSE;
return TRUE;
}
BOOL CnList::HasGroupState(int nGroupId, DWORD dwState)
{
LVGROUP lg = {0};
lg.cbSize = sizeof(lg);
lg.mask = LVGF_STATE;
lg.stateMask = dwState;
if ( GetGroupInfo(nGroupId, (PLVGROUP)&lg) == -1)
return FALSE;
return lg.state==dwState;
}
void CnList::CustDraw( NMHDR * pNMHDR, LRESULT * pResult )
{
LPNMCUSTOMDRAW pNMCD = reinterpret_cast<lpnmcustomdraw>(pNMHDR);
NMTVCUSTOMDRAW* pLVCD = reinterpret_cast<nmtvcustomdraw>( pNMHDR );
switch( pNMCD->dwDrawStage )
{
case CDDS_PREPAINT:
*pResult= CDRF_NOTIFYITEMDRAW;
break;
case CDDS_ITEMPREPAINT:
{
if( ( CDIS_SELECTED == ( pNMCD->uItemState & CDIS_SELECTED )))
{
pNMCD->uItemState = CDIS_DEFAULT;
pLVCD->clrText = mForeColor;
pLVCD->clrTextBk = mBkColor;
}
else
{
COLORREF crText = RGB(0,0,0);
COLORREF mBkColor = RGB(255,255,0);
if ((pLVCD->nmcd.dwItemSpec %2) == 0) {
crText = RGB(0,0,0);
mBkColor = RGB(0,255,255);
}
pLVCD->clrText = crText;
pLVCD->clrTextBk = mBkColor;
}
}
break;
default:
*pResult = CDRF_DODEFAULT;
break;
}
}
IMPLEMENT_DYNAMIC(MyList, CListCtrl)
MyList::MyList():mBkColor(RGB(255,0,255)),
mForeColor(RGB(0,255,255))
{
}
MyList::~MyList()
{
}
BEGIN_MESSAGE_MAP(MyList, CListCtrl)
ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnNMCustomdraw)
END_MESSAGE_MAP()
void MyList::OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMCUSTOMDRAW pNMCD = reinterpret_cast<lpnmcustomdraw>(pNMHDR);
NMTVCUSTOMDRAW* pLVCD = reinterpret_cast<nmtvcustomdraw>( pNMHDR );
switch( pNMCD->dwDrawStage )
{
case CDDS_PREPAINT:
*pResult= CDRF_NOTIFYITEMDRAW;
break;
case CDDS_ITEMPREPAINT:
{
if( ( CDIS_SELECTED == ( pNMCD->uItemState & CDIS_SELECTED )))
{
pNMCD->uItemState = CDIS_DEFAULT;
pLVCD->clrText = mForeColor;
pLVCD->clrTextBk = mBkColor;
}
else
{
COLORREF crText = RGB(0,0,0);
COLORREF mBkColor = RGB(255,255,0);
if ((pLVCD->nmcd.dwItemSpec %2) == 0) {
crText = RGB(0,0,0);
mBkColor = RGB(0,255,255);
}
pLVCD->clrText = crText;
pLVCD->clrTextBk = mBkColor;
}
}
break;
default:
*pResult = CDRF_DODEFAULT;
break;
}
}