base
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
// ConfigSubDlg.cpp: implementation of the CConfigSubDlg class.
|
||||
//
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "ConfigSubDlg.h"
|
||||
|
||||
#ifdef _DEBUG
|
||||
#undef THIS_FILE
|
||||
static char THIS_FILE[]=__FILE__;
|
||||
#define new DEBUG_NEW
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
IMPLEMENT_DYNCREATE(CConfigSubDlg, CDialog)
|
||||
|
||||
CConfigSubDlg::CConfigSubDlg()
|
||||
{
|
||||
ASSERT(0);
|
||||
// don't use this constructor!
|
||||
}
|
||||
|
||||
CConfigSubDlg::CConfigSubDlg(UINT nID, CWnd *pParent /*=NULL*/)
|
||||
: CDialog(nID)
|
||||
{
|
||||
m_nID = nID;
|
||||
}
|
||||
|
||||
CConfigSubDlg::~CConfigSubDlg()
|
||||
{
|
||||
}
|
||||
|
||||
BEGIN_MESSAGE_MAP(CConfigSubDlg, CDialog)
|
||||
//{{AFX_MSG_MAP(CHTMLAppearance)
|
||||
//}}AFX_MSG_MAP
|
||||
END_MESSAGE_MAP()
|
||||
|
||||
void CConfigSubDlg::OnOK()
|
||||
{
|
||||
EndDialog(IDOK);
|
||||
}
|
||||
|
||||
void CConfigSubDlg::OnCancel()
|
||||
{
|
||||
EndDialog(IDCANCEL);
|
||||
}
|
||||
|
||||
BOOL CConfigSubDlg::PreTranslateMessage(MSG* pMsg)
|
||||
{
|
||||
// Don't let CDialog process the Escape key.
|
||||
if ((pMsg->message == WM_KEYDOWN) && (pMsg->wParam == VK_ESCAPE))
|
||||
return TRUE;
|
||||
|
||||
// Don't let CDialog process the Return key, if a multi-line edit has focus
|
||||
if ((pMsg->message == WM_KEYDOWN) && (pMsg->wParam == VK_RETURN)) {
|
||||
// Special case: if control with focus is an edit control with
|
||||
// ES_WANTRETURN style, let it handle the Return key.
|
||||
TCHAR szClass[10];
|
||||
|
||||
CWnd* pWndFocus = GetFocus();
|
||||
if (((pWndFocus = GetFocus()) != NULL) &&
|
||||
IsChild(pWndFocus) &&
|
||||
(pWndFocus->GetStyle() & ES_WANTRETURN) &&
|
||||
GetClassName(pWndFocus->m_hWnd, szClass, 10) &&
|
||||
(lstrcmpi(szClass, _T("EDIT")) == 0)) {
|
||||
pWndFocus->SendMessage(WM_CHAR, pMsg->wParam, pMsg->lParam);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return CDialog::PreTranslateMessage(pMsg);
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// ConfigSubDlg.h: interface for the CConfigSubDlg class.
|
||||
//
|
||||
|
||||
#if _MSC_VER >= 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER >= 1000
|
||||
|
||||
class CConfigSubDlg : public CDialog
|
||||
{
|
||||
public:
|
||||
DECLARE_DYNCREATE(CConfigSubDlg)
|
||||
|
||||
CConfigSubDlg();
|
||||
CConfigSubDlg(UINT nID, CWnd *pParent = NULL);
|
||||
virtual ~CConfigSubDlg();
|
||||
|
||||
UINT m_nID;
|
||||
|
||||
UINT GetID() {return m_nID;}
|
||||
|
||||
public:
|
||||
virtual BOOL PreTranslateMessage(MSG* pMsg);
|
||||
virtual void OnOK();
|
||||
virtual void OnCancel();
|
||||
|
||||
DECLARE_MESSAGE_MAP()
|
||||
};
|
||||
@@ -0,0 +1,67 @@
|
||||
// Crypt.h
|
||||
//
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "crypt.h"
|
||||
|
||||
#ifdef _DEBUG
|
||||
#undef THIS_FILE
|
||||
static char THIS_FILE[]=__FILE__;
|
||||
#define new DEBUG_NEW
|
||||
#endif
|
||||
|
||||
char* CCrypt::m_pszKey = "SPConsole1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
|
||||
CString CCrypt::Encrypt(CString sString)
|
||||
{
|
||||
USES_CONVERSION;
|
||||
|
||||
int nKeyLen = (int)strlen(m_pszKey);
|
||||
int iPos = (int)sString.GetLength() % nKeyLen;
|
||||
|
||||
CString sRet;
|
||||
|
||||
LPCSTR pszAscii = T2CA(sString);
|
||||
for (unsigned int i = 0;i < strlen(pszAscii); i++) {
|
||||
CString sTemp = sRet;
|
||||
sRet.Format(_T("%s%03d"), sTemp, (unsigned char)pszAscii[i] ^ m_pszKey[(i + iPos) % nKeyLen]);
|
||||
}
|
||||
|
||||
return sRet;
|
||||
}
|
||||
|
||||
CString CCrypt::Decrypt(CString sString)
|
||||
{
|
||||
USES_CONVERSION;
|
||||
|
||||
LPCSTR pszAscii = T2CA(sString);
|
||||
|
||||
int nKeyLen = (int)strlen(m_pszKey);
|
||||
int iPos = ((int)strlen(pszAscii) / 3) % nKeyLen;
|
||||
|
||||
CString sRet;
|
||||
|
||||
TCHAR szTemp[2];
|
||||
szTemp[1] = 0;
|
||||
for (unsigned int i = 0; i < strlen(pszAscii) / 3; i++) {
|
||||
int nDigit, nNumber = 0;
|
||||
|
||||
nDigit = pszAscii[i * 3];
|
||||
if (nDigit < '0' || nDigit > '9')
|
||||
return _T("");
|
||||
nNumber += (nDigit - '0') * 100;
|
||||
nDigit = pszAscii[i * 3 + 1];
|
||||
if (nDigit < '0' || nDigit > '9')
|
||||
return _T("");
|
||||
nNumber += (nDigit - '0') * 10;
|
||||
nDigit = pszAscii[i * 3 + 2];
|
||||
if (nDigit < '0' || nDigit > '9')
|
||||
return _T("");
|
||||
nNumber += nDigit - '0';
|
||||
|
||||
szTemp[0] = nNumber ^ m_pszKey[(i + iPos) % nKeyLen];
|
||||
sRet += szTemp;
|
||||
}
|
||||
|
||||
return sRet;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
#if !defined(AFX_CRYPT_H__613C5174_16F0_42A5_9493_C7489534C080__INCLUDED_)
|
||||
#define AFX_CRYPT_H__613C5174_16F0_42A5_9493_C7489534C080__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
class CCrypt
|
||||
{
|
||||
static char *m_pszKey;
|
||||
|
||||
public:
|
||||
static CString Decrypt(CString sString);
|
||||
static CString Encrypt(CString sString);
|
||||
};
|
||||
|
||||
#endif // !defined(AFX_CRYPT_H__613C5174_16F0_42A5_9493_C7489534C080__INCLUDED_)
|
||||
@@ -0,0 +1,285 @@
|
||||
// DSLog.cpp: implementation of the Log class.
|
||||
//
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "DSLog.h"
|
||||
|
||||
const DWORD CDSLog::modeDebug = 0x01;
|
||||
const DWORD CDSLog::modeFile = 0x02;
|
||||
const DWORD CDSLog::modeConsole = 0x04;
|
||||
|
||||
const CHAR CDSLog::m_szExt[] = ".log";
|
||||
|
||||
const static int LINE_BUFFER_SIZE = 1024;
|
||||
|
||||
// Create a new dslog object.
|
||||
// nMode - specifies where output should go, using combination
|
||||
// of flags above.
|
||||
// nFlag - the flag
|
||||
// pszFileName - if flag CDSLog::modeFile is specified in the type,
|
||||
// a filename must be specified here.
|
||||
// bAppend - if logging to a file, whether or not to append to any
|
||||
// existing log.
|
||||
// bDaily - if logging to a file, whether or not to replace log every day.
|
||||
|
||||
CDSLog::CDSLog(DWORD dwMode, DWORD dwLevel, LPSTR pszFileName, BOOL bAppend, BOOL bDaily)
|
||||
{
|
||||
m_nLastLogTime = 0;
|
||||
m_szLastLogDay[0] = 0;
|
||||
|
||||
m_pszFileName = NULL;
|
||||
m_hFile = NULL;
|
||||
|
||||
m_pszEventSource = NULL;
|
||||
|
||||
m_bDebugMode = false;
|
||||
m_bFileMode = false;
|
||||
m_bConsoleMode = false;
|
||||
m_bAppend = false;
|
||||
m_bDaily = false;
|
||||
|
||||
m_dwLevel = dwLevel;
|
||||
|
||||
SetFile(pszFileName, bAppend, bDaily);
|
||||
SetMode(dwMode);
|
||||
}
|
||||
|
||||
CDSLog::~CDSLog()
|
||||
{
|
||||
if (m_pszFileName)
|
||||
free(m_pszFileName);
|
||||
|
||||
if (m_pszEventSource)
|
||||
free(m_pszEventSource);
|
||||
|
||||
CloseFile();
|
||||
}
|
||||
|
||||
void CDSLog::EventLog(WORD wType, LPSTR pszFormat, ...)
|
||||
{
|
||||
va_list val;
|
||||
|
||||
va_start(val, pszFormat);
|
||||
|
||||
if (m_pszEventSource) {
|
||||
HANDLE hEventSource;
|
||||
|
||||
CHAR szBuf[256];
|
||||
LPSTR ppszBuf[2];
|
||||
|
||||
vsprintf(szBuf, pszFormat, val);
|
||||
|
||||
hEventSource = RegisterEventSource(NULL, m_pszEventSource);
|
||||
|
||||
ppszBuf[0] = m_pszEventSource;
|
||||
ppszBuf[1] = szBuf;
|
||||
|
||||
if (hEventSource) {
|
||||
ReportEvent(
|
||||
hEventSource, // handle of event source
|
||||
wType, // event type
|
||||
0, // event category
|
||||
0, // event ID
|
||||
NULL, // current user's SID
|
||||
2, // strings in 'strings'
|
||||
0, // no bytes of raw data
|
||||
(const char **)ppszBuf, // array of error strings
|
||||
NULL); // no raw data
|
||||
|
||||
DeregisterEventSource(hEventSource);
|
||||
}
|
||||
}
|
||||
|
||||
if (DSLL_STATE & m_dwLevel)
|
||||
_Print(pszFormat, val);
|
||||
|
||||
va_end(val);
|
||||
}
|
||||
|
||||
void CDSLog::EventLogError(LPSTR pszMsg)
|
||||
{
|
||||
DWORD dwError = GetLastError();
|
||||
TCHAR szBuf[256];
|
||||
|
||||
wsprintf(szBuf, "%s, error code : %d", pszMsg, dwError);
|
||||
EventLog(EVENTLOG_ERROR_TYPE, szBuf);
|
||||
}
|
||||
|
||||
void CDSLog::EventLogWSAError(LPSTR pszMsg)
|
||||
{
|
||||
// DWORD dwError = WSAGetLastError();
|
||||
// TCHAR szBuf[256];
|
||||
|
||||
// wsprintf(szBuf, "%s, WSA error code : %d", pszMsg, dwError);
|
||||
// EventLog(EVENTLOG_ERROR_TYPE, szBuf);
|
||||
}
|
||||
|
||||
void CDSLog::SetMode(DWORD dwMode)
|
||||
{
|
||||
m_bDebugMode = dwMode & modeDebug;
|
||||
|
||||
if (dwMode & modeFile) {
|
||||
if (!m_bFileMode)
|
||||
OpenFile();
|
||||
}
|
||||
else {
|
||||
CloseFile();
|
||||
m_bFileMode = false;
|
||||
}
|
||||
|
||||
if (dwMode & modeConsole) {
|
||||
if (!m_bConsoleMode)
|
||||
AllocConsole();
|
||||
|
||||
m_bConsoleMode = true;
|
||||
}
|
||||
else {
|
||||
m_bConsoleMode = false;
|
||||
}
|
||||
}
|
||||
|
||||
void CDSLog::SetLevel(DWORD dwLevel)
|
||||
{
|
||||
m_dwLevel = dwLevel;
|
||||
}
|
||||
|
||||
void CDSLog::SetFile(LPSTR pszFileName, BOOL bAppend, BOOL bDaily)
|
||||
{
|
||||
CloseFile();
|
||||
|
||||
if (m_pszFileName)
|
||||
free(m_pszFileName);
|
||||
|
||||
if (pszFileName)
|
||||
m_pszFileName = strdup(pszFileName);
|
||||
|
||||
m_bAppend = bAppend;
|
||||
m_bDaily = bDaily;
|
||||
|
||||
if (m_bFileMode)
|
||||
OpenFile();
|
||||
}
|
||||
|
||||
void CDSLog::SetEventSource(LPSTR pszEventSource)
|
||||
{
|
||||
if (m_pszEventSource)
|
||||
free(m_pszEventSource);
|
||||
|
||||
if (pszEventSource)
|
||||
m_pszEventSource = strdup(pszEventSource);
|
||||
}
|
||||
|
||||
void CDSLog::_Print(LPSTR pszFormat, va_list val)
|
||||
{
|
||||
UINT64 nCurrentTime = _time64(0);
|
||||
|
||||
if (m_bFileMode && m_bDaily && m_hFile) {
|
||||
CHAR szDate[7];
|
||||
|
||||
MakeSurfix(szDate);
|
||||
|
||||
if (szDate[6] != m_szLastLogDay[6] || szDate[5] != m_szLastLogDay[5]) {
|
||||
CloseFile();
|
||||
OpenFile();
|
||||
}
|
||||
}
|
||||
|
||||
if (nCurrentTime != m_nLastLogTime) {
|
||||
m_nLastLogTime = nCurrentTime;
|
||||
_PrintLine(_ctime64((__time64_t*)&m_nLastLogTime));
|
||||
}
|
||||
|
||||
// - Write the log message
|
||||
TCHAR szLine[LINE_BUFFER_SIZE];
|
||||
|
||||
vsprintf(szLine, pszFormat, val);
|
||||
_PrintLine(szLine);
|
||||
}
|
||||
|
||||
inline void CDSLog::_PrintLine(LPSTR pszLine)
|
||||
{
|
||||
if (m_bDebugMode)
|
||||
OutputDebugString(pszLine);
|
||||
|
||||
DWORD dwWritten;
|
||||
|
||||
if (m_bConsoleMode)
|
||||
WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), pszLine, (DWORD)strlen(pszLine), &dwWritten, NULL);
|
||||
|
||||
if (m_bFileMode && m_hFile)
|
||||
WriteFile(m_hFile, pszLine, (DWORD)strlen(pszLine), &dwWritten, NULL);
|
||||
}
|
||||
|
||||
void CDSLog::OpenFile()
|
||||
{
|
||||
if (!m_pszFileName) {
|
||||
m_bDebugMode = true;
|
||||
m_bFileMode = false;
|
||||
|
||||
Print(0, "Error opening log file\n");
|
||||
return;
|
||||
}
|
||||
|
||||
char szFileName[MAX_PATH];
|
||||
|
||||
strcpy(szFileName, m_pszFileName);
|
||||
|
||||
if (m_bDaily) {
|
||||
CHAR szDate[7];
|
||||
|
||||
MakeSurfix(szDate);
|
||||
|
||||
strcat(szFileName, szDate);
|
||||
|
||||
strcpy(m_szLastLogDay, szDate);
|
||||
}
|
||||
|
||||
strcat(szFileName, m_szExt);
|
||||
|
||||
m_bFileMode = true;
|
||||
|
||||
m_hFile = CreateFile(szFileName, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
if (m_hFile == INVALID_HANDLE_VALUE) {
|
||||
m_bDebugMode = true;
|
||||
m_bFileMode = false;
|
||||
|
||||
Print(0, "Error opening log file %s\n", szFileName);
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_bAppend)
|
||||
SetFilePointer(m_hFile, 0, NULL, FILE_END);
|
||||
else
|
||||
SetEndOfFile(m_hFile);
|
||||
}
|
||||
|
||||
void CDSLog::CloseFile()
|
||||
{
|
||||
if (m_hFile) {
|
||||
CloseHandle(m_hFile);
|
||||
m_hFile = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void CDSLog::MakeSurfix(CHAR *pszBuf)
|
||||
{
|
||||
WORD wMonth, wDay, wYear;
|
||||
|
||||
SYSTEMTIME st;
|
||||
GetLocalTime(&st);
|
||||
|
||||
wYear = st.wYear % 100;
|
||||
wMonth = st.wMonth;
|
||||
wDay = st.wDay;
|
||||
|
||||
pszBuf[0] = (CHAR)(wYear / 10 + '0');
|
||||
pszBuf[1] = (CHAR)(wYear % 10 + '0');
|
||||
|
||||
pszBuf[2] = (CHAR)(wMonth / 10 + '0');
|
||||
pszBuf[3] = (CHAR)(wMonth % 10 + '0');
|
||||
|
||||
pszBuf[4] = (CHAR)(wDay / 10 + '0');
|
||||
pszBuf[5] = (CHAR)(wDay % 10 + '0');
|
||||
|
||||
pszBuf[6] = 0;
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
#ifndef __DSLOG_H__
|
||||
#define __DSLOG_H__
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
// Log Level
|
||||
#define DSLL_STATE 0x0001
|
||||
#define DSLL_INFO 0x0002
|
||||
#define DSLL_ERROR 0x0004
|
||||
#define DSLL_DEBUG 0x0008
|
||||
|
||||
#define LOG(s) (__FILE__ " : " s)
|
||||
|
||||
class CDSLog
|
||||
{
|
||||
// Methods
|
||||
public:
|
||||
CDSLog(DWORD dwMode = modeDebug, DWORD dwLevel = DSLL_STATE, LPSTR szFileName = NULL, BOOL bAppend = TRUE, BOOL bDaily = TRUE);
|
||||
virtual ~CDSLog();
|
||||
|
||||
inline void Print(DWORD dwLevel, LPSTR pszFormat, ...) {
|
||||
if (!(dwLevel & m_dwLevel))
|
||||
return;
|
||||
|
||||
va_list val;
|
||||
|
||||
va_start(val, pszFormat);
|
||||
_Print(pszFormat, val);
|
||||
va_end(val);
|
||||
}
|
||||
|
||||
void EventLog(WORD wType, LPSTR pszFormat, ...);
|
||||
void EventLogError(LPSTR pszMsg);
|
||||
void EventLogWSAError(LPSTR pszMsg);
|
||||
|
||||
void SetMode(DWORD dwMode);
|
||||
void SetLevel(DWORD dwLevel);
|
||||
|
||||
void SetFile(LPSTR pszFileName, BOOL bAppend = TRUE, BOOL bDaily = TRUE);
|
||||
|
||||
void SetEventSource(LPSTR pszEventSource);
|
||||
|
||||
private:
|
||||
void _Print(LPSTR pszFormat, va_list val);
|
||||
void _PrintLine(LPSTR pszLine);
|
||||
void OpenFile();
|
||||
void CloseFile();
|
||||
void MakeSurfix(LPSTR pszBuf);
|
||||
|
||||
// Properties
|
||||
protected:
|
||||
UINT64 m_nLastLogTime;
|
||||
CHAR m_szLastLogDay[7];
|
||||
|
||||
LPSTR m_pszFileName;
|
||||
HANDLE m_hFile;
|
||||
|
||||
LPSTR m_pszEventSource;
|
||||
|
||||
BOOL m_bDebugMode, m_bFileMode, m_bConsoleMode;
|
||||
DWORD m_dwLevel;
|
||||
BOOL m_bAppend, m_bDaily;
|
||||
|
||||
public:
|
||||
static const DWORD modeDebug;
|
||||
static const DWORD modeFile;
|
||||
static const DWORD modeConsole;
|
||||
|
||||
static const CHAR m_szExt[];
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,210 @@
|
||||
// GdStatic.cpp : implementation file
|
||||
//
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "GdStatic.h"
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define new DEBUG_NEW
|
||||
#undef THIS_FILE
|
||||
static char THIS_FILE[] = __FILE__;
|
||||
#endif
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CGdStatic
|
||||
|
||||
CGdStatic::CGdStatic()
|
||||
{
|
||||
m_crText = ::GetSysColor(COLOR_3DFACE);
|
||||
m_nFontWeight = FW_NORMAL;
|
||||
m_nFontSize = 12;
|
||||
}
|
||||
|
||||
CGdStatic::~CGdStatic()
|
||||
{
|
||||
if (m_bitmap.GetSafeHandle())
|
||||
m_bitmap.DeleteObject();
|
||||
|
||||
if (m_fontCaption.GetSafeHandle())
|
||||
m_fontCaption.DeleteObject();
|
||||
|
||||
if (m_fontName.GetSafeHandle())
|
||||
m_fontName.DeleteObject();
|
||||
}
|
||||
|
||||
|
||||
BEGIN_MESSAGE_MAP(CGdStatic, CStatic)
|
||||
//{{AFX_MSG_MAP(CGdStatic)
|
||||
ON_WM_PAINT()
|
||||
ON_WM_ERASEBKGND()
|
||||
ON_MESSAGE(WM_SETTEXT, OnSetText)
|
||||
//}}AFX_MSG_MAP
|
||||
END_MESSAGE_MAP()
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CGdStatic message handlers
|
||||
|
||||
void CGdStatic::OnPaint()
|
||||
{
|
||||
CPaintDC dc(this); // device context for painting
|
||||
|
||||
CFont *pfontOld = NULL;
|
||||
|
||||
if (m_sFontName.GetLength() == 0) {
|
||||
CWnd *pwndParent = GetParent();
|
||||
|
||||
if (pwndParent)
|
||||
dc.SelectObject(pwndParent->GetFont());
|
||||
}
|
||||
else {
|
||||
// create a font, if we need to
|
||||
if (!m_fontCaption.GetSafeHandle()) {
|
||||
m_fontCaption.CreateFont( m_nFontSize,
|
||||
0, 0, 0, m_nFontWeight,
|
||||
0, 0, 0, DEFAULT_CHARSET,
|
||||
OUT_DEFAULT_PRECIS,
|
||||
CLIP_DEFAULT_PRECIS,
|
||||
DEFAULT_QUALITY,
|
||||
FF_MODERN,
|
||||
m_sFontName);
|
||||
}
|
||||
|
||||
if (m_fontCaption.GetSafeHandle())
|
||||
pfontOld = dc.SelectObject(&m_fontCaption);
|
||||
}
|
||||
|
||||
// Draw text
|
||||
CString sText;
|
||||
GetWindowText(sText);
|
||||
|
||||
dc.SetTextColor(m_crText);
|
||||
dc.SetBkMode(TRANSPARENT);
|
||||
|
||||
// vertical center
|
||||
CRect rc;
|
||||
GetClientRect(rc);
|
||||
|
||||
rc.left += 5;
|
||||
dc.DrawText(sText, rc, DT_SINGLELINE | DT_LEFT | DT_VCENTER);
|
||||
|
||||
if (pfontOld)
|
||||
dc.SelectObject(pfontOld);
|
||||
}
|
||||
|
||||
BOOL CGdStatic::OnEraseBkgnd(CDC* pDC)
|
||||
{
|
||||
if (!m_bitmap.GetSafeHandle())
|
||||
MakeCaptionBitmap();
|
||||
|
||||
if (m_bitmap.GetSafeHandle()) {
|
||||
CRect rc;
|
||||
GetClientRect(rc);
|
||||
|
||||
CDC memDC;
|
||||
memDC.CreateCompatibleDC(pDC);
|
||||
|
||||
CBitmap *pbitmap = memDC.SelectObject(&m_bitmap);
|
||||
|
||||
pDC->BitBlt(0, 0, rc.Width(), rc.Height(), &memDC, 0,0, SRCCOPY);
|
||||
|
||||
memDC.SelectObject(pbitmap);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
LRESULT CGdStatic::OnSetText(WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
DefWindowProc(WM_SETTEXT, wParam, lParam);
|
||||
|
||||
Invalidate(TRUE);
|
||||
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Helper to paint rectangle with a color.
|
||||
|
||||
static void PaintRect(CDC& dc, int x, int y, int w, int h, COLORREF cr)
|
||||
{
|
||||
CBrush br(cr);
|
||||
CBrush* pbrOld = dc.SelectObject(&br);
|
||||
|
||||
dc.PatBlt(x, y, w, h, PATCOPY);
|
||||
dc.SelectObject(pbrOld);
|
||||
}
|
||||
|
||||
void CGdStatic::MakeCaptionBitmap()
|
||||
{
|
||||
if (m_bitmap.m_hObject)
|
||||
return; // already have bitmap; return
|
||||
|
||||
CRect rc;
|
||||
GetClientRect(rc);
|
||||
|
||||
int w = rc.Width();
|
||||
int h = rc.Height();
|
||||
|
||||
// Create bitmap same size as caption area and select into memory DC
|
||||
CWindowDC dcWin(this);
|
||||
CDC dc;
|
||||
|
||||
dc.CreateCompatibleDC(&dcWin);
|
||||
m_bitmap.DeleteObject();
|
||||
m_bitmap.CreateCompatibleBitmap(&dcWin, w, h);
|
||||
CBitmap* pbitmapOld = dc.SelectObject(&m_bitmap);
|
||||
|
||||
COLORREF crBG = ::GetSysColor(COLOR_3DFACE); // background color
|
||||
|
||||
int r = GetRValue(crBG); // red..
|
||||
int g = GetGValue(crBG); // ..green
|
||||
int b = GetBValue(crBG); // ..blue color vals
|
||||
int x = 8*rc.right/8; // start 5/6 of the way right
|
||||
int w1 = x - rc.left; // width of area to shade
|
||||
|
||||
const int NCOLORSHADES = 128; // this many shades in gradient
|
||||
|
||||
int xDelta = max(w / NCOLORSHADES , 1); // width of one shade band
|
||||
|
||||
PaintRect(dc, x, 0, rc.right-x, h, crBG);
|
||||
|
||||
while (x > xDelta) { // paint bands right to left
|
||||
x -= xDelta; // next band
|
||||
int wmx2 = (w1-x)*(w1-x); // w minus x squared
|
||||
int w2 = w1*w1; // w squared
|
||||
PaintRect(dc, x, 0, xDelta, h, RGB(r-(r*wmx2)/w2, g-(g*wmx2)/w2, b-(b*wmx2)/w2));
|
||||
}
|
||||
|
||||
PaintRect(dc,0,0,x,h,RGB(0,0,0)); // whatever's left ==> black
|
||||
|
||||
// draw the 'constant' text
|
||||
|
||||
// create a font, if we need to
|
||||
if (m_fontName.GetSafeHandle()==NULL) {
|
||||
m_fontName.CreateFont( 18, 0, 0, 0, FW_BOLD,
|
||||
0, 0, 0, ANSI_CHARSET,
|
||||
OUT_DEFAULT_PRECIS,
|
||||
CLIP_DEFAULT_PRECIS,
|
||||
DEFAULT_QUALITY,
|
||||
FF_MODERN,
|
||||
m_sFontName);
|
||||
}
|
||||
|
||||
CFont * pfontOld = dc.SelectObject(&m_fontName);
|
||||
|
||||
// back up a little
|
||||
rc.right -= 5;
|
||||
|
||||
// draw text in DC
|
||||
dc.SetBkMode(TRANSPARENT);
|
||||
dc.SetTextColor(::GetSysColor( COLOR_3DHILIGHT));
|
||||
dc.DrawText(m_sConstantText, rc + CPoint(1,1), DT_SINGLELINE | DT_RIGHT | DT_VCENTER);
|
||||
dc.SetTextColor(::GetSysColor( COLOR_3DSHADOW));
|
||||
dc.DrawText(m_sConstantText, rc, DT_SINGLELINE | DT_RIGHT | DT_VCENTER);
|
||||
|
||||
// restore old font
|
||||
dc.SelectObject(pfontOld);
|
||||
|
||||
// Restore DC
|
||||
dc.SelectObject(pbitmapOld);
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
// GdStatic.h : header file
|
||||
//
|
||||
|
||||
#if _MSC_VER >= 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER >= 1000
|
||||
|
||||
class CGdStatic : public CStatic
|
||||
{
|
||||
// Construction
|
||||
public:
|
||||
CGdStatic();
|
||||
|
||||
// Attributes
|
||||
public:
|
||||
|
||||
// Operations
|
||||
public:
|
||||
CString m_sFontName;
|
||||
int m_nFontSize, m_nFontWeight;
|
||||
BOOL m_bGrayText;
|
||||
COLORREF m_crText;
|
||||
|
||||
void SetConstantText(LPCTSTR lpszText) {m_sConstantText = lpszText;}
|
||||
|
||||
// Overrides
|
||||
// ClassWizard generated virtual function overrides
|
||||
//{{AFX_VIRTUAL(CGdStatic)
|
||||
//}}AFX_VIRTUAL
|
||||
|
||||
// Implementation
|
||||
public:
|
||||
virtual ~CGdStatic();
|
||||
|
||||
protected:
|
||||
CFont m_fontCaption, m_fontName;
|
||||
CBitmap m_bitmap;
|
||||
CString m_sConstantText;
|
||||
|
||||
void MakeCaptionBitmap();
|
||||
|
||||
// Generated message map functions
|
||||
protected:
|
||||
//{{AFX_MSG(CGdStatic)
|
||||
afx_msg void OnPaint();
|
||||
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
|
||||
afx_msg LRESULT OnSetText(WPARAM wParam, LPARAM lParam);
|
||||
//}}AFX_MSG
|
||||
|
||||
DECLARE_MESSAGE_MAP()
|
||||
};
|
||||
@@ -0,0 +1,118 @@
|
||||
// ImplDispatch.cpp (IDispatch for Extending Dynamic HTML Object Model)
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "ImpIDispatch.h"
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define new DEBUG_NEW
|
||||
#undef THIS_FILE
|
||||
static char THIS_FILE[] = __FILE__;
|
||||
#endif
|
||||
|
||||
// Hardcoded information for extending the Object Model
|
||||
// Typically this would be supplied through a TypeInfo
|
||||
// In this case the name "xxyyzz" maps to DISPID_Extend
|
||||
const WCHAR pszExtend[10]=L"xxyyzz";
|
||||
|
||||
#define DISPID_Extend 12345
|
||||
|
||||
CImpIDispatch::CImpIDispatch(void)
|
||||
{
|
||||
m_cRef = 0;
|
||||
}
|
||||
|
||||
CImpIDispatch::~CImpIDispatch(void)
|
||||
{
|
||||
ASSERT(m_cRef == 0);
|
||||
}
|
||||
|
||||
STDMETHODIMP CImpIDispatch::QueryInterface(REFIID riid, void **ppv)
|
||||
{
|
||||
*ppv = NULL;
|
||||
|
||||
if (IID_IDispatch == riid)
|
||||
*ppv = this;
|
||||
|
||||
if (NULL != *ppv) {
|
||||
((LPUNKNOWN)*ppv)->AddRef();
|
||||
return NOERROR;
|
||||
}
|
||||
|
||||
return E_NOINTERFACE;
|
||||
}
|
||||
|
||||
|
||||
STDMETHODIMP_(ULONG) CImpIDispatch::AddRef(void)
|
||||
{
|
||||
return ++m_cRef;
|
||||
}
|
||||
|
||||
STDMETHODIMP_(ULONG) CImpIDispatch::Release(void)
|
||||
{
|
||||
return --m_cRef;
|
||||
}
|
||||
|
||||
STDMETHODIMP CImpIDispatch::GetTypeInfoCount(UINT* /*pctinfo*/)
|
||||
{
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
STDMETHODIMP CImpIDispatch::GetTypeInfo(
|
||||
/* [in] */ UINT /*iTInfo*/,
|
||||
/* [in] */ LCID /*lcid*/,
|
||||
/* [out] */ ITypeInfo** /*ppTInfo*/)
|
||||
{
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
STDMETHODIMP CImpIDispatch::GetIDsOfNames(
|
||||
/* [in] */ REFIID riid,
|
||||
/* [size_is][in] */ OLECHAR** rgszNames,
|
||||
/* [in] */ UINT cNames,
|
||||
/* [in] */ LCID lcid,
|
||||
/* [size_is][out] */ DISPID* rgDispId)
|
||||
{
|
||||
HRESULT hr = NOERROR;
|
||||
|
||||
// Hardcoded mapping for this sample
|
||||
// A more usual procedure would be to use a TypeInfo
|
||||
for (UINT i = 0; i < cNames; i++) {
|
||||
if (2 == CompareString(lcid, NORM_IGNOREWIDTH, (char*)pszExtend, 3, (char*)rgszNames[i], 3)) {
|
||||
rgDispId[i] = DISPID_Extend;
|
||||
}
|
||||
else {
|
||||
// One or more are unknown so set the return code accordingly
|
||||
hr = ResultFromScode(DISP_E_UNKNOWNNAME);
|
||||
rgDispId[i] = DISPID_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
return hr;
|
||||
}
|
||||
|
||||
STDMETHODIMP CImpIDispatch::Invoke(
|
||||
/* [in] */ DISPID dispIdMember,
|
||||
/* [in] */ REFIID /*riid*/,
|
||||
/* [in] */ LCID /*lcid*/,
|
||||
/* [in] */ WORD wFlags,
|
||||
/* [out][in] */ DISPPARAMS* pDispParams,
|
||||
/* [out] */ VARIANT* pVarResult,
|
||||
/* [out] */ EXCEPINFO* /*pExcepInfo*/,
|
||||
/* [out] */ UINT* puArgErr)
|
||||
{
|
||||
// For this sample we only support a Property Get on DISPID_Extend
|
||||
// returning a BSTR with "Wibble" as the value
|
||||
if (dispIdMember == DISPID_Extend) {
|
||||
if (wFlags & DISPATCH_PROPERTYGET) {
|
||||
if (pVarResult != NULL) {
|
||||
WCHAR buff[10] = L"Wibble";
|
||||
BSTR bstrRet = SysAllocString(buff);
|
||||
VariantInit(pVarResult);
|
||||
V_VT(pVarResult) = VT_BSTR;
|
||||
V_BSTR(pVarResult) = bstrRet;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
// ImplDispatch.h
|
||||
|
||||
#ifndef _IDISPIMP_H_
|
||||
#define _IDISPIMP_H_
|
||||
|
||||
#pragma once
|
||||
|
||||
class CImpIDispatch : public IDispatch
|
||||
{
|
||||
protected:
|
||||
ULONG m_cRef;
|
||||
|
||||
public:
|
||||
CImpIDispatch(void);
|
||||
~CImpIDispatch(void);
|
||||
|
||||
STDMETHODIMP QueryInterface(REFIID, void **);
|
||||
STDMETHODIMP_(ULONG) AddRef(void);
|
||||
STDMETHODIMP_(ULONG) Release(void);
|
||||
|
||||
//IDispatch
|
||||
STDMETHODIMP GetTypeInfoCount(UINT* pctinfo);
|
||||
STDMETHODIMP GetTypeInfo(
|
||||
/* [in] */ UINT iTInfo,
|
||||
/* [in] */ LCID lcid,
|
||||
/* [out] */ ITypeInfo** ppTInfo);
|
||||
STDMETHODIMP GetIDsOfNames(
|
||||
/* [in] */ REFIID riid,
|
||||
/* [size_is][in] */ LPOLESTR *rgszNames,
|
||||
/* [in] */ UINT cNames,
|
||||
/* [in] */ LCID lcid,
|
||||
/* [size_is][out] */ DISPID *rgDispId);
|
||||
STDMETHODIMP Invoke(
|
||||
/* [in] */ DISPID dispIdMember,
|
||||
/* [in] */ REFIID riid,
|
||||
/* [in] */ LCID lcid,
|
||||
/* [in] */ WORD wFlags,
|
||||
/* [out][in] */ DISPPARAMS *pDispParams,
|
||||
/* [out] */ VARIANT *pVarResult,
|
||||
/* [out] */ EXCEPINFO *pExcepInfo,
|
||||
/* [out] */ UINT *puArgErr);
|
||||
};
|
||||
|
||||
#endif //_IDISPIMP_H_
|
||||
@@ -0,0 +1,260 @@
|
||||
// MD5.cpp: implementation of the CMD5 class.
|
||||
//
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "MD5.h"
|
||||
|
||||
#ifdef _DEBUG
|
||||
#undef THIS_FILE
|
||||
static char THIS_FILE[]=__FILE__;
|
||||
//#define new DEBUG_NEW
|
||||
#endif
|
||||
|
||||
|
||||
#define S11 7
|
||||
#define S12 12
|
||||
#define S13 17
|
||||
#define S14 22
|
||||
#define S21 5
|
||||
#define S22 9
|
||||
#define S23 14
|
||||
#define S24 20
|
||||
#define S31 4
|
||||
#define S32 11
|
||||
#define S33 16
|
||||
#define S34 23
|
||||
#define S41 6
|
||||
#define S42 10
|
||||
#define S43 15
|
||||
#define S44 21
|
||||
|
||||
static BYTE PADDING[64] = {
|
||||
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||
};
|
||||
|
||||
// F, G, H and I are basic MD5 functions.
|
||||
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
|
||||
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
|
||||
#define H(x, y, z) ((x) ^ (y) ^ (z))
|
||||
#define I(x, y, z) ((y) ^ ((x) | (~z)))
|
||||
|
||||
// ROTATE_LEFT rotates x left n bits.
|
||||
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
|
||||
|
||||
// FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
|
||||
// Rotation is separate from addition to prevent recomputation.
|
||||
#define FF(a, b, c, d, x, s, ac) { \
|
||||
(a) += F ((b), (c), (d)) + (x) + (UINT)(ac); \
|
||||
(a) = ROTATE_LEFT ((a), (s)); \
|
||||
(a) += (b); \
|
||||
}
|
||||
#define GG(a, b, c, d, x, s, ac) { \
|
||||
(a) += G ((b), (c), (d)) + (x) + (UINT)(ac); \
|
||||
(a) = ROTATE_LEFT ((a), (s)); \
|
||||
(a) += (b); \
|
||||
}
|
||||
#define HH(a, b, c, d, x, s, ac) { \
|
||||
(a) += H ((b), (c), (d)) + (x) + (UINT)(ac); \
|
||||
(a) = ROTATE_LEFT ((a), (s)); \
|
||||
(a) += (b); \
|
||||
}
|
||||
#define II(a, b, c, d, x, s, ac) { \
|
||||
(a) += I ((b), (c), (d)) + (x) + (UINT)(ac); \
|
||||
(a) = ROTATE_LEFT ((a), (s)); \
|
||||
(a) += (b); \
|
||||
}
|
||||
|
||||
static void MD5Transform(UINT uState[4], BYTE byBlock[64]);
|
||||
static void Encode(BYTE* byOutput, UINT* uInput, UINT uLen);
|
||||
static void Decode(UINT* uOutput, BYTE* byInput, UINT uLen);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
|
||||
CMD5::CMD5()
|
||||
{
|
||||
}
|
||||
|
||||
CMD5::~CMD5()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void CMD5::GetHash(LPSTR pszStr, LPSTR pszHash)
|
||||
{
|
||||
MD5_CTX md5ctx;
|
||||
BYTE byDigest[16];
|
||||
|
||||
MD5Init(&md5ctx);
|
||||
MD5Update(&md5ctx, (BYTE*)pszStr, (UINT)strlen(pszStr));
|
||||
MD5Final(byDigest, &md5ctx);
|
||||
|
||||
pszHash[0] = NULL;
|
||||
|
||||
char szTemp[5];
|
||||
for (int i = 0; i < 16; i++) {
|
||||
sprintf(szTemp, "%02X", byDigest[i]);
|
||||
strcat(pszHash, szTemp);
|
||||
}
|
||||
}
|
||||
|
||||
void CMD5::MD5Init(MD5_CTX* md5ctx)
|
||||
{
|
||||
md5ctx->count[0] = md5ctx->count[1] = 0;
|
||||
|
||||
md5ctx->state[0] = 0x67452301;
|
||||
md5ctx->state[1] = 0xefcdab89;
|
||||
md5ctx->state[2] = 0x98badcfe;
|
||||
md5ctx->state[3] = 0x10325476;
|
||||
}
|
||||
|
||||
void CMD5::MD5Update (MD5_CTX* md5ctx, BYTE* byInput, UINT uInputLen)
|
||||
{
|
||||
UINT i, uIndex, nPartLen;
|
||||
|
||||
uIndex = (UINT)((md5ctx->count[0] >> 3) & 0x3F);
|
||||
|
||||
if ((md5ctx->count[0] += ((UINT)uInputLen << 3)) < ((UINT)uInputLen << 3))
|
||||
md5ctx->count[1]++;
|
||||
|
||||
md5ctx->count[1] += ((UINT)uInputLen >> 29);
|
||||
nPartLen = 64 - uIndex;
|
||||
|
||||
if (uInputLen >= nPartLen) {
|
||||
memcpy(&md5ctx->buffer[uIndex], byInput, nPartLen);
|
||||
MD5Transform(md5ctx->state, md5ctx->buffer);
|
||||
|
||||
for (i = nPartLen; i + 63 < uInputLen; i += 64)
|
||||
MD5Transform (md5ctx->state, &byInput[i]);
|
||||
|
||||
uIndex = 0;
|
||||
}
|
||||
else
|
||||
i = 0;
|
||||
|
||||
memcpy(&md5ctx->buffer[uIndex], &byInput[i], uInputLen - i);
|
||||
}
|
||||
|
||||
void CMD5::MD5Final(BYTE* byDigest, MD5_CTX* md5ctx)
|
||||
{
|
||||
BYTE byBits[8];
|
||||
UINT uIndex, nPadLen;
|
||||
|
||||
Encode(byBits, md5ctx->count, 8);
|
||||
|
||||
uIndex = (UINT)((md5ctx->count[0] >> 3) & 0x3f);
|
||||
nPadLen = uIndex < 56 ? (56 - uIndex) : (120 - uIndex);
|
||||
MD5Update(md5ctx, PADDING, nPadLen);
|
||||
|
||||
MD5Update(md5ctx, byBits, 8);
|
||||
|
||||
Encode (byDigest, md5ctx->state, 16);
|
||||
memset (md5ctx, 0, sizeof(*md5ctx));
|
||||
}
|
||||
|
||||
|
||||
static void MD5Transform(UINT uState[4], BYTE byBlock[64])
|
||||
{
|
||||
UINT a = uState[0], b = uState[1], c = uState[2], d = uState[3], x[16];
|
||||
|
||||
Decode(x, byBlock, 64);
|
||||
|
||||
// Round 1
|
||||
FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
|
||||
FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
|
||||
FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
|
||||
FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
|
||||
FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
|
||||
FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
|
||||
FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
|
||||
FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
|
||||
FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
|
||||
FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
|
||||
FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
|
||||
FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
|
||||
FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
|
||||
FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
|
||||
FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
|
||||
FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
|
||||
|
||||
// Round 2
|
||||
GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
|
||||
GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
|
||||
GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
|
||||
GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
|
||||
GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
|
||||
GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */
|
||||
GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
|
||||
GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
|
||||
GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
|
||||
GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
|
||||
GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
|
||||
GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
|
||||
GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
|
||||
GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
|
||||
GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
|
||||
GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
|
||||
|
||||
// Round 3
|
||||
HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
|
||||
HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
|
||||
HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
|
||||
HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
|
||||
HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
|
||||
HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
|
||||
HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
|
||||
HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
|
||||
HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
|
||||
HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
|
||||
HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
|
||||
HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */
|
||||
HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
|
||||
HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
|
||||
HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
|
||||
HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */
|
||||
|
||||
// Round 4
|
||||
II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
|
||||
II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
|
||||
II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
|
||||
II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
|
||||
II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
|
||||
II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
|
||||
II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
|
||||
II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
|
||||
II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
|
||||
II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
|
||||
II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
|
||||
II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
|
||||
II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
|
||||
II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
|
||||
II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
|
||||
II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */
|
||||
|
||||
uState[0] += a;
|
||||
uState[1] += b;
|
||||
uState[2] += c;
|
||||
uState[3] += d;
|
||||
|
||||
// Zeroize sensitive information.
|
||||
memset(x, 0, sizeof(x));
|
||||
}
|
||||
|
||||
static void Encode(BYTE* byOutput, UINT* uInput, UINT uLen)
|
||||
{
|
||||
for (UINT i = 0, j = 0; j < uLen; i++, j += 4) {
|
||||
byOutput[j] = (BYTE)(uInput[i] & 0xff);
|
||||
byOutput[j + 1] = (BYTE)((uInput[i] >> 8) & 0xff);
|
||||
byOutput[j + 2] = (BYTE)((uInput[i] >> 16) & 0xff);
|
||||
byOutput[j + 3] = (BYTE)((uInput[i] >> 24) & 0xff);
|
||||
}
|
||||
}
|
||||
|
||||
static void Decode(UINT* uOutput, BYTE* byInput, UINT uLen)
|
||||
{
|
||||
for (UINT i = 0, j = 0; j < uLen; i++, j += 4)
|
||||
uOutput[i] = ((UINT)byInput[j]) | (((UINT)byInput[j + 1]) << 8) |
|
||||
(((UINT)byInput[j + 2]) << 16) | (((UINT)byInput[j + 3]) << 24);
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
class CMD5
|
||||
{
|
||||
typedef struct {
|
||||
UINT state[4]; // state (ABCD)
|
||||
UINT count[2]; // number of bits, modulo 2^64 (lsb first)
|
||||
BYTE buffer[64]; // input buffer
|
||||
} MD5_CTX;
|
||||
|
||||
public:
|
||||
CMD5();
|
||||
virtual ~CMD5();
|
||||
|
||||
static void GetHash(LPSTR pszStr, LPSTR pszHash);
|
||||
|
||||
protected:
|
||||
static void MD5Init(MD5_CTX* ctx);
|
||||
static void MD5Update(MD5_CTX* ctx, BYTE* input, UINT inputlen);
|
||||
static void MD5Final(BYTE* digest, MD5_CTX* ctx);
|
||||
};
|
||||
@@ -0,0 +1,129 @@
|
||||
#include "stdafx.h"
|
||||
|
||||
//#include "MFC64bitFix.h"
|
||||
|
||||
__int64 GetLength64(CFile &file)
|
||||
{
|
||||
DWORD low;
|
||||
DWORD high;
|
||||
low=GetFileSize((void *)file.m_hFile, &high);
|
||||
_int64 size=((_int64)high<<32)+low;
|
||||
return size;
|
||||
}
|
||||
|
||||
BOOL GetLength64(CString filename, _int64 &size)
|
||||
{
|
||||
WIN32_FIND_DATA findFileData;
|
||||
HANDLE hFind = FindFirstFile(filename, &findFileData);
|
||||
if (hFind == INVALID_HANDLE_VALUE)
|
||||
return FALSE;
|
||||
VERIFY(FindClose(hFind));
|
||||
|
||||
size=((_int64)findFileData.nFileSizeHigh<<32)+findFileData.nFileSizeLow;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL AFXAPI AfxFullPath(LPTSTR lpszPathOut, LPCTSTR lpszFileIn);
|
||||
|
||||
BOOL PASCAL GetStatus64(LPCTSTR lpszFileName, CFileStatus64& rStatus)
|
||||
{
|
||||
// attempt to fully qualify path first
|
||||
if (!AfxFullPath(rStatus.m_szFullName, lpszFileName))
|
||||
{
|
||||
rStatus.m_szFullName[0] = '\0';
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
WIN32_FIND_DATA findFileData;
|
||||
HANDLE hFind = FindFirstFile((LPTSTR)lpszFileName, &findFileData);
|
||||
if (hFind == INVALID_HANDLE_VALUE)
|
||||
return FALSE;
|
||||
VERIFY(FindClose(hFind));
|
||||
|
||||
// strip attribute of NORMAL bit, our API doesn't have a "normal" bit.
|
||||
rStatus.m_attribute = (BYTE)
|
||||
(findFileData.dwFileAttributes & ~FILE_ATTRIBUTE_NORMAL);
|
||||
|
||||
rStatus.m_size = ((_int64)findFileData.nFileSizeHigh<<32)+findFileData.nFileSizeLow;
|
||||
|
||||
// convert times as appropriate
|
||||
TRY
|
||||
{
|
||||
rStatus.m_ctime = CTime(findFileData.ftCreationTime);
|
||||
rStatus.m_has_ctime = true;
|
||||
}
|
||||
CATCH_ALL(e)
|
||||
{
|
||||
rStatus.m_has_ctime = false;
|
||||
}
|
||||
END_CATCH_ALL;
|
||||
|
||||
TRY
|
||||
{
|
||||
rStatus.m_atime = CTime(findFileData.ftLastAccessTime);
|
||||
rStatus.m_has_atime = true;
|
||||
}
|
||||
CATCH_ALL(e)
|
||||
{
|
||||
rStatus.m_has_atime = false;
|
||||
}
|
||||
END_CATCH_ALL;
|
||||
|
||||
TRY
|
||||
{
|
||||
rStatus.m_mtime = CTime(findFileData.ftLastWriteTime);
|
||||
rStatus.m_has_mtime = true;
|
||||
}
|
||||
CATCH_ALL(e)
|
||||
{
|
||||
rStatus.m_has_mtime = false;
|
||||
}
|
||||
END_CATCH_ALL;
|
||||
|
||||
if (!rStatus.m_has_ctime || rStatus.m_ctime.GetTime() == 0)
|
||||
{
|
||||
if (rStatus.m_has_mtime)
|
||||
{
|
||||
rStatus.m_ctime = rStatus.m_mtime;
|
||||
rStatus.m_has_ctime = true;
|
||||
}
|
||||
else
|
||||
rStatus.m_has_ctime = false;
|
||||
}
|
||||
|
||||
|
||||
if (!rStatus.m_has_atime || rStatus.m_atime.GetTime() == 0)
|
||||
{
|
||||
if (rStatus.m_has_mtime)
|
||||
{
|
||||
rStatus.m_atime = rStatus.m_mtime;
|
||||
rStatus.m_has_atime = true;
|
||||
}
|
||||
else
|
||||
rStatus.m_has_atime = false;
|
||||
}
|
||||
|
||||
if (!rStatus.m_has_mtime || rStatus.m_mtime.GetTime() == 0)
|
||||
{
|
||||
if (rStatus.m_has_ctime)
|
||||
{
|
||||
rStatus.m_mtime = rStatus.m_ctime;
|
||||
rStatus.m_has_mtime = true;
|
||||
}
|
||||
else
|
||||
rStatus.m_has_mtime = false;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
_int64 GetPosition64(CFile &file)
|
||||
{
|
||||
LONG low=0;
|
||||
LONG high=0;
|
||||
low=SetFilePointer((HANDLE)file.m_hFile, low, &high, FILE_CURRENT);
|
||||
if (low==0xFFFFFFFF && GetLastError!=NO_ERROR)
|
||||
CFileException::ThrowOsError((LONG)::GetLastError());
|
||||
return ((_int64)high<<32)+low;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
__int64 GetLength64(CFile &file);
|
||||
BOOL GetLength64(CString filename, _int64 &size);
|
||||
|
||||
//#if 0
|
||||
struct CFileStatus64
|
||||
{
|
||||
bool m_has_ctime;
|
||||
bool m_has_mtime;
|
||||
bool m_has_atime;
|
||||
CTime m_ctime; // creation date/time of file
|
||||
CTime m_mtime; // last modification date/time of file
|
||||
CTime m_atime; // last access date/time of file
|
||||
_int64 m_size; // logical size of file in bytes
|
||||
BYTE m_attribute; // logical OR of CFile::Attribute enum values
|
||||
BYTE _m_padding; // pad the structure to a WORD
|
||||
TCHAR m_szFullName[_MAX_PATH]; // absolute path name
|
||||
};
|
||||
//#endif
|
||||
|
||||
BOOL PASCAL GetStatus64(LPCTSTR lpszFileName, CFileStatus64& rStatus);
|
||||
|
||||
_int64 GetPosition64(CFile &file);
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,205 @@
|
||||
// Markup.h: interface for the CMarkupSTL class.
|
||||
//
|
||||
// Markup Release 6.3
|
||||
// Copyright (C) 1999-2002 First Objective Software, Inc. All rights reserved
|
||||
// Go to www.firstobject.com for the latest CMarkupSTL and EDOM documentation
|
||||
// Use in commercial applications requires written permission
|
||||
// This software is provided "as is", with no warranty.
|
||||
|
||||
#if !defined(AFX_MARKUP_H__948A2705_9E68_11D2_A0BF_00105A27C570__INCLUDED_)
|
||||
#define AFX_MARKUP_H__948A2705_9E68_11D2_A0BF_00105A27C570__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define _DS(i) (i?&((LPCTSTR)m_csDoc)[m_aPos[i].nStartL]:0)
|
||||
#define MARKUP_SETDEBUGSTATE m_pMainDS=_DS(m_iPos); m_pChildDS=_DS(m_iPosChild)
|
||||
#else
|
||||
#define MARKUP_SETDEBUGSTATE
|
||||
#endif
|
||||
|
||||
class CMarkupSTL
|
||||
{
|
||||
public:
|
||||
CMarkupSTL() { SetDoc( NULL ); };
|
||||
CMarkupSTL( LPCTSTR szDoc ) { SetDoc( szDoc ); };
|
||||
CMarkupSTL( const CMarkupSTL& markup ) { *this = markup; };
|
||||
void operator=( const CMarkupSTL& markup );
|
||||
virtual ~CMarkupSTL() {};
|
||||
|
||||
// Navigate
|
||||
bool Load( LPCTSTR szFileName );
|
||||
bool SetDoc( LPCTSTR szDoc );
|
||||
bool IsWellFormed();
|
||||
bool FindElem( LPCTSTR szName=NULL );
|
||||
bool FindChildElem( LPCTSTR szName=NULL );
|
||||
bool IntoElem();
|
||||
bool OutOfElem();
|
||||
void ResetChildPos() { x_SetPos(m_iPosParent,m_iPos,0); };
|
||||
void ResetMainPos() { x_SetPos(m_iPosParent,0,0); };
|
||||
void ResetPos() { x_SetPos(0,0,0); };
|
||||
CString GetTagName() const;
|
||||
CString GetChildTagName() const { return x_GetTagName(m_iPosChild); };
|
||||
CString GetData() const { return x_GetData(m_iPos); };
|
||||
CString GetChildData() const { return x_GetData(m_iPosChild); };
|
||||
CString GetAttrib( LPCTSTR szAttrib ) const { return x_GetAttrib(m_iPos,szAttrib); };
|
||||
CString GetChildAttrib( LPCTSTR szAttrib ) const { return x_GetAttrib(m_iPosChild,szAttrib); };
|
||||
CString GetAttribName( int n ) const;
|
||||
bool SavePos( LPCTSTR szPosName=_T("") );
|
||||
bool RestorePos( LPCTSTR szPosName=_T("") );
|
||||
bool GetOffsets( int& nStart, int& nEnd ) const;
|
||||
CString GetError() const { return m_csError; };
|
||||
|
||||
enum MarkupNodeType
|
||||
{
|
||||
MNT_ELEMENT = 1, // 0x01
|
||||
MNT_TEXT = 2, // 0x02
|
||||
MNT_WHITESPACE = 4, // 0x04
|
||||
MNT_CDATA_SECTION = 8, // 0x08
|
||||
MNT_PROCESSING_INSTRUCTION = 16, // 0x10
|
||||
MNT_COMMENT = 32, // 0x20
|
||||
MNT_DOCUMENT_TYPE = 64, // 0x40
|
||||
MNT_EXCLUDE_WHITESPACE = 123,// 0x7b
|
||||
};
|
||||
|
||||
// Create
|
||||
bool Save( LPCTSTR szFileName );
|
||||
CString GetDoc() const { return m_csDoc; };
|
||||
bool AddElem( LPCTSTR szName, LPCTSTR szData=NULL ) { return x_AddElem(szName,szData,false,false); };
|
||||
bool InsertElem( LPCTSTR szName, LPCTSTR szData=NULL ) { return x_AddElem(szName,szData,true,false); };
|
||||
bool AddChildElem( LPCTSTR szName, LPCTSTR szData=NULL ) { return x_AddElem(szName,szData,false,true); };
|
||||
bool InsertChildElem( LPCTSTR szName, LPCTSTR szData=NULL ) { return x_AddElem(szName,szData,true,true); };
|
||||
bool AddAttrib( LPCTSTR szAttrib, LPCTSTR szValue ) { return x_SetAttrib(m_iPos,szAttrib,szValue); };
|
||||
bool AddChildAttrib( LPCTSTR szAttrib, LPCTSTR szValue ) { return x_SetAttrib(m_iPosChild,szAttrib,szValue); };
|
||||
bool AddAttrib( LPCTSTR szAttrib, int nValue ) { return x_SetAttrib(m_iPos,szAttrib,nValue); };
|
||||
bool AddChildAttrib( LPCTSTR szAttrib, int nValue ) { return x_SetAttrib(m_iPosChild,szAttrib,nValue); };
|
||||
bool AddChildAttrib( LPCTSTR szAttrib, __int64 nValue ) { return x_SetAttrib(m_iPosChild,szAttrib,nValue); };
|
||||
bool AddChildSubDoc( LPCTSTR szSubDoc ) { return x_AddSubDoc(szSubDoc,false,true); };
|
||||
bool InsertChildSubDoc( LPCTSTR szSubDoc ) { return x_AddSubDoc(szSubDoc,true,true); };
|
||||
CString GetChildSubDoc() const;
|
||||
|
||||
// Modify
|
||||
bool RemoveElem();
|
||||
bool RemoveChildElem();
|
||||
bool SetAttrib( LPCTSTR szAttrib, LPCTSTR szValue ) { return x_SetAttrib(m_iPos,szAttrib,szValue); };
|
||||
bool SetChildAttrib( LPCTSTR szAttrib, LPCTSTR szValue ) { return x_SetAttrib(m_iPosChild,szAttrib,szValue); };
|
||||
bool SetAttrib( LPCTSTR szAttrib, int nValue ) { return x_SetAttrib(m_iPos,szAttrib,nValue); };
|
||||
bool SetChildAttrib( LPCTSTR szAttrib, int nValue ) { return x_SetAttrib(m_iPosChild,szAttrib,nValue); };
|
||||
bool SetData( LPCTSTR szData, int nCDATA=0 ) { return x_SetData(m_iPos,szData,nCDATA); };
|
||||
bool SetChildData( LPCTSTR szData, int nCDATA=0 ) { return x_SetData(m_iPosChild,szData,nCDATA); };
|
||||
|
||||
protected:
|
||||
|
||||
#ifdef _DEBUG
|
||||
LPCTSTR m_pMainDS;
|
||||
LPCTSTR m_pChildDS;
|
||||
#endif
|
||||
|
||||
CString m_csDoc;
|
||||
CString m_csError;
|
||||
|
||||
struct ElemPos
|
||||
{
|
||||
ElemPos() { Clear(); };
|
||||
ElemPos( const ElemPos& pos ) { *this = pos; };
|
||||
bool IsEmptyElement() const { return (nStartR == nEndL + 1); };
|
||||
void Clear()
|
||||
{
|
||||
nStartL=0; nStartR=0; nEndL=0; nEndR=0; nReserved=0;
|
||||
iElemParent=0; iElemChild=0; iElemNext=0;
|
||||
};
|
||||
void AdjustStart( int n ) { nStartL+=n; nStartR+=n; };
|
||||
void AdjustEnd( int n ) { nEndL+=n; nEndR+=n; };
|
||||
int nStartL;
|
||||
int nStartR;
|
||||
int nEndL;
|
||||
int nEndR;
|
||||
int nReserved;
|
||||
int iElemParent;
|
||||
int iElemChild;
|
||||
int iElemNext;
|
||||
};
|
||||
|
||||
std::vector<ElemPos> m_aPos;
|
||||
int m_iPosParent;
|
||||
int m_iPos;
|
||||
int m_iPosChild;
|
||||
int m_iPosFree;
|
||||
int m_nNodeType;
|
||||
|
||||
struct TokenPos
|
||||
{
|
||||
TokenPos( LPCTSTR sz ) { Clear(); szDoc = sz; };
|
||||
bool IsValid() const { return (nL <= nR); };
|
||||
void Clear() { nL=0; nR=-1; nNext=0; bIsString=false; };
|
||||
bool Match( LPCTSTR szName )
|
||||
{
|
||||
int nLen = nR - nL + 1;
|
||||
// To ignore case, define MARKUP_IGNORECASE
|
||||
#ifdef MARKUP_IGNORECASE
|
||||
return ( (_tcsncicmp( &szDoc[nL], szName, nLen ) == 0)
|
||||
#else
|
||||
return ( (_tcsnccmp( &szDoc[nL], szName, nLen ) == 0)
|
||||
#endif
|
||||
&& ( szName[nLen] == _T('\0') || _tcschr(_T(" =/["),szName[nLen]) ) );
|
||||
};
|
||||
int nL;
|
||||
int nR;
|
||||
int nNext;
|
||||
LPCTSTR szDoc;
|
||||
bool bIsString;
|
||||
};
|
||||
|
||||
struct SavedPos
|
||||
{
|
||||
int iPosParent;
|
||||
int iPos;
|
||||
int iPosChild;
|
||||
};
|
||||
std::map<CString, SavedPos> m_mapSavedPos;
|
||||
|
||||
void x_SetPos( int iPosParent, int iPos, int iPosChild )
|
||||
{
|
||||
m_iPosParent = iPosParent;
|
||||
m_iPos = iPos;
|
||||
m_iPosChild = iPosChild;
|
||||
m_nNodeType = iPos?MNT_ELEMENT:0;
|
||||
MARKUP_SETDEBUGSTATE;
|
||||
};
|
||||
|
||||
int x_GetFreePos();
|
||||
int x_ReleasePos();
|
||||
|
||||
int x_ParseElem( int iPos );
|
||||
int x_ParseError( LPCTSTR szError, LPCTSTR szName = NULL );
|
||||
static bool x_FindChar( LPCTSTR szDoc, int& nChar, _TCHAR c );
|
||||
static bool x_FindToken( TokenPos& token );
|
||||
CString x_GetToken( const TokenPos& token ) const;
|
||||
int x_FindElem( int iPosParent, int iPos, LPCTSTR szPath );
|
||||
CString x_GetTagName( int iPos ) const;
|
||||
CString x_GetData( int iPos ) const;
|
||||
CString x_GetAttrib( int iPos, LPCTSTR szAttrib ) const;
|
||||
bool x_AddElem( LPCTSTR szName, LPCTSTR szValue, bool bInsert, bool bAddChild );
|
||||
bool x_AddSubDoc( LPCTSTR szSubDoc, bool bInsert, bool bAddChild );
|
||||
bool x_FindAttrib( TokenPos& token, LPCTSTR szAttrib=NULL ) const;
|
||||
bool x_SetAttrib( int iPos, LPCTSTR szAttrib, LPCTSTR szValue );
|
||||
bool x_SetAttrib( int iPos, LPCTSTR szAttrib, int nValue );
|
||||
bool x_SetAttrib( int iPos, LPCTSTR szAttrib, __int64 nValue );
|
||||
bool x_CreateNode( CString& csNode, int nNodeType, LPCTSTR szText );
|
||||
void x_LocateNew( int iPosParent, int& iPosRel, int& nOffset, int nLength, int nFlags );
|
||||
int x_ParseNode( TokenPos& token );
|
||||
bool x_SetData( int iPos, LPCTSTR szData, int nCDATA );
|
||||
int x_RemoveElem( int iPos );
|
||||
void x_DocChange( int nLeft, int nReplace, const CString& csInsert );
|
||||
void x_PosInsert( int iPos, int nInsertLength );
|
||||
void x_Adjust( int iPos, int nShift, bool bAfterPos = false );
|
||||
CString x_TextToDoc( LPCTSTR szText, bool bAttrib = false ) const;
|
||||
CString x_TextFromDoc( int nLeft, int nRight ) const;
|
||||
};
|
||||
|
||||
#endif // !defined(AFX_MARKUP_H__948A2705_9E68_11D2_A0BF_00105A27C570__INCLUDED_)
|
||||
@@ -0,0 +1,288 @@
|
||||
#include "StdAfx.h"
|
||||
#include ".\myping.h"
|
||||
|
||||
CMyPing::CMyPing(void)
|
||||
{
|
||||
}
|
||||
|
||||
CMyPing::~CMyPing(void)
|
||||
{
|
||||
}
|
||||
|
||||
int CMyPing::SendEchoRequest(SOCKET s,LPSOCKADDR_IN lpstToAddr)
|
||||
{
|
||||
static ECHOREQUEST echoReq;
|
||||
static int nId = 1;
|
||||
static int nSeq = 1;
|
||||
int nRet;
|
||||
|
||||
// Fill in echo request
|
||||
echoReq.icmpHdr.Type = ICMP_ECHOREQ;
|
||||
echoReq.icmpHdr.Code = 0;
|
||||
echoReq.icmpHdr.Checksum = 0;
|
||||
echoReq.icmpHdr.ID = nId++;
|
||||
echoReq.icmpHdr.Seq = nSeq++;
|
||||
|
||||
// Fill in some data to send
|
||||
for (nRet = 0; nRet < REQ_DATASIZE; nRet++)
|
||||
echoReq.cData[nRet] = ' '+nRet;
|
||||
|
||||
// Save tick count when sent
|
||||
echoReq.dwTime = GetTickCount();
|
||||
|
||||
// Put data in packet and compute checksum
|
||||
echoReq.icmpHdr.Checksum = in_cksum((u_short *)&echoReq, sizeof(ECHOREQUEST));
|
||||
|
||||
// Send the echo request
|
||||
nRet = sendto(s, /* socket */
|
||||
(LPSTR)&echoReq, /* buffer */
|
||||
sizeof(ECHOREQUEST),
|
||||
0, /* flags */
|
||||
(LPSOCKADDR)lpstToAddr, /* destination */
|
||||
sizeof(SOCKADDR_IN)); /* address length */
|
||||
|
||||
if (nRet == SOCKET_ERROR)
|
||||
WSAError("sendto()");
|
||||
return (nRet);
|
||||
}
|
||||
|
||||
DWORD CMyPing::RecvEchoReply(SOCKET s, LPSOCKADDR_IN lpsaFrom, u_char *pTTL)
|
||||
{
|
||||
ECHOREPLY echoReply;
|
||||
int nRet;
|
||||
int nAddrLen = sizeof(struct sockaddr_in);
|
||||
|
||||
// Receive the echo reply
|
||||
nRet = recvfrom(s, // socket
|
||||
(LPSTR)&echoReply, // buffer
|
||||
sizeof(ECHOREPLY), // size of buffer
|
||||
0, // flags
|
||||
(LPSOCKADDR)lpsaFrom, // From address
|
||||
&nAddrLen); // pointer to address len
|
||||
|
||||
// Check return value
|
||||
if (nRet == SOCKET_ERROR)
|
||||
WSAError("recvfrom()");
|
||||
|
||||
// return time sent and IP TTL
|
||||
*pTTL = echoReply.ipHdr.TTL;
|
||||
|
||||
return(echoReply.echoRequest.dwTime);
|
||||
}
|
||||
|
||||
int CMyPing::WaitForEchoReply(SOCKET s)
|
||||
{
|
||||
struct timeval Timeout;
|
||||
fd_set readfds;
|
||||
|
||||
readfds.fd_count = 1;
|
||||
readfds.fd_array[0] = s;
|
||||
Timeout.tv_sec = 1;
|
||||
Timeout.tv_usec = 0;
|
||||
|
||||
return(select(1, &readfds, NULL, NULL, &Timeout));
|
||||
}
|
||||
|
||||
void CMyPing::WSAError(LPCSTR lpMsg)
|
||||
{
|
||||
CString strMsg;
|
||||
strMsg.Format("%s - WSAError: %ld",lpMsg,WSAGetLastError());
|
||||
MessageBox(NULL,strMsg,"ERROR",MB_OK);
|
||||
}
|
||||
|
||||
u_short CMyPing::in_cksum(u_short *addr, int len)
|
||||
{
|
||||
register int nleft = len;
|
||||
register u_short *w = addr;
|
||||
register u_short answer;
|
||||
register int sum = 0;
|
||||
|
||||
/*
|
||||
* Our algorithm is simple, using a 32 bit accumulator (sum),
|
||||
* we add sequential 16 bit words to it, and at the end, fold
|
||||
* back all the carry bits from the top 16 bits into the lower
|
||||
* 16 bits.
|
||||
*/
|
||||
while( nleft > 1 ) {
|
||||
sum += *w++;
|
||||
nleft -= 2;
|
||||
}
|
||||
|
||||
/* mop up an odd byte, if necessary */
|
||||
if( nleft == 1 ) {
|
||||
u_short u = 0;
|
||||
|
||||
*(u_char *)(&u) = *(u_char *)w ;
|
||||
sum += u;
|
||||
}
|
||||
|
||||
/*
|
||||
* add back carry outs from top 16 bits to low 16 bits
|
||||
*/
|
||||
sum = (sum >> 16) + (sum & 0xffff); /* add hi 16 to low 16 */
|
||||
sum += (sum >> 16); /* add carry */
|
||||
answer = ~sum; /* truncate to 16 bits */
|
||||
return (answer);
|
||||
}
|
||||
|
||||
BOOL CMyPing::Ping(UINT nRetries,LPCSTR pstrHost)
|
||||
{
|
||||
SOCKET rawSocket;
|
||||
LPHOSTENT lpHost;
|
||||
// UINT nLoop;
|
||||
int nRet;
|
||||
struct sockaddr_in saDest;
|
||||
// struct sockaddr_in saSrc;
|
||||
// DWORD dwTimeSent;
|
||||
// DWORD dwElapsed;
|
||||
// u_char cTTL;
|
||||
|
||||
// CString str;
|
||||
|
||||
WSADATA wsa;
|
||||
if (WSAStartup(MAKEWORD(1, 1), &wsa) != 0)
|
||||
return FALSE;
|
||||
|
||||
// Create a Raw socket
|
||||
rawSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
if (rawSocket == SOCKET_ERROR)
|
||||
{
|
||||
WSAError("socket()");
|
||||
WSACleanup();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Lookup host
|
||||
lpHost = gethostbyname(pstrHost);
|
||||
if (lpHost == NULL)
|
||||
{
|
||||
// str.Format("Host not found: %s", pstrHost);
|
||||
WSACleanup();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Setup destination socket address
|
||||
saDest.sin_addr.s_addr = *((u_long FAR *) (lpHost->h_addr));
|
||||
saDest.sin_family = AF_INET;
|
||||
saDest.sin_port = htons(80);
|
||||
|
||||
if (connect(rawSocket, (SOCKADDR*)&saDest, sizeof(saDest)) == SOCKET_ERROR)
|
||||
{
|
||||
DWORD error = WSAGetLastError();
|
||||
closesocket(rawSocket);
|
||||
WSACleanup();
|
||||
return FALSE;
|
||||
}
|
||||
/*
|
||||
// Tell the user what we're doing
|
||||
str.Format("Pinging %s [%s] with %d bytes of data:",
|
||||
pstrHost,
|
||||
inet_ntoa(saDest.sin_addr),
|
||||
REQ_DATASIZE);
|
||||
|
||||
// Ping multiple times
|
||||
for (nLoop = 0; nLoop < nRetries; nLoop++)
|
||||
{
|
||||
// Send ICMP echo request
|
||||
SendEchoRequest(rawSocket, &saDest);
|
||||
|
||||
Sleep(1000);
|
||||
nRet = WaitForEchoReply(rawSocket);
|
||||
if (nRet == SOCKET_ERROR)
|
||||
{
|
||||
WSAError("select()");
|
||||
break;
|
||||
}
|
||||
|
||||
if (!nRet)
|
||||
{
|
||||
str.Format("Request Timed Out");
|
||||
WSACleanup();
|
||||
return FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Receive reply
|
||||
dwTimeSent = RecvEchoReply(rawSocket, &saSrc, &cTTL);
|
||||
|
||||
// Calculate elapsed time
|
||||
dwElapsed = GetTickCount() - dwTimeSent;
|
||||
str.Format("Reply[%d] from: %s: bytes=%d time=%ldms TTL=%d",
|
||||
nLoop+1,
|
||||
inet_ntoa(saSrc.sin_addr),
|
||||
REQ_DATASIZE,
|
||||
dwElapsed/100,
|
||||
cTTL);
|
||||
WSACleanup();
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
*/
|
||||
nRet = closesocket(rawSocket);
|
||||
if (nRet == SOCKET_ERROR)
|
||||
WSAError("closesocket()");
|
||||
|
||||
WSACleanup();
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
unsigned long conv_addr(const char *name)
|
||||
{
|
||||
struct hostent *he;
|
||||
int max;
|
||||
unsigned long retval;
|
||||
|
||||
if ((retval = inet_addr(name)) != INADDR_NONE)
|
||||
return retval;
|
||||
|
||||
he = gethostbyname(name);
|
||||
if (he == NULL)
|
||||
return INADDR_NONE;
|
||||
|
||||
for (max = 0; he->h_addr_list[max]; max++) ;
|
||||
if (max == 1) return *((unsigned long *)(he->h_addr_list[0]));
|
||||
else return *((unsigned long *)(he->h_addr_list[rand() % max]));
|
||||
}
|
||||
|
||||
BOOL CMyPing::Ping2(UINT nRetries,LPCSTR pstrHost)
|
||||
{
|
||||
return TRUE;
|
||||
|
||||
|
||||
LPHOSTENT lpHost;
|
||||
|
||||
SOCKET sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
if (sock == INVALID_SOCKET) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
bool bRet = false;
|
||||
DWORD dwWritten;
|
||||
char s[1024];
|
||||
|
||||
lpHost = gethostbyname(pstrHost);
|
||||
|
||||
sockaddr_in sa;
|
||||
sa.sin_family = AF_INET;
|
||||
sa.sin_addr.s_addr = *((u_long FAR *) (lpHost->h_addr));
|
||||
|
||||
sa.sin_port = htons(80);
|
||||
int nNonBlocking = 1;
|
||||
ioctlsocket(sock, FIONBIO, (u_long FAR*)&nNonBlocking);
|
||||
|
||||
if (connect(sock, (SOCKADDR*)&sa, sizeof(sa)) )
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (sock != INVALID_SOCKET)
|
||||
closesocket(sock);
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
#pragma pack(1)
|
||||
|
||||
#define ICMP_ECHOREPLY 0
|
||||
#define ICMP_ECHOREQ 8
|
||||
|
||||
class CMyPing
|
||||
{
|
||||
public:
|
||||
CMyPing(void);
|
||||
~CMyPing(void);
|
||||
private:
|
||||
int SendEchoRequest(SOCKET s,LPSOCKADDR_IN lpstToAddr);
|
||||
DWORD RecvEchoReply(SOCKET s, LPSOCKADDR_IN lpsaFrom, u_char *pTTL);
|
||||
int WaitForEchoReply(SOCKET s);
|
||||
void WSAError(LPCSTR lpMsg);
|
||||
u_short in_cksum(u_short *addr, int len);
|
||||
|
||||
// IP Header -- RFC 791
|
||||
typedef struct tagIPHDR
|
||||
{
|
||||
u_char VIHL; // Version and IHL
|
||||
u_char TOS; // Type Of Service
|
||||
short TotLen; // Total Length
|
||||
short ID; // Identification
|
||||
short FlagOff; // Flags and Fragment Offset
|
||||
u_char TTL; // Time To Live
|
||||
u_char Protocol; // Protocol
|
||||
u_short Checksum; // Checksum
|
||||
struct in_addr iaSrc; // Internet Address - Source
|
||||
struct in_addr iaDst; // Internet Address - Destination
|
||||
}IPHDR, *PIPHDR;
|
||||
|
||||
|
||||
// ICMP Header - RFC 792
|
||||
typedef struct tagICMPHDR
|
||||
{
|
||||
u_char Type; // Type
|
||||
u_char Code; // Code
|
||||
u_short Checksum; // Checksum
|
||||
u_short ID; // Identification
|
||||
u_short Seq; // Sequence
|
||||
char Data; // Data
|
||||
}ICMPHDR, *PICMPHDR;
|
||||
|
||||
|
||||
#define REQ_DATASIZE 32 // Echo Request Data size
|
||||
|
||||
// ICMP Echo Request
|
||||
typedef struct tagECHOREQUEST
|
||||
{
|
||||
ICMPHDR icmpHdr;
|
||||
DWORD dwTime;
|
||||
char cData[REQ_DATASIZE];
|
||||
}ECHOREQUEST, *PECHOREQUEST;
|
||||
|
||||
|
||||
// ICMP Echo Reply
|
||||
typedef struct tagECHOREPLY
|
||||
{
|
||||
IPHDR ipHdr;
|
||||
ECHOREQUEST echoRequest;
|
||||
char cFiller[256];
|
||||
}ECHOREPLY, *PECHOREPLY;
|
||||
|
||||
public:
|
||||
BOOL Ping(UINT nRetries,LPCSTR pstrHost);
|
||||
BOOL Ping2(UINT nRetries,LPCSTR pstrHost);
|
||||
};
|
||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@@ -0,0 +1,402 @@
|
||||
|
||||
|
||||
/* this ALWAYS GENERATED file contains the IIDs and CLSIDs */
|
||||
|
||||
/* link this file in with the server and any clients */
|
||||
|
||||
|
||||
/* File created by MIDL compiler version 6.00.0361 */
|
||||
/* at Tue Jul 26 18:51:36 2005
|
||||
*/
|
||||
/* Compiler settings for PTxSCP.IDL:
|
||||
Oicf, W1, Zp8, env=Win32 (32b run)
|
||||
protocol : dce , ms_ext, c_ext, robust
|
||||
error checks: allocation ref bounds_check enum stub_data
|
||||
VC __declspec() decoration level:
|
||||
__declspec(uuid()), __declspec(selectany), __declspec(novtable)
|
||||
DECLSPEC_UUID(), MIDL_INTERFACE()
|
||||
*/
|
||||
//@@MIDL_FILE_HEADING( )
|
||||
|
||||
#if !defined(_M_IA64) && !defined(_M_AMD64)
|
||||
|
||||
|
||||
#pragma warning( disable: 4049 ) /* more than 64k source lines */
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
#endif
|
||||
|
||||
|
||||
#include <rpc.h>
|
||||
#include <rpcndr.h>
|
||||
|
||||
#ifdef _MIDL_USE_GUIDDEF_
|
||||
|
||||
#ifndef INITGUID
|
||||
#define INITGUID
|
||||
#include <guiddef.h>
|
||||
#undef INITGUID
|
||||
#else
|
||||
#include <guiddef.h>
|
||||
#endif
|
||||
|
||||
#define MIDL_DEFINE_GUID(type,name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) \
|
||||
DEFINE_GUID(name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8)
|
||||
|
||||
#else // !_MIDL_USE_GUIDDEF_
|
||||
|
||||
#ifndef __IID_DEFINED__
|
||||
#define __IID_DEFINED__
|
||||
|
||||
typedef struct _IID
|
||||
{
|
||||
unsigned long x;
|
||||
unsigned short s1;
|
||||
unsigned short s2;
|
||||
unsigned char c[8];
|
||||
} IID;
|
||||
|
||||
#endif // __IID_DEFINED__
|
||||
|
||||
#ifndef CLSID_DEFINED
|
||||
#define CLSID_DEFINED
|
||||
typedef IID CLSID;
|
||||
#endif // CLSID_DEFINED
|
||||
|
||||
#define MIDL_DEFINE_GUID(type,name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) \
|
||||
const type name = {l,w1,w2,{b1,b2,b3,b4,b5,b6,b7,b8}}
|
||||
|
||||
#endif !_MIDL_USE_GUIDDEF_
|
||||
|
||||
MIDL_DEFINE_GUID(IID, LIBID_PTxSCP,0xC8E24C00,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(IID, IID_IPTxShHitTestInfo,0xC8E24C21,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(IID, IID_IPTxStrings,0xC8E24C42,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(IID, IID_IPTxDataObject,0xC8E24C43,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(IID, IID_IPTxShFolder,0xC8E24C20,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(IID, IID_IPTxGroup,0xC8E24C24,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(IID, DIID_IPTxGroupEvents,0xC8E24C25,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(IID, IID_IPTxContextMenu,0xC8E24C44,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(IID, IID_IPTxMenuItems,0xC8E24C46,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(IID, IID_IPTxMenuItem,0xC8E24C45,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(IID, IID_IPTxShUtils,0xC8E24C22,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(IID, IID_IPTxShLink,0xC8E24C30,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(IID, IID_IPTxShListColumn,0xC8E24C36,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(IID, IID_IPTxShListColumns,0xC8E24C37,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(IID, IID_IPTxShListItem,0xC8E24C32,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(IID, IID_IPTxShListItems,0xC8E24C33,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(IID, IID_IPTxShList,0xC8E24C34,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(IID, IID_IPTxShListSearch,0xC8E24C31,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(IID, DIID_IPTxShListEvents,0xC8E24C35,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(IID, IID_IPTxShTreeNode,0xC8E24C3E,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(IID, IID_IPTxShTreeNodes,0xC8E24C3F,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(IID, IID_IPTxShTree,0xC8E24C40,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(IID, DIID_IPTxShTreeEvents,0xC8E24C41,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(IID, IID_IPTxShComboItem,0xC8E24C27,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(IID, IID_IPTxShComboItems,0xC8E24C28,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(IID, IID_IPTxShCombo,0xC8E24C29,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(IID, DIID_IPTxShComboEvents,0xC8E24C2A,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(IID, IID_IPTxShOpenSaveDlg,0xC8E24C38,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(IID, DIID_IPTxShOpenSaveDlgEvents,0xC8E24C39,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(IID, IID_IPTxShFolderBrowseDlg,0xC8E24C2E,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(IID, DIID_IPTxShFolderBrowseDlgEvents,0xC8E24C2F,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(CLSID, CLSID_PTxGroup,0xC8E24C06,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(CLSID, CLSID_PTxContextMenu,0xC8E24C0D,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(CLSID, CLSID_PTxShUtils,0xC8E24C0C,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(CLSID, CLSID_PTxShLink,0xC8E24C05,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(CLSID, CLSID_PTxShList,0xC8E24C08,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(CLSID, CLSID_PTxShTree,0xC8E24C07,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(CLSID, CLSID_PTxShCombo,0xC8E24C09,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(CLSID, CLSID_PTxShOpenSaveDlg,0xC8E24C0A,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(CLSID, CLSID_PTxShFolderBrowseDlg,0xC8E24C0B,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
#undef MIDL_DEFINE_GUID
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif /* !defined(_M_IA64) && !defined(_M_AMD64)*/
|
||||
|
||||
|
||||
|
||||
/* this ALWAYS GENERATED file contains the IIDs and CLSIDs */
|
||||
|
||||
/* link this file in with the server and any clients */
|
||||
|
||||
|
||||
/* File created by MIDL compiler version 6.00.0361 */
|
||||
/* at Tue Jul 26 18:51:36 2005
|
||||
*/
|
||||
/* Compiler settings for PTxSCP.IDL:
|
||||
Oicf, W1, Zp8, env=Win64 (32b run,appending)
|
||||
protocol : dce , ms_ext, c_ext, robust
|
||||
error checks: allocation ref bounds_check enum stub_data
|
||||
VC __declspec() decoration level:
|
||||
__declspec(uuid()), __declspec(selectany), __declspec(novtable)
|
||||
DECLSPEC_UUID(), MIDL_INTERFACE()
|
||||
*/
|
||||
//@@MIDL_FILE_HEADING( )
|
||||
|
||||
#if defined(_M_IA64) || defined(_M_AMD64)
|
||||
|
||||
|
||||
#pragma warning( disable: 4049 ) /* more than 64k source lines */
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
#endif
|
||||
|
||||
|
||||
#include <rpc.h>
|
||||
#include <rpcndr.h>
|
||||
|
||||
#ifdef _MIDL_USE_GUIDDEF_
|
||||
|
||||
#ifndef INITGUID
|
||||
#define INITGUID
|
||||
#include <guiddef.h>
|
||||
#undef INITGUID
|
||||
#else
|
||||
#include <guiddef.h>
|
||||
#endif
|
||||
|
||||
#define MIDL_DEFINE_GUID(type,name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) \
|
||||
DEFINE_GUID(name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8)
|
||||
|
||||
#else // !_MIDL_USE_GUIDDEF_
|
||||
|
||||
#ifndef __IID_DEFINED__
|
||||
#define __IID_DEFINED__
|
||||
|
||||
typedef struct _IID
|
||||
{
|
||||
unsigned long x;
|
||||
unsigned short s1;
|
||||
unsigned short s2;
|
||||
unsigned char c[8];
|
||||
} IID;
|
||||
|
||||
#endif // __IID_DEFINED__
|
||||
|
||||
#ifndef CLSID_DEFINED
|
||||
#define CLSID_DEFINED
|
||||
typedef IID CLSID;
|
||||
#endif // CLSID_DEFINED
|
||||
|
||||
#define MIDL_DEFINE_GUID(type,name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) \
|
||||
const type name = {l,w1,w2,{b1,b2,b3,b4,b5,b6,b7,b8}}
|
||||
|
||||
#endif !_MIDL_USE_GUIDDEF_
|
||||
|
||||
MIDL_DEFINE_GUID(IID, LIBID_PTxSCP,0xC8E24C00,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(IID, IID_IPTxShHitTestInfo,0xC8E24C21,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(IID, IID_IPTxStrings,0xC8E24C42,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(IID, IID_IPTxDataObject,0xC8E24C43,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(IID, IID_IPTxShFolder,0xC8E24C20,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(IID, IID_IPTxGroup,0xC8E24C24,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(IID, DIID_IPTxGroupEvents,0xC8E24C25,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(IID, IID_IPTxContextMenu,0xC8E24C44,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(IID, IID_IPTxMenuItems,0xC8E24C46,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(IID, IID_IPTxMenuItem,0xC8E24C45,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(IID, IID_IPTxShUtils,0xC8E24C22,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(IID, IID_IPTxShLink,0xC8E24C30,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(IID, IID_IPTxShListColumn,0xC8E24C36,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(IID, IID_IPTxShListColumns,0xC8E24C37,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(IID, IID_IPTxShListItem,0xC8E24C32,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(IID, IID_IPTxShListItems,0xC8E24C33,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(IID, IID_IPTxShList,0xC8E24C34,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(IID, IID_IPTxShListSearch,0xC8E24C31,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(IID, DIID_IPTxShListEvents,0xC8E24C35,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(IID, IID_IPTxShTreeNode,0xC8E24C3E,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(IID, IID_IPTxShTreeNodes,0xC8E24C3F,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(IID, IID_IPTxShTree,0xC8E24C40,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(IID, DIID_IPTxShTreeEvents,0xC8E24C41,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(IID, IID_IPTxShComboItem,0xC8E24C27,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(IID, IID_IPTxShComboItems,0xC8E24C28,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(IID, IID_IPTxShCombo,0xC8E24C29,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(IID, DIID_IPTxShComboEvents,0xC8E24C2A,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(IID, IID_IPTxShOpenSaveDlg,0xC8E24C38,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(IID, DIID_IPTxShOpenSaveDlgEvents,0xC8E24C39,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(IID, IID_IPTxShFolderBrowseDlg,0xC8E24C2E,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(IID, DIID_IPTxShFolderBrowseDlgEvents,0xC8E24C2F,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(CLSID, CLSID_PTxGroup,0xC8E24C06,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(CLSID, CLSID_PTxContextMenu,0xC8E24C0D,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(CLSID, CLSID_PTxShUtils,0xC8E24C0C,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(CLSID, CLSID_PTxShLink,0xC8E24C05,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(CLSID, CLSID_PTxShList,0xC8E24C08,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(CLSID, CLSID_PTxShTree,0xC8E24C07,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(CLSID, CLSID_PTxShCombo,0xC8E24C09,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(CLSID, CLSID_PTxShOpenSaveDlg,0xC8E24C0A,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
|
||||
MIDL_DEFINE_GUID(CLSID, CLSID_PTxShFolderBrowseDlg,0xC8E24C0B,0xE2CA,0x11D1,0x81,0xA0,0x00,0x00,0x21,0x55,0x93,0x81);
|
||||
|
||||
#undef MIDL_DEFINE_GUID
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif /* defined(_M_IA64) || defined(_M_AMD64)*/
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
// 컴퓨터에서 Microsoft Visual C++를 사용하여 생성한 IDispatch 래퍼 클래스입니다.
|
||||
|
||||
// 참고: 이 파일의 내용을 수정하지 마십시오. Microsoft Visual C++에서
|
||||
// 이 클래스를 다시 생성할 때 수정한 내용을 덮어씁니다.
|
||||
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "ptxshcombo.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CPTxShCombo
|
||||
|
||||
IMPLEMENT_DYNCREATE(CPTxShCombo, CComboBox)
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CPTxShCombo 속성입니다.
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CPTxShCombo 작업입니다.
|
||||
@@ -0,0 +1,347 @@
|
||||
#pragma once
|
||||
|
||||
// 컴퓨터에서 Microsoft Visual C++를 사용하여 생성한 IDispatch 래퍼 클래스입니다.
|
||||
|
||||
// 참고: 이 파일의 내용을 수정하지 마십시오. Microsoft Visual C++에서
|
||||
// 이 클래스를 다시 생성할 때 수정한 내용을 덮어씁니다.
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CPTxShCombo 래퍼 클래스입니다.
|
||||
|
||||
class CPTxShCombo : public CComboBox
|
||||
{
|
||||
protected:
|
||||
DECLARE_DYNCREATE(CPTxShCombo)
|
||||
public:
|
||||
CLSID const& GetClsid()
|
||||
{
|
||||
static CLSID const clsid
|
||||
= { 0xC8E24C09, 0xE2CA, 0x11D1, { 0x81, 0xA0, 0x0, 0x0, 0x21, 0x55, 0x93, 0x81 } };
|
||||
return clsid;
|
||||
}
|
||||
virtual BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle,
|
||||
const RECT& rect, CWnd* pParentWnd, UINT nID,
|
||||
CCreateContext* pContext = NULL)
|
||||
{
|
||||
return CreateControl(GetClsid(), lpszWindowName, dwStyle, rect, pParentWnd, nID);
|
||||
}
|
||||
|
||||
BOOL Create(LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd,
|
||||
UINT nID, CFile* pPersist = NULL, BOOL bStorage = FALSE,
|
||||
BSTR bstrLicKey = NULL)
|
||||
{
|
||||
return CreateControl(GetClsid(), lpszWindowName, dwStyle, rect, pParentWnd, nID,
|
||||
pPersist, bStorage, bstrLicKey);
|
||||
}
|
||||
|
||||
// 특성
|
||||
public:
|
||||
enum
|
||||
{
|
||||
pttaLeftJustify = 0,
|
||||
pttaRightJustify = 1,
|
||||
pttaCenter = 2
|
||||
}TPTxAlignment;
|
||||
enum
|
||||
{
|
||||
ptbsNone = 0,
|
||||
ptbsFlat = 1,
|
||||
ptbsSunken = 2
|
||||
}TPTxBorderStyle;
|
||||
enum
|
||||
{
|
||||
csidlDesktop = 0,
|
||||
csidlPrograms = 2,
|
||||
csidlControls = 3,
|
||||
csidlPrinters = 4,
|
||||
csidlPersonal = 5,
|
||||
csidlFavorites = 6,
|
||||
csidlStartup = 7,
|
||||
csidlRecent = 8,
|
||||
csidlSendTo = 9,
|
||||
csidlBitBucket = 10,
|
||||
csidlRecycleBin = 10,
|
||||
csidlStartMenu = 11,
|
||||
csidlDesktopDirectory = 16,
|
||||
csidlDrives = 17,
|
||||
csidlNetwork = 18,
|
||||
csidlNethood = 19,
|
||||
csidlFonts = 20,
|
||||
csidlTemplates = 21,
|
||||
csidlCommonStartMenu = 22,
|
||||
csidlCommonPrograms = 23,
|
||||
csidlCommonStartup = 24,
|
||||
csidlCommonDesktopDirectory = 25,
|
||||
csidlAppData = 26,
|
||||
csidlPrintHood = 27,
|
||||
csidlNone = 28
|
||||
}TPTxCSIDL;
|
||||
enum
|
||||
{
|
||||
ptfsNone = 0,
|
||||
ptfsGroup = 1,
|
||||
ptfsLowered = 2,
|
||||
ptfsRaised = 3,
|
||||
ptfsDint = 4,
|
||||
ptfsBump = 5,
|
||||
ptfsSingle = 6,
|
||||
ptfsHorzLine = 7,
|
||||
ptfsHorzEdge = 8,
|
||||
ptfsVertLine = 9,
|
||||
ptfsVertEdge = 10
|
||||
}TPTxFrameStyle;
|
||||
enum
|
||||
{
|
||||
smallIcons = 0,
|
||||
largeIcons = 1
|
||||
}TPTxSysImageListSize;
|
||||
enum
|
||||
{
|
||||
ptvsIcon = 0,
|
||||
ptvsSmallIcon = 1,
|
||||
ptvsList = 2,
|
||||
ptvsReport = 3,
|
||||
ptvsThumbnails = 4
|
||||
}TPTxViewStyle;
|
||||
enum
|
||||
{
|
||||
ptlvhsdmNone = 0,
|
||||
ptlvhsdmLeftAlign = 1,
|
||||
ptlvhsdmRightOfText = 2,
|
||||
ptlvhsdmRightAlign = 3
|
||||
}TPTxLvHeaderSortDisplayMode;
|
||||
enum
|
||||
{
|
||||
ptlvsdLeft = 0,
|
||||
ptlvsdRight = 1,
|
||||
ptlvsdAbove = 2,
|
||||
ptlvsdBelow = 3,
|
||||
ptlvsdAll = 4
|
||||
}TPTxLvSearchDirection;
|
||||
enum
|
||||
{
|
||||
ptnaAdd = 0,
|
||||
ptnaAddFirst = 1,
|
||||
ptnaInsert = 2,
|
||||
ptnaAddChild = 3,
|
||||
ptnaAddChildFirst = 4
|
||||
}TPTxNodeAttachMode;
|
||||
|
||||
|
||||
// 작업
|
||||
public:
|
||||
|
||||
// IPTxShCombo
|
||||
|
||||
// Functions
|
||||
//
|
||||
|
||||
VARIANT get__ObjectDefault()
|
||||
{
|
||||
VARIANT result;
|
||||
InvokeHelper(0x0, DISPATCH_PROPERTYGET, VT_VARIANT, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void AboutBox()
|
||||
{
|
||||
InvokeHelper(DISPID_ABOUTBOX, DISPATCH_METHOD, VT_EMPTY, NULL, NULL);
|
||||
}
|
||||
unsigned long get_BackColor()
|
||||
{
|
||||
unsigned long result;
|
||||
InvokeHelper(DISPID_BACKCOLOR, DISPATCH_PROPERTYGET, VT_UI4, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_BackColor(unsigned long newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_UI4 ;
|
||||
InvokeHelper(DISPID_BACKCOLOR, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
unsigned long get_ForeColor()
|
||||
{
|
||||
unsigned long result;
|
||||
InvokeHelper(DISPID_FORECOLOR, DISPATCH_PROPERTYGET, VT_UI4, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_ForeColor(unsigned long newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_UI4 ;
|
||||
InvokeHelper(DISPID_FORECOLOR, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
BOOL get_Enabled()
|
||||
{
|
||||
BOOL result;
|
||||
InvokeHelper(0x1, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_Enabled(BOOL newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_BOOL ;
|
||||
InvokeHelper(0x1, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
BOOL get_Visible()
|
||||
{
|
||||
BOOL result;
|
||||
InvokeHelper(0x2, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_Visible(BOOL newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_BOOL ;
|
||||
InvokeHelper(0x2, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
LPDISPATCH get_Font()
|
||||
{
|
||||
LPDISPATCH result;
|
||||
InvokeHelper(DISPID_FONT, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_Font(LPDISPATCH newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_DISPATCH ;
|
||||
InvokeHelper(DISPID_FONT, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
long get_hWnd()
|
||||
{
|
||||
long result;
|
||||
InvokeHelper(DISPID_HWND, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
float get_IndentSize()
|
||||
{
|
||||
float result;
|
||||
InvokeHelper(0x3, DISPATCH_PROPERTYGET, VT_R4, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_IndentSize(float newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_R4 ;
|
||||
InvokeHelper(0x3, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
LPDISPATCH get_ShList()
|
||||
{
|
||||
LPDISPATCH result;
|
||||
InvokeHelper(0xa, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_ShList(LPDISPATCH newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_DISPATCH ;
|
||||
InvokeHelper(0xa, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
LPDISPATCH get_ShTree()
|
||||
{
|
||||
LPDISPATCH result;
|
||||
InvokeHelper(0xb, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_ShTree(LPDISPATCH newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_DISPATCH ;
|
||||
InvokeHelper(0xb, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
void Synchronize(BOOL aApplyToGroup)
|
||||
{
|
||||
static BYTE parms[] = VTS_BOOL ;
|
||||
InvokeHelper(0x4, DISPATCH_METHOD, VT_EMPTY, NULL, parms, aApplyToGroup);
|
||||
}
|
||||
void Refresh()
|
||||
{
|
||||
InvokeHelper(0x5, DISPATCH_METHOD, VT_EMPTY, NULL, NULL);
|
||||
}
|
||||
void GoUp(long aLevels)
|
||||
{
|
||||
static BYTE parms[] = VTS_I4 ;
|
||||
InvokeHelper(0x6, DISPATCH_METHOD, VT_EMPTY, NULL, parms, aLevels);
|
||||
}
|
||||
LPDISPATCH Items()
|
||||
{
|
||||
LPDISPATCH result;
|
||||
InvokeHelper(0x7, DISPATCH_METHOD, VT_DISPATCH, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
long get_SelectedIndex()
|
||||
{
|
||||
long result;
|
||||
InvokeHelper(0x8, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_SelectedIndex(long newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_I4 ;
|
||||
InvokeHelper(0x8, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
LPDISPATCH get_SelectedItem()
|
||||
{
|
||||
LPDISPATCH result;
|
||||
InvokeHelper(0x9, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
LPDISPATCH get_SelectedFolder()
|
||||
{
|
||||
LPDISPATCH result;
|
||||
InvokeHelper(0x11, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_SelectedFolder(LPDISPATCH newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_DISPATCH ;
|
||||
InvokeHelper(0x11, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
long get_DropDownLines()
|
||||
{
|
||||
long result;
|
||||
InvokeHelper(0xd, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_DropDownLines(long newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_I4 ;
|
||||
InvokeHelper(0xd, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
LPUNKNOWN get__IUnk()
|
||||
{
|
||||
LPUNKNOWN result;
|
||||
InvokeHelper(0xc, DISPATCH_PROPERTYGET, VT_UNKNOWN, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
BOOL get_VirtualFolders()
|
||||
{
|
||||
BOOL result;
|
||||
InvokeHelper(0xe, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_VirtualFolders(BOOL newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_BOOL ;
|
||||
InvokeHelper(0xe, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
BOOL get_IncludeNonFolders()
|
||||
{
|
||||
BOOL result;
|
||||
InvokeHelper(0xf, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_IncludeNonFolders(BOOL newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_BOOL ;
|
||||
InvokeHelper(0xf, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
BOOL get_AutoDropDownLines()
|
||||
{
|
||||
BOOL result;
|
||||
InvokeHelper(0x10, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_AutoDropDownLines(BOOL newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_BOOL ;
|
||||
InvokeHelper(0x10, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
|
||||
// Properties
|
||||
//
|
||||
|
||||
|
||||
|
||||
};
|
||||
@@ -0,0 +1,19 @@
|
||||
// 컴퓨터에서 Microsoft Visual C++를 사용하여 생성한 IDispatch 래퍼 클래스입니다.
|
||||
|
||||
// 참고: 이 파일의 내용을 수정하지 마십시오. Microsoft Visual C++에서
|
||||
// 이 클래스를 다시 생성할 때 수정한 내용을 덮어씁니다.
|
||||
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "ptxshlist.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CPTxShList
|
||||
|
||||
IMPLEMENT_DYNCREATE(CPTxShList, CListCtrl)
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CPTxShList 속성입니다.
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CPTxShList 작업입니다.
|
||||
@@ -0,0 +1,583 @@
|
||||
#pragma once
|
||||
|
||||
// 컴퓨터에서 Microsoft Visual C++를 사용하여 생성한 IDispatch 래퍼 클래스입니다.
|
||||
|
||||
// 참고: 이 파일의 내용을 수정하지 마십시오. Microsoft Visual C++에서
|
||||
// 이 클래스를 다시 생성할 때 수정한 내용을 덮어씁니다.
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CPTxShList 래퍼 클래스입니다.
|
||||
|
||||
class CPTxShList : public CListCtrl
|
||||
{
|
||||
protected:
|
||||
DECLARE_DYNCREATE(CPTxShList)
|
||||
public:
|
||||
CLSID const& GetClsid()
|
||||
{
|
||||
static CLSID const clsid
|
||||
= { 0xC8E24C08, 0xE2CA, 0x11D1, { 0x81, 0xA0, 0x0, 0x0, 0x21, 0x55, 0x93, 0x81 } };
|
||||
return clsid;
|
||||
}
|
||||
virtual BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle,
|
||||
const RECT& rect, CWnd* pParentWnd, UINT nID,
|
||||
CCreateContext* pContext = NULL)
|
||||
{
|
||||
return CreateControl(GetClsid(), lpszWindowName, dwStyle, rect, pParentWnd, nID);
|
||||
}
|
||||
|
||||
BOOL Create(LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd,
|
||||
UINT nID, CFile* pPersist = NULL, BOOL bStorage = FALSE,
|
||||
BSTR bstrLicKey = NULL)
|
||||
{
|
||||
return CreateControl(GetClsid(), lpszWindowName, dwStyle, rect, pParentWnd, nID,
|
||||
pPersist, bStorage, bstrLicKey);
|
||||
}
|
||||
|
||||
// 특성
|
||||
public:
|
||||
enum
|
||||
{
|
||||
pttaLeftJustify = 0,
|
||||
pttaRightJustify = 1,
|
||||
pttaCenter = 2
|
||||
}TPTxAlignment;
|
||||
enum
|
||||
{
|
||||
ptbsNone = 0,
|
||||
ptbsFlat = 1,
|
||||
ptbsSunken = 2
|
||||
}TPTxBorderStyle;
|
||||
enum
|
||||
{
|
||||
csidlDesktop = 0,
|
||||
csidlPrograms = 2,
|
||||
csidlControls = 3,
|
||||
csidlPrinters = 4,
|
||||
csidlPersonal = 5,
|
||||
csidlFavorites = 6,
|
||||
csidlStartup = 7,
|
||||
csidlRecent = 8,
|
||||
csidlSendTo = 9,
|
||||
csidlBitBucket = 10,
|
||||
csidlRecycleBin = 10,
|
||||
csidlStartMenu = 11,
|
||||
csidlDesktopDirectory = 16,
|
||||
csidlDrives = 17,
|
||||
csidlNetwork = 18,
|
||||
csidlNethood = 19,
|
||||
csidlFonts = 20,
|
||||
csidlTemplates = 21,
|
||||
csidlCommonStartMenu = 22,
|
||||
csidlCommonPrograms = 23,
|
||||
csidlCommonStartup = 24,
|
||||
csidlCommonDesktopDirectory = 25,
|
||||
csidlAppData = 26,
|
||||
csidlPrintHood = 27,
|
||||
csidlNone = 28
|
||||
}TPTxCSIDL;
|
||||
enum
|
||||
{
|
||||
ptfsNone = 0,
|
||||
ptfsGroup = 1,
|
||||
ptfsLowered = 2,
|
||||
ptfsRaised = 3,
|
||||
ptfsDint = 4,
|
||||
ptfsBump = 5,
|
||||
ptfsSingle = 6,
|
||||
ptfsHorzLine = 7,
|
||||
ptfsHorzEdge = 8,
|
||||
ptfsVertLine = 9,
|
||||
ptfsVertEdge = 10
|
||||
}TPTxFrameStyle;
|
||||
enum
|
||||
{
|
||||
smallIcons = 0,
|
||||
largeIcons = 1
|
||||
}TPTxSysImageListSize;
|
||||
enum
|
||||
{
|
||||
ptvsIcon = 0,
|
||||
ptvsSmallIcon = 1,
|
||||
ptvsList = 2,
|
||||
ptvsReport = 3,
|
||||
ptvsThumbnails = 4
|
||||
}TPTxViewStyle;
|
||||
enum
|
||||
{
|
||||
ptlvhsdmNone = 0,
|
||||
ptlvhsdmLeftAlign = 1,
|
||||
ptlvhsdmRightOfText = 2,
|
||||
ptlvhsdmRightAlign = 3
|
||||
}TPTxLvHeaderSortDisplayMode;
|
||||
enum
|
||||
{
|
||||
ptlvsdLeft = 0,
|
||||
ptlvsdRight = 1,
|
||||
ptlvsdAbove = 2,
|
||||
ptlvsdBelow = 3,
|
||||
ptlvsdAll = 4
|
||||
}TPTxLvSearchDirection;
|
||||
enum
|
||||
{
|
||||
ptnaAdd = 0,
|
||||
ptnaAddFirst = 1,
|
||||
ptnaInsert = 2,
|
||||
ptnaAddChild = 3,
|
||||
ptnaAddChildFirst = 4
|
||||
}TPTxNodeAttachMode;
|
||||
|
||||
|
||||
// 작업
|
||||
public:
|
||||
|
||||
// IPTxShList
|
||||
|
||||
// Functions
|
||||
//
|
||||
|
||||
VARIANT get__ObjectDefault()
|
||||
{
|
||||
VARIANT result;
|
||||
InvokeHelper(0x0, DISPATCH_PROPERTYGET, VT_VARIANT, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
BOOL get_Visible()
|
||||
{
|
||||
BOOL result;
|
||||
InvokeHelper(0x1, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_Visible(BOOL newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_BOOL ;
|
||||
InvokeHelper(0x1, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
CString get_FileFilter()
|
||||
{
|
||||
CString result;
|
||||
InvokeHelper(0x10, DISPATCH_PROPERTYGET, VT_BSTR, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_FileFilter(LPCTSTR newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_BSTR ;
|
||||
InvokeHelper(0x10, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
BOOL get_GridLines()
|
||||
{
|
||||
BOOL result;
|
||||
InvokeHelper(0x11, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_GridLines(BOOL newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_BOOL ;
|
||||
InvokeHelper(0x11, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
BOOL get_HotTrack()
|
||||
{
|
||||
BOOL result;
|
||||
InvokeHelper(0x12, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_HotTrack(BOOL newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_BOOL ;
|
||||
InvokeHelper(0x12, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
BOOL get_RowSelect()
|
||||
{
|
||||
BOOL result;
|
||||
InvokeHelper(0x13, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_RowSelect(BOOL newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_BOOL ;
|
||||
InvokeHelper(0x13, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
unsigned long get_BackColor()
|
||||
{
|
||||
unsigned long result;
|
||||
InvokeHelper(DISPID_BACKCOLOR, DISPATCH_PROPERTYGET, VT_UI4, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_BackColor(unsigned long newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_UI4 ;
|
||||
InvokeHelper(DISPID_BACKCOLOR, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
unsigned long get_ForeColor()
|
||||
{
|
||||
unsigned long result;
|
||||
InvokeHelper(DISPID_FORECOLOR, DISPATCH_PROPERTYGET, VT_UI4, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_ForeColor(unsigned long newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_UI4 ;
|
||||
InvokeHelper(DISPID_FORECOLOR, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
LPDISPATCH get_Folder()
|
||||
{
|
||||
LPDISPATCH result;
|
||||
InvokeHelper(0xe, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_Folder(LPDISPATCH newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_DISPATCH ;
|
||||
InvokeHelper(0xe, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
LPDISPATCH get_Highlight()
|
||||
{
|
||||
LPDISPATCH result;
|
||||
InvokeHelper(0x2, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_Highlight(LPDISPATCH newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_DISPATCH ;
|
||||
InvokeHelper(0x2, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
BOOL get_HideSelection()
|
||||
{
|
||||
BOOL result;
|
||||
InvokeHelper(0x3, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_HideSelection(BOOL newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_BOOL ;
|
||||
InvokeHelper(0x3, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
BOOL get_Enabled()
|
||||
{
|
||||
BOOL result;
|
||||
InvokeHelper(DISPID_ENABLED, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_Enabled(BOOL newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_BOOL ;
|
||||
InvokeHelper(DISPID_ENABLED, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
BOOL get_Checkboxes()
|
||||
{
|
||||
BOOL result;
|
||||
InvokeHelper(0xb, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_Checkboxes(BOOL newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_BOOL ;
|
||||
InvokeHelper(0xb, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
LPDISPATCH get_Font()
|
||||
{
|
||||
LPDISPATCH result;
|
||||
InvokeHelper(DISPID_FONT, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_Font(LPDISPATCH newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_DISPATCH ;
|
||||
InvokeHelper(DISPID_FONT, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
long get_hWnd()
|
||||
{
|
||||
long result;
|
||||
InvokeHelper(DISPID_HWND, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
LPDISPATCH get_Items()
|
||||
{
|
||||
LPDISPATCH result;
|
||||
InvokeHelper(0x4, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
long get_BorderStyle()
|
||||
{
|
||||
long result;
|
||||
InvokeHelper(0x5, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_BorderStyle(long newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_I4 ;
|
||||
InvokeHelper(0x5, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
BOOL get_ReadOnly()
|
||||
{
|
||||
BOOL result;
|
||||
InvokeHelper(0x6, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_ReadOnly(BOOL newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_BOOL ;
|
||||
InvokeHelper(0x6, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
long get_ViewStyle()
|
||||
{
|
||||
long result;
|
||||
InvokeHelper(0x7, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_ViewStyle(long newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_I4 ;
|
||||
InvokeHelper(0x7, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
void GoUp(long aLevels)
|
||||
{
|
||||
static BYTE parms[] = VTS_I4 ;
|
||||
InvokeHelper(0x8, DISPATCH_METHOD, VT_EMPTY, NULL, parms, aLevels);
|
||||
}
|
||||
void AboutBox()
|
||||
{
|
||||
InvokeHelper(DISPID_ABOUTBOX, DISPATCH_METHOD, VT_EMPTY, NULL, NULL);
|
||||
}
|
||||
BOOL CreateNewFolder(BOOL aEditNow)
|
||||
{
|
||||
BOOL result;
|
||||
static BYTE parms[] = VTS_BOOL ;
|
||||
InvokeHelper(0x9, DISPATCH_METHOD, VT_BOOL, (void*)&result, parms, aEditNow);
|
||||
return result;
|
||||
}
|
||||
void Refresh()
|
||||
{
|
||||
InvokeHelper(DISPID_REFRESH, DISPATCH_METHOD, VT_EMPTY, NULL, NULL);
|
||||
}
|
||||
void Synchronize(BOOL aApplyToGroup)
|
||||
{
|
||||
static BYTE parms[] = VTS_BOOL ;
|
||||
InvokeHelper(0xa, DISPATCH_METHOD, VT_EMPTY, NULL, parms, aApplyToGroup);
|
||||
}
|
||||
LPDISPATCH get_Selected()
|
||||
{
|
||||
LPDISPATCH result;
|
||||
InvokeHelper(0xc, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_Selected(LPDISPATCH newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_DISPATCH ;
|
||||
InvokeHelper(0xc, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
BOOL get_AutoFill()
|
||||
{
|
||||
BOOL result;
|
||||
InvokeHelper(0x14, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_AutoFill(BOOL newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_BOOL ;
|
||||
InvokeHelper(0x14, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
BOOL get_NonFileSystemAncestors()
|
||||
{
|
||||
BOOL result;
|
||||
InvokeHelper(0x15, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_NonFileSystemAncestors(BOOL newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_BOOL ;
|
||||
InvokeHelper(0x15, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
BOOL get_DefaultKeyHandling()
|
||||
{
|
||||
BOOL result;
|
||||
InvokeHelper(0x16, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_DefaultKeyHandling(BOOL newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_BOOL ;
|
||||
InvokeHelper(0x16, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
BOOL get_ContextMenus()
|
||||
{
|
||||
BOOL result;
|
||||
InvokeHelper(0x17, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_ContextMenus(BOOL newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_BOOL ;
|
||||
InvokeHelper(0x17, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
BOOL get_DontChangeFolder()
|
||||
{
|
||||
BOOL result;
|
||||
InvokeHelper(0x18, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_DontChangeFolder(BOOL newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_BOOL ;
|
||||
InvokeHelper(0x18, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
BOOL get_DynamicRefresh()
|
||||
{
|
||||
BOOL result;
|
||||
InvokeHelper(0x19, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_DynamicRefresh(BOOL newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_BOOL ;
|
||||
InvokeHelper(0x19, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
BOOL get_HideFoldersWhenLinkedToTree()
|
||||
{
|
||||
BOOL result;
|
||||
InvokeHelper(0x1a, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_HideFoldersWhenLinkedToTree(BOOL newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_BOOL ;
|
||||
InvokeHelper(0x1a, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
BOOL get_OleDrag()
|
||||
{
|
||||
BOOL result;
|
||||
InvokeHelper(0x1b, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_OleDrag(BOOL newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_BOOL ;
|
||||
InvokeHelper(0x1b, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
BOOL get_OleDrop()
|
||||
{
|
||||
BOOL result;
|
||||
InvokeHelper(0x1c, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_OleDrop(BOOL newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_BOOL ;
|
||||
InvokeHelper(0x1c, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
BOOL get_FolderContextMenu()
|
||||
{
|
||||
BOOL result;
|
||||
InvokeHelper(0x1d, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_FolderContextMenu(BOOL newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_BOOL ;
|
||||
InvokeHelper(0x1d, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
LPUNKNOWN get__IUnk()
|
||||
{
|
||||
LPUNKNOWN result;
|
||||
InvokeHelper(0xd, DISPATCH_PROPERTYGET, VT_UNKNOWN, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
BOOL get_MultiSelect()
|
||||
{
|
||||
BOOL result;
|
||||
InvokeHelper(0x1e, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_MultiSelect(BOOL newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_BOOL ;
|
||||
InvokeHelper(0x1e, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
void DoCommandForAllSelected(LPCTSTR aCmd)
|
||||
{
|
||||
static BYTE parms[] = VTS_BSTR ;
|
||||
InvokeHelper(0x1f, DISPATCH_METHOD, VT_EMPTY, NULL, parms, aCmd);
|
||||
}
|
||||
void DoCommandForFolder(LPCTSTR aCmd)
|
||||
{
|
||||
static BYTE parms[] = VTS_BSTR ;
|
||||
InvokeHelper(0x20, DISPATCH_METHOD, VT_EMPTY, NULL, parms, aCmd);
|
||||
}
|
||||
void SortByColumn(long aColumn, BOOL aAscending)
|
||||
{
|
||||
static BYTE parms[] = VTS_I4 VTS_BOOL ;
|
||||
InvokeHelper(0x21, DISPATCH_METHOD, VT_EMPTY, NULL, parms, aColumn, aAscending);
|
||||
}
|
||||
BOOL get_ShowHidden()
|
||||
{
|
||||
BOOL result;
|
||||
InvokeHelper(0x22, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_ShowHidden(BOOL newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_BOOL ;
|
||||
InvokeHelper(0x22, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
LPDISPATCH get_Columns()
|
||||
{
|
||||
LPDISPATCH result;
|
||||
InvokeHelper(0x24, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
long get_HeaderSortDisplayMode()
|
||||
{
|
||||
long result;
|
||||
InvokeHelper(0x25, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_HeaderSortDisplayMode(long newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_I4 ;
|
||||
InvokeHelper(0x25, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
LPDISPATCH StartSearch()
|
||||
{
|
||||
LPDISPATCH result;
|
||||
InvokeHelper(0x26, DISPATCH_METHOD, VT_DISPATCH, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
LPDISPATCH HitTest(float x, float y)
|
||||
{
|
||||
LPDISPATCH result;
|
||||
static BYTE parms[] = VTS_R4 VTS_R4 ;
|
||||
InvokeHelper(0x27, DISPATCH_METHOD, VT_DISPATCH, (void*)&result, parms, x, y);
|
||||
return result;
|
||||
}
|
||||
LPDISPATCH HitTestInfo(float x, float y)
|
||||
{
|
||||
LPDISPATCH result;
|
||||
static BYTE parms[] = VTS_R4 VTS_R4 ;
|
||||
InvokeHelper(0x28, DISPATCH_METHOD, VT_DISPATCH, (void*)&result, parms, x, y);
|
||||
return result;
|
||||
}
|
||||
LPDISPATCH AddCustomItem(LPCTSTR aCaption, long AIconIndex)
|
||||
{
|
||||
LPDISPATCH result;
|
||||
static BYTE parms[] = VTS_BSTR VTS_I4 ;
|
||||
InvokeHelper(0x29, DISPATCH_METHOD, VT_DISPATCH, (void*)&result, parms, aCaption, AIconIndex);
|
||||
return result;
|
||||
}
|
||||
long get_SortColumn()
|
||||
{
|
||||
long result;
|
||||
InvokeHelper(0x2a, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_SortColumn(long newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_I4 ;
|
||||
InvokeHelper(0x2a, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
|
||||
// Properties
|
||||
//
|
||||
|
||||
|
||||
|
||||
};
|
||||
@@ -0,0 +1,19 @@
|
||||
// 컴퓨터에서 Microsoft Visual C++를 사용하여 생성한 IDispatch 래퍼 클래스입니다.
|
||||
|
||||
// 참고: 이 파일의 내용을 수정하지 마십시오. Microsoft Visual C++에서
|
||||
// 이 클래스를 다시 생성할 때 수정한 내용을 덮어씁니다.
|
||||
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "ptxshtree.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CPTxShTree
|
||||
|
||||
IMPLEMENT_DYNCREATE(CPTxShTree, CTreeCtrl)
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CPTxShTree 속성입니다.
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CPTxShTree 작업입니다.
|
||||
@@ -0,0 +1,533 @@
|
||||
#pragma once
|
||||
|
||||
// 컴퓨터에서 Microsoft Visual C++를 사용하여 생성한 IDispatch 래퍼 클래스입니다.
|
||||
|
||||
// 참고: 이 파일의 내용을 수정하지 마십시오. Microsoft Visual C++에서
|
||||
// 이 클래스를 다시 생성할 때 수정한 내용을 덮어씁니다.
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CPTxShTree 래퍼 클래스입니다.
|
||||
|
||||
class CPTxShTree : public CTreeCtrl
|
||||
{
|
||||
protected:
|
||||
DECLARE_DYNCREATE(CPTxShTree)
|
||||
public:
|
||||
CLSID const& GetClsid()
|
||||
{
|
||||
static CLSID const clsid
|
||||
= { 0xC8E24C07, 0xE2CA, 0x11D1, { 0x81, 0xA0, 0x0, 0x0, 0x21, 0x55, 0x93, 0x81 } };
|
||||
return clsid;
|
||||
}
|
||||
virtual BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle,
|
||||
const RECT& rect, CWnd* pParentWnd, UINT nID,
|
||||
CCreateContext* pContext = NULL)
|
||||
{
|
||||
return CreateControl(GetClsid(), lpszWindowName, dwStyle, rect, pParentWnd, nID);
|
||||
}
|
||||
|
||||
BOOL Create(LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd,
|
||||
UINT nID, CFile* pPersist = NULL, BOOL bStorage = FALSE,
|
||||
BSTR bstrLicKey = NULL)
|
||||
{
|
||||
return CreateControl(GetClsid(), lpszWindowName, dwStyle, rect, pParentWnd, nID,
|
||||
pPersist, bStorage, bstrLicKey);
|
||||
}
|
||||
|
||||
// 특성
|
||||
public:
|
||||
enum
|
||||
{
|
||||
pttaLeftJustify = 0,
|
||||
pttaRightJustify = 1,
|
||||
pttaCenter = 2
|
||||
}TPTxAlignment;
|
||||
enum
|
||||
{
|
||||
ptbsNone = 0,
|
||||
ptbsFlat = 1,
|
||||
ptbsSunken = 2
|
||||
}TPTxBorderStyle;
|
||||
enum
|
||||
{
|
||||
csidlDesktop = 0,
|
||||
csidlPrograms = 2,
|
||||
csidlControls = 3,
|
||||
csidlPrinters = 4,
|
||||
csidlPersonal = 5,
|
||||
csidlFavorites = 6,
|
||||
csidlStartup = 7,
|
||||
csidlRecent = 8,
|
||||
csidlSendTo = 9,
|
||||
csidlBitBucket = 10,
|
||||
csidlRecycleBin = 10,
|
||||
csidlStartMenu = 11,
|
||||
csidlDesktopDirectory = 16,
|
||||
csidlDrives = 17,
|
||||
csidlNetwork = 18,
|
||||
csidlNethood = 19,
|
||||
csidlFonts = 20,
|
||||
csidlTemplates = 21,
|
||||
csidlCommonStartMenu = 22,
|
||||
csidlCommonPrograms = 23,
|
||||
csidlCommonStartup = 24,
|
||||
csidlCommonDesktopDirectory = 25,
|
||||
csidlAppData = 26,
|
||||
csidlPrintHood = 27,
|
||||
csidlNone = 28
|
||||
}TPTxCSIDL;
|
||||
enum
|
||||
{
|
||||
ptfsNone = 0,
|
||||
ptfsGroup = 1,
|
||||
ptfsLowered = 2,
|
||||
ptfsRaised = 3,
|
||||
ptfsDint = 4,
|
||||
ptfsBump = 5,
|
||||
ptfsSingle = 6,
|
||||
ptfsHorzLine = 7,
|
||||
ptfsHorzEdge = 8,
|
||||
ptfsVertLine = 9,
|
||||
ptfsVertEdge = 10
|
||||
}TPTxFrameStyle;
|
||||
enum
|
||||
{
|
||||
smallIcons = 0,
|
||||
largeIcons = 1
|
||||
}TPTxSysImageListSize;
|
||||
enum
|
||||
{
|
||||
ptvsIcon = 0,
|
||||
ptvsSmallIcon = 1,
|
||||
ptvsList = 2,
|
||||
ptvsReport = 3,
|
||||
ptvsThumbnails = 4
|
||||
}TPTxViewStyle;
|
||||
enum
|
||||
{
|
||||
ptlvhsdmNone = 0,
|
||||
ptlvhsdmLeftAlign = 1,
|
||||
ptlvhsdmRightOfText = 2,
|
||||
ptlvhsdmRightAlign = 3
|
||||
}TPTxLvHeaderSortDisplayMode;
|
||||
enum
|
||||
{
|
||||
ptlvsdLeft = 0,
|
||||
ptlvsdRight = 1,
|
||||
ptlvsdAbove = 2,
|
||||
ptlvsdBelow = 3,
|
||||
ptlvsdAll = 4
|
||||
}TPTxLvSearchDirection;
|
||||
enum
|
||||
{
|
||||
ptnaAdd = 0,
|
||||
ptnaAddFirst = 1,
|
||||
ptnaInsert = 2,
|
||||
ptnaAddChild = 3,
|
||||
ptnaAddChildFirst = 4
|
||||
}TPTxNodeAttachMode;
|
||||
|
||||
|
||||
// 작업
|
||||
public:
|
||||
|
||||
// IPTxShTree
|
||||
|
||||
// Functions
|
||||
//
|
||||
|
||||
VARIANT get__ObjectDefault()
|
||||
{
|
||||
VARIANT result;
|
||||
InvokeHelper(0x0, DISPATCH_PROPERTYGET, VT_VARIANT, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void AboutBox()
|
||||
{
|
||||
InvokeHelper(DISPID_ABOUTBOX, DISPATCH_METHOD, VT_EMPTY, NULL, NULL);
|
||||
}
|
||||
BOOL get_Visible()
|
||||
{
|
||||
BOOL result;
|
||||
InvokeHelper(0x1, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_Visible(BOOL newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_BOOL ;
|
||||
InvokeHelper(0x1, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
void Refresh()
|
||||
{
|
||||
InvokeHelper(DISPID_REFRESH, DISPATCH_METHOD, VT_EMPTY, NULL, NULL);
|
||||
}
|
||||
unsigned long get_BackColor()
|
||||
{
|
||||
unsigned long result;
|
||||
InvokeHelper(DISPID_BACKCOLOR, DISPATCH_PROPERTYGET, VT_UI4, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_BackColor(unsigned long newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_UI4 ;
|
||||
InvokeHelper(DISPID_BACKCOLOR, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
unsigned long get_ForeColor()
|
||||
{
|
||||
unsigned long result;
|
||||
InvokeHelper(DISPID_FORECOLOR, DISPATCH_PROPERTYGET, VT_UI4, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_ForeColor(unsigned long newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_UI4 ;
|
||||
InvokeHelper(DISPID_FORECOLOR, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
LPDISPATCH get_BaseFolder()
|
||||
{
|
||||
LPDISPATCH result;
|
||||
InvokeHelper(0xe, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_BaseFolder(LPDISPATCH newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_DISPATCH ;
|
||||
InvokeHelper(0xe, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
LPDISPATCH get_SelectedNode()
|
||||
{
|
||||
LPDISPATCH result;
|
||||
InvokeHelper(0xf, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_SelectedNode(LPDISPATCH newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_DISPATCH ;
|
||||
InvokeHelper(0xf, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
LPDISPATCH get_SelectedFolder()
|
||||
{
|
||||
LPDISPATCH result;
|
||||
InvokeHelper(0x10, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_SelectedFolder(LPDISPATCH newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_DISPATCH ;
|
||||
InvokeHelper(0x10, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
long get_BorderStyle()
|
||||
{
|
||||
long result;
|
||||
InvokeHelper(0x2, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_BorderStyle(long newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_I4 ;
|
||||
InvokeHelper(0x2, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
LPDISPATCH get_Highlight()
|
||||
{
|
||||
LPDISPATCH result;
|
||||
InvokeHelper(0x3, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_Highlight(LPDISPATCH newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_DISPATCH ;
|
||||
InvokeHelper(0x3, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
BOOL get_Enabled()
|
||||
{
|
||||
BOOL result;
|
||||
InvokeHelper(DISPID_ENABLED, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_Enabled(BOOL newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_BOOL ;
|
||||
InvokeHelper(DISPID_ENABLED, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
LPDISPATCH get_Font()
|
||||
{
|
||||
LPDISPATCH result;
|
||||
InvokeHelper(DISPID_FONT, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_Font(LPDISPATCH newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_DISPATCH ;
|
||||
InvokeHelper(DISPID_FONT, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
BOOL get_HideSelection()
|
||||
{
|
||||
BOOL result;
|
||||
InvokeHelper(0x4, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_HideSelection(BOOL newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_BOOL ;
|
||||
InvokeHelper(0x4, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
long get_hWnd()
|
||||
{
|
||||
long result;
|
||||
InvokeHelper(DISPID_HWND, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
float get_Indentation()
|
||||
{
|
||||
float result;
|
||||
InvokeHelper(0x5, DISPATCH_PROPERTYGET, VT_R4, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_Indentation(float newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_R4 ;
|
||||
InvokeHelper(0x5, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
LPDISPATCH get_Nodes()
|
||||
{
|
||||
LPDISPATCH result;
|
||||
InvokeHelper(0x6, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
BOOL get_ReadOnly()
|
||||
{
|
||||
BOOL result;
|
||||
InvokeHelper(0x7, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_ReadOnly(BOOL newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_BOOL ;
|
||||
InvokeHelper(0x7, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
LPDISPATCH get_ShList()
|
||||
{
|
||||
LPDISPATCH result;
|
||||
InvokeHelper(0x8, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_ShList(LPDISPATCH newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_DISPATCH ;
|
||||
InvokeHelper(0x8, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
BOOL CreateNewFolder(BOOL aEditName)
|
||||
{
|
||||
BOOL result;
|
||||
static BYTE parms[] = VTS_BOOL ;
|
||||
InvokeHelper(0x9, DISPATCH_METHOD, VT_BOOL, (void*)&result, parms, aEditName);
|
||||
return result;
|
||||
}
|
||||
void GoUp(long aLevels)
|
||||
{
|
||||
static BYTE parms[] = VTS_I4 ;
|
||||
InvokeHelper(0xa, DISPATCH_METHOD, VT_EMPTY, NULL, parms, aLevels);
|
||||
}
|
||||
LPDISPATCH HitTest(float x, float y)
|
||||
{
|
||||
LPDISPATCH result;
|
||||
static BYTE parms[] = VTS_R4 VTS_R4 ;
|
||||
InvokeHelper(0xb, DISPATCH_METHOD, VT_DISPATCH, (void*)&result, parms, x, y);
|
||||
return result;
|
||||
}
|
||||
LPDISPATCH HitTestInfo(float x, float y)
|
||||
{
|
||||
LPDISPATCH result;
|
||||
static BYTE parms[] = VTS_R4 VTS_R4 ;
|
||||
InvokeHelper(0x1e, DISPATCH_METHOD, VT_DISPATCH, (void*)&result, parms, x, y);
|
||||
return result;
|
||||
}
|
||||
LPDISPATCH AddCustomNode(LPDISPATCH aRelative, LPCTSTR aCaption, long aClosedImageIndex, long aOpenImageIndex, long aAttachMode)
|
||||
{
|
||||
LPDISPATCH result;
|
||||
static BYTE parms[] = VTS_DISPATCH VTS_BSTR VTS_I4 VTS_I4 VTS_I4 ;
|
||||
InvokeHelper(0x1f, DISPATCH_METHOD, VT_DISPATCH, (void*)&result, parms, aRelative, aCaption, aClosedImageIndex, aOpenImageIndex, aAttachMode);
|
||||
return result;
|
||||
}
|
||||
LPDISPATCH AddCustomFirstNode(LPDISPATCH aSiblingNode, LPCTSTR aCaption, long aClosedImageIndex, long aOpenImageIndex)
|
||||
{
|
||||
LPDISPATCH result;
|
||||
static BYTE parms[] = VTS_DISPATCH VTS_BSTR VTS_I4 VTS_I4 ;
|
||||
InvokeHelper(0x20, DISPATCH_METHOD, VT_DISPATCH, (void*)&result, parms, aSiblingNode, aCaption, aClosedImageIndex, aOpenImageIndex);
|
||||
return result;
|
||||
}
|
||||
LPDISPATCH AddCustomChildNode(LPDISPATCH aParentNode, LPCTSTR aCaption, long aClosedImageIndex, long aOpenImageIndex)
|
||||
{
|
||||
LPDISPATCH result;
|
||||
static BYTE parms[] = VTS_DISPATCH VTS_BSTR VTS_I4 VTS_I4 ;
|
||||
InvokeHelper(0x21, DISPATCH_METHOD, VT_DISPATCH, (void*)&result, parms, aParentNode, aCaption, aClosedImageIndex, aOpenImageIndex);
|
||||
return result;
|
||||
}
|
||||
LPDISPATCH AddCustomChildFirstNode(LPDISPATCH aParentNode, LPCTSTR aCaption, long aClosedImageIndex, long aOpenImageIndex)
|
||||
{
|
||||
LPDISPATCH result;
|
||||
static BYTE parms[] = VTS_DISPATCH VTS_BSTR VTS_I4 VTS_I4 ;
|
||||
InvokeHelper(0x22, DISPATCH_METHOD, VT_DISPATCH, (void*)&result, parms, aParentNode, aCaption, aClosedImageIndex, aOpenImageIndex);
|
||||
return result;
|
||||
}
|
||||
void Synchronize(BOOL aApplyToGroup)
|
||||
{
|
||||
static BYTE parms[] = VTS_BOOL ;
|
||||
InvokeHelper(0xc, DISPATCH_METHOD, VT_EMPTY, NULL, parms, aApplyToGroup);
|
||||
}
|
||||
BOOL get_Checkboxes()
|
||||
{
|
||||
BOOL result;
|
||||
InvokeHelper(0x11, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_Checkboxes(BOOL newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_BOOL ;
|
||||
InvokeHelper(0x11, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
BOOL get_AutoFill()
|
||||
{
|
||||
BOOL result;
|
||||
InvokeHelper(0x12, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_AutoFill(BOOL newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_BOOL ;
|
||||
InvokeHelper(0x12, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
BOOL get_VirtualFolders()
|
||||
{
|
||||
BOOL result;
|
||||
InvokeHelper(0x13, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_VirtualFolders(BOOL newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_BOOL ;
|
||||
InvokeHelper(0x13, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
BOOL get_DefaultKeyHandling()
|
||||
{
|
||||
BOOL result;
|
||||
InvokeHelper(0x14, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_DefaultKeyHandling(BOOL newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_BOOL ;
|
||||
InvokeHelper(0x14, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
BOOL get_ContextMenus()
|
||||
{
|
||||
BOOL result;
|
||||
InvokeHelper(0x15, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_ContextMenus(BOOL newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_BOOL ;
|
||||
InvokeHelper(0x15, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
BOOL get_DynamicRefresh()
|
||||
{
|
||||
BOOL result;
|
||||
InvokeHelper(0x16, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_DynamicRefresh(BOOL newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_BOOL ;
|
||||
InvokeHelper(0x16, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
BOOL get_IncludeNonFolders()
|
||||
{
|
||||
BOOL result;
|
||||
InvokeHelper(0x17, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_IncludeNonFolders(BOOL newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_BOOL ;
|
||||
InvokeHelper(0x17, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
BOOL get_OleDrag()
|
||||
{
|
||||
BOOL result;
|
||||
InvokeHelper(0x18, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_OleDrag(BOOL newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_BOOL ;
|
||||
InvokeHelper(0x18, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
BOOL get_OleDrop()
|
||||
{
|
||||
BOOL result;
|
||||
InvokeHelper(0x19, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_OleDrop(BOOL newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_BOOL ;
|
||||
InvokeHelper(0x19, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
BOOL get_ShowButtons()
|
||||
{
|
||||
BOOL result;
|
||||
InvokeHelper(0x1a, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_ShowButtons(BOOL newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_BOOL ;
|
||||
InvokeHelper(0x1a, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
BOOL get_ShowLines()
|
||||
{
|
||||
BOOL result;
|
||||
InvokeHelper(0x1b, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_ShowLines(BOOL newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_BOOL ;
|
||||
InvokeHelper(0x1b, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
BOOL get_ShowRoot()
|
||||
{
|
||||
BOOL result;
|
||||
InvokeHelper(0x1c, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_ShowRoot(BOOL newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_BOOL ;
|
||||
InvokeHelper(0x1c, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
BOOL get_ShowHidden()
|
||||
{
|
||||
BOOL result;
|
||||
InvokeHelper(0x1d, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
void put_ShowHidden(BOOL newValue)
|
||||
{
|
||||
static BYTE parms[] = VTS_BOOL ;
|
||||
InvokeHelper(0x1d, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
|
||||
}
|
||||
LPUNKNOWN get__IUnk()
|
||||
{
|
||||
LPUNKNOWN result;
|
||||
InvokeHelper(0xd, DISPATCH_PROPERTYGET, VT_UNKNOWN, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
|
||||
// Properties
|
||||
//
|
||||
|
||||
|
||||
|
||||
};
|
||||
@@ -0,0 +1,425 @@
|
||||
#include "stdafx.h"
|
||||
#include "PathDialog.h"
|
||||
|
||||
#include <io.h>
|
||||
#include <errno.h>
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define new DEBUG_NEW
|
||||
#undef THIS_FILE
|
||||
static char THIS_FILE[] = __FILE__;
|
||||
#endif
|
||||
|
||||
#define IDC_FOLDERTREE 0x3741
|
||||
#define IDC_TITLE 0x3742
|
||||
#define IDC_STATUSTEXT 0x3743
|
||||
|
||||
//#define IDC_NEW_EDIT_PATH 0x3744
|
||||
#define IDC_NEW_EDIT_PATH 0xFFFF
|
||||
|
||||
|
||||
// Class CDlgWnd
|
||||
BEGIN_MESSAGE_MAP(CPathDialogSub, CWnd)
|
||||
ON_BN_CLICKED(IDOK, OnOK)
|
||||
ON_EN_CHANGE(IDC_NEW_EDIT_PATH, OnChangeEditPath)
|
||||
END_MESSAGE_MAP()
|
||||
|
||||
void CPathDialogSub::OnOK()
|
||||
{
|
||||
::GetWindowText(::GetDlgItem(m_hWnd, IDC_NEW_EDIT_PATH), m_pdlg->m_szPathName, MAX_PATH);
|
||||
|
||||
if (CPathDialog::MakeSurePathExists(m_pdlg->m_szPathName) == 0) {
|
||||
m_pdlg->m_bSuccess = TRUE;
|
||||
|
||||
::EndDialog(m_pdlg->m_hWnd, IDOK);
|
||||
}
|
||||
else {
|
||||
::SetFocus(::GetDlgItem(m_hWnd, IDC_NEW_EDIT_PATH));
|
||||
}
|
||||
}
|
||||
|
||||
void CPathDialogSub::OnChangeEditPath()
|
||||
{
|
||||
::GetWindowText(::GetDlgItem(m_hWnd, IDC_NEW_EDIT_PATH), m_pdlg->m_szPathName, MAX_PATH);
|
||||
|
||||
SendMessage(BFFM_ENABLEOK, 0, _tcslen(m_pdlg->m_szPathName) > 0);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CPathDialog dialog
|
||||
CPathDialog::CPathDialog(LPCTSTR pszCaption, LPCTSTR pszTitle, LPCTSTR pszInitialPath, CWnd* pParent)
|
||||
{
|
||||
m_dlg.m_pdlg = this;
|
||||
|
||||
m_hWnd = NULL;
|
||||
|
||||
// Get the true parent of the dialog
|
||||
m_pwndParent = CWnd::GetSafeOwner(pParent);
|
||||
|
||||
m_pszCaption = pszCaption;
|
||||
m_pszInitialPath = pszInitialPath;
|
||||
|
||||
memset(&m_bi, 0, sizeof(m_bi));
|
||||
m_bi.hwndOwner = !m_pwndParent ? NULL : m_pwndParent->GetSafeHwnd();
|
||||
m_bi.pszDisplayName = 0;
|
||||
m_bi.pidlRoot = 0;
|
||||
// m_bi.ulFlags = BIF_NEWDIALOGSTYLE | BIF_RETURNONLYFSDIRS | BIF_STATUSTEXT;
|
||||
m_bi.ulFlags = BIF_NEWDIALOGSTYLE;
|
||||
m_bi.lpfn = BrowseCallbackProc;
|
||||
m_bi.lpszTitle = pszTitle;
|
||||
// m_bi.lParam = (LPARAM)pszInitialPath;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CPathDialog message handlers
|
||||
|
||||
CString CPathDialog::GetPathName()
|
||||
{
|
||||
return m_szPathName;
|
||||
}
|
||||
|
||||
int CALLBACK CPathDialog::BrowseCallbackProc(HWND hwnd,UINT uMsg,LPARAM lParam, LPARAM pData)
|
||||
{
|
||||
CPathDialog* pdlg = (CPathDialog*)pData;
|
||||
|
||||
switch (uMsg) {
|
||||
case BFFM_INITIALIZED:
|
||||
{
|
||||
pdlg->m_hWnd = hwnd;
|
||||
|
||||
if (pdlg->m_pszCaption != NULL)
|
||||
::SetWindowText(hwnd, pdlg->m_pszCaption);
|
||||
|
||||
VERIFY(pdlg->m_dlg.SubclassWindow(hwnd));
|
||||
|
||||
::ShowWindow(::GetDlgItem(hwnd, IDC_STATUSTEXT), SW_HIDE);
|
||||
|
||||
RECT rc;
|
||||
::GetWindowRect(::GetDlgItem(hwnd, IDC_FOLDERTREE), &rc);
|
||||
|
||||
rc.bottom = rc.top - 2;
|
||||
rc.top = rc.bottom - 23;
|
||||
rc.left = rc.left + 2;
|
||||
::ScreenToClient(hwnd, (LPPOINT)&rc);
|
||||
::ScreenToClient(hwnd, ((LPPOINT)&rc) + 1);
|
||||
|
||||
HWND hwndEdit = ::CreateWindowEx(WS_EX_CLIENTEDGE, _T("EDIT"), _T(""),
|
||||
WS_VISIBLE | WS_CHILD | WS_TABSTOP,
|
||||
rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top,
|
||||
hwnd, NULL, NULL, NULL);
|
||||
::SetWindowLong(hwndEdit, GWL_ID, IDC_NEW_EDIT_PATH);
|
||||
::ShowWindow(hwndEdit, SW_SHOW);
|
||||
|
||||
HFONT hfont = (HFONT)::SendMessage(hwnd, WM_GETFONT, 0, 0);
|
||||
::SendMessage(hwndEdit, WM_SETFONT, (WPARAM)hfont, MAKELPARAM(TRUE, 0));
|
||||
|
||||
LPCTSTR lpszPath = pdlg->m_pszInitialPath;
|
||||
|
||||
TCHAR szPath[MAX_PATH];
|
||||
if (lpszPath == NULL) {
|
||||
::GetCurrentDirectory(MAX_PATH, szPath);
|
||||
lpszPath = szPath;
|
||||
}
|
||||
|
||||
if (GetFileAttributes(lpszPath) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND) {
|
||||
SHGetSpecialFolderPath(hwnd, szPath, CSIDL_PERSONAL, 0);
|
||||
lpszPath = szPath;
|
||||
}
|
||||
else
|
||||
::SendMessage(hwnd,BFFM_SETSELECTION, TRUE, (LPARAM)lpszPath);
|
||||
|
||||
::SetWindowText(::GetDlgItem(hwnd, IDC_NEW_EDIT_PATH), lpszPath);
|
||||
}
|
||||
|
||||
break;
|
||||
case BFFM_SELCHANGED:
|
||||
{
|
||||
char szSelection[MAX_PATH];
|
||||
// if (!::SHGetPathFromIDList((LPITEMIDLIST)lParam, szSelection) || szSelection[1]!=':') {
|
||||
if (!::SHGetPathFromIDList((LPITEMIDLIST)lParam, szSelection)) {
|
||||
szSelection[0] = NULL;
|
||||
::SendMessage(hwnd, BFFM_ENABLEOK, 0, FALSE);
|
||||
}
|
||||
else {
|
||||
::SendMessage(hwnd, BFFM_ENABLEOK, 0, TRUE);
|
||||
}
|
||||
|
||||
// ::SendMessage(hwnd,BFFM_SETSTATUSTEXT,0,(LPARAM)szSelection);
|
||||
::SetWindowText(::GetDlgItem(hwnd, IDC_NEW_EDIT_PATH), szSelection);
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CPathDialog::DoModal()
|
||||
{
|
||||
TCHAR szDiaplayName[MAX_PATH];
|
||||
|
||||
m_bi.lpfn = BrowseCallbackProc;
|
||||
m_bi.lParam = (LPARAM)this;
|
||||
m_bi.pszDisplayName = szDiaplayName;
|
||||
|
||||
LPITEMIDLIST pidl;
|
||||
LPMALLOC pmalloc;
|
||||
|
||||
int nRet = -1;
|
||||
if (SUCCEEDED(SHGetMalloc(&pmalloc))) {
|
||||
m_bSuccess = FALSE;
|
||||
|
||||
pidl = SHBrowseForFolder(&m_bi);
|
||||
if (pidl)
|
||||
pmalloc->Free(pidl);
|
||||
|
||||
if (m_bSuccess)
|
||||
nRet = IDOK;
|
||||
|
||||
pmalloc->Release();
|
||||
}
|
||||
|
||||
return nRet;
|
||||
}
|
||||
|
||||
BOOL CPathDialog::IsValidFileName(LPCTSTR pszFileName)
|
||||
{
|
||||
if (pszFileName == NULL)
|
||||
return FALSE;
|
||||
|
||||
int nLen = (int)_tcslen(pszFileName);
|
||||
if (nLen <= 0)
|
||||
return FALSE;
|
||||
|
||||
//check first char
|
||||
switch (pszFileName[0]) {
|
||||
case _T('.'):
|
||||
case _T(' '):
|
||||
case _T('\t'):
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
//check last char
|
||||
switch (pszFileName[nLen-1]) {
|
||||
case _T('.'):
|
||||
case _T(' '):
|
||||
case _T('\t'):
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
//check all
|
||||
int i = 0;
|
||||
while (pszFileName[i] != 0) {
|
||||
switch (pszFileName[i]) {
|
||||
case _T('\\'):
|
||||
case _T('/'):
|
||||
case _T(':'):
|
||||
case _T('*'):
|
||||
case _T('?'):
|
||||
case _T('\"'):
|
||||
case _T('<'):
|
||||
case _T('>'):
|
||||
case _T('|'):
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
const TCHAR c_FolderDoesNotPermission[] = _T(
|
||||
"폴더 : \n"
|
||||
"%s\n\n"
|
||||
"에 접근할 수 없습니다. 다른 위치를 선택하십시오."
|
||||
);
|
||||
const TCHAR c_FolderDoesNotExist[] = _T(
|
||||
"폴더 : \n"
|
||||
"%s\n\n"
|
||||
"가 존재하시 않습니다. 폴더를 생성하시겠습니까?"
|
||||
);
|
||||
const TCHAR c_szErrInvalidPath[] = _T(
|
||||
"폴더 : \n"
|
||||
"%s\n\n"
|
||||
"가 잘못되었습니다. 다시 입력하십시오."
|
||||
);
|
||||
const TCHAR c_szErrCreatePath[] = _T(
|
||||
"폴더 : \n"
|
||||
"%s\n\n"
|
||||
"를 만들 수 없습니다. 폴더이름을 확인하십시오."
|
||||
);
|
||||
|
||||
//return -1: user break;
|
||||
//return 0: no error
|
||||
//return 1: lpPath is invalid
|
||||
//return 2: can not create lpPath
|
||||
int CPathDialog::MakeSurePathExists(LPCTSTR pszPath)
|
||||
{
|
||||
int nRet;
|
||||
|
||||
CString sMessage;
|
||||
|
||||
try
|
||||
{
|
||||
//validate path
|
||||
nRet = Touch(pszPath, TRUE);
|
||||
if (nRet != 0)
|
||||
throw nRet;
|
||||
|
||||
if (_access(pszPath, 06) == 0) {
|
||||
if (pszPath[0] == '\\' && pszPath[1] == '\\') {
|
||||
char szFile[MAX_PATH];
|
||||
if (GetTempFileName(pszPath, "she", 0, szFile) == 0) {
|
||||
sMessage.Format(c_FolderDoesNotPermission, pszPath);
|
||||
AfxMessageBox(sMessage, MB_ICONWARNING);
|
||||
return -1;
|
||||
}
|
||||
DeleteFile(szFile);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (errno == ENOENT) {
|
||||
sMessage.Format(c_FolderDoesNotExist, pszPath);
|
||||
if (AfxMessageBox(sMessage, MB_YESNO | MB_ICONQUESTION) != IDYES)
|
||||
return -1;
|
||||
|
||||
//create path
|
||||
nRet = Touch(pszPath, FALSE);
|
||||
if (nRet != 0)
|
||||
throw nRet;
|
||||
}
|
||||
else if (errno == EACCES) {
|
||||
char szFile[MAX_PATH];
|
||||
if (!GetTempFileName(pszPath, "she", 0, szFile)) {
|
||||
sMessage.Format(c_FolderDoesNotPermission, pszPath);
|
||||
AfxMessageBox(sMessage, MB_ICONWARNING);
|
||||
return -1;
|
||||
}
|
||||
DeleteFile(szFile);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
catch (int nErrCode)
|
||||
{
|
||||
switch (nErrCode) {
|
||||
case 1:
|
||||
sMessage.Format(c_szErrInvalidPath, pszPath);
|
||||
break;
|
||||
case 2:
|
||||
default:
|
||||
sMessage.Format(c_szErrCreatePath, pszPath);
|
||||
break;
|
||||
}
|
||||
|
||||
AfxMessageBox(sMessage, MB_OK | MB_ICONEXCLAMATION);
|
||||
}
|
||||
|
||||
return nRet;
|
||||
}
|
||||
|
||||
//return 0: no error
|
||||
//return 1: lpPath is invalid
|
||||
//return 2: lpPath can not be created(bValidate == FALSE)
|
||||
int CPathDialog::Touch(LPCTSTR pszPath, BOOL bValidate)
|
||||
{
|
||||
if (pszPath == NULL)
|
||||
return 1;
|
||||
|
||||
TCHAR szPath[MAX_PATH];
|
||||
_tcscpy(szPath, pszPath);
|
||||
|
||||
int nLen = (int)_tcslen(szPath);
|
||||
|
||||
//path must be "x:\..."
|
||||
/*
|
||||
if ((nLen < 3)
|
||||
|| ((szPath[0] < _T('A') || _T('Z') < szPath[0])
|
||||
&& (szPath[0] < _T('a') || _T('z') < szPath[0])
|
||||
|| (szPath[1] != _T(':')) || (szPath[2] != _T('\\'))))
|
||||
*/
|
||||
|
||||
if (nLen == 3) {
|
||||
if (!bValidate) {
|
||||
if (_access(szPath, 0)!=0) {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int i = 3;
|
||||
|
||||
BOOL bLastOne = TRUE;
|
||||
LPTSTR lpCurrentName;
|
||||
while (szPath[i] != 0) {
|
||||
lpCurrentName = &szPath[i];
|
||||
while( (szPath[i]!=0) && (szPath[i]!=_T('\\')) )
|
||||
{
|
||||
i++;
|
||||
}
|
||||
|
||||
bLastOne =(szPath[i]==0);
|
||||
szPath[i] = 0;
|
||||
|
||||
if( !IsValidFileName(lpCurrentName) )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(!bValidate)
|
||||
{
|
||||
CreateDirectory(szPath, NULL);
|
||||
if(_taccess(szPath, 0)!=0)
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
if(bLastOne)
|
||||
{
|
||||
break; //it's done
|
||||
}
|
||||
else
|
||||
{
|
||||
szPath[i] = _T('\\');
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
return (bLastOne?0:1);
|
||||
}
|
||||
|
||||
//return 0: ok
|
||||
//return 1: error
|
||||
int CPathDialog::ConcatPath(LPTSTR lpRoot, LPCTSTR lpMorePath)
|
||||
{
|
||||
if (lpRoot==NULL)
|
||||
return 1;
|
||||
|
||||
int nLen = (int)_tcslen(lpRoot);
|
||||
|
||||
if (nLen<3)
|
||||
return 1;
|
||||
|
||||
if (lpMorePath == NULL)
|
||||
return 0;
|
||||
|
||||
if (nLen == 3) {
|
||||
_tcscat(lpRoot, lpMorePath);
|
||||
return 0;
|
||||
}
|
||||
|
||||
_tcscat(lpRoot, _T("\\"));
|
||||
_tcscat(lpRoot, lpMorePath);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
#pragma once
|
||||
|
||||
#include "shlobj.h"
|
||||
|
||||
class CPathDialog;
|
||||
|
||||
class CPathDialogSub : public CWnd
|
||||
{
|
||||
friend CPathDialog;
|
||||
|
||||
public:
|
||||
CPathDialog* m_pdlg;
|
||||
|
||||
protected:
|
||||
afx_msg void OnOK(); // OK button clicked
|
||||
afx_msg void OnChangeEditPath();
|
||||
DECLARE_MESSAGE_MAP()
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CPathDialog dialog
|
||||
|
||||
class CPathDialog
|
||||
{
|
||||
friend CPathDialogSub;
|
||||
|
||||
// Construction
|
||||
public:
|
||||
CPathDialog(LPCTSTR pszCaption = NULL, LPCTSTR pszTitle = NULL, LPCTSTR pszInitialPath = NULL, CWnd* pParent = NULL);
|
||||
|
||||
CString GetPathName();
|
||||
virtual int DoModal();
|
||||
|
||||
static int Touch(LPCTSTR pszPath, BOOL bValidate = TRUE);
|
||||
static int MakeSurePathExists(LPCTSTR pszPath);
|
||||
static BOOL IsValidFileName(LPCTSTR pszFileName);
|
||||
static int ConcatPath(LPTSTR pszRoot, LPCTSTR pszMorePath);
|
||||
|
||||
private:
|
||||
static int CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg,LPARAM lParam, LPARAM pData);
|
||||
|
||||
LPCTSTR m_pszCaption;
|
||||
LPCTSTR m_pszInitialPath;
|
||||
|
||||
TCHAR m_szPathName[MAX_PATH];
|
||||
|
||||
BROWSEINFO m_bi;
|
||||
HWND m_hWnd;
|
||||
CWnd* m_pwndParent;
|
||||
BOOL m_bSuccess;
|
||||
|
||||
CPathDialogSub m_dlg;
|
||||
};
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,305 @@
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// PictureEx.cpp: implementation of the CPictureEx class.
|
||||
//
|
||||
// Picture displaying control with support for the following formats:
|
||||
// GIF (including animated GIF87a and GIF89a), JPEG, BMP, WMF, ICO, CUR
|
||||
//
|
||||
// Written by Oleg Bykov (oleg_bykoff@rsdn.ru)
|
||||
// Copyright (c) 2001
|
||||
//
|
||||
// To use CPictureEx, follow these steps:
|
||||
// - place a static control on your dialog (either a text or a bitmap)
|
||||
// - change its identifier to something else (e.g. IDC_MYPIC)
|
||||
// - associate a CStatic with it using ClassWizard
|
||||
// - in your dialog's header file replace CStatic with CPictureEx
|
||||
// (don't forget to #include "PictureEx.h" and add
|
||||
// PictureEx.h and PictureEx.cpp to your project)
|
||||
// - call one of the overloaded CPictureEx::Load() functions somewhere
|
||||
// (OnInitDialog is a good place to start)
|
||||
// - if the preceding Load() succeeded call Draw()
|
||||
//
|
||||
// You can also add the control by defining a member variable of type
|
||||
// CPictureEx, calling CPictureEx::Create (derived from CStatic), then
|
||||
// CPictureEx::Load and CPictureEx::Draw.
|
||||
//
|
||||
// By default, the control initializes its background to COLOR_3DFACE
|
||||
// (see CPictureEx::PrepareDC()). You can change the background by
|
||||
// calling CPictureEx::SetBkColor(COLORREF) after CPictureEx::Load().
|
||||
//
|
||||
// I decided to leave in the class the functions to write separate frames from
|
||||
// animated GIF to disk. If you want to use them, uncomment #define GIF_TRACING
|
||||
// and an appropriate section in CPictureEx::Load(HGLOBAL, DWORD). These functions
|
||||
// won't be compiled and linked to your project unless you uncomment #define GIF_TRACING,
|
||||
// so you don't have to worry.
|
||||
//
|
||||
// Warning: this code hasn't been subject to a heavy testing, so
|
||||
// use it on your own risk. The author accepts no liability for the
|
||||
// possible damage caused by this code.
|
||||
//
|
||||
// Version 1.0 7 Aug 2001
|
||||
// Initial release
|
||||
//
|
||||
// Version 1.1 6 Sept 2001
|
||||
// ATL version of the class
|
||||
//
|
||||
// Version 1.2 14 Oct 2001
|
||||
// - Fixed a problem with loading GIFs from resources
|
||||
// in MFC-version of the class for multi-modules apps.
|
||||
// Thanks to Ruben Avila-Carretero for finding this out.
|
||||
//
|
||||
// - Got rid of waitable timer in ThreadAnimation()
|
||||
// Now CPictureEx[Wnd] works in Win95 too.
|
||||
// Thanks to Alex Egiazarov and Wayne King for the idea.
|
||||
//
|
||||
// - Fixed a visual glitch of using SetBkColor.
|
||||
// Thanks to Kwangjin Lee for finding this out.
|
||||
//
|
||||
// Version 1.3 10 Nov 2001
|
||||
// - Fixed a DC leak. One DC leaked per each UnLoad()
|
||||
// (forgot to put a ReleaseDC() in the end of
|
||||
// CPictureExWnd::PrepareDC() function).
|
||||
//
|
||||
// - Now it is possible to set a clipping rectangle using
|
||||
// CPictureEx[Wnd]::SetPaintRect(const LPRECT) function.
|
||||
// The LPRECT parameter tells the class what portion of
|
||||
// a picture should it display. If the clipping rect is
|
||||
// not set, the whole picture is shown.
|
||||
// Thanks to Fabrice Rodriguez for the idea.
|
||||
//
|
||||
// - Added support for Stop/Draw. Now you can Stop() an
|
||||
// animated GIF, then Draw() it again, it will continue
|
||||
// animation from the frame it was stopped on. You can
|
||||
// also know if a GIF is currently playing with the
|
||||
// IsPlaying() function.
|
||||
//
|
||||
// - Got rid of math.h and made m_bExitThread volatile.
|
||||
// Thanks to Piotr Sawicki for the suggestion.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_PICTUREEX_H__0EFE5DE0_7B68_4DB7_8B34_5DC634948438__INCLUDED_)
|
||||
#define AFX_PICTUREEX_H__0EFE5DE0_7B68_4DB7_8B34_5DC634948438__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
#include <vector>
|
||||
|
||||
//#define GIF_TRACING // uncomment it if you want detailed TRACEs
|
||||
|
||||
class CPictureEx : public CStatic
|
||||
{
|
||||
public:
|
||||
|
||||
struct TFrame // structure that keeps a single frame info
|
||||
{
|
||||
IPicture *m_pPicture; // pointer to the interface used for drawing
|
||||
SIZE m_frameSize;
|
||||
SIZE m_frameOffset;
|
||||
UINT m_nDelay; // delay (in 1/100s of a second)
|
||||
UINT m_nDisposal; // disposal method
|
||||
};
|
||||
|
||||
#pragma pack(1) // turn byte alignment on
|
||||
|
||||
enum GIFBlockTypes
|
||||
{
|
||||
BLOCK_UNKNOWN,
|
||||
BLOCK_APPEXT,
|
||||
BLOCK_COMMEXT,
|
||||
BLOCK_CONTROLEXT,
|
||||
BLOCK_PLAINTEXT,
|
||||
BLOCK_IMAGE,
|
||||
BLOCK_TRAILER
|
||||
};
|
||||
|
||||
enum ControlExtValues // graphic control extension packed field values
|
||||
{
|
||||
GCX_PACKED_DISPOSAL, // disposal method
|
||||
GCX_PACKED_USERINPUT,
|
||||
GCX_PACKED_TRANSPCOLOR
|
||||
};
|
||||
|
||||
enum LSDPackedValues // logical screen descriptor packed field values
|
||||
{
|
||||
LSD_PACKED_GLOBALCT,
|
||||
LSD_PACKED_CRESOLUTION,
|
||||
LSD_PACKED_SORT,
|
||||
LSD_PACKED_GLOBALCTSIZE
|
||||
};
|
||||
|
||||
enum IDPackedValues // image descriptor packed field values
|
||||
{
|
||||
ID_PACKED_LOCALCT,
|
||||
ID_PACKED_INTERLACE,
|
||||
ID_PACKED_SORT,
|
||||
ID_PACKED_LOCALCTSIZE
|
||||
};
|
||||
|
||||
struct TGIFHeader // GIF header
|
||||
{
|
||||
char m_cSignature[3]; // Signature - Identifies the GIF Data Stream
|
||||
// This field contains the fixed value 'GIF'
|
||||
char m_cVersion[3]; // Version number. May be one of the following:
|
||||
// "87a" or "89a"
|
||||
};
|
||||
|
||||
struct TGIFLSDescriptor // Logical Screen Descriptor
|
||||
{
|
||||
WORD m_wWidth; // 2 bytes. Logical screen width
|
||||
WORD m_wHeight; // 2 bytes. Logical screen height
|
||||
|
||||
unsigned char m_cPacked; // packed field
|
||||
|
||||
unsigned char m_cBkIndex; // 1 byte. Background color index
|
||||
unsigned char m_cPixelAspect; // 1 byte. Pixel aspect ratio
|
||||
inline int GetPackedValue(enum LSDPackedValues Value);
|
||||
};
|
||||
|
||||
struct TGIFAppExtension // application extension block
|
||||
{
|
||||
unsigned char m_cExtIntroducer; // extension introducer (0x21)
|
||||
unsigned char m_cExtLabel; // app. extension label (0xFF)
|
||||
unsigned char m_cBlockSize; // fixed value of 11
|
||||
char m_cAppIdentifier[8]; // application identifier
|
||||
char m_cAppAuth[3]; // application authentication code
|
||||
};
|
||||
|
||||
struct TGIFControlExt // graphic control extension block
|
||||
{
|
||||
unsigned char m_cExtIntroducer; // extension introducer (0x21)
|
||||
unsigned char m_cControlLabel; // control extension label (0xF9)
|
||||
unsigned char m_cBlockSize; // fixed value of 4
|
||||
unsigned char m_cPacked; // packed field
|
||||
WORD m_wDelayTime; // delay time
|
||||
unsigned char m_cTColorIndex; // transparent color index
|
||||
unsigned char m_cBlockTerm; // block terminator (0x00)
|
||||
public:
|
||||
inline int GetPackedValue(enum ControlExtValues Value);
|
||||
};
|
||||
|
||||
struct TGIFCommentExt // comment extension block
|
||||
{
|
||||
unsigned char m_cExtIntroducer; // extension introducer (0x21)
|
||||
unsigned char m_cCommentLabel; // comment extension label (0xFE)
|
||||
};
|
||||
|
||||
struct TGIFPlainTextExt // plain text extension block
|
||||
{
|
||||
unsigned char m_cExtIntroducer; // extension introducer (0x21)
|
||||
unsigned char m_cPlainTextLabel; // text extension label (0x01)
|
||||
unsigned char m_cBlockSize; // fixed value of 12
|
||||
WORD m_wLeftPos; // text grid left position
|
||||
WORD m_wTopPos; // text grid top position
|
||||
WORD m_wGridWidth; // text grid width
|
||||
WORD m_wGridHeight; // text grid height
|
||||
unsigned char m_cCellWidth; // character cell width
|
||||
unsigned char m_cCellHeight; // character cell height
|
||||
unsigned char m_cFgColor; // text foreground color index
|
||||
unsigned char m_cBkColor; // text background color index
|
||||
};
|
||||
|
||||
struct TGIFImageDescriptor // image descriptor block
|
||||
{
|
||||
unsigned char m_cImageSeparator; // image separator byte (0x2C)
|
||||
WORD m_wLeftPos; // image left position
|
||||
WORD m_wTopPos; // image top position
|
||||
WORD m_wWidth; // image width
|
||||
WORD m_wHeight; // image height
|
||||
unsigned char m_cPacked; // packed field
|
||||
inline int GetPackedValue(enum IDPackedValues Value);
|
||||
};
|
||||
|
||||
#pragma pack() // turn byte alignment off
|
||||
|
||||
public:
|
||||
BOOL GetPaintRect(RECT *lpRect);
|
||||
BOOL SetPaintRect(const RECT *lpRect);
|
||||
CPictureEx();
|
||||
virtual ~CPictureEx();
|
||||
void Stop(); // stops animation
|
||||
void UnLoad(); // stops animation plus releases all resources
|
||||
|
||||
BOOL IsGIF() const;
|
||||
BOOL IsPlaying() const;
|
||||
BOOL IsAnimatedGIF() const;
|
||||
SIZE GetSize() const;
|
||||
int GetFrameCount() const;
|
||||
COLORREF GetBkColor() const;
|
||||
void SetBkColor(COLORREF clr);
|
||||
|
||||
// draws the picture (starts an animation thread if needed)
|
||||
// if an animation was previously stopped by Stop(),
|
||||
// continues it from the last displayed frame
|
||||
BOOL Draw();
|
||||
|
||||
// loads a picture from a file
|
||||
// i.e. Load(_T("mypic.gif"));
|
||||
BOOL Load(LPCTSTR szFileName);
|
||||
|
||||
// loads a picture from a global memory block (allocated by GlobalAlloc)
|
||||
// Warning: this function DOES NOT free the global memory, pointed to by hGlobal
|
||||
BOOL Load(HGLOBAL hGlobal, DWORD dwSize);
|
||||
|
||||
// loads a picture from a program resource
|
||||
// i.e. Load(MAKEINTRESOURCE(IDR_MYPIC),_T("GIFTYPE"));
|
||||
BOOL Load(LPCTSTR szResourceName,LPCTSTR szResourceType);
|
||||
|
||||
protected:
|
||||
|
||||
#ifdef GIF_TRACING
|
||||
void EnumGIFBlocks();
|
||||
void WriteDataOnDisk(CString szFileName, HGLOBAL hData, DWORD dwSize);
|
||||
#endif // GIF_TRACING
|
||||
|
||||
RECT m_PaintRect;
|
||||
SIZE m_PictureSize;
|
||||
COLORREF m_clrBackground;
|
||||
UINT m_nCurrFrame;
|
||||
UINT m_nDataSize;
|
||||
UINT m_nCurrOffset;
|
||||
UINT m_nGlobalCTSize;
|
||||
BOOL m_bIsGIF;
|
||||
BOOL m_bIsPlaying;
|
||||
volatile BOOL m_bExitThread;
|
||||
BOOL m_bIsInitialized;
|
||||
HDC m_hMemDC;
|
||||
|
||||
HDC m_hDispMemDC;
|
||||
HBITMAP m_hDispMemBM;
|
||||
HBITMAP m_hDispOldBM;
|
||||
|
||||
HBITMAP m_hBitmap;
|
||||
HBITMAP m_hOldBitmap;
|
||||
HANDLE m_hThread;
|
||||
HANDLE m_hExitEvent;
|
||||
IPicture * m_pPicture;
|
||||
TGIFHeader * m_pGIFHeader;
|
||||
unsigned char * m_pRawData;
|
||||
TGIFLSDescriptor * m_pGIFLSDescriptor;
|
||||
std::vector<TFrame> m_arrFrames;
|
||||
|
||||
void ThreadAnimation();
|
||||
static UINT WINAPI _ThreadAnimation(LPVOID pParam);
|
||||
|
||||
int GetNextBlockLen() const;
|
||||
BOOL SkipNextBlock();
|
||||
BOOL SkipNextGraphicBlock();
|
||||
BOOL PrepareDC(int nWidth, int nHeight);
|
||||
void ResetDataPointer();
|
||||
enum GIFBlockTypes GetNextBlock() const;
|
||||
UINT GetSubBlocksLen(UINT nStartingOffset) const;
|
||||
HGLOBAL GetNextGraphicBlock(UINT *pBlockLen, UINT *pDelay,
|
||||
SIZE *pBlockSize, SIZE *pBlockOffset, UINT *pDisposal);
|
||||
|
||||
// Generated message map functions
|
||||
//{{AFX_MSG(CPictureEx)
|
||||
afx_msg void OnDestroy();
|
||||
afx_msg void OnPaint();
|
||||
//}}AFX_MSG
|
||||
|
||||
DECLARE_MESSAGE_MAP()
|
||||
};
|
||||
|
||||
#endif // !defined(AFX_PICTUREEX_H__0EFE5DE0_7B68_4DB7_8B34_5DC634948438__INCLUDED_)
|
||||
@@ -0,0 +1,100 @@
|
||||
// RegUtil.cpp: implementation of the CRegUtil class.
|
||||
//
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "RegUtil.h"
|
||||
|
||||
#ifdef _DEBUG
|
||||
#undef THIS_FILE
|
||||
static char THIS_FILE[]=__FILE__;
|
||||
#define new DEBUG_NEW
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
CRegUtil::CRegUtil()
|
||||
{
|
||||
m_hKey = NULL;
|
||||
}
|
||||
|
||||
CRegUtil::~CRegUtil()
|
||||
{
|
||||
if (!m_hKey)
|
||||
CloseKey();
|
||||
}
|
||||
|
||||
BOOL CRegUtil::OpenKey(HKEY hKey, CString sKey)
|
||||
{
|
||||
LONG lRet = RegOpenKeyEx(hKey, TEXT(sKey), 0, KEY_ALL_ACCESS, &m_hKey);
|
||||
if (lRet == ERROR_SUCCESS)
|
||||
return TRUE;
|
||||
else {
|
||||
DWORD dwDisp;
|
||||
|
||||
lRet = RegCreateKeyEx(hKey, TEXT(sKey), 0, "REG_BINARY", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, 0, &m_hKey, &dwDisp);
|
||||
if(lRet == ERROR_SUCCESS)
|
||||
return TRUE;
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
void CRegUtil::CloseKey()
|
||||
{
|
||||
if (m_hKey)
|
||||
RegCloseKey(m_hKey);
|
||||
|
||||
m_hKey = NULL;
|
||||
}
|
||||
|
||||
BOOL CRegUtil::SetStrValue(CString sName, CString sValue)
|
||||
{
|
||||
TCHAR szValue[MAX_PATH] = {'\0'};
|
||||
|
||||
_tcscpy(szValue, sValue);
|
||||
|
||||
LONG lRet = RegSetValueEx(m_hKey, TEXT(sName), NULL, REG_SZ, (PBYTE)&szValue, (DWORD)strlen(szValue));
|
||||
if (lRet == ERROR_SUCCESS)
|
||||
return TRUE;
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
CString CRegUtil::GetStrValue(CString sName)
|
||||
{
|
||||
DWORD dwType = REG_SZ;
|
||||
char szValue[MAX_PATH];
|
||||
DWORD dwLength = sizeof(szValue);
|
||||
|
||||
LONG lRet = RegQueryValueEx(m_hKey, TEXT(sName), NULL, &dwType, (PBYTE)szValue, &dwLength);
|
||||
if (lRet == ERROR_SUCCESS) {
|
||||
szValue[dwLength] = NULL;
|
||||
return CString(szValue);
|
||||
}
|
||||
else
|
||||
return "";
|
||||
}
|
||||
|
||||
BOOL CRegUtil::SetNumValue(CString sName, UINT nValue)
|
||||
{
|
||||
LONG lRet = RegSetValueEx(m_hKey, TEXT(sName), NULL, REG_DWORD, (PBYTE)&nValue, (DWORD)sizeof(nValue));
|
||||
if (lRet == ERROR_SUCCESS)
|
||||
return TRUE;
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
UINT CRegUtil::GetNumValue(CString sName)
|
||||
{
|
||||
DWORD dwType = REG_DWORD;
|
||||
DWORD dwValue;
|
||||
DWORD dwLength = sizeof(DWORD);
|
||||
|
||||
LONG lRet = RegQueryValueEx(m_hKey, TEXT(sName), NULL, &dwType, (PBYTE)&dwValue, &dwLength);
|
||||
if (lRet == ERROR_SUCCESS)
|
||||
return (UINT)dwValue;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
// RegUtil.h: interface for the CRegUtil class.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
class CRegUtil
|
||||
{
|
||||
public:
|
||||
CRegUtil();
|
||||
virtual ~CRegUtil();
|
||||
|
||||
public:
|
||||
BOOL OpenKey(HKEY, CString);
|
||||
void CloseKey();
|
||||
|
||||
BOOL SetStrValue(CString, CString);
|
||||
CString GetStrValue(CString);
|
||||
BOOL SetNumValue(CString, UINT);
|
||||
UINT GetNumValue(CString);
|
||||
|
||||
private:
|
||||
HKEY m_hKey;
|
||||
};
|
||||
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#define AXSTATE_COMPLETE 1
|
||||
#define AXSTATE_SKIPED 2
|
||||
#define AXSTATE_CANCELED 3
|
||||
#define AXSTATE_ERROR 4
|
||||
|
||||
#define AXCLOSE_COMPLETE 1
|
||||
#define AXCLOSE_CANCELED 2
|
||||
#define AXCLOSE_WITHERROR 3
|
||||
|
||||
#define AXERROR_INVALID_PROPERTIES 20001
|
||||
#define AXERROR_TRANSFER_IS_BUSY 20002
|
||||
@@ -0,0 +1,219 @@
|
||||
// ShellContextMenu.cpp: implementation of the CShellContextMenu class.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2000-2001 by Paolo Messina
|
||||
// (http://www.geocities.com/ppescher - ppescher@yahoo.com)
|
||||
//
|
||||
// The contents of this file are subject to the Artistic License (the "License").
|
||||
// You may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at:
|
||||
// http://www.opensource.org/licenses/artistic-license.html
|
||||
//
|
||||
// If you find this code useful, credits would be nice!
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "ShellContextMenu.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
BOOL CShellContextMenu::InvokeCommand(UINT nCmdID)
|
||||
{
|
||||
if (!IsValid() || !IsCommandInRange(nCmdID))
|
||||
return FALSE;
|
||||
|
||||
CMINVOKECOMMANDINFO cmi;
|
||||
ZeroMemory(&cmi, sizeof(CMINVOKECOMMANDINFO));
|
||||
cmi.cbSize = sizeof(CMINVOKECOMMANDINFO);
|
||||
cmi.hwnd = m_pOwner->GetSafeHwnd();
|
||||
cmi.lpVerb = MAKEINTRESOURCE(nCmdID - m_nCmdFirstID);
|
||||
cmi.nShow = SW_SHOWNORMAL;
|
||||
|
||||
return (NOERROR == m_pCtxMenu->InvokeCommand(&cmi));
|
||||
}
|
||||
|
||||
BOOL CShellContextMenu::FillMenu(CMenu *pMenu, UINT nStartIndex, UINT nCmdFirstID, UINT nCmdLastID, UINT nFlags)
|
||||
{
|
||||
if (!IsValid())
|
||||
return FALSE;
|
||||
|
||||
m_nCmdFirstID = nCmdFirstID;
|
||||
m_nCmdLastID = nCmdLastID;
|
||||
|
||||
UINT nDefID = pMenu->GetDefaultItem(GMDI_USEDISABLED, TRUE);
|
||||
|
||||
HRESULT hr = m_pCtxMenu->QueryContextMenu(pMenu->GetSafeHmenu(),
|
||||
nStartIndex, m_nCmdFirstID, m_nCmdLastID, nFlags);
|
||||
|
||||
if (nFlags & CMF_NODEFAULT)
|
||||
pMenu->SetDefaultItem(nDefID, TRUE);
|
||||
|
||||
if (FAILED(hr))
|
||||
{
|
||||
m_nCmdLastID = m_nCmdFirstID = 0;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
m_nCmdLastID = m_nCmdFirstID + HRESULT_CODE(hr) - 1;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL CShellContextMenu::HandleMenuMessage(UINT message, WPARAM wParam, LPARAM lParam, LRESULT *pLResult)
|
||||
{
|
||||
if (!IsValid())
|
||||
return FALSE;
|
||||
|
||||
switch (message)
|
||||
{
|
||||
case WM_MENUSELECT:
|
||||
{
|
||||
// look for a parent frame, to update its status bar
|
||||
if (m_pOwner == NULL)
|
||||
return FALSE;
|
||||
CFrameWnd* pFrame = m_pOwner->GetTopLevelFrame();
|
||||
if (pFrame == NULL)
|
||||
return FALSE;
|
||||
|
||||
// provide status bar text
|
||||
*pLResult = 0;
|
||||
CString sStatusText;
|
||||
|
||||
UINT uItem = (UINT) LOWORD(wParam);
|
||||
UINT fuFlags = (UINT) HIWORD(wParam);
|
||||
|
||||
if (fuFlags == 0xFFFF) // menu was closed
|
||||
return FALSE;
|
||||
|
||||
// get the first item of submenu, if popup item
|
||||
if (fuFlags & MF_POPUP)
|
||||
uItem = ::GetMenuItemID(::GetSubMenu((HMENU)lParam, uItem), 0);
|
||||
|
||||
// check if it's a valid item
|
||||
if (!(fuFlags & MF_SEPARATOR)
|
||||
&& (uItem == 0 || !IsCommandInRange(uItem)))
|
||||
return FALSE;
|
||||
|
||||
// get description
|
||||
if (!(fuFlags & MF_SEPARATOR))
|
||||
GetCommandDescription(uItem, sStatusText);
|
||||
|
||||
// update status text, even if empty
|
||||
pFrame->SetMessageText(sStatusText);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
break;
|
||||
|
||||
case WM_INITMENUPOPUP: // initialize sub-menus
|
||||
case WM_MEASUREITEM: // handle owner-draw items
|
||||
case WM_DRAWITEM:
|
||||
{
|
||||
// prepare result in case we handle the message
|
||||
// (if we don't, it will be discarded)
|
||||
*pLResult = TRUE;
|
||||
if (message == WM_INITMENUPOPUP)
|
||||
*pLResult = 0;
|
||||
|
||||
// check if it's a menu message
|
||||
if (message == WM_MEASUREITEM
|
||||
&& ((LPMEASUREITEMSTRUCT)lParam)->CtlType != ODT_MENU)
|
||||
return FALSE;
|
||||
if (message == WM_DRAWITEM
|
||||
&& ((LPDRAWITEMSTRUCT)lParam)->CtlType != ODT_MENU)
|
||||
return FALSE;
|
||||
|
||||
// these messages need interface version 2
|
||||
SContextMenu2Ptr pCtxMenu2(m_pCtxMenu);
|
||||
if (!pCtxMenu2.IsValid())
|
||||
return FALSE;
|
||||
|
||||
return (NOERROR == pCtxMenu2->HandleMenuMsg(message, wParam, lParam));
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BOOL CShellContextMenu::GetCommandDescription(UINT nCmdID, CString& rText)
|
||||
{
|
||||
if (!IsValid() || !IsCommandInRange(nCmdID))
|
||||
return FALSE;
|
||||
|
||||
// make a buffer large enough to hold either a Unicode or Ansi
|
||||
// string and initialize it to zeroes, because some shell
|
||||
// extensions return success even when they don't copy anything
|
||||
// to the buffer. Conversion is achieved by a CString object.
|
||||
WCHAR szHelpText[MAX_PATH];
|
||||
ZeroMemory(szHelpText, sizeof(WCHAR)*MAX_PATH);
|
||||
|
||||
// try with Unicode first (it seems Explorer does so)
|
||||
HRESULT hr = m_pCtxMenu->GetCommandString(nCmdID - m_nCmdFirstID,
|
||||
GCS_HELPTEXTW, NULL, (LPSTR)szHelpText, MAX_PATH);
|
||||
if (*(LPWSTR)szHelpText != 0) // buffer was used
|
||||
rText = (LPWSTR)szHelpText;
|
||||
else
|
||||
{
|
||||
// otherwise try with Ansi
|
||||
hr = m_pCtxMenu->GetCommandString(nCmdID - m_nCmdFirstID,
|
||||
GCS_HELPTEXTA, NULL, (LPSTR)szHelpText, MAX_PATH);
|
||||
if (*(LPSTR)szHelpText != 0) // buffer was used
|
||||
rText = (LPSTR)szHelpText;
|
||||
}
|
||||
|
||||
return SUCCEEDED(hr);
|
||||
}
|
||||
|
||||
BOOL CShellContextMenu::Create(IShellFolder *pParentFolder, LPCITEMIDLIST pidl)
|
||||
{
|
||||
m_pCtxMenu = SContextMenuPtr(pParentFolder, pidl);
|
||||
return m_pCtxMenu.IsValid();
|
||||
}
|
||||
|
||||
// a NULL pointer to unsubclass
|
||||
void CShellContextMenu::SetOwner(CWnd *pOwner)
|
||||
{
|
||||
if (m_pOwner != NULL || pOwner == NULL)
|
||||
UnsubclassOwner();
|
||||
|
||||
m_pOwner = pOwner;
|
||||
if (m_pOwner != NULL)
|
||||
SubclassOwner();
|
||||
}
|
||||
|
||||
const LPCTSTR SH_CTXMENU_OBJ = _T("ShellContextMenu");
|
||||
|
||||
void CShellContextMenu::SubclassOwner()
|
||||
{
|
||||
ASSERT(::IsWindow(m_pOwner->GetSafeHwnd()));
|
||||
|
||||
m_oldWndProc = (WNDPROC)::GetWindowLong(*m_pOwner, GWL_WNDPROC);
|
||||
::SetProp(*m_pOwner, SH_CTXMENU_OBJ, (HANDLE)this);
|
||||
::SetWindowLong(*m_pOwner, GWL_WNDPROC, (LONG)WindowProc);
|
||||
}
|
||||
|
||||
LRESULT CALLBACK CShellContextMenu::WindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
CShellContextMenu *pThis =
|
||||
(CShellContextMenu*)::GetProp(hwnd, SH_CTXMENU_OBJ);
|
||||
|
||||
LRESULT lResult;
|
||||
if (pThis->HandleMenuMessage(message, wParam, lParam, &lResult))
|
||||
return lResult; // success, no default processing
|
||||
|
||||
if (message == WM_DESTROY)
|
||||
pThis->UnsubclassOwner();
|
||||
|
||||
return ::CallWindowProc(pThis->m_oldWndProc, hwnd, message, wParam, lParam);
|
||||
}
|
||||
|
||||
void CShellContextMenu::UnsubclassOwner()
|
||||
{
|
||||
ASSERT(::IsWindow(m_pOwner->GetSafeHwnd()));
|
||||
|
||||
::RemoveProp(*m_pOwner, SH_CTXMENU_OBJ);
|
||||
::SetWindowLong(*m_pOwner, GWL_WNDPROC, (LONG)m_oldWndProc);
|
||||
m_pOwner = NULL;
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
// ShellContextMenu.h: interface for the CShellContextMenu class.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2000-2001 by Paolo Messina
|
||||
// (http://www.geocities.com/ppescher - ppescher@yahoo.com)
|
||||
//
|
||||
// The contents of this file are subject to the Artistic License (the "License").
|
||||
// You may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at:
|
||||
// http://www.opensource.org/licenses/artistic-license.html
|
||||
//
|
||||
// If you find this code useful, credits would be nice!
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_SHELLCONTEXTMENU_H__B690453B_A97A_4D33_A6A5_0A0BDE5EB1A4__INCLUDED_)
|
||||
#define AFX_SHELLCONTEXTMENU_H__B690453B_A97A_4D33_A6A5_0A0BDE5EB1A4__INCLUDED_
|
||||
|
||||
#include <shlobj.h>
|
||||
#include "ShellWrappers.h"
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
class CShellContextMenu
|
||||
{
|
||||
protected:
|
||||
SContextMenuPtr m_pCtxMenu;
|
||||
UINT m_nCmdFirstID;
|
||||
UINT m_nCmdLastID;
|
||||
CWnd* m_pOwner; // NULL means no owner (no subclassing in act)
|
||||
WNDPROC m_oldWndProc;
|
||||
|
||||
public:
|
||||
BOOL Create(IShellFolder* pParentFolder, LPCITEMIDLIST pidl);
|
||||
CShellContextMenu();
|
||||
virtual ~CShellContextMenu();
|
||||
|
||||
BOOL InvokeCommand(UINT nCmdID);
|
||||
|
||||
BOOL FillMenu(CMenu *pMenu, UINT nStartIndex = 0, UINT nCmdFirstID = 1, UINT nCmdLastID = 0x7FFF, UINT nFlags = 0);
|
||||
|
||||
BOOL HandleMenuMessage(UINT message, WPARAM wParam, LPARAM lParam, LRESULT *pLResult);
|
||||
|
||||
BOOL GetCommandDescription(UINT nCmdID, CString& rText);
|
||||
|
||||
BOOL IsValid();
|
||||
|
||||
// commands
|
||||
void GetCommandRange(UINT& nCmdFirstID, UINT& nCmdLastID);
|
||||
BOOL IsCommandInRange(UINT nCmdID);
|
||||
|
||||
// owner
|
||||
void SetOwner(CWnd *pOwner);
|
||||
CWnd* GetOwner();
|
||||
|
||||
protected:
|
||||
void SubclassOwner();
|
||||
void UnsubclassOwner();
|
||||
static LRESULT CALLBACK WindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
|
||||
};
|
||||
|
||||
// inline functions
|
||||
|
||||
inline CShellContextMenu::CShellContextMenu()
|
||||
{
|
||||
m_nCmdFirstID = 0;
|
||||
m_nCmdLastID = 0;
|
||||
m_pOwner = NULL;
|
||||
m_oldWndProc = NULL;
|
||||
}
|
||||
|
||||
inline CShellContextMenu::~CShellContextMenu()
|
||||
{
|
||||
if (m_pOwner != NULL)
|
||||
UnsubclassOwner();
|
||||
}
|
||||
|
||||
inline BOOL CShellContextMenu::IsValid()
|
||||
{
|
||||
return (m_pCtxMenu.IsValid());
|
||||
}
|
||||
|
||||
inline void CShellContextMenu::GetCommandRange(UINT &nCmdFirstID, UINT &nCmdLastID)
|
||||
{
|
||||
nCmdFirstID = m_nCmdFirstID;
|
||||
nCmdLastID = m_nCmdLastID;
|
||||
}
|
||||
|
||||
inline BOOL CShellContextMenu::IsCommandInRange(UINT nCmdID)
|
||||
{
|
||||
return IsValid() && (nCmdID >= m_nCmdFirstID && nCmdID <= m_nCmdLastID);
|
||||
}
|
||||
|
||||
inline CWnd* CShellContextMenu::GetOwner()
|
||||
{
|
||||
return m_pOwner;
|
||||
}
|
||||
|
||||
#endif // !defined(AFX_SHELLCONTEXTMENU_H__B690453B_A97A_4D33_A6A5_0A0BDE5EB1A4__INCLUDED_)
|
||||
@@ -0,0 +1,231 @@
|
||||
// ShellPidl.cpp: implementation of the CShellPidl class.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2000-2001 by Paolo Messina
|
||||
// (http://www.geocities.com/ppescher - ppescher@yahoo.com)
|
||||
//
|
||||
// The contents of this file are subject to the Artistic License (the "License").
|
||||
// You may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at:
|
||||
// http://www.opensource.org/licenses/artistic-license.html
|
||||
//
|
||||
// If you find this code useful, credits would be nice!
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "stdafx.h"
|
||||
#include <afxpriv.h>
|
||||
#include "ShellPidl.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Static Functions
|
||||
|
||||
// does not include terminating zero
|
||||
// NULL objects get a zero length
|
||||
UINT CShellPidl::ILGetLength(LPCITEMIDLIST pidl)
|
||||
{
|
||||
if (pidl == NULL)
|
||||
return 0;
|
||||
|
||||
UINT length = 0, cb;
|
||||
do
|
||||
{
|
||||
cb = pidl->mkid.cb;
|
||||
pidl = (LPCITEMIDLIST)((LPBYTE)pidl + cb);
|
||||
length += cb;
|
||||
}
|
||||
while (cb != 0);
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
LPCITEMIDLIST CShellPidl::ILGetNext(LPCITEMIDLIST pidl)
|
||||
{
|
||||
if (pidl == NULL)
|
||||
return NULL;
|
||||
|
||||
// Get the size of the specified item identifier.
|
||||
int cb = pidl->mkid.cb;
|
||||
|
||||
// If the size is zero, it is the end of the list.
|
||||
if (cb == 0)
|
||||
return NULL;
|
||||
|
||||
// Add cb to pidl (casting to increment by bytes).
|
||||
pidl = (LPCITEMIDLIST)((LPBYTE)pidl + cb);
|
||||
|
||||
// Return NULL if we reached the terminator, or a pidl otherwise.
|
||||
return (pidl->mkid.cb == 0) ? NULL : pidl;
|
||||
}
|
||||
|
||||
LPCITEMIDLIST CShellPidl::ILGetLast(LPCITEMIDLIST pidl)
|
||||
{
|
||||
LPCITEMIDLIST pidlLast = pidl, tmp = ILGetNext(pidl);
|
||||
while (tmp != NULL)
|
||||
{
|
||||
pidlLast = tmp;
|
||||
tmp = ILGetNext(tmp);
|
||||
}
|
||||
|
||||
return pidlLast;
|
||||
}
|
||||
|
||||
LPITEMIDLIST CShellPidl::ILCombine(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
|
||||
{
|
||||
// check arguments
|
||||
if (pidl1 == NULL && pidl2 == NULL)
|
||||
return NULL;
|
||||
|
||||
// Get the size of the resulting item identifier list
|
||||
UINT cb1 = ILGetLength(pidl1);
|
||||
UINT cb2 = ILGetLength(pidl2);
|
||||
|
||||
// Allocate a new item identifier list
|
||||
SMallocPtr pMalloc;
|
||||
LPITEMIDLIST pidlNew = (LPITEMIDLIST)pMalloc->Alloc(cb1 + cb2 + sizeof(USHORT));
|
||||
LPITEMIDLIST pidlEnd = pidlNew;
|
||||
if (pidlNew != NULL)
|
||||
{
|
||||
// Copy the first item identifier list and terminating 0
|
||||
if (cb1 > 0)
|
||||
{
|
||||
CopyMemory(pidlEnd, pidl1, cb1);
|
||||
pidlEnd = (LPITEMIDLIST)((LPBYTE)pidlEnd + cb1);
|
||||
}
|
||||
|
||||
// Copy the second item identifier list and terminating 0
|
||||
if (cb2 > 0)
|
||||
{
|
||||
CopyMemory(pidlEnd, pidl2, cb2);
|
||||
pidlEnd = (LPITEMIDLIST)((LPBYTE)pidlEnd + cb2);
|
||||
}
|
||||
|
||||
// Append a terminating zero.
|
||||
pidlEnd->mkid.cb = 0;
|
||||
}
|
||||
return pidlNew;
|
||||
}
|
||||
|
||||
LPITEMIDLIST CShellPidl::ILCloneFirst(LPCITEMIDLIST pidl)
|
||||
{
|
||||
LPITEMIDLIST pidlNew = NULL;
|
||||
|
||||
if (pidl != NULL)
|
||||
{
|
||||
// Get the size of the first item identifier.
|
||||
int cb = pidl->mkid.cb;
|
||||
|
||||
// Allocate a new item identifier list.
|
||||
SMallocPtr pMalloc;
|
||||
pidlNew = (LPITEMIDLIST)pMalloc->Alloc(cb + sizeof(USHORT));
|
||||
|
||||
if (pidlNew != NULL)
|
||||
{
|
||||
// Copy the specified item identifier.
|
||||
CopyMemory(pidlNew, pidl, cb);
|
||||
|
||||
// Append a terminating zero.
|
||||
((LPITEMIDLIST)((LPBYTE)pidlNew + cb))->mkid.cb = 0;
|
||||
}
|
||||
}
|
||||
return pidlNew;
|
||||
}
|
||||
|
||||
LPITEMIDLIST CShellPidl::ILCloneParent(LPCITEMIDLIST pidl)
|
||||
{
|
||||
// Get the size of the parent item identifier.
|
||||
UINT cb = (UINT)ILGetLast(pidl) - (UINT)pidl;
|
||||
|
||||
SMallocPtr pMalloc;
|
||||
LPITEMIDLIST pidlNew = (LPITEMIDLIST)pMalloc->Alloc(cb + sizeof(USHORT));
|
||||
|
||||
if (pidlNew != NULL)
|
||||
{
|
||||
// Copy the specified item identifier.
|
||||
CopyMemory(pidlNew, pidl, cb);
|
||||
|
||||
// Append a terminating zero.
|
||||
((LPITEMIDLIST)((LPBYTE)pidlNew + cb))->mkid.cb = 0;
|
||||
}
|
||||
return pidlNew;
|
||||
}
|
||||
|
||||
LPITEMIDLIST CShellPidl::ILFromPath(LPCTSTR pszPath, HWND hOwner)
|
||||
{
|
||||
USES_CONVERSION;
|
||||
|
||||
ULONG count = 0;
|
||||
LPITEMIDLIST pidlNew = NULL;
|
||||
|
||||
SDesktopFolderPtr pDesktopFolder;
|
||||
pDesktopFolder->ParseDisplayName(hOwner, NULL,
|
||||
T2OLE(pszPath), &count, &pidlNew, NULL);
|
||||
|
||||
return pidlNew;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Member Functions
|
||||
|
||||
// debug
|
||||
|
||||
#ifdef _DEBUG
|
||||
void CShellPidl::Dump(CDumpContext& dc) const
|
||||
{
|
||||
dc << "addr = " << (void*)m_pObj << "\n";
|
||||
if (m_pObj == NULL)
|
||||
return;
|
||||
|
||||
dc << "[structure]\n";
|
||||
|
||||
LPCITEMIDLIST pidl = m_pObj;
|
||||
while (pidl != NULL)
|
||||
{
|
||||
dc << " " << pidl->mkid.cb;
|
||||
pidl = ILGetNext(pidl);
|
||||
}
|
||||
dc << "\n";
|
||||
}
|
||||
#endif //_DEBUG
|
||||
|
||||
int CShellPidl::CompareItemID(LPCITEMIDLIST pidl1,LPCITEMIDLIST pidl2)
|
||||
{
|
||||
if(pidl1 == pidl2)
|
||||
return 0;
|
||||
if(!pidl1 || !pidl2)
|
||||
return -1;
|
||||
if(GetItemIDSize(pidl1) != GetItemIDSize(pidl2))
|
||||
return -1;
|
||||
return memcmp(pidl1,pidl2,GetItemIDSize(pidl1));
|
||||
}
|
||||
|
||||
|
||||
int CShellPidl::GetItemIDSize(LPCITEMIDLIST pidl)
|
||||
{
|
||||
if(!pidl)
|
||||
return 0;
|
||||
int nSize = 0;
|
||||
while(pidl -> mkid.cb)
|
||||
{
|
||||
nSize += pidl -> mkid.cb;
|
||||
pidl = (LPCITEMIDLIST)(((LPBYTE)pidl) + pidl -> mkid.cb);
|
||||
}
|
||||
return nSize;
|
||||
}
|
||||
|
||||
LPITEMIDLIST CShellPidl::GetObject()
|
||||
{
|
||||
return this -> m_pObj;
|
||||
}
|
||||
|
||||
int CShellPidl::CompareItemID(int nSpecialFolder)
|
||||
{
|
||||
CShellPidl compareID(nSpecialFolder);
|
||||
return CompareItemID(m_pObj, compareID);
|
||||
}
|
||||
|
||||
int CShellPidl::CompareItemID(LPITEMIDLIST cmpid)
|
||||
{
|
||||
return CompareItemID(m_pObj, cmpid);
|
||||
}
|
||||
@@ -0,0 +1,182 @@
|
||||
// ShellPidl.h: interface for the CShellPidl class.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2000-2001 by Paolo Messina
|
||||
// (http://www.geocities.com/ppescher - ppescher@yahoo.com)
|
||||
//
|
||||
// The contents of this file are subject to the Artistic License (the "License").
|
||||
// You may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at:
|
||||
// http://www.opensource.org/licenses/artistic-license.html
|
||||
//
|
||||
// If you find this code useful, credits would be nice!
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_SHELLPIDL_H__98F90381_3F3A_4DF6_948D_B9BB960E7A96__INCLUDED_)
|
||||
#define AFX_SHELLPIDL_H__98F90381_3F3A_4DF6_948D_B9BB960E7A96__INCLUDED_
|
||||
|
||||
#include <shlobj.h>
|
||||
#include "ShellWrappers.h"
|
||||
|
||||
#include <shlwapi.h>
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
class CShellPidl : public TSharedObject<ITEMIDLIST>
|
||||
{
|
||||
protected:
|
||||
static LPCITEMIDLIST ILGetLast(LPCITEMIDLIST pidl);
|
||||
// manage PIDLs
|
||||
static UINT ILGetLength(LPCITEMIDLIST pidl);
|
||||
static LPCITEMIDLIST ILGetNext(LPCITEMIDLIST pidl);
|
||||
static LPITEMIDLIST ILCombine(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2);
|
||||
static LPITEMIDLIST ILClone(LPCITEMIDLIST pidl);
|
||||
static LPITEMIDLIST ILCloneFirst(LPCITEMIDLIST pidl);
|
||||
static LPITEMIDLIST ILCloneParent(LPCITEMIDLIST pidl);
|
||||
static LPITEMIDLIST ILFromPath(LPCTSTR pszPath, HWND hOwner = NULL);
|
||||
|
||||
public:
|
||||
int CompareItemID(LPITEMIDLIST);
|
||||
int CompareItemID(int);
|
||||
LPITEMIDLIST GetObject();
|
||||
int CompareItemID(LPCITEMIDLIST,LPCITEMIDLIST);
|
||||
CShellPidl(LPCTSTR pszPath, HWND hOwner = NULL);
|
||||
CShellPidl(UINT nSpecialFolder, HWND hOwner = NULL);
|
||||
CShellPidl(LPCITEMIDLIST pidlParent, LPCITEMIDLIST pidlRel);
|
||||
CShellPidl(LPCITEMIDLIST pidl);
|
||||
CShellPidl();
|
||||
virtual ~CShellPidl();
|
||||
|
||||
int GetIconIndex(UINT uFlags = SHGFI_SMALLICON) const;
|
||||
BOOL IsRoot() const;
|
||||
|
||||
void Combine(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2);
|
||||
void CloneLastParent(LPCITEMIDLIST pidl);
|
||||
void CloneLastChild(LPCITEMIDLIST pidl);
|
||||
void CloneFirstParent(LPCITEMIDLIST pidl);
|
||||
void CloneFirstChild(LPCITEMIDLIST pidl);
|
||||
|
||||
LPCITEMIDLIST GetFirstChild();
|
||||
LPCITEMIDLIST GetLastChild();
|
||||
|
||||
CString GetPath() const;
|
||||
|
||||
// debug support
|
||||
#ifdef _DEBUG
|
||||
void Dump(CDumpContext& dc) const;
|
||||
#endif //_DEBUG
|
||||
private:
|
||||
int GetItemIDSize(LPCITEMIDLIST);
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Inline Member Functions
|
||||
|
||||
inline CShellPidl::CShellPidl()
|
||||
{
|
||||
}
|
||||
|
||||
inline CShellPidl::~CShellPidl()
|
||||
{
|
||||
}
|
||||
|
||||
inline CShellPidl::CShellPidl(LPCITEMIDLIST pidl)
|
||||
{
|
||||
m_pObj = ILClone(pidl);
|
||||
}
|
||||
|
||||
inline CShellPidl::CShellPidl(LPCITEMIDLIST pidlParent, LPCITEMIDLIST pidlRel)
|
||||
{
|
||||
m_pObj = ILCombine(pidlParent, pidlRel);
|
||||
}
|
||||
|
||||
inline CShellPidl::CShellPidl(UINT nSpecialFolder, HWND hOwner)
|
||||
{
|
||||
SHGetSpecialFolderLocation(hOwner, nSpecialFolder, &m_pObj);
|
||||
}
|
||||
|
||||
inline CShellPidl::CShellPidl(LPCTSTR pszPath, HWND hOwner)
|
||||
{
|
||||
m_pObj = ILFromPath(pszPath, hOwner);
|
||||
}
|
||||
|
||||
inline BOOL CShellPidl::IsRoot() const
|
||||
{
|
||||
return (m_pObj != NULL) && (m_pObj->mkid.cb == 0);
|
||||
}
|
||||
|
||||
inline CString CShellPidl::GetPath() const
|
||||
{
|
||||
CString path;
|
||||
BOOL bSuccess = SHGetPathFromIDList(m_pObj, path.GetBuffer(MAX_PATH));
|
||||
path.ReleaseBuffer();
|
||||
if (!bSuccess)
|
||||
path.Empty();
|
||||
return path;
|
||||
}
|
||||
|
||||
inline int CShellPidl::GetIconIndex(UINT uFlags) const
|
||||
{
|
||||
SHFILEINFO sfi;
|
||||
ZeroMemory(&sfi, sizeof(SHFILEINFO));
|
||||
uFlags |= SHGFI_PIDL | SHGFI_SYSICONINDEX;
|
||||
SHGetFileInfo((LPCTSTR)m_pObj, 0, &sfi, sizeof(SHFILEINFO), uFlags);
|
||||
return sfi.iIcon;
|
||||
}
|
||||
|
||||
inline void CShellPidl::Combine(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
|
||||
{
|
||||
Destroy();
|
||||
Attach(ILCombine(pidl1, pidl2));
|
||||
}
|
||||
|
||||
// get the first ancestor
|
||||
inline void CShellPidl::CloneFirstParent(LPCITEMIDLIST pidl)
|
||||
{
|
||||
Destroy();
|
||||
Attach(ILCloneFirst(pidl));
|
||||
}
|
||||
|
||||
inline void CShellPidl::CloneFirstChild(LPCITEMIDLIST pidl)
|
||||
{
|
||||
Destroy();
|
||||
Attach(ILClone(ILGetNext(pidl)));
|
||||
}
|
||||
|
||||
inline LPCITEMIDLIST CShellPidl::GetFirstChild()
|
||||
{
|
||||
return ILGetNext(m_pObj);
|
||||
}
|
||||
|
||||
// get the immediate parent
|
||||
inline void CShellPidl::CloneLastParent(LPCITEMIDLIST pidl)
|
||||
{
|
||||
Destroy();
|
||||
Attach(ILCloneParent(pidl));
|
||||
}
|
||||
|
||||
inline void CShellPidl::CloneLastChild(LPCITEMIDLIST pidl)
|
||||
{
|
||||
Destroy();
|
||||
Attach(ILClone(ILGetLast(pidl)));
|
||||
}
|
||||
|
||||
inline LPCITEMIDLIST CShellPidl::GetLastChild()
|
||||
{
|
||||
return ILGetLast(m_pObj);
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Inline Static Functions
|
||||
|
||||
inline LPITEMIDLIST CShellPidl::ILClone(LPCITEMIDLIST pidl)
|
||||
{
|
||||
return ILCombine(NULL, pidl);
|
||||
}
|
||||
|
||||
|
||||
#endif // !defined(AFX_SHELLPIDL_H__98F90381_3F3A_4DF6_948D_B9BB960E7A96__INCLUDED_)
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
// ShellString.cpp: implementation of the CShellString class.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2000-2001 by Paolo Messina
|
||||
// (http://www.geocities.com/ppescher - ppescher@yahoo.com)
|
||||
//
|
||||
// The contents of this file are subject to the Artistic License (the "License").
|
||||
// You may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at:
|
||||
// http://www.opensource.org/licenses/artistic-license.html
|
||||
//
|
||||
// If you find this code useful, credits would be nice!
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "ShellString.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
void CShellString::Destroy()
|
||||
{
|
||||
SMallocPtr pMalloc;
|
||||
if (m_str.uType == STRRET_WSTR && m_str.pOleStr != NULL)
|
||||
{
|
||||
pMalloc->Free(m_str.pOleStr);
|
||||
m_str.pOleStr = NULL;
|
||||
}
|
||||
ZeroMemory(&m_str, sizeof(STRRET));
|
||||
}
|
||||
|
||||
STRRET* CShellString::GetPointer(LPCITEMIDLIST pidl, UINT uDesiredType)
|
||||
{
|
||||
// reset the object
|
||||
Destroy();
|
||||
// init object
|
||||
m_pidl = pidl;
|
||||
ASSERT(m_pidl.IsValid());
|
||||
m_str.uType = uDesiredType;
|
||||
|
||||
return &m_str;
|
||||
}
|
||||
|
||||
CShellString::operator CString() const
|
||||
{
|
||||
CString string;
|
||||
switch (m_str.uType)
|
||||
{
|
||||
case STRRET_WSTR:
|
||||
string = m_str.pOleStr;
|
||||
break;
|
||||
case STRRET_CSTR:
|
||||
string = m_str.cStr;
|
||||
break;
|
||||
case STRRET_OFFSET:
|
||||
string = ((LPBYTE)(LPCITEMIDLIST)m_pidl + m_str.uOffset);
|
||||
}
|
||||
return string;
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
// ShellString.h: interface for the CShellString class.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2000-2001 by Paolo Messina
|
||||
// (http://www.geocities.com/ppescher - ppescher@yahoo.com)
|
||||
//
|
||||
// The contents of this file are subject to the Artistic License (the "License").
|
||||
// You may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at:
|
||||
// http://www.opensource.org/licenses/artistic-license.html
|
||||
//
|
||||
// If you find this code useful, credits would be nice!
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_SHELLSTRING_H__1E9F6E1A_5076_4264_8747_713C53BAD6FE__INCLUDED_)
|
||||
#define AFX_SHELLSTRING_H__1E9F6E1A_5076_4264_8747_713C53BAD6FE__INCLUDED_
|
||||
|
||||
#include <shlobj.h>
|
||||
#include "ShellWrappers.h"
|
||||
#include "ShellPidl.h"
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
class CShellString
|
||||
{
|
||||
protected:
|
||||
CShellPidl m_pidl;
|
||||
STRRET m_str;
|
||||
|
||||
public:
|
||||
CShellString();
|
||||
virtual ~CShellString();
|
||||
|
||||
// obtain an empty object by pointer
|
||||
STRRET* GetPointer(LPCITEMIDLIST pidl, UINT uDesiredType = STRRET_WSTR);
|
||||
|
||||
operator CString() const;
|
||||
|
||||
protected:
|
||||
|
||||
void Destroy();
|
||||
};
|
||||
|
||||
// inline functions
|
||||
|
||||
inline CShellString::CShellString()
|
||||
{
|
||||
ZeroMemory(&m_str, sizeof(STRRET));
|
||||
}
|
||||
|
||||
inline CShellString::~CShellString()
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
|
||||
#endif // !defined(AFX_SHELLSTRING_H__1E9F6E1A_5076_4264_8747_713C53BAD6FE__INCLUDED_)
|
||||
@@ -0,0 +1,414 @@
|
||||
// ShellTreeCtrl.cpp : implementation file
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2000-2001 by Paolo Messina
|
||||
// (http://www.geocities.com/ppescher - ppescher@yahoo.com)
|
||||
//
|
||||
// The contents of this file are subject to the Artistic License (the "License").
|
||||
// You may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at:
|
||||
// http://www.opensource.org/licenses/artistic-license.html
|
||||
//
|
||||
// If you find this code useful, credits would be nice!
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "ShellTreeCtrl.h"
|
||||
#include ".\shelltreectrl.h"
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define new DEBUG_NEW
|
||||
#undef THIS_FILE
|
||||
static char THIS_FILE[] = __FILE__;
|
||||
#endif
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CShellTreeCtrl
|
||||
|
||||
CShellTreeCtrl::CShellTreeCtrl()
|
||||
{
|
||||
m_nCallbackMask = 0;
|
||||
}
|
||||
|
||||
CShellTreeCtrl::~CShellTreeCtrl()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
BEGIN_MESSAGE_MAP(CShellTreeCtrl, CWaitingTreeCtrl)
|
||||
//{{AFX_MSG_MAP(CShellTreeCtrl)
|
||||
ON_NOTIFY_REFLECT(TVN_DELETEITEM, OnDeleteItem)
|
||||
ON_NOTIFY_REFLECT(TVN_GETDISPINFO, OnGetDispInfo)
|
||||
//}}AFX_MSG_MAP
|
||||
// ON_NOTIFY_REFLECT(TVN_SELCHANGED, OnTvnSelchanged)
|
||||
// ON_NOTIFY_REFLECT(TVN_ITEMEXPANDED, OnTvnItemexpanded)
|
||||
END_MESSAGE_MAP()
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CShellTreeCtrl message handlers
|
||||
|
||||
BOOL CShellTreeCtrl::PopulateItem(HTREEITEM hParent)
|
||||
{
|
||||
if (hParent == TVI_ROOT)
|
||||
{
|
||||
// not handled yet, do nothing in Release builds
|
||||
ASSERT(FALSE);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
TVITEMDATA* pData = (TVITEMDATA*)GetItemData(hParent);
|
||||
if (pData == NULL)
|
||||
return TRUE; // invalid shell item, ignore it silently
|
||||
|
||||
// get parent pidl
|
||||
ASSERT(pData->IsValid());
|
||||
CShellPidl& pidlParent = pData->pidlAbs;
|
||||
|
||||
if (!EnumFolderItems(hParent, pidlParent, pData->nFlags))
|
||||
return TRUE; // failed, won't try anymore!
|
||||
|
||||
// TODO: change this method!!
|
||||
|
||||
// do not check for children if parent is a removable media
|
||||
// (just try: if it's a filesystem object, it has a path)
|
||||
TCHAR path[MAX_PATH];
|
||||
if (SHGetPathFromIDList(pidlParent, path))
|
||||
{
|
||||
path[3] = 0;
|
||||
UINT type = GetDriveType(path);
|
||||
if (type != DRIVE_FIXED)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void CShellTreeCtrl::PreSubclassWindow()
|
||||
{
|
||||
InitializeControl();
|
||||
|
||||
CWaitingTreeCtrl::PreSubclassWindow();
|
||||
}
|
||||
|
||||
void CShellTreeCtrl::InitializeControl()
|
||||
{
|
||||
// Attach to the system image list
|
||||
CShellPidl pidl((UINT)CSIDL_DESKTOP, m_hWnd);
|
||||
|
||||
SHFILEINFO sfi;
|
||||
ZeroMemory(&sfi, sizeof(SHFILEINFO));
|
||||
HIMAGELIST hSysImageList = (HIMAGELIST) SHGetFileInfo((LPCTSTR)(LPCITEMIDLIST)pidl,
|
||||
0, &sfi, sizeof(SHFILEINFO), SHGFI_PIDL | SHGFI_SYSICONINDEX | SHGFI_SMALLICON);
|
||||
|
||||
//TreeView_SetImageList(m_hWnd, hSysImageList, TVSIL_NORMAL);
|
||||
// postpone imagelist attaching
|
||||
// (seems it doesn't like a sendmessage when dynamically created
|
||||
// maybe because it has not received the WM_CREATE message yet?)
|
||||
PostMessage(TVM_SETIMAGELIST, TVSIL_NORMAL, (LPARAM)hSysImageList);
|
||||
}
|
||||
|
||||
void CShellTreeCtrl::AddRootFolderContent(LPCITEMIDLIST pidlFolder, UINT nFlags)
|
||||
{
|
||||
if (pidlFolder == NULL)
|
||||
{
|
||||
CShellPidl pidl((UINT)CSIDL_DESKTOP, m_hWnd);
|
||||
InsertSubItem(TVI_ROOT, m_pDesktopFolder, NULL, pidl, nFlags);
|
||||
//HTREEITEM root = GetRootItem();
|
||||
//Expand(root, TVE_EXPAND);
|
||||
//AfxMessageBox(GetItemText(GetChildItem(root)));
|
||||
//PopulateItem(GetRootItem());
|
||||
//Expand(GetRootItem(), 1);
|
||||
return;
|
||||
}
|
||||
|
||||
SetRedraw(FALSE);
|
||||
EnumFolderItems(TVI_ROOT, pidlFolder, nFlags);
|
||||
SetRedraw(TRUE);
|
||||
}
|
||||
|
||||
|
||||
int CALLBACK CShellTreeCtrl::CompareFunc(LPARAM lParam1,
|
||||
LPARAM lParam2, LPARAM /*lParamSort*/)
|
||||
{
|
||||
TVITEMDATA* pData1 = (TVITEMDATA*)lParam1;
|
||||
TVITEMDATA* pData2 = (TVITEMDATA*)lParam2;
|
||||
ASSERT(pData1->IsValid() && pData2->IsValid());
|
||||
|
||||
// TODO: parent folders should be checked some day
|
||||
SShellFolderPtr pParentFolder = pData2->pParentFolder;
|
||||
|
||||
HRESULT hr = pParentFolder->CompareIDs(0,
|
||||
pData1->pidlAbs.GetLastChild(),
|
||||
pData2->pidlAbs.GetLastChild() );
|
||||
if (FAILED(hr))
|
||||
return 0; // error, don't sort
|
||||
|
||||
short ret = (short)HRESULT_CODE(hr);
|
||||
if (ret < 0)
|
||||
return -1;
|
||||
if (ret > 0)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void CShellTreeCtrl::FillItem(TVITEM& item)
|
||||
{
|
||||
DWORD dwAttributes;
|
||||
|
||||
// get item data
|
||||
TVITEMDATA* pData = (TVITEMDATA*)item.lParam;
|
||||
ASSERT(pData->IsValid());
|
||||
|
||||
// get a relative pidl
|
||||
LPCITEMIDLIST pidlRel = pData->pidlAbs.GetLastChild();
|
||||
|
||||
if (item.mask & TVIF_TEXT)
|
||||
{
|
||||
// get display name
|
||||
CString sName;
|
||||
CShellString str;
|
||||
|
||||
if (pData->nFlags & STCF_SHOWPATH)
|
||||
{
|
||||
// use an absolute or relative path, if possible
|
||||
sName = pData->pidlAbs.GetPath();
|
||||
if (!sName.IsEmpty() && !(pData->nFlags & STCF_SHOWFULLNAME))
|
||||
sName = sName.Right(sName.ReverseFind(_T('\\')));
|
||||
}
|
||||
if (sName.IsEmpty())
|
||||
{
|
||||
// use a global or contextual displayname
|
||||
DWORD uDisplayFlags = SHGDN_INFOLDER;
|
||||
if (pData->nFlags & STCF_SHOWFULLNAME)
|
||||
uDisplayFlags = SHGDN_NORMAL;
|
||||
|
||||
// pData->pParentFolder->GetDisplayNameOf(pidlRel, uDisplayFlags
|
||||
// | SHGDN_INCLUDE_NONFILESYS, str.GetPointer(pidlRel));
|
||||
pData->pParentFolder->GetDisplayNameOf(pidlRel, uDisplayFlags, str.GetPointer(pidlRel));
|
||||
sName = str; // copy to string
|
||||
}
|
||||
// set item text
|
||||
lstrcpyn(item.pszText, (LPCTSTR)sName, item.cchTextMax);
|
||||
}
|
||||
|
||||
if (item.mask & (TVIF_IMAGE | TVIF_SELECTEDIMAGE))
|
||||
{
|
||||
// get some attributes
|
||||
dwAttributes = SFGAO_FOLDER | SFGAO_LINK | SFGAO_SHARE | SFGAO_GHOSTED;
|
||||
pData->pParentFolder->GetAttributesOf(1, &pidlRel, &dwAttributes);
|
||||
|
||||
// set correct icon
|
||||
if (dwAttributes & SFGAO_GHOSTED)
|
||||
{
|
||||
item.mask |= LVIF_STATE;
|
||||
item.stateMask |= LVIS_CUT;
|
||||
item.state |= LVIS_CUT;
|
||||
}
|
||||
if (dwAttributes & SFGAO_SHARE)
|
||||
{
|
||||
item.mask |= LVIF_STATE;
|
||||
item.state &= ~LVIS_OVERLAYMASK;
|
||||
item.state |= INDEXTOOVERLAYMASK(1);
|
||||
item.stateMask |= LVIS_OVERLAYMASK;
|
||||
}
|
||||
else if (dwAttributes & SFGAO_LINK)
|
||||
{
|
||||
item.mask |= LVIF_STATE;
|
||||
item.state &= ~LVIS_OVERLAYMASK;
|
||||
item.state |= INDEXTOOVERLAYMASK(2);
|
||||
item.stateMask |= LVIS_OVERLAYMASK;
|
||||
}
|
||||
if (item.mask & TVIF_IMAGE)
|
||||
{
|
||||
item.iImage = pData->pidlAbs.GetIconIndex(SHGFI_SMALLICON);
|
||||
item.iSelectedImage = item.iImage;
|
||||
}
|
||||
if ((item.mask & TVIF_SELECTEDIMAGE)
|
||||
&& (dwAttributes & SFGAO_FOLDER))
|
||||
{
|
||||
item.iSelectedImage = pData->pidlAbs.GetIconIndex(SHGFI_SMALLICON
|
||||
|SHGFI_OPENICON);
|
||||
}
|
||||
}
|
||||
|
||||
if (item.mask & TVIF_CHILDREN)
|
||||
{
|
||||
// get some attributes
|
||||
dwAttributes = SFGAO_FOLDER;
|
||||
pData->pParentFolder->GetAttributesOf(1, &pidlRel, &dwAttributes);
|
||||
|
||||
// get children
|
||||
item.cChildren = 0;
|
||||
if (dwAttributes & SFGAO_FOLDER)
|
||||
{
|
||||
if (pData->nFlags & STCF_INCLUDEFILES)
|
||||
item.cChildren = 1;
|
||||
else if (dwAttributes & SFGAO_REMOVABLE)
|
||||
item.cChildren = 1;
|
||||
else
|
||||
{
|
||||
dwAttributes = SFGAO_HASSUBFOLDER;
|
||||
pData->pParentFolder->GetAttributesOf(1, &pidlRel, &dwAttributes);
|
||||
|
||||
item.cChildren = (dwAttributes & SFGAO_HASSUBFOLDER) ? 1 : 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void CShellTreeCtrl::OnDeleteItem(NMHDR* pNMHDR, LRESULT* pResult)
|
||||
{
|
||||
TVITEM& item = ((LPNMTREEVIEW)pNMHDR)->itemOld;
|
||||
|
||||
// free item data, ignore invalid shell items
|
||||
if (item.lParam != 0)
|
||||
delete (TVITEMDATA*)item.lParam;
|
||||
|
||||
*pResult = 0;
|
||||
}
|
||||
|
||||
void CShellTreeCtrl::OnGetDispInfo(NMHDR* pNMHDR, LRESULT* pResult)
|
||||
{
|
||||
TVITEM& item = ((LPNMTVDISPINFO)pNMHDR)->item;
|
||||
|
||||
// use the provided buffer for text
|
||||
FillItem(item);
|
||||
|
||||
*pResult = 0;
|
||||
}
|
||||
|
||||
CShellPidl CShellTreeCtrl::GetItemIDList(HTREEITEM hItem)
|
||||
{
|
||||
TVITEMDATA* pData = (TVITEMDATA*)GetItemData(hItem);
|
||||
if (pData != NULL)
|
||||
{
|
||||
ASSERT(pData->IsValid());
|
||||
return pData->pidlAbs;
|
||||
}
|
||||
return CShellPidl(); // invalid pidl
|
||||
}
|
||||
|
||||
void CShellTreeCtrl::InsertSubItem(HTREEITEM hParent, LPSHELLFOLDER pParentFolder, LPCITEMIDLIST pidlParent, LPCITEMIDLIST pidl, UINT nFlags)
|
||||
{
|
||||
TVINSERTSTRUCT tvis;
|
||||
ZeroMemory(&tvis, sizeof(TVINSERTSTRUCT));
|
||||
tvis.hParent = hParent;
|
||||
tvis.hInsertAfter = TVI_LAST;
|
||||
|
||||
// provide a buffer for the item text
|
||||
TCHAR szText[MAX_PATH];
|
||||
tvis.item.pszText = szText;
|
||||
tvis.item.cchTextMax = MAX_PATH;
|
||||
|
||||
// used fields
|
||||
const UINT nTVIFlags = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE
|
||||
| TVIF_CHILDREN | TVIF_PARAM;
|
||||
|
||||
// prepare item data
|
||||
TVITEMDATA* pData = new TVITEMDATA;
|
||||
pData->pidlAbs.Combine(pidlParent, pidl);
|
||||
pData->pParentFolder = pParentFolder;
|
||||
pData->nFlags = nFlags;
|
||||
|
||||
// set item data
|
||||
ASSERT(pData->IsValid());
|
||||
tvis.item.lParam = (LPARAM)pData;
|
||||
|
||||
// fill with pidl, text, icons and children - handle callbacks
|
||||
tvis.item.mask = nTVIFlags & ~m_nCallbackMask;
|
||||
FillItem(tvis.item);
|
||||
|
||||
if (m_nCallbackMask & TVIF_IMAGE)
|
||||
tvis.item.iImage = I_IMAGECALLBACK;
|
||||
if (m_nCallbackMask & TVIF_SELECTEDIMAGE)
|
||||
tvis.item.iSelectedImage = I_IMAGECALLBACK;
|
||||
if (m_nCallbackMask & TVIF_TEXT)
|
||||
tvis.item.pszText = LPSTR_TEXTCALLBACK;
|
||||
if (m_nCallbackMask & TVIF_CHILDREN)
|
||||
tvis.item.cChildren = I_CHILDRENCALLBACK;
|
||||
tvis.item.mask |= nTVIFlags;
|
||||
|
||||
// then insert new item
|
||||
InsertItem(&tvis);
|
||||
}
|
||||
|
||||
void CShellTreeCtrl::AddRootItem(LPCITEMIDLIST pidlRoot, UINT nFlags)
|
||||
{
|
||||
// not needed if pParentFolder is an argument
|
||||
CShellPidl pidlParent;
|
||||
pidlParent.CloneLastParent(pidlRoot);
|
||||
SShellFolderPtr pParentFolder(m_pDesktopFolder, pidlParent);
|
||||
|
||||
InsertSubItem(TVI_ROOT, pParentFolder, NULL, pidlRoot, nFlags);
|
||||
}
|
||||
|
||||
BOOL CShellTreeCtrl::EnumFolderItems(HTREEITEM hParent, LPCITEMIDLIST pidlParent, UINT nFlags)
|
||||
{
|
||||
// get parent shell folder
|
||||
SShellFolderPtr pParentFolder(m_pDesktopFolder, pidlParent);
|
||||
|
||||
// not a valid folder object
|
||||
if (!pParentFolder.IsValid())
|
||||
return FALSE; // failed!
|
||||
|
||||
// enum child pidls
|
||||
SEnumIDListPtr pEnumIDList(pParentFolder, SHCONTF_FOLDERS
|
||||
| ((nFlags & STCF_INCLUDEFILES) ? SHCONTF_NONFOLDERS : 0)
|
||||
| ((nFlags & STCF_INCLUDEHIDDEN) ? SHCONTF_INCLUDEHIDDEN : 0), m_hWnd);
|
||||
|
||||
if (pEnumIDList.IsValid())
|
||||
{
|
||||
SetPopulationCount(0);
|
||||
|
||||
CShellPidl pidl;
|
||||
while (NOERROR == pEnumIDList->Next(1, pidl.GetPointer(), NULL))
|
||||
{
|
||||
// add child item, inherit some flags (inclusion)
|
||||
InsertSubItem(hParent, pParentFolder, pidlParent, pidl,
|
||||
nFlags & STCF_INCLUDEMASK);
|
||||
|
||||
// notify progress
|
||||
IncreasePopulation();
|
||||
}
|
||||
}
|
||||
|
||||
if (GetPopulationCount() > 0)
|
||||
{
|
||||
// sort items
|
||||
TVSORTCB tvscb;
|
||||
tvscb.hParent = hParent;
|
||||
tvscb.lpfnCompare = CompareFunc;
|
||||
// tvscb.lParam = 0; // not meaningful yet
|
||||
SortChildrenCB(&tvscb);
|
||||
}
|
||||
|
||||
// notify progress
|
||||
SetPopulationCount(1,1);
|
||||
|
||||
// success!
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL CShellTreeCtrl::GetItemContextMenu(HTREEITEM hItem, CShellContextMenu& rCtxMenu)
|
||||
{
|
||||
TVITEMDATA* pData = (TVITEMDATA*)GetItemData(hItem);
|
||||
if (!pData->IsValid())
|
||||
return FALSE;
|
||||
|
||||
return rCtxMenu.Create(pData->pParentFolder,
|
||||
pData->pidlAbs.GetLastChild());
|
||||
}
|
||||
|
||||
void CShellTreeCtrl::SetCallbackMask(UINT nMask)
|
||||
{
|
||||
m_nCallbackMask = nMask &
|
||||
(TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_CHILDREN);
|
||||
}
|
||||
|
||||
UINT CShellTreeCtrl::GetCallbackMask()
|
||||
{
|
||||
return m_nCallbackMask;
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
#if !defined(AFX_SHELLTREECTRL_H__98BDBB7B_E2C3_4145_A5D5_693274C6B99B__INCLUDED_)
|
||||
#define AFX_SHELLTREECTRL_H__98BDBB7B_E2C3_4145_A5D5_693274C6B99B__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
// ShellTreeCtrl.h : header file
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2000-2001 by Paolo Messina
|
||||
// (http://www.geocities.com/ppescher - ppescher@yahoo.com)
|
||||
//
|
||||
// The contents of this file are subject to the Artistic License (the "License").
|
||||
// You may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at:
|
||||
// http://www.opensource.org/licenses/artistic-license.html
|
||||
//
|
||||
// If you find this code useful, credits would be nice!
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "WaitingTreeCtrl.h"
|
||||
#include "ShellPidl.h"
|
||||
#include "ShellString.h"
|
||||
#include "ShellContextMenu.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CShellTreeCtrl window
|
||||
|
||||
// item flags
|
||||
#define STCF_DEFAULT 0x00
|
||||
#define STCF_INCLUDEFILES 0x01
|
||||
#define STCF_INCLUDEHIDDEN 0x02
|
||||
#define STCF_INCLUDEALL (STCF_INCLUDEFILES|STCF_INCLUDEHIDDEN)
|
||||
#define STCF_INCLUDEMASK 0x0F
|
||||
#define STCF_SHOWFULLNAME 0x10
|
||||
#define STCF_SHOWPATH 0x20
|
||||
#define STCF_SHOWFULLPATH (STCF_SHOWPATH|STCF_SHOWFULLNAME)
|
||||
#define STCF_SHOWMASK 0xF0
|
||||
//#define STCF_DEFERLINKS 0x100
|
||||
|
||||
class CShellTreeCtrl : public CWaitingTreeCtrl
|
||||
{
|
||||
private:
|
||||
struct TVITEMDATA
|
||||
{
|
||||
SShellFolderPtr pParentFolder;
|
||||
CShellPidl pidlAbs;
|
||||
UINT nFlags;
|
||||
|
||||
BOOL IsValid()
|
||||
{
|
||||
return (this != NULL)
|
||||
&& pParentFolder.IsValid() && pidlAbs.IsValid();
|
||||
}
|
||||
};
|
||||
|
||||
SDesktopFolderPtr m_pDesktopFolder;
|
||||
UINT m_nCallbackMask;
|
||||
|
||||
private:
|
||||
// generic
|
||||
void InitializeControl();
|
||||
|
||||
BOOL EnumFolderItems(HTREEITEM hParent, LPCITEMIDLIST pidlParent, UINT nFlags);
|
||||
void InsertSubItem(HTREEITEM hParent, LPSHELLFOLDER pParentFolder, LPCITEMIDLIST pidlParent, LPCITEMIDLIST pidl, UINT nFlags);
|
||||
void FillItem(TVITEM& item);
|
||||
|
||||
static int CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort);
|
||||
|
||||
protected:
|
||||
virtual BOOL PopulateItem(HTREEITEM hParent);
|
||||
|
||||
// Construction
|
||||
public:
|
||||
CShellTreeCtrl();
|
||||
virtual ~CShellTreeCtrl();
|
||||
|
||||
// Attributes
|
||||
public:
|
||||
|
||||
// Operations
|
||||
public:
|
||||
|
||||
// Overrides
|
||||
// ClassWizard generated virtual function overrides
|
||||
//{{AFX_VIRTUAL(CShellTreeCtrl)
|
||||
protected:
|
||||
virtual void PreSubclassWindow();
|
||||
//}}AFX_VIRTUAL
|
||||
|
||||
// Implementation
|
||||
public:
|
||||
UINT GetCallbackMask();
|
||||
void SetCallbackMask(UINT nMask);
|
||||
void AddRootItem(LPCITEMIDLIST pidl, UINT nFlags = STCF_DEFAULT);
|
||||
void AddRootFolderContent(LPCITEMIDLIST pidl, UINT nFlags = STCF_DEFAULT);
|
||||
CShellPidl GetItemIDList(HTREEITEM hItem);
|
||||
BOOL GetItemContextMenu(HTREEITEM hItem, CShellContextMenu &rCtxMenu);
|
||||
|
||||
// Generated message map functions
|
||||
protected:
|
||||
//{{AFX_MSG(CShellTreeCtrl)
|
||||
afx_msg void OnDeleteItem(NMHDR* pNMHDR, LRESULT* pResult);
|
||||
afx_msg void OnGetDispInfo(NMHDR* pNMHDR, LRESULT* pResult);
|
||||
//}}AFX_MSG
|
||||
|
||||
DECLARE_MESSAGE_MAP()
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//{{AFX_INSERT_LOCATION}}
|
||||
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
|
||||
|
||||
#endif // !defined(AFX_SHELLTREECTRL_H__98BDBB7B_E2C3_4145_A5D5_693274C6B99B__INCLUDED_)
|
||||
@@ -0,0 +1,217 @@
|
||||
// SmartInterfacePtr.h: interface for the TInterfacePtr class.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2000-2001 by Paolo Messina
|
||||
// (http://www.geocities.com/ppescher - ppescher@yahoo.com)
|
||||
//
|
||||
// The contents of this file are subject to the Artistic License (the "License").
|
||||
// You may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at:
|
||||
// http://www.opensource.org/licenses/artistic-license.html
|
||||
//
|
||||
// If you find this code useful, credits would be nice!
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_SHELLWRAPPERS_H__B0E1BBE7_A5D8_4A80_9A36_ED5553FE74F6__INCLUDED_)
|
||||
#define AFX_SHELLWRAPPERS_H__B0E1BBE7_A5D8_4A80_9A36_ED5553FE74F6__INCLUDED_
|
||||
|
||||
#include <shlobj.h>
|
||||
#include "SmartInterfacePtr.h"
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
class SMallocPtr : public TStaticInterfacePtr<IMalloc>
|
||||
{
|
||||
public:
|
||||
SMallocPtr()
|
||||
{
|
||||
if (m_pIface == NULL)
|
||||
SHGetMalloc(&m_pIface);
|
||||
else
|
||||
m_pIface->AddRef();
|
||||
}
|
||||
};
|
||||
|
||||
class SDesktopFolderPtr : public TStaticInterfacePtr<IShellFolder>
|
||||
{
|
||||
public:
|
||||
SDesktopFolderPtr()
|
||||
{
|
||||
if (m_pIface == NULL)
|
||||
SHGetDesktopFolder(&m_pIface);
|
||||
else
|
||||
m_pIface->AddRef();
|
||||
}
|
||||
};
|
||||
|
||||
class SShellFolderPtr : public TInterfacePtr<IShellFolder>
|
||||
{
|
||||
public:
|
||||
SShellFolderPtr() {}
|
||||
|
||||
SShellFolderPtr(IShellFolder* pFolder) { Copy(pFolder); }
|
||||
SShellFolderPtr(IShellFolder* pParentFolder, LPCITEMIDLIST pidlRel)
|
||||
{
|
||||
if (pidlRel != NULL && pidlRel->mkid.cb == 0)
|
||||
{
|
||||
// it's a root element, copy the parent folder
|
||||
Copy(pParentFolder);
|
||||
}
|
||||
else
|
||||
{
|
||||
pParentFolder->BindToObject(pidlRel,
|
||||
NULL, IID_IShellFolder, (LPVOID*)&m_pIface);
|
||||
}
|
||||
}
|
||||
|
||||
SShellFolderPtr(LPCITEMIDLIST pidlAbs)
|
||||
{
|
||||
SDesktopFolderPtr pDesktopFolder;
|
||||
if (pidlAbs != NULL && pidlAbs->mkid.cb == 0)
|
||||
{
|
||||
// it's a root element, copy the parent folder
|
||||
Copy(pDesktopFolder);
|
||||
}
|
||||
else
|
||||
{
|
||||
pDesktopFolder->BindToObject(pidlAbs,
|
||||
NULL, IID_IShellFolder, (LPVOID*)&m_pIface);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class SEnumIDListPtr : public TInterfacePtr<IEnumIDList>
|
||||
{
|
||||
public:
|
||||
SEnumIDListPtr(IShellFolder* pParentFolder, UINT nFlags, HWND hOwner = NULL)
|
||||
{
|
||||
pParentFolder->EnumObjects(hOwner, nFlags, &m_pIface);
|
||||
}
|
||||
};
|
||||
|
||||
class SContextMenuPtr : public TInterfacePtr<IContextMenu>
|
||||
{
|
||||
public:
|
||||
SContextMenuPtr() {}
|
||||
|
||||
SContextMenuPtr(IShellFolder* pParentFolder, LPCITEMIDLIST pidlRel, HWND hOwner = NULL)
|
||||
{
|
||||
pParentFolder->GetUIObjectOf(hOwner, 1, &pidlRel,
|
||||
IID_IContextMenu, NULL, (LPVOID*)&m_pIface);
|
||||
}
|
||||
};
|
||||
|
||||
class SContextMenu2Ptr : public TInterfacePtr<IContextMenu2>
|
||||
{
|
||||
public:
|
||||
SContextMenu2Ptr(IContextMenu* pIface)
|
||||
{
|
||||
if (pIface != NULL)
|
||||
pIface->QueryInterface(IID_IContextMenu2, (LPVOID*)&m_pIface);
|
||||
}
|
||||
};
|
||||
|
||||
// templates
|
||||
|
||||
template <class TYPE>
|
||||
class TSharedObject
|
||||
{
|
||||
public:
|
||||
~TSharedObject()
|
||||
{ Destroy(); }
|
||||
|
||||
protected:
|
||||
TYPE* m_pObj;
|
||||
|
||||
TSharedObject()
|
||||
{ m_pObj = NULL; }
|
||||
|
||||
TSharedObject(const TSharedObject& shobj)
|
||||
{ Copy(shobj); }
|
||||
|
||||
void Copy(const TSharedObject& shobj);
|
||||
|
||||
public:
|
||||
operator const TYPE * () const
|
||||
{ return m_pObj; }
|
||||
|
||||
const TSharedObject& operator = (const TSharedObject& shobj)
|
||||
{
|
||||
Destroy();
|
||||
Copy(shobj);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
BOOL IsValid() const
|
||||
{ return m_pObj != NULL; }
|
||||
|
||||
void Attach(TYPE* pObj)
|
||||
{
|
||||
ASSERT(m_pObj == NULL); // can't attach two times!
|
||||
m_pObj = pObj;
|
||||
}
|
||||
|
||||
TYPE* Detach()
|
||||
{
|
||||
TYPE* ret = m_pObj;
|
||||
m_pObj = NULL;
|
||||
return ret;
|
||||
}
|
||||
|
||||
// obtain a void object by pointer
|
||||
TYPE** GetPointer()
|
||||
{
|
||||
Destroy();
|
||||
return &m_pObj;
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
void DumpRaw(CDumpContext& dc) const
|
||||
{
|
||||
dc << "addr = " << (void*)m_pObj << "\n";
|
||||
if (m_pObj == NULL)
|
||||
return;
|
||||
|
||||
SMallocPtr pMalloc;
|
||||
ULONG size = pMalloc->GetSize((void*)m_pObj);
|
||||
cd << "[hex dump]\n";
|
||||
dc.HexDump(".", (BYTE*)m_pObj, (int)size, 16);
|
||||
dc << "\n";
|
||||
}
|
||||
#endif //_DEBUG
|
||||
|
||||
protected:
|
||||
|
||||
void Destroy()
|
||||
{
|
||||
SMallocPtr pMalloc;
|
||||
pMalloc->Free(Detach());
|
||||
}
|
||||
};
|
||||
|
||||
template <class TYPE>
|
||||
void TSharedObject<TYPE>::Copy(const TSharedObject& shobj)
|
||||
{
|
||||
m_pObj = NULL;
|
||||
if (shobj.m_pObj == NULL)
|
||||
return;
|
||||
|
||||
// obj to copy must have been allocated this way
|
||||
SMallocPtr pMalloc;
|
||||
ULONG size = (ULONG)pMalloc->GetSize((void*)shobj.m_pObj);
|
||||
ASSERT(size > 0);
|
||||
|
||||
if (shobj.m_pObj != NULL)
|
||||
{
|
||||
m_pObj = (TYPE*)pMalloc->Alloc(size);
|
||||
CopyMemory(m_pObj, shobj.m_pObj, size);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif //!defined(AFX_SHELLWRAPPERS_H__B0E1BBE7_A5D8_4A80_9A36_ED5553FE74F6__INCLUDED_)
|
||||
@@ -0,0 +1,126 @@
|
||||
// SmartInterfacePtr.h: interface for the TInterfacePtr class.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2000-2001 by Paolo Messina
|
||||
// (http://www.geocities.com/ppescher - ppescher@yahoo.com)
|
||||
//
|
||||
// The contents of this file are subject to the Artistic License (the "License").
|
||||
// You may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at:
|
||||
// http://www.opensource.org/licenses/artistic-license.html
|
||||
//
|
||||
// If you find this code useful, credits would be nice!
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_SMARTINTERFACEPTR_H__A0E1BBE7_A5D8_4A80_9A36_ED5553FE74F6__INCLUDED_)
|
||||
#define AFX_SMARTINTERFACEPTR_H__A0E1BBE7_A5D8_4A80_9A36_ED5553FE74F6__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
template <class TYPE>
|
||||
class TInterfacePtr
|
||||
{
|
||||
public:
|
||||
~TInterfacePtr()
|
||||
{ Free(); }
|
||||
|
||||
BOOL IsValid() const
|
||||
{ return m_pIface != NULL; }
|
||||
|
||||
TYPE * operator -> ()
|
||||
{ return m_pIface; }
|
||||
|
||||
const TYPE * operator -> () const
|
||||
{ return m_pIface; }
|
||||
|
||||
operator TYPE * ()
|
||||
{ return m_pIface; }
|
||||
|
||||
protected:
|
||||
TYPE * m_pIface;
|
||||
|
||||
// must derive from this class
|
||||
TInterfacePtr()
|
||||
{ m_pIface = NULL; }
|
||||
|
||||
TInterfacePtr(const TInterfacePtr& obj)
|
||||
{ Copy(obj.m_pIface); }
|
||||
|
||||
const TInterfacePtr& operator = (const TInterfacePtr& obj)
|
||||
{
|
||||
Free();
|
||||
Copy(obj.m_pIface);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void Copy(TYPE * pIface);
|
||||
void Free();
|
||||
};
|
||||
|
||||
template <class TYPE>
|
||||
inline void TInterfacePtr<TYPE>::Copy(TYPE * pIface)
|
||||
{
|
||||
m_pIface = pIface;
|
||||
if (m_pIface != NULL)
|
||||
m_pIface->AddRef();
|
||||
}
|
||||
|
||||
template <class TYPE>
|
||||
inline void TInterfacePtr<TYPE>::Free()
|
||||
{
|
||||
if (m_pIface != NULL)
|
||||
{
|
||||
m_pIface->Release();
|
||||
m_pIface = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// static storage
|
||||
|
||||
template <class TYPE>
|
||||
class TStaticInterfacePtr
|
||||
{
|
||||
public:
|
||||
~TStaticInterfacePtr()
|
||||
{ Free(); }
|
||||
|
||||
BOOL IsValid() const
|
||||
{ return m_pIface != NULL; }
|
||||
|
||||
TYPE * operator -> ()
|
||||
{ return m_pIface; }
|
||||
|
||||
const TYPE * operator -> () const
|
||||
{ return m_pIface; }
|
||||
|
||||
operator TYPE * ()
|
||||
{ return m_pIface; }
|
||||
|
||||
protected:
|
||||
static TYPE * m_pIface;
|
||||
|
||||
TStaticInterfacePtr() {}
|
||||
// cannot copy - use another instance
|
||||
TStaticInterfacePtr(const TStaticInterfacePtr&) {}
|
||||
const TStaticInterfacePtr& operator = (const TStaticInterfacePtr&) {}
|
||||
|
||||
void Free();
|
||||
};
|
||||
|
||||
template <class TYPE>
|
||||
TYPE * TStaticInterfacePtr<TYPE>::m_pIface = NULL;
|
||||
|
||||
template <class TYPE>
|
||||
inline void TStaticInterfacePtr<TYPE>::Free()
|
||||
{
|
||||
if (m_pIface != NULL)
|
||||
if (0 == m_pIface->Release())
|
||||
m_pIface = NULL;
|
||||
}
|
||||
|
||||
|
||||
#endif // !defined(AFX_SMARTINTERFACEPTR_H__A0E1BBE7_A5D8_4A80_9A36_ED5553FE74F6__INCLUDED_)
|
||||
@@ -0,0 +1,450 @@
|
||||
// WaitingTreeCtrl.cpp : implementation file
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2000-2001 by Paolo Messina
|
||||
// (http://www.geocities.com/ppescher - ppescher@yahoo.com)
|
||||
//
|
||||
// The contents of this file are subject to the Artistic License (the "License").
|
||||
// You may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at:
|
||||
// http://www.opensource.org/licenses/artistic-license.html
|
||||
//
|
||||
// If you find this code useful, credits would be nice!
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "WaitingTreeCtrl.h"
|
||||
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable: 4201)
|
||||
#include <mmsystem.h>
|
||||
#pragma warning(pop)
|
||||
|
||||
#pragma comment(lib, "winmm.lib")
|
||||
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define new DEBUG_NEW
|
||||
#undef THIS_FILE
|
||||
static char THIS_FILE[] = __FILE__;
|
||||
#endif
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CWaitingTreeCtrl
|
||||
|
||||
CWaitingTreeCtrl::CWaitingTreeCtrl()
|
||||
{
|
||||
m_bDrawSnapshot = FALSE;
|
||||
|
||||
m_sWaitMsg = _T("Loading...");
|
||||
m_bShowWaitMsg = FALSE;
|
||||
m_hIconMsg = NULL; // default: blank icon
|
||||
m_nTimerDelay = 0; // default: no timer
|
||||
|
||||
m_hRedrawEvent = NULL;
|
||||
m_hTimerEvent = NULL;
|
||||
m_hThread = NULL;
|
||||
}
|
||||
|
||||
CWaitingTreeCtrl::~CWaitingTreeCtrl()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
BEGIN_MESSAGE_MAP(CWaitingTreeCtrl, CTreeCtrl)
|
||||
//{{AFX_MSG_MAP(CWaitingTreeCtrl)
|
||||
ON_NOTIFY_REFLECT(TVN_ITEMEXPANDING, OnItemExpanding)
|
||||
ON_NOTIFY_REFLECT(TVN_ITEMEXPANDED, OnItemExpanded)
|
||||
ON_WM_ERASEBKGND()
|
||||
//}}AFX_MSG_MAP
|
||||
END_MESSAGE_MAP()
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CWaitingTreeCtrl message handlers
|
||||
|
||||
void CWaitingTreeCtrl::OnItemExpanding(NMHDR* pNMHDR, LRESULT* pResult)
|
||||
{
|
||||
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
|
||||
|
||||
if (pNMTreeView->action & TVE_EXPAND)
|
||||
PreExpandItem(pNMTreeView->itemNew.hItem);
|
||||
|
||||
*pResult = 0;
|
||||
}
|
||||
|
||||
void CWaitingTreeCtrl::OnItemExpanded(NMHDR* pNMHDR, LRESULT* pResult)
|
||||
{
|
||||
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
|
||||
|
||||
if (pNMTreeView->action & TVE_EXPAND)
|
||||
ExpandItem(pNMTreeView->itemNew.hItem);
|
||||
else if (pNMTreeView->action & TVE_COLLAPSE)
|
||||
{
|
||||
if (WantsRefresh(pNMTreeView->itemNew.hItem))
|
||||
{
|
||||
// delete child items
|
||||
DeleteChildren(pNMTreeView->itemNew.hItem);
|
||||
}
|
||||
}
|
||||
|
||||
*pResult = 0;
|
||||
}
|
||||
|
||||
void CWaitingTreeCtrl::PreAnimation(HTREEITEM hItemMsg)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(hItemMsg);
|
||||
}
|
||||
|
||||
void CWaitingTreeCtrl::PostAnimation()
|
||||
{
|
||||
}
|
||||
|
||||
void CWaitingTreeCtrl::DoAnimation(BOOL bTimerEvent, int iMaxSteps, int iStep)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(bTimerEvent);
|
||||
UNREFERENCED_PARAMETER(iMaxSteps);
|
||||
UNREFERENCED_PARAMETER(iStep);
|
||||
}
|
||||
|
||||
int CWaitingTreeCtrl::GetPopulationCount(int *piMaxSubItems)
|
||||
{
|
||||
if (piMaxSubItems != NULL)
|
||||
*piMaxSubItems = m_iItemCount;
|
||||
return m_iItemIndex;
|
||||
}
|
||||
|
||||
void CWaitingTreeCtrl::SetPopulationCount(int iMaxSubItems, int iFirstSubItem)
|
||||
{
|
||||
m_iItemCount = iMaxSubItems;
|
||||
m_iItemIndex = iFirstSubItem;
|
||||
|
||||
SetEvent(m_hRedrawEvent);
|
||||
}
|
||||
|
||||
void CWaitingTreeCtrl::UpdatePopulation(int iSubItems)
|
||||
{
|
||||
m_iItemIndex = iSubItems;
|
||||
|
||||
SetEvent(m_hRedrawEvent);
|
||||
}
|
||||
|
||||
void CWaitingTreeCtrl::IncreasePopulation(int iSubItemsToAdd)
|
||||
{
|
||||
m_iItemIndex += iSubItemsToAdd;
|
||||
|
||||
SetEvent(m_hRedrawEvent);
|
||||
}
|
||||
|
||||
void CWaitingTreeCtrl::SetAnimationDelay(UINT nMilliseconds)
|
||||
{
|
||||
// if greater than zero, periodic DoAnimation() will be called
|
||||
m_nTimerDelay = nMilliseconds;
|
||||
}
|
||||
|
||||
DWORD WINAPI CWaitingTreeCtrl::AnimationThreadProc(LPVOID pThis)
|
||||
{
|
||||
CWaitingTreeCtrl* me = (CWaitingTreeCtrl*)pThis;
|
||||
|
||||
HANDLE events[2] = { me->m_hTimerEvent, me->m_hRedrawEvent };
|
||||
|
||||
while (!me->m_bAbortAnimation)
|
||||
{
|
||||
DWORD wait = WaitForMultipleObjects(2, events, FALSE, INFINITE);
|
||||
|
||||
if (me->m_bAbortAnimation || wait == WAIT_FAILED)
|
||||
break;
|
||||
|
||||
if (wait == WAIT_OBJECT_0) // timer event
|
||||
me->DoAnimation(TRUE, me->m_iItemCount, me->m_iItemIndex);
|
||||
else // redraw event
|
||||
me->DoAnimation(FALSE, me->m_iItemCount, me->m_iItemIndex);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void CWaitingTreeCtrl::StartAnimation()
|
||||
{
|
||||
// user-defined setup
|
||||
PreAnimation(m_hItemMsg);
|
||||
|
||||
// animation can go
|
||||
m_bAbortAnimation = FALSE;
|
||||
// automatic reset events, signaled
|
||||
m_hTimerEvent = CreateEvent(NULL, FALSE, TRUE, NULL);
|
||||
m_hRedrawEvent = CreateEvent(NULL, FALSE, TRUE, NULL);
|
||||
// start animation thread
|
||||
DWORD dwThreadID = 0;
|
||||
m_hThread = CreateThread(NULL, 0, AnimationThreadProc, this,
|
||||
THREAD_PRIORITY_HIGHEST, &dwThreadID);
|
||||
// setup timer, if specified
|
||||
if (m_nTimerDelay > 0)
|
||||
m_nTimerID = (UINT)timeSetEvent(m_nTimerDelay, 5, (LPTIMECALLBACK)m_hTimerEvent,
|
||||
0, TIME_PERIODIC | TIME_CALLBACK_EVENT_SET);
|
||||
}
|
||||
|
||||
void CWaitingTreeCtrl::StopAnimation()
|
||||
{
|
||||
// stop and destroy timer
|
||||
timeKillEvent(m_nTimerID);
|
||||
// signal thread to terminate
|
||||
m_bAbortAnimation = TRUE;
|
||||
SetEvent(m_hRedrawEvent); // make sure it can see the signal
|
||||
// wait thread termination
|
||||
WaitForSingleObject(m_hThread, INFINITE);
|
||||
// clean up
|
||||
CloseHandle(m_hTimerEvent);
|
||||
m_hTimerEvent = NULL;
|
||||
CloseHandle(m_hRedrawEvent);
|
||||
m_hRedrawEvent = NULL;
|
||||
CloseHandle(m_hThread);
|
||||
m_hThread = NULL;
|
||||
|
||||
// user-defined cleanup
|
||||
PostAnimation();
|
||||
}
|
||||
|
||||
void CWaitingTreeCtrl::PopulateRoot()
|
||||
{
|
||||
PreExpandItem(TVI_ROOT);
|
||||
ExpandItem(TVI_ROOT);
|
||||
// force update, don't scroll
|
||||
SetRedraw(FALSE);
|
||||
SCROLLINFO si;
|
||||
GetScrollInfo(SB_HORZ, &si);
|
||||
EnsureVisible(GetChildItem(TVI_ROOT));
|
||||
SetScrollInfo(SB_HORZ, &si, FALSE);
|
||||
SetRedraw();
|
||||
}
|
||||
|
||||
void CWaitingTreeCtrl::PreExpandItem(HTREEITEM hItem)
|
||||
{
|
||||
if (!NeedsChildren(hItem))
|
||||
{
|
||||
if (WantsRefresh(hItem))
|
||||
{
|
||||
// delete child items before populating
|
||||
DeleteChildren(hItem);
|
||||
}
|
||||
else
|
||||
{
|
||||
// doesn't want new items
|
||||
m_hItemToPopulate = NULL;
|
||||
return;
|
||||
}
|
||||
}
|
||||
// if it wants new child items, go on
|
||||
m_hItemToPopulate = hItem;
|
||||
|
||||
// fix redraw when expanded programatically
|
||||
UpdateWindow();
|
||||
// hide changes until it's expanded
|
||||
SetRedraw(FALSE);
|
||||
// add wait msg, to allow item expansion
|
||||
m_hItemMsg = InsertItem(m_sWaitMsg, m_hItemToPopulate);
|
||||
// zero progress
|
||||
m_iItemCount = 1;
|
||||
m_iItemIndex = 0;
|
||||
}
|
||||
|
||||
void CWaitingTreeCtrl::ExpandItem(HTREEITEM hItem)
|
||||
{
|
||||
if (m_hItemToPopulate == NULL)
|
||||
return; // just expand, doesn't want new items
|
||||
|
||||
ASSERT(hItem == m_hItemToPopulate); // should never fail!!!
|
||||
|
||||
if (m_bShowWaitMsg)
|
||||
{
|
||||
// display wait msg now, make sure it's visible
|
||||
SetRedraw();
|
||||
EnsureVisible(m_hItemMsg);
|
||||
UpdateWindow();
|
||||
}
|
||||
// setup animation thread, call PreAnimation
|
||||
StartAnimation();
|
||||
// draw icon
|
||||
if (m_bShowWaitMsg)
|
||||
DrawUserIcon();
|
||||
// delay redraw after populating
|
||||
SetRedraw(FALSE);
|
||||
// take a snapshot of the background
|
||||
TakeSnapshot();
|
||||
// del temporary item (wait msg still shown)
|
||||
DeleteItem(m_hItemMsg);
|
||||
// fill in with sub items
|
||||
BOOL bCheckChildren = PopulateItem(hItem);
|
||||
// clean up animation thread, call PostAnimation
|
||||
StopAnimation();
|
||||
// change parent to reflect current children number
|
||||
if (hItem != TVI_ROOT)
|
||||
{
|
||||
TVITEM item;
|
||||
item.hItem = hItem;
|
||||
item.mask = TVIF_HANDLE | TVIF_CHILDREN;
|
||||
item.cChildren = NeedsChildren(hItem) ? 0 : 1;
|
||||
if (bCheckChildren)
|
||||
SetItem(&item);
|
||||
else if (item.cChildren == 0)
|
||||
// restore item's plus button if no children inserted
|
||||
SetItemState(hItem, 0, TVIS_EXPANDED);
|
||||
}
|
||||
// clean up snapshot
|
||||
DestroySnapshot();
|
||||
// redraw now
|
||||
SetRedraw(TRUE);
|
||||
// scroll like in a standard expansion
|
||||
HTREEITEM hChild = GetChildItem(hItem);
|
||||
while (hChild != NULL && GetFirstVisibleItem() != hItem)
|
||||
{
|
||||
// EnsureVisible(hChild);
|
||||
hChild = GetNextSiblingItem(hChild);
|
||||
}
|
||||
}
|
||||
|
||||
BOOL CWaitingTreeCtrl::WantsRefresh(HTREEITEM hItem)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(hItem);
|
||||
|
||||
// default implementation, no refresh
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BOOL CWaitingTreeCtrl::GetItemImageRect(HTREEITEM hItem, LPRECT pRect)
|
||||
{
|
||||
if (GetImageList(TVSIL_NORMAL) == NULL)
|
||||
return FALSE; // no images
|
||||
|
||||
CRect rc;
|
||||
// get item rect
|
||||
if (!GetItemRect(hItem, &rc, TRUE))
|
||||
return FALSE;
|
||||
|
||||
int cx = GetSystemMetrics(SM_CXSMICON);
|
||||
int cy = GetSystemMetrics(SM_CYSMICON);
|
||||
|
||||
// move onto the icon space
|
||||
int margin = (rc.Height()-cy)/2;
|
||||
rc.OffsetRect(-cx-3 , margin);
|
||||
rc.right = rc.left + cx; // make it square
|
||||
rc.bottom = rc.top + cy; // make it square
|
||||
|
||||
*pRect = rc;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void CWaitingTreeCtrl::DrawUserIcon()
|
||||
{
|
||||
// draw user defined icon
|
||||
|
||||
CRect rcIcon;
|
||||
if (!GetItemImageRect(m_hItemMsg, &rcIcon))
|
||||
return; // no image
|
||||
|
||||
// create background brush with current bg color (take rgb part only)
|
||||
HBRUSH hBrush = CreateSolidBrush(GetBkColor() & 0x00FFFFFF);
|
||||
|
||||
CClientDC dc(this);
|
||||
|
||||
if (m_hIconMsg != NULL)
|
||||
DrawIconEx(dc.GetSafeHdc(), rcIcon.left, rcIcon.top, m_hIconMsg,
|
||||
rcIcon.Width(), rcIcon.Height(), 0, hBrush, DI_NORMAL);
|
||||
else
|
||||
FillRect(dc.GetSafeHdc(), &rcIcon, hBrush);
|
||||
|
||||
DeleteObject(hBrush);
|
||||
}
|
||||
|
||||
void CWaitingTreeCtrl::SetWaitMessage(LPCTSTR pszText, HICON hIcon)
|
||||
{
|
||||
m_sWaitMsg = pszText;
|
||||
m_hIconMsg = hIcon;
|
||||
}
|
||||
|
||||
void CWaitingTreeCtrl::RefreshSubItems(HTREEITEM hParent)
|
||||
{
|
||||
if (hParent != TVI_ROOT && !ItemHasChildren(hParent))
|
||||
return;
|
||||
|
||||
SetRedraw(FALSE);
|
||||
DeleteChildren(hParent);
|
||||
if (hParent == TVI_ROOT)
|
||||
PopulateRoot();
|
||||
else
|
||||
{
|
||||
PreExpandItem(hParent);
|
||||
ExpandItem(hParent);
|
||||
}
|
||||
SetRedraw(TRUE);
|
||||
}
|
||||
|
||||
inline BOOL CWaitingTreeCtrl::NeedsChildren(HTREEITEM hParent)
|
||||
{
|
||||
return (GetChildItem(hParent) == NULL);
|
||||
}
|
||||
|
||||
void CWaitingTreeCtrl::DeleteChildren(HTREEITEM hParent)
|
||||
{
|
||||
HTREEITEM hChild = GetChildItem(hParent);
|
||||
HTREEITEM hNext;
|
||||
|
||||
while (hChild != NULL)
|
||||
{
|
||||
hNext = GetNextSiblingItem(hChild);
|
||||
DeleteItem(hChild);
|
||||
hChild = hNext;
|
||||
}
|
||||
}
|
||||
|
||||
BOOL CWaitingTreeCtrl::OnEraseBkgnd(CDC* pDC)
|
||||
{
|
||||
if (!m_bDrawSnapshot)
|
||||
return CTreeCtrl::OnEraseBkgnd(pDC);
|
||||
|
||||
DrawSnapshot(pDC);
|
||||
SetEvent(m_hRedrawEvent);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void CWaitingTreeCtrl::TakeSnapshot()
|
||||
{
|
||||
CClientDC dc(this);
|
||||
CRect rcClient;
|
||||
GetClientRect(&rcClient);
|
||||
int width = rcClient.Width(), height = rcClient.Height();
|
||||
|
||||
// create the snapshot
|
||||
CDC dcSnapshot;
|
||||
dcSnapshot.CreateCompatibleDC(&dc);
|
||||
m_bmpSnapshot.CreateCompatibleBitmap(&dc, width, height);
|
||||
// copy the control's background
|
||||
CBitmap* pOldBmp = dcSnapshot.SelectObject(&m_bmpSnapshot);
|
||||
dcSnapshot.BitBlt(0, 0, width, height, &dc, 0, 0, SRCCOPY);
|
||||
dcSnapshot.SelectObject(pOldBmp);
|
||||
|
||||
m_bDrawSnapshot = TRUE;
|
||||
}
|
||||
|
||||
void CWaitingTreeCtrl::DrawSnapshot(CDC *pDC)
|
||||
{
|
||||
BITMAP bm;
|
||||
m_bmpSnapshot.GetBitmap(&bm);
|
||||
|
||||
// prepare the snapshot
|
||||
CDC dcSnapshot;
|
||||
dcSnapshot.CreateCompatibleDC(pDC);
|
||||
// copy to the control's background
|
||||
CBitmap* pOldBmp = dcSnapshot.SelectObject(&m_bmpSnapshot);
|
||||
pDC->BitBlt(0, 0, bm.bmWidth, bm.bmHeight, &dcSnapshot, 0, 0, SRCCOPY);
|
||||
dcSnapshot.SelectObject(pOldBmp);
|
||||
}
|
||||
|
||||
void CWaitingTreeCtrl::DestroySnapshot()
|
||||
{
|
||||
m_bmpSnapshot.DeleteObject();
|
||||
|
||||
m_bDrawSnapshot = FALSE;
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
// WaitingTreeCtrl.h : header file
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2000-2001 by Paolo Messina
|
||||
// (http://www.geocities.com/ppescher - ppescher@yahoo.com)
|
||||
//
|
||||
// The contents of this file are subject to the Artistic License (the "License").
|
||||
// You may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at:
|
||||
// http://www.opensource.org/licenses/artistic-license.html
|
||||
//
|
||||
// If you find this code useful, credits would be nice!
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_WAITINGTREECTRL_H__80CBE29B_F1A6_41D5_9DF3_B725E73BCF0F__INCLUDED_)
|
||||
#define AFX_WAITINGTREECTRL_H__80CBE29B_F1A6_41D5_9DF3_B725E73BCF0F__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CWaitingTreeCtrl window
|
||||
|
||||
class CWaitingTreeCtrl : public CTreeCtrl
|
||||
{
|
||||
private:
|
||||
void DestroySnapshot();
|
||||
void DrawSnapshot(CDC* pDC);
|
||||
void TakeSnapshot();
|
||||
HANDLE m_hThread; // secondary thread for animations
|
||||
HANDLE m_hTimerEvent; // signaled at each timer period
|
||||
HANDLE m_hRedrawEvent; // signaled at each population update
|
||||
volatile BOOL m_bAbortAnimation; // request to terminate secondary thread
|
||||
BOOL m_bDrawSnapshot; // whether to draw background during populating
|
||||
CBitmap m_bmpSnapshot; // snapshot bitmap
|
||||
UINT m_nTimerID; // animation timer id
|
||||
UINT m_nTimerDelay; // animation timer period (ms)
|
||||
CString m_sWaitMsg; // text for the wait message
|
||||
HICON m_hIconMsg; // icon for the wait message
|
||||
BOOL m_bShowWaitMsg; // wether to show the wait message
|
||||
int m_iItemIndex; // population progress index
|
||||
int m_iItemCount; // population progress max index
|
||||
HTREEITEM m_hItemMsg; // wait message item
|
||||
HTREEITEM m_hItemToPopulate; // item being populated
|
||||
|
||||
// secondary thread entry point
|
||||
static DWORD WINAPI AnimationThreadProc(LPVOID pThis);
|
||||
|
||||
void StartAnimation(); // set up animation thread
|
||||
void StopAnimation(); // animation clean up
|
||||
|
||||
void PreExpandItem(HTREEITEM hItem); // before expanding
|
||||
void ExpandItem(HTREEITEM hItem); // after expanded
|
||||
|
||||
BOOL NeedsChildren(HTREEITEM hParent); // true if no child items
|
||||
void DeleteChildren(HTREEITEM hParent);
|
||||
|
||||
void DrawUserIcon(); // draw wait message icon
|
||||
|
||||
// Construction
|
||||
public:
|
||||
CWaitingTreeCtrl();
|
||||
virtual ~CWaitingTreeCtrl();
|
||||
|
||||
// Attributes
|
||||
public:
|
||||
|
||||
// Operations
|
||||
public:
|
||||
|
||||
// Overrides
|
||||
// ClassWizard generated virtual function overrides
|
||||
//{{AFX_VIRTUAL(CWaitingTreeCtrl)
|
||||
public:
|
||||
//}}AFX_VIRTUAL
|
||||
|
||||
// Implementation
|
||||
public:
|
||||
void RefreshSubItems(HTREEITEM hParent);
|
||||
void SetWaitMessage(LPCTSTR pszText, HICON hIcon = NULL);
|
||||
void ShowWaitMessage()
|
||||
{
|
||||
m_bShowWaitMsg = TRUE;
|
||||
};
|
||||
|
||||
protected:
|
||||
// animation functions (with timer)
|
||||
void SetAnimationDelay(UINT nMilliseconds);
|
||||
|
||||
// animation functions (with or without timer)
|
||||
virtual void PreAnimation(HTREEITEM hItemMsg);
|
||||
virtual void DoAnimation(BOOL bTimerEvent, int iMaxSteps, int iStep);
|
||||
virtual void PostAnimation();
|
||||
BOOL GetItemImageRect(HTREEITEM hItem, LPRECT pRect);
|
||||
|
||||
// tree content functions
|
||||
void PopulateRoot();
|
||||
virtual BOOL WantsRefresh(HTREEITEM hItem);
|
||||
virtual BOOL PopulateItem(HTREEITEM hParent) = 0; // must be implemented
|
||||
|
||||
// tree content functions (for animations without timer)
|
||||
int GetPopulationCount(int *piMaxSubItems = NULL);
|
||||
void SetPopulationCount(int iMaxSubItems, int iFirstSubItem = 0);
|
||||
void IncreasePopulation(int iSubItemsToAdd = 1);
|
||||
void UpdatePopulation(int iSubItems);
|
||||
|
||||
// Generated message map functions
|
||||
//{{AFX_MSG(CWaitingTreeCtrl)
|
||||
afx_msg void OnItemExpanding(NMHDR* pNMHDR, LRESULT* pResult);
|
||||
afx_msg void OnItemExpanded(NMHDR* pNMHDR, LRESULT* pResult);
|
||||
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
|
||||
//}}AFX_MSG
|
||||
|
||||
DECLARE_MESSAGE_MAP()
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//{{AFX_INSERT_LOCATION}}
|
||||
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
|
||||
|
||||
#endif // !defined(AFX_WAITINGTREECTRL_H__80CBE29B_F1A6_41D5_9DF3_B725E73BCF0F__INCLUDED_)
|
||||
@@ -0,0 +1,727 @@
|
||||
/*
|
||||
Module : SNTP.CPP
|
||||
Purpose: implementation for a MFC class to encapsulate the SNTP protocol
|
||||
Created: PJN / 05-08-1998
|
||||
History: PJN / 16-11-1998 1. m_nOriginateTime was getting set incorrectly in the SNTP response
|
||||
2. GetLastError now works when a timeout occurs.
|
||||
|
||||
Copyright (c) 1998 by PJ Naughter.
|
||||
All rights reserved.
|
||||
|
||||
*/
|
||||
|
||||
///////////////////////////////// Includes //////////////////////////////////
|
||||
#include "stdafx.h"
|
||||
#include "sntp.h"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
|
||||
///////////////////////////////// Macros / Locals ///////////////////////////
|
||||
|
||||
#ifdef _DEBUG
|
||||
//#define new DEBUG_NEW
|
||||
#undef THIS_FILE
|
||||
static char THIS_FILE[] = __FILE__;
|
||||
#endif
|
||||
|
||||
const double NTP_FRACTIONAL_TO_MS = (((double)1000.0)/0xFFFFFFFF);
|
||||
const double NTP_TO_SECOND = (((double)1.0)/0xFFFFFFFF);
|
||||
const long JAN_1ST_1900 = 2415021;
|
||||
|
||||
//Lookup table to convert from Milliseconds (hence 1000 Entries)
|
||||
//to fractions of a second expressed as a DWORD
|
||||
DWORD CNtpTime::m_MsToNTP[1000] =
|
||||
{
|
||||
0x00000000, 0x00418937, 0x0083126f, 0x00c49ba6, 0x010624dd, 0x0147ae14,
|
||||
0x0189374c, 0x01cac083, 0x020c49ba, 0x024dd2f2, 0x028f5c29, 0x02d0e560,
|
||||
0x03126e98, 0x0353f7cf, 0x03958106, 0x03d70a3d, 0x04189375, 0x045a1cac,
|
||||
0x049ba5e3, 0x04dd2f1b, 0x051eb852, 0x05604189, 0x05a1cac1, 0x05e353f8,
|
||||
0x0624dd2f, 0x06666666, 0x06a7ef9e, 0x06e978d5, 0x072b020c, 0x076c8b44,
|
||||
0x07ae147b, 0x07ef9db2, 0x083126e9, 0x0872b021, 0x08b43958, 0x08f5c28f,
|
||||
0x09374bc7, 0x0978d4fe, 0x09ba5e35, 0x09fbe76d, 0x0a3d70a4, 0x0a7ef9db,
|
||||
0x0ac08312, 0x0b020c4a, 0x0b439581, 0x0b851eb8, 0x0bc6a7f0, 0x0c083127,
|
||||
0x0c49ba5e, 0x0c8b4396, 0x0ccccccd, 0x0d0e5604, 0x0d4fdf3b, 0x0d916873,
|
||||
0x0dd2f1aa, 0x0e147ae1, 0x0e560419, 0x0e978d50, 0x0ed91687, 0x0f1a9fbe,
|
||||
0x0f5c28f6, 0x0f9db22d, 0x0fdf3b64, 0x1020c49c, 0x10624dd3, 0x10a3d70a,
|
||||
0x10e56042, 0x1126e979, 0x116872b0, 0x11a9fbe7, 0x11eb851f, 0x122d0e56,
|
||||
0x126e978d, 0x12b020c5, 0x12f1a9fc, 0x13333333, 0x1374bc6a, 0x13b645a2,
|
||||
0x13f7ced9, 0x14395810, 0x147ae148, 0x14bc6a7f, 0x14fdf3b6, 0x153f7cee,
|
||||
0x15810625, 0x15c28f5c, 0x16041893, 0x1645a1cb, 0x16872b02, 0x16c8b439,
|
||||
0x170a3d71, 0x174bc6a8, 0x178d4fdf, 0x17ced917, 0x1810624e, 0x1851eb85,
|
||||
0x189374bc, 0x18d4fdf4, 0x1916872b, 0x19581062, 0x1999999a, 0x19db22d1,
|
||||
0x1a1cac08, 0x1a5e353f, 0x1a9fbe77, 0x1ae147ae, 0x1b22d0e5, 0x1b645a1d,
|
||||
0x1ba5e354, 0x1be76c8b, 0x1c28f5c3, 0x1c6a7efa, 0x1cac0831, 0x1ced9168,
|
||||
0x1d2f1aa0, 0x1d70a3d7, 0x1db22d0e, 0x1df3b646, 0x1e353f7d, 0x1e76c8b4,
|
||||
0x1eb851ec, 0x1ef9db23, 0x1f3b645a, 0x1f7ced91, 0x1fbe76c9, 0x20000000,
|
||||
0x20418937, 0x2083126f, 0x20c49ba6, 0x210624dd, 0x2147ae14, 0x2189374c,
|
||||
0x21cac083, 0x220c49ba, 0x224dd2f2, 0x228f5c29, 0x22d0e560, 0x23126e98,
|
||||
0x2353f7cf, 0x23958106, 0x23d70a3d, 0x24189375, 0x245a1cac, 0x249ba5e3,
|
||||
0x24dd2f1b, 0x251eb852, 0x25604189, 0x25a1cac1, 0x25e353f8, 0x2624dd2f,
|
||||
0x26666666, 0x26a7ef9e, 0x26e978d5, 0x272b020c, 0x276c8b44, 0x27ae147b,
|
||||
0x27ef9db2, 0x283126e9, 0x2872b021, 0x28b43958, 0x28f5c28f, 0x29374bc7,
|
||||
0x2978d4fe, 0x29ba5e35, 0x29fbe76d, 0x2a3d70a4, 0x2a7ef9db, 0x2ac08312,
|
||||
0x2b020c4a, 0x2b439581, 0x2b851eb8, 0x2bc6a7f0, 0x2c083127, 0x2c49ba5e,
|
||||
0x2c8b4396, 0x2ccccccd, 0x2d0e5604, 0x2d4fdf3b, 0x2d916873, 0x2dd2f1aa,
|
||||
0x2e147ae1, 0x2e560419, 0x2e978d50, 0x2ed91687, 0x2f1a9fbe, 0x2f5c28f6,
|
||||
0x2f9db22d, 0x2fdf3b64, 0x3020c49c, 0x30624dd3, 0x30a3d70a, 0x30e56042,
|
||||
0x3126e979, 0x316872b0, 0x31a9fbe7, 0x31eb851f, 0x322d0e56, 0x326e978d,
|
||||
0x32b020c5, 0x32f1a9fc, 0x33333333, 0x3374bc6a, 0x33b645a2, 0x33f7ced9,
|
||||
0x34395810, 0x347ae148, 0x34bc6a7f, 0x34fdf3b6, 0x353f7cee, 0x35810625,
|
||||
0x35c28f5c, 0x36041893, 0x3645a1cb, 0x36872b02, 0x36c8b439, 0x370a3d71,
|
||||
0x374bc6a8, 0x378d4fdf, 0x37ced917, 0x3810624e, 0x3851eb85, 0x389374bc,
|
||||
0x38d4fdf4, 0x3916872b, 0x39581062, 0x3999999a, 0x39db22d1, 0x3a1cac08,
|
||||
0x3a5e353f, 0x3a9fbe77, 0x3ae147ae, 0x3b22d0e5, 0x3b645a1d, 0x3ba5e354,
|
||||
0x3be76c8b, 0x3c28f5c3, 0x3c6a7efa, 0x3cac0831, 0x3ced9168, 0x3d2f1aa0,
|
||||
0x3d70a3d7, 0x3db22d0e, 0x3df3b646, 0x3e353f7d, 0x3e76c8b4, 0x3eb851ec,
|
||||
0x3ef9db23, 0x3f3b645a, 0x3f7ced91, 0x3fbe76c9, 0x40000000, 0x40418937,
|
||||
0x4083126f, 0x40c49ba6, 0x410624dd, 0x4147ae14, 0x4189374c, 0x41cac083,
|
||||
0x420c49ba, 0x424dd2f2, 0x428f5c29, 0x42d0e560, 0x43126e98, 0x4353f7cf,
|
||||
0x43958106, 0x43d70a3d, 0x44189375, 0x445a1cac, 0x449ba5e3, 0x44dd2f1b,
|
||||
0x451eb852, 0x45604189, 0x45a1cac1, 0x45e353f8, 0x4624dd2f, 0x46666666,
|
||||
0x46a7ef9e, 0x46e978d5, 0x472b020c, 0x476c8b44, 0x47ae147b, 0x47ef9db2,
|
||||
0x483126e9, 0x4872b021, 0x48b43958, 0x48f5c28f, 0x49374bc7, 0x4978d4fe,
|
||||
0x49ba5e35, 0x49fbe76d, 0x4a3d70a4, 0x4a7ef9db, 0x4ac08312, 0x4b020c4a,
|
||||
0x4b439581, 0x4b851eb8, 0x4bc6a7f0, 0x4c083127, 0x4c49ba5e, 0x4c8b4396,
|
||||
0x4ccccccd, 0x4d0e5604, 0x4d4fdf3b, 0x4d916873, 0x4dd2f1aa, 0x4e147ae1,
|
||||
0x4e560419, 0x4e978d50, 0x4ed91687, 0x4f1a9fbe, 0x4f5c28f6, 0x4f9db22d,
|
||||
0x4fdf3b64, 0x5020c49c, 0x50624dd3, 0x50a3d70a, 0x50e56042, 0x5126e979,
|
||||
0x516872b0, 0x51a9fbe7, 0x51eb851f, 0x522d0e56, 0x526e978d, 0x52b020c5,
|
||||
0x52f1a9fc, 0x53333333, 0x5374bc6a, 0x53b645a2, 0x53f7ced9, 0x54395810,
|
||||
0x547ae148, 0x54bc6a7f, 0x54fdf3b6, 0x553f7cee, 0x55810625, 0x55c28f5c,
|
||||
0x56041893, 0x5645a1cb, 0x56872b02, 0x56c8b439, 0x570a3d71, 0x574bc6a8,
|
||||
0x578d4fdf, 0x57ced917, 0x5810624e, 0x5851eb85, 0x589374bc, 0x58d4fdf4,
|
||||
0x5916872b, 0x59581062, 0x5999999a, 0x59db22d1, 0x5a1cac08, 0x5a5e353f,
|
||||
0x5a9fbe77, 0x5ae147ae, 0x5b22d0e5, 0x5b645a1d, 0x5ba5e354, 0x5be76c8b,
|
||||
0x5c28f5c3, 0x5c6a7efa, 0x5cac0831, 0x5ced9168, 0x5d2f1aa0, 0x5d70a3d7,
|
||||
0x5db22d0e, 0x5df3b646, 0x5e353f7d, 0x5e76c8b4, 0x5eb851ec, 0x5ef9db23,
|
||||
0x5f3b645a, 0x5f7ced91, 0x5fbe76c9, 0x60000000, 0x60418937, 0x6083126f,
|
||||
0x60c49ba6, 0x610624dd, 0x6147ae14, 0x6189374c, 0x61cac083, 0x620c49ba,
|
||||
0x624dd2f2, 0x628f5c29, 0x62d0e560, 0x63126e98, 0x6353f7cf, 0x63958106,
|
||||
0x63d70a3d, 0x64189375, 0x645a1cac, 0x649ba5e3, 0x64dd2f1b, 0x651eb852,
|
||||
0x65604189, 0x65a1cac1, 0x65e353f8, 0x6624dd2f, 0x66666666, 0x66a7ef9e,
|
||||
0x66e978d5, 0x672b020c, 0x676c8b44, 0x67ae147b, 0x67ef9db2, 0x683126e9,
|
||||
0x6872b021, 0x68b43958, 0x68f5c28f, 0x69374bc7, 0x6978d4fe, 0x69ba5e35,
|
||||
0x69fbe76d, 0x6a3d70a4, 0x6a7ef9db, 0x6ac08312, 0x6b020c4a, 0x6b439581,
|
||||
0x6b851eb8, 0x6bc6a7f0, 0x6c083127, 0x6c49ba5e, 0x6c8b4396, 0x6ccccccd,
|
||||
0x6d0e5604, 0x6d4fdf3b, 0x6d916873, 0x6dd2f1aa, 0x6e147ae1, 0x6e560419,
|
||||
0x6e978d50, 0x6ed91687, 0x6f1a9fbe, 0x6f5c28f6, 0x6f9db22d, 0x6fdf3b64,
|
||||
0x7020c49c, 0x70624dd3, 0x70a3d70a, 0x70e56042, 0x7126e979, 0x716872b0,
|
||||
0x71a9fbe7, 0x71eb851f, 0x722d0e56, 0x726e978d, 0x72b020c5, 0x72f1a9fc,
|
||||
0x73333333, 0x7374bc6a, 0x73b645a2, 0x73f7ced9, 0x74395810, 0x747ae148,
|
||||
0x74bc6a7f, 0x74fdf3b6, 0x753f7cee, 0x75810625, 0x75c28f5c, 0x76041893,
|
||||
0x7645a1cb, 0x76872b02, 0x76c8b439, 0x770a3d71, 0x774bc6a8, 0x778d4fdf,
|
||||
0x77ced917, 0x7810624e, 0x7851eb85, 0x789374bc, 0x78d4fdf4, 0x7916872b,
|
||||
0x79581062, 0x7999999a, 0x79db22d1, 0x7a1cac08, 0x7a5e353f, 0x7a9fbe77,
|
||||
0x7ae147ae, 0x7b22d0e5, 0x7b645a1d, 0x7ba5e354, 0x7be76c8b, 0x7c28f5c3,
|
||||
0x7c6a7efa, 0x7cac0831, 0x7ced9168, 0x7d2f1aa0, 0x7d70a3d7, 0x7db22d0e,
|
||||
0x7df3b646, 0x7e353f7d, 0x7e76c8b4, 0x7eb851ec, 0x7ef9db23, 0x7f3b645a,
|
||||
0x7f7ced91, 0x7fbe76c9, 0x80000000, 0x80418937, 0x8083126f, 0x80c49ba6,
|
||||
0x810624dd, 0x8147ae14, 0x8189374c, 0x81cac083, 0x820c49ba, 0x824dd2f2,
|
||||
0x828f5c29, 0x82d0e560, 0x83126e98, 0x8353f7cf, 0x83958106, 0x83d70a3d,
|
||||
0x84189375, 0x845a1cac, 0x849ba5e3, 0x84dd2f1b, 0x851eb852, 0x85604189,
|
||||
0x85a1cac1, 0x85e353f8, 0x8624dd2f, 0x86666666, 0x86a7ef9e, 0x86e978d5,
|
||||
0x872b020c, 0x876c8b44, 0x87ae147b, 0x87ef9db2, 0x883126e9, 0x8872b021,
|
||||
0x88b43958, 0x88f5c28f, 0x89374bc7, 0x8978d4fe, 0x89ba5e35, 0x89fbe76d,
|
||||
0x8a3d70a4, 0x8a7ef9db, 0x8ac08312, 0x8b020c4a, 0x8b439581, 0x8b851eb8,
|
||||
0x8bc6a7f0, 0x8c083127, 0x8c49ba5e, 0x8c8b4396, 0x8ccccccd, 0x8d0e5604,
|
||||
0x8d4fdf3b, 0x8d916873, 0x8dd2f1aa, 0x8e147ae1, 0x8e560419, 0x8e978d50,
|
||||
0x8ed91687, 0x8f1a9fbe, 0x8f5c28f6, 0x8f9db22d, 0x8fdf3b64, 0x9020c49c,
|
||||
0x90624dd3, 0x90a3d70a, 0x90e56042, 0x9126e979, 0x916872b0, 0x91a9fbe7,
|
||||
0x91eb851f, 0x922d0e56, 0x926e978d, 0x92b020c5, 0x92f1a9fc, 0x93333333,
|
||||
0x9374bc6a, 0x93b645a2, 0x93f7ced9, 0x94395810, 0x947ae148, 0x94bc6a7f,
|
||||
0x94fdf3b6, 0x953f7cee, 0x95810625, 0x95c28f5c, 0x96041893, 0x9645a1cb,
|
||||
0x96872b02, 0x96c8b439, 0x970a3d71, 0x974bc6a8, 0x978d4fdf, 0x97ced917,
|
||||
0x9810624e, 0x9851eb85, 0x989374bc, 0x98d4fdf4, 0x9916872b, 0x99581062,
|
||||
0x9999999a, 0x99db22d1, 0x9a1cac08, 0x9a5e353f, 0x9a9fbe77, 0x9ae147ae,
|
||||
0x9b22d0e5, 0x9b645a1d, 0x9ba5e354, 0x9be76c8b, 0x9c28f5c3, 0x9c6a7efa,
|
||||
0x9cac0831, 0x9ced9168, 0x9d2f1aa0, 0x9d70a3d7, 0x9db22d0e, 0x9df3b646,
|
||||
0x9e353f7d, 0x9e76c8b4, 0x9eb851ec, 0x9ef9db23, 0x9f3b645a, 0x9f7ced91,
|
||||
0x9fbe76c9, 0xa0000000, 0xa0418937, 0xa083126f, 0xa0c49ba6, 0xa10624dd,
|
||||
0xa147ae14, 0xa189374c, 0xa1cac083, 0xa20c49ba, 0xa24dd2f2, 0xa28f5c29,
|
||||
0xa2d0e560, 0xa3126e98, 0xa353f7cf, 0xa3958106, 0xa3d70a3d, 0xa4189375,
|
||||
0xa45a1cac, 0xa49ba5e3, 0xa4dd2f1b, 0xa51eb852, 0xa5604189, 0xa5a1cac1,
|
||||
0xa5e353f8, 0xa624dd2f, 0xa6666666, 0xa6a7ef9e, 0xa6e978d5, 0xa72b020c,
|
||||
0xa76c8b44, 0xa7ae147b, 0xa7ef9db2, 0xa83126e9, 0xa872b021, 0xa8b43958,
|
||||
0xa8f5c28f, 0xa9374bc7, 0xa978d4fe, 0xa9ba5e35, 0xa9fbe76d, 0xaa3d70a4,
|
||||
0xaa7ef9db, 0xaac08312, 0xab020c4a, 0xab439581, 0xab851eb8, 0xabc6a7f0,
|
||||
0xac083127, 0xac49ba5e, 0xac8b4396, 0xaccccccd, 0xad0e5604, 0xad4fdf3b,
|
||||
0xad916873, 0xadd2f1aa, 0xae147ae1, 0xae560419, 0xae978d50, 0xaed91687,
|
||||
0xaf1a9fbe, 0xaf5c28f6, 0xaf9db22d, 0xafdf3b64, 0xb020c49c, 0xb0624dd3,
|
||||
0xb0a3d70a, 0xb0e56042, 0xb126e979, 0xb16872b0, 0xb1a9fbe7, 0xb1eb851f,
|
||||
0xb22d0e56, 0xb26e978d, 0xb2b020c5, 0xb2f1a9fc, 0xb3333333, 0xb374bc6a,
|
||||
0xb3b645a2, 0xb3f7ced9, 0xb4395810, 0xb47ae148, 0xb4bc6a7f, 0xb4fdf3b6,
|
||||
0xb53f7cee, 0xb5810625, 0xb5c28f5c, 0xb6041893, 0xb645a1cb, 0xb6872b02,
|
||||
0xb6c8b439, 0xb70a3d71, 0xb74bc6a8, 0xb78d4fdf, 0xb7ced917, 0xb810624e,
|
||||
0xb851eb85, 0xb89374bc, 0xb8d4fdf4, 0xb916872b, 0xb9581062, 0xb999999a,
|
||||
0xb9db22d1, 0xba1cac08, 0xba5e353f, 0xba9fbe77, 0xbae147ae, 0xbb22d0e5,
|
||||
0xbb645a1d, 0xbba5e354, 0xbbe76c8b, 0xbc28f5c3, 0xbc6a7efa, 0xbcac0831,
|
||||
0xbced9168, 0xbd2f1aa0, 0xbd70a3d7, 0xbdb22d0e, 0xbdf3b646, 0xbe353f7d,
|
||||
0xbe76c8b4, 0xbeb851ec, 0xbef9db23, 0xbf3b645a, 0xbf7ced91, 0xbfbe76c9,
|
||||
0xc0000000, 0xc0418937, 0xc083126f, 0xc0c49ba6, 0xc10624dd, 0xc147ae14,
|
||||
0xc189374c, 0xc1cac083, 0xc20c49ba, 0xc24dd2f2, 0xc28f5c29, 0xc2d0e560,
|
||||
0xc3126e98, 0xc353f7cf, 0xc3958106, 0xc3d70a3d, 0xc4189375, 0xc45a1cac,
|
||||
0xc49ba5e3, 0xc4dd2f1b, 0xc51eb852, 0xc5604189, 0xc5a1cac1, 0xc5e353f8,
|
||||
0xc624dd2f, 0xc6666666, 0xc6a7ef9e, 0xc6e978d5, 0xc72b020c, 0xc76c8b44,
|
||||
0xc7ae147b, 0xc7ef9db2, 0xc83126e9, 0xc872b021, 0xc8b43958, 0xc8f5c28f,
|
||||
0xc9374bc7, 0xc978d4fe, 0xc9ba5e35, 0xc9fbe76d, 0xca3d70a4, 0xca7ef9db,
|
||||
0xcac08312, 0xcb020c4a, 0xcb439581, 0xcb851eb8, 0xcbc6a7f0, 0xcc083127,
|
||||
0xcc49ba5e, 0xcc8b4396, 0xcccccccd, 0xcd0e5604, 0xcd4fdf3b, 0xcd916873,
|
||||
0xcdd2f1aa, 0xce147ae1, 0xce560419, 0xce978d50, 0xced91687, 0xcf1a9fbe,
|
||||
0xcf5c28f6, 0xcf9db22d, 0xcfdf3b64, 0xd020c49c, 0xd0624dd3, 0xd0a3d70a,
|
||||
0xd0e56042, 0xd126e979, 0xd16872b0, 0xd1a9fbe7, 0xd1eb851f, 0xd22d0e56,
|
||||
0xd26e978d, 0xd2b020c5, 0xd2f1a9fc, 0xd3333333, 0xd374bc6a, 0xd3b645a2,
|
||||
0xd3f7ced9, 0xd4395810, 0xd47ae148, 0xd4bc6a7f, 0xd4fdf3b6, 0xd53f7cee,
|
||||
0xd5810625, 0xd5c28f5c, 0xd6041893, 0xd645a1cb, 0xd6872b02, 0xd6c8b439,
|
||||
0xd70a3d71, 0xd74bc6a8, 0xd78d4fdf, 0xd7ced917, 0xd810624e, 0xd851eb85,
|
||||
0xd89374bc, 0xd8d4fdf4, 0xd916872b, 0xd9581062, 0xd999999a, 0xd9db22d1,
|
||||
0xda1cac08, 0xda5e353f, 0xda9fbe77, 0xdae147ae, 0xdb22d0e5, 0xdb645a1d,
|
||||
0xdba5e354, 0xdbe76c8b, 0xdc28f5c3, 0xdc6a7efa, 0xdcac0831, 0xdced9168,
|
||||
0xdd2f1aa0, 0xdd70a3d7, 0xddb22d0e, 0xddf3b646, 0xde353f7d, 0xde76c8b4,
|
||||
0xdeb851ec, 0xdef9db23, 0xdf3b645a, 0xdf7ced91, 0xdfbe76c9, 0xe0000000,
|
||||
0xe0418937, 0xe083126f, 0xe0c49ba6, 0xe10624dd, 0xe147ae14, 0xe189374c,
|
||||
0xe1cac083, 0xe20c49ba, 0xe24dd2f2, 0xe28f5c29, 0xe2d0e560, 0xe3126e98,
|
||||
0xe353f7cf, 0xe3958106, 0xe3d70a3d, 0xe4189375, 0xe45a1cac, 0xe49ba5e3,
|
||||
0xe4dd2f1b, 0xe51eb852, 0xe5604189, 0xe5a1cac1, 0xe5e353f8, 0xe624dd2f,
|
||||
0xe6666666, 0xe6a7ef9e, 0xe6e978d5, 0xe72b020c, 0xe76c8b44, 0xe7ae147b,
|
||||
0xe7ef9db2, 0xe83126e9, 0xe872b021, 0xe8b43958, 0xe8f5c28f, 0xe9374bc7,
|
||||
0xe978d4fe, 0xe9ba5e35, 0xe9fbe76d, 0xea3d70a4, 0xea7ef9db, 0xeac08312,
|
||||
0xeb020c4a, 0xeb439581, 0xeb851eb8, 0xebc6a7f0, 0xec083127, 0xec49ba5e,
|
||||
0xec8b4396, 0xeccccccd, 0xed0e5604, 0xed4fdf3b, 0xed916873, 0xedd2f1aa,
|
||||
0xee147ae1, 0xee560419, 0xee978d50, 0xeed91687, 0xef1a9fbe, 0xef5c28f6,
|
||||
0xef9db22d, 0xefdf3b64, 0xf020c49c, 0xf0624dd3, 0xf0a3d70a, 0xf0e56042,
|
||||
0xf126e979, 0xf16872b0, 0xf1a9fbe7, 0xf1eb851f, 0xf22d0e56, 0xf26e978d,
|
||||
0xf2b020c5, 0xf2f1a9fc, 0xf3333333, 0xf374bc6a, 0xf3b645a2, 0xf3f7ced9,
|
||||
0xf4395810, 0xf47ae148, 0xf4bc6a7f, 0xf4fdf3b6, 0xf53f7cee, 0xf5810625,
|
||||
0xf5c28f5c, 0xf6041893, 0xf645a1cb, 0xf6872b02, 0xf6c8b439, 0xf70a3d71,
|
||||
0xf74bc6a8, 0xf78d4fdf, 0xf7ced917, 0xf810624e, 0xf851eb85, 0xf89374bc,
|
||||
0xf8d4fdf4, 0xf916872b, 0xf9581062, 0xf999999a, 0xf9db22d1, 0xfa1cac08,
|
||||
0xfa5e353f, 0xfa9fbe77, 0xfae147ae, 0xfb22d0e5, 0xfb645a1d, 0xfba5e354,
|
||||
0xfbe76c8b, 0xfc28f5c3, 0xfc6a7efa, 0xfcac0831, 0xfced9168, 0xfd2f1aa0,
|
||||
0xfd70a3d7, 0xfdb22d0e, 0xfdf3b646, 0xfe353f7d, 0xfe76c8b4, 0xfeb851ec,
|
||||
0xfef9db23, 0xff3b645a, 0xff7ced91, 0xffbe76c9
|
||||
};
|
||||
|
||||
//The mandatory part of an NTP packet
|
||||
struct NtpBasicInfo
|
||||
{
|
||||
BYTE m_LiVnMode;
|
||||
BYTE m_Stratum;
|
||||
char m_Poll;
|
||||
char m_Precision;
|
||||
long m_RootDelay;
|
||||
long m_RootDispersion;
|
||||
char m_ReferenceID[4];
|
||||
CNtpTimePacket m_ReferenceTimestamp;
|
||||
CNtpTimePacket m_OriginateTimestamp;
|
||||
CNtpTimePacket m_ReceiveTimestamp;
|
||||
CNtpTimePacket m_TransmitTimestamp;
|
||||
};
|
||||
|
||||
//The optional part of an NTP packet
|
||||
struct NtpAuthenticationInfo
|
||||
{
|
||||
unsigned long m_KeyID;
|
||||
BYTE m_MessageDigest[16];
|
||||
};
|
||||
|
||||
//The Full NTP packet
|
||||
struct NtpFullPacket
|
||||
{
|
||||
NtpBasicInfo m_Basic;
|
||||
NtpAuthenticationInfo m_Auth;
|
||||
};
|
||||
|
||||
//Simple wrapper class for an Ntp socket
|
||||
class CNtpSocket
|
||||
{
|
||||
public:
|
||||
//Constructors / Destructors
|
||||
CNtpSocket();
|
||||
~CNtpSocket();
|
||||
|
||||
//General functions
|
||||
BOOL Create();
|
||||
BOOL Connect(LPCTSTR pszHostAddress, int nPort);
|
||||
BOOL Send(LPCSTR pszBuf, int nBuf);
|
||||
int Receive(LPSTR pszBuf, int nBuf);
|
||||
void Close();
|
||||
BOOL IsReadible(BOOL& bReadible, DWORD dwTimeout);
|
||||
|
||||
protected:
|
||||
BOOL Connect(const SOCKADDR* lpSockAddr, int nSockAddrLen);
|
||||
SOCKET m_hSocket;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
///////////////////////////////// Implementation //////////////////////////////
|
||||
|
||||
CNtpTime::CNtpTime()
|
||||
{
|
||||
m_Time = 0;
|
||||
}
|
||||
|
||||
CNtpTime::CNtpTime(const CNtpTime& time)
|
||||
{
|
||||
*this = time;
|
||||
}
|
||||
|
||||
CNtpTime::CNtpTime(CNtpTimePacket& packet)
|
||||
{
|
||||
DWORD dwLow = ntohl(packet.m_dwFractional);
|
||||
DWORD dwHigh = ntohl(packet.m_dwInteger);
|
||||
m_Time = ((unsigned __int64) dwHigh) << 32;
|
||||
m_Time += dwLow;
|
||||
}
|
||||
|
||||
CNtpTime::CNtpTime(const SYSTEMTIME& st)
|
||||
{
|
||||
//Currently this function only operates correctly in
|
||||
//the 1900 - 2036 primary epoch defined by NTP
|
||||
|
||||
long JD = GetJulianDay(st.wYear, st.wMonth, st.wDay);
|
||||
JD -= JAN_1ST_1900;
|
||||
|
||||
// ASSERT(JD >= 0); //NTP only supports dates greater than 1900
|
||||
unsigned __int64 Seconds = JD;
|
||||
Seconds = (Seconds * 24) + st.wHour;
|
||||
Seconds = (Seconds * 60) + st.wMinute;
|
||||
Seconds = (Seconds * 60) + st.wSecond;
|
||||
// ASSERT(Seconds <= 0xFFFFFFFF); //NTP Only supports up to 2036
|
||||
m_Time = (Seconds << 32) + MsToNtpFraction(st.wMilliseconds);
|
||||
}
|
||||
|
||||
long CNtpTime::GetJulianDay(WORD Year, WORD Month, WORD Day)
|
||||
{
|
||||
long y = (long) Year;
|
||||
long m = (long) Month;
|
||||
long d = (long) Day;
|
||||
if (m > 2)
|
||||
m = m - 3;
|
||||
else
|
||||
{
|
||||
m = m + 9;
|
||||
y = y - 1;
|
||||
}
|
||||
long c = y / 100;
|
||||
long ya = y - 100 * c;
|
||||
long j = (146097L * c) / 4 + (1461L * ya) / 4 + (153L * m + 2) / 5 + d + 1721119L;
|
||||
return j;
|
||||
}
|
||||
|
||||
void CNtpTime::GetGregorianDate(long JD, WORD& Year, WORD& Month, WORD& Day)
|
||||
{
|
||||
long j = JD - 1721119;
|
||||
long y = (4 * j - 1) / 146097;
|
||||
j = 4 * j - 1 - 146097 * y;
|
||||
long d = j / 4;
|
||||
j = (4 * d + 3) / 1461;
|
||||
d = 4 * d + 3 - 1461 * j;
|
||||
d = (d + 4) / 4;
|
||||
long m = (5 * d - 3) / 153;
|
||||
d = 5 * d - 3 - 153 * m;
|
||||
d = (d + 5) / 5;
|
||||
y = 100 * y + j;
|
||||
if (m < 10)
|
||||
m = m + 3;
|
||||
else
|
||||
{
|
||||
m = m - 9;
|
||||
y = y + 1;
|
||||
}
|
||||
|
||||
Year = (WORD) y;
|
||||
Month = (WORD) m;
|
||||
Day = (WORD) d;
|
||||
}
|
||||
|
||||
CNtpTime& CNtpTime::operator=(const CNtpTime& time)
|
||||
{
|
||||
m_Time = time.m_Time;
|
||||
return *this;
|
||||
}
|
||||
|
||||
double CNtpTime::operator-(const CNtpTime& time) const
|
||||
{
|
||||
if (m_Time >= time.m_Time)
|
||||
{
|
||||
CNtpTime diff;
|
||||
diff.m_Time = m_Time - time.m_Time;
|
||||
return diff.Seconds() + NtpFractionToSecond(diff.Fraction());
|
||||
}
|
||||
else
|
||||
{
|
||||
CNtpTime diff;
|
||||
diff.m_Time = time.m_Time - m_Time;
|
||||
return -(diff.Seconds() + NtpFractionToSecond(diff.Fraction()));
|
||||
}
|
||||
}
|
||||
|
||||
CNtpTime CNtpTime::operator+(const double& timespan) const
|
||||
{
|
||||
CNtpTime rVal;
|
||||
rVal.m_Time = m_Time;
|
||||
|
||||
if (timespan >= 0)
|
||||
{
|
||||
unsigned __int64 diff = ((unsigned __int64) timespan) << 32;
|
||||
double intpart;
|
||||
double frac = modf(timespan, &intpart);
|
||||
diff += (unsigned __int64) (frac * 0xFFFFFFFF);
|
||||
|
||||
rVal.m_Time += diff;
|
||||
}
|
||||
else
|
||||
{
|
||||
double d = -timespan;
|
||||
unsigned __int64 diff = ((unsigned __int64) d) << 32;
|
||||
double intpart;
|
||||
double frac = modf(d, &intpart);
|
||||
diff += (unsigned __int64) (frac * 0xFFFFFFFF);
|
||||
|
||||
rVal.m_Time -= diff;
|
||||
}
|
||||
|
||||
return rVal;
|
||||
}
|
||||
|
||||
CNtpTime::operator SYSTEMTIME() const
|
||||
{
|
||||
//Currently this function only operates correctly in
|
||||
//the 1900 - 2036 primary epoch defined by NTP
|
||||
|
||||
SYSTEMTIME st;
|
||||
DWORD s = Seconds();
|
||||
st.wSecond = (WORD)(s % 60);
|
||||
s /= 60;
|
||||
st.wMinute = (WORD)(s % 60);
|
||||
s /= 60;
|
||||
st.wHour = (WORD)(s % 24);
|
||||
s /= 24;
|
||||
long JD = s + JAN_1ST_1900;
|
||||
st.wDayOfWeek = (WORD)((JD + 1) % 7);
|
||||
GetGregorianDate(JD, st.wYear, st.wMonth, st.wDay);
|
||||
st.wMilliseconds = NtpFractionToMs(Fraction());
|
||||
|
||||
return st;
|
||||
}
|
||||
|
||||
DWORD CNtpTime::Seconds() const
|
||||
{
|
||||
return (DWORD) ((m_Time & 0xFFFFFFFF00000000) >> 32);
|
||||
}
|
||||
|
||||
DWORD CNtpTime::Fraction() const
|
||||
{
|
||||
return (DWORD) (m_Time & 0xFFFFFFFF);
|
||||
}
|
||||
|
||||
CNtpTime::operator CNtpTimePacket() const
|
||||
{
|
||||
CNtpTimePacket ntp;
|
||||
ntp.m_dwInteger = htonl(Seconds());
|
||||
ntp.m_dwFractional = htonl(Fraction());
|
||||
return ntp;
|
||||
}
|
||||
|
||||
CNtpTime CNtpTime::GetCurrentTime()
|
||||
{
|
||||
SYSTEMTIME st;
|
||||
GetSystemTime(&st);
|
||||
CNtpTime t(st);
|
||||
return t;
|
||||
}
|
||||
|
||||
DWORD CNtpTime::MsToNtpFraction(WORD wMilliSeconds)
|
||||
{
|
||||
// ASSERT(wMilliSeconds < 1000);
|
||||
return m_MsToNTP[wMilliSeconds];
|
||||
}
|
||||
|
||||
WORD CNtpTime::NtpFractionToMs(DWORD dwFraction)
|
||||
{
|
||||
return (WORD)((((double)dwFraction) * NTP_FRACTIONAL_TO_MS) + 0.5);
|
||||
}
|
||||
|
||||
double CNtpTime::NtpFractionToSecond(DWORD dwFraction)
|
||||
{
|
||||
double d = (double)dwFraction;
|
||||
d *= NTP_TO_SECOND;
|
||||
return ((double)dwFraction) * NTP_TO_SECOND;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
CNtpSocket::CNtpSocket()
|
||||
{
|
||||
m_hSocket = INVALID_SOCKET; //default to an invalid scoket descriptor
|
||||
}
|
||||
|
||||
CNtpSocket::~CNtpSocket()
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
BOOL CNtpSocket::Create()
|
||||
{
|
||||
//NTP Uses UDP instead of the usual TCP
|
||||
m_hSocket = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
return (m_hSocket != INVALID_SOCKET);
|
||||
}
|
||||
|
||||
BOOL CNtpSocket::Connect(LPCTSTR pszHostAddress, int nPort)
|
||||
{
|
||||
//For correct operation of the T2A macro, see MFC Tech Note 59
|
||||
USES_CONVERSION;
|
||||
|
||||
//must have been created first
|
||||
// ASSERT(m_hSocket != INVALID_SOCKET);
|
||||
|
||||
LPSTR lpszAscii = T2A((LPTSTR)pszHostAddress);
|
||||
|
||||
//Determine if the address is in dotted notation
|
||||
SOCKADDR_IN sockAddr;
|
||||
ZeroMemory(&sockAddr, sizeof(sockAddr));
|
||||
sockAddr.sin_family = AF_INET;
|
||||
sockAddr.sin_port = htons((u_short)nPort);
|
||||
sockAddr.sin_addr.s_addr = inet_addr(lpszAscii);
|
||||
|
||||
//If the address is not dotted notation, then do a DNS
|
||||
//lookup of it.
|
||||
if (sockAddr.sin_addr.s_addr == INADDR_NONE)
|
||||
{
|
||||
LPHOSTENT lphost;
|
||||
lphost = gethostbyname(lpszAscii);
|
||||
if (lphost != NULL)
|
||||
sockAddr.sin_addr.s_addr = ((LPIN_ADDR)lphost->h_addr)->s_addr;
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
//Call the protected version which takes an address
|
||||
//in the form of a standard C style struct.
|
||||
return Connect((SOCKADDR*)&sockAddr, sizeof(sockAddr));
|
||||
}
|
||||
|
||||
BOOL CNtpSocket::Connect(const SOCKADDR* lpSockAddr, int nSockAddrLen)
|
||||
{
|
||||
int nConnect = connect(m_hSocket, lpSockAddr, nSockAddrLen);
|
||||
return (nConnect == 0);
|
||||
}
|
||||
|
||||
BOOL CNtpSocket::Send(LPCSTR pszBuf, int nBuf)
|
||||
{
|
||||
//must have been created first
|
||||
// ASSERT(m_hSocket != INVALID_SOCKET);
|
||||
|
||||
return (send(m_hSocket, pszBuf, nBuf, 0) != SOCKET_ERROR);
|
||||
}
|
||||
|
||||
int CNtpSocket::Receive(LPSTR pszBuf, int nBuf)
|
||||
{
|
||||
//must have been created first
|
||||
// ASSERT(m_hSocket != INVALID_SOCKET);
|
||||
|
||||
return recv(m_hSocket, pszBuf, nBuf, 0);
|
||||
}
|
||||
|
||||
void CNtpSocket::Close()
|
||||
{
|
||||
if (m_hSocket != INVALID_SOCKET)
|
||||
{
|
||||
// VERIFY(SOCKET_ERROR != closesocket(m_hSocket));
|
||||
m_hSocket = INVALID_SOCKET;
|
||||
}
|
||||
}
|
||||
|
||||
BOOL CNtpSocket::IsReadible(BOOL& bReadible, DWORD dwTimeout)
|
||||
{
|
||||
timeval timeout;
|
||||
timeout.tv_sec = dwTimeout / 1000;
|
||||
timeout.tv_usec = dwTimeout % 1000;
|
||||
fd_set fds;
|
||||
FD_ZERO(&fds);
|
||||
FD_SET(m_hSocket, &fds);
|
||||
int nStatus = select(0, &fds, NULL, NULL, &timeout);
|
||||
if (nStatus == SOCKET_ERROR)
|
||||
return FALSE;
|
||||
else
|
||||
{
|
||||
bReadible = !(nStatus == 0);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
CSNTPClient::CSNTPClient()
|
||||
{
|
||||
m_dwTimeout = 5000; //Default timeout of 5 seconds
|
||||
}
|
||||
|
||||
BOOL CSNTPClient::GetServerTime(LPCTSTR pszHostName, NtpServerResponse& response, int nPort)
|
||||
{
|
||||
//For correct operation of the T2A macro, see MFC Tech Note 59
|
||||
USES_CONVERSION;
|
||||
|
||||
//paramater validity checking
|
||||
// ASSERT(pszHostName);
|
||||
|
||||
//Create the socket, Allocated of the heap so we can control
|
||||
//the time when it's destructor is called. This means that
|
||||
//we can call SetLastError after its destructor
|
||||
CNtpSocket* pSocket = new CNtpSocket();
|
||||
if (!pSocket->Create())
|
||||
{
|
||||
// TRACE(_T("Failed to create client socket, GetLastError returns: %d\n"), GetLastError());
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
//Connect to the SNTP server
|
||||
if (!pSocket->Connect(pszHostName, nPort))
|
||||
{
|
||||
// TRACE(_T("Could not connect to the SNTP server %s on port %d, GetLastError returns: %d\n"), pszHostName, nPort, GetLastError());
|
||||
|
||||
//Tidy up prior to returning
|
||||
DWORD dwError = GetLastError();
|
||||
delete pSocket;
|
||||
SetLastError(dwError);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Initialise the NtpBasicInfo packet
|
||||
NtpBasicInfo nbi;
|
||||
int nSendSize = sizeof(NtpBasicInfo);
|
||||
ZeroMemory(&nbi, nSendSize);
|
||||
nbi.m_LiVnMode = 27; //Encoded representation which represents NTP Client Request & NTP version 3.0
|
||||
nbi.m_TransmitTimestamp = CNtpTime::GetCurrentTime();
|
||||
|
||||
//Send off the NtpBasicInfo packet
|
||||
if (!pSocket->Send((LPCSTR) &nbi, nSendSize))
|
||||
{
|
||||
// TRACE(_T("Failed in call to send NTP request to the SNTP server, GetLastError returns %d\n"), GetLastError());
|
||||
|
||||
//Tidy up prior to returning
|
||||
DWORD dwError = GetLastError();
|
||||
delete pSocket;
|
||||
SetLastError(dwError);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
//Need to use select to determine readibilty of socket
|
||||
BOOL bReadable;
|
||||
if (!pSocket->IsReadible(bReadable, m_dwTimeout) || !bReadable)
|
||||
{
|
||||
// TRACE(_T("Unable to wait for NTP reply from the SNTP server, GetLastError returns %d\n"), WSAETIMEDOUT);
|
||||
|
||||
//Tidy up prior to returning
|
||||
delete pSocket;
|
||||
SetLastError(WSAETIMEDOUT);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
response.m_DestinationTime = CNtpTime::GetCurrentTime();
|
||||
|
||||
//read back the response into the NtpFullPacket struct
|
||||
NtpFullPacket nfp;
|
||||
int nReceiveSize = sizeof(NtpFullPacket);
|
||||
ZeroMemory(&nfp, nReceiveSize);
|
||||
if (!pSocket->Receive((LPSTR) &nfp, nReceiveSize))
|
||||
{
|
||||
// TRACE(_T("Unable to read reply from the SNTP server, GetLastError returns %d\n"), GetLastError());
|
||||
|
||||
//Tidy up prior to returning
|
||||
DWORD dwError = GetLastError();
|
||||
delete pSocket;
|
||||
SetLastError(dwError);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
//Transfer all the useful info into the response structure
|
||||
response.m_nStratum = nfp.m_Basic.m_Stratum;
|
||||
response.m_nLeapIndicator = (nfp.m_Basic.m_LiVnMode & 0xC0) >> 6;
|
||||
response.m_OriginateTime = nfp.m_Basic.m_OriginateTimestamp;
|
||||
response.m_ReceiveTime = nfp.m_Basic.m_ReceiveTimestamp;
|
||||
response.m_TransmitTime = nfp.m_Basic.m_TransmitTimestamp;
|
||||
response.m_RoundTripDelay = (response.m_DestinationTime - response.m_OriginateTime) - (response.m_ReceiveTime - response.m_TransmitTime);
|
||||
response.m_LocalClockOffset = ((response.m_ReceiveTime - response.m_OriginateTime) + (response.m_TransmitTime - response.m_DestinationTime)) / 2;
|
||||
|
||||
//Tidy up prior to returning
|
||||
delete pSocket;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
BOOL CSNTPClient::EnableSetTimePriviledge()
|
||||
{
|
||||
BOOL bOpenToken = OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES |
|
||||
TOKEN_QUERY, &m_hToken);
|
||||
|
||||
m_bTakenPriviledge = FALSE;
|
||||
if (!bOpenToken)
|
||||
{
|
||||
if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
|
||||
{
|
||||
//Must be running on 95 or 98 not NT. In that case just ignore the error
|
||||
SetLastError(ERROR_SUCCESS);
|
||||
return TRUE;
|
||||
}
|
||||
// TRACE(_T("Failed to get Adjust priviledge token\n"));
|
||||
return FALSE;
|
||||
}
|
||||
ZeroMemory(&m_TokenPriv, sizeof(TOKEN_PRIVILEGES));
|
||||
if (!LookupPrivilegeValue(NULL, SE_SYSTEMTIME_NAME, &m_TokenPriv.Privileges[0].Luid))
|
||||
{
|
||||
// TRACE(_T("Failed in callup to lookup priviledge\n"));
|
||||
return FALSE;
|
||||
}
|
||||
m_TokenPriv.PrivilegeCount = 1;
|
||||
m_TokenPriv.Privileges[0].Attributes |= SE_PRIVILEGE_ENABLED;
|
||||
m_bTakenPriviledge = TRUE;
|
||||
|
||||
BOOL bSuccess = AdjustTokenPrivileges(m_hToken, FALSE, &m_TokenPriv, 0, NULL, 0);
|
||||
// if (!bSuccess)
|
||||
// TRACE(_T("Failed to adjust SetTime priviledge\n"));
|
||||
|
||||
return bSuccess;
|
||||
}
|
||||
|
||||
void CSNTPClient::RevertSetTimePriviledge()
|
||||
{
|
||||
if (m_bTakenPriviledge)
|
||||
{
|
||||
m_TokenPriv.Privileges[0].Attributes &= (~SE_PRIVILEGE_ENABLED);
|
||||
AdjustTokenPrivileges(m_hToken, FALSE, &m_TokenPriv, 0, NULL, 0);
|
||||
// if (!AdjustTokenPrivileges(m_hToken, FALSE, &m_TokenPriv, 0, NULL, 0))
|
||||
// TRACE(_T("Failed to reset SetTime priviledge\n"));
|
||||
}
|
||||
}
|
||||
|
||||
BOOL CSNTPClient::SetClientTime(const CNtpTime& NewTime)
|
||||
{
|
||||
BOOL bSuccess = FALSE;
|
||||
if (EnableSetTimePriviledge())
|
||||
{
|
||||
SYSTEMTIME st = NewTime;
|
||||
bSuccess = SetSystemTime(&st);
|
||||
// if (!bSuccess)
|
||||
// TRACE(_T("Failed in call to set the system time\n"));
|
||||
}
|
||||
RevertSetTimePriviledge();
|
||||
|
||||
return bSuccess;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
Module : SNTP.H
|
||||
Purpose: Interface for a MFC class to encapsulate the SNTP protocol
|
||||
Created: PJN / 05-08-1998
|
||||
History: PJN / None
|
||||
|
||||
|
||||
Copyright (c) 1998 by PJ Naughter.
|
||||
All rights reserved.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#ifndef __SNTP_H__
|
||||
#define __SNTP_H__
|
||||
|
||||
|
||||
|
||||
///////////////////////////////// Classes //////////////////////////////
|
||||
|
||||
//Representation of an NTP timestamp
|
||||
struct CNtpTimePacket
|
||||
{
|
||||
DWORD m_dwInteger;
|
||||
DWORD m_dwFractional;
|
||||
};
|
||||
|
||||
//Helper class to encapulate NTP time stamps
|
||||
class CNtpTime
|
||||
{
|
||||
public:
|
||||
//Constructors / Destructors
|
||||
CNtpTime();
|
||||
CNtpTime(const CNtpTime& time);
|
||||
CNtpTime(CNtpTimePacket& packet);
|
||||
CNtpTime(const SYSTEMTIME& st);
|
||||
|
||||
//General functions
|
||||
CNtpTime& operator=(const CNtpTime& time);
|
||||
double operator-(const CNtpTime& time) const;
|
||||
CNtpTime operator+(const double& timespan) const;
|
||||
operator SYSTEMTIME() const;
|
||||
operator CNtpTimePacket() const;
|
||||
operator unsigned __int64() const { return m_Time; };
|
||||
DWORD Seconds() const;
|
||||
DWORD Fraction() const;
|
||||
|
||||
//Static functions
|
||||
static CNtpTime GetCurrentTime();
|
||||
static DWORD MsToNtpFraction(WORD wMilliSeconds);
|
||||
static WORD NtpFractionToMs(DWORD dwFraction);
|
||||
static double NtpFractionToSecond(DWORD dwFraction);
|
||||
|
||||
protected:
|
||||
//Internal static functions and data
|
||||
static long GetJulianDay(WORD Year, WORD Month, WORD Day);
|
||||
static void GetGregorianDate(long JD, WORD& Year, WORD& Month, WORD& Day);
|
||||
static DWORD m_MsToNTP[1000];
|
||||
|
||||
//The actual data
|
||||
unsigned __int64 m_Time;
|
||||
};
|
||||
|
||||
struct NtpServerResponse
|
||||
{
|
||||
int m_nLeapIndicator; //0: no warning
|
||||
//1: last minute in day has 61 seconds
|
||||
//2: last minute has 59 seconds
|
||||
//3: clock not synchronized
|
||||
|
||||
int m_nStratum; //0: unspecified or unavailable
|
||||
//1: primary reference (e.g., radio clock)
|
||||
//2-15: secondary reference (via NTP or SNTP)
|
||||
//16-255: reserved
|
||||
|
||||
CNtpTime m_OriginateTime; //Time when the request was sent from the client to the SNTP server
|
||||
CNtpTime m_ReceiveTime; //Time when the request was received by the server
|
||||
CNtpTime m_TransmitTime; //Time when the server sent the request back to the client
|
||||
CNtpTime m_DestinationTime; //Time when the reply was received by the client
|
||||
double m_RoundTripDelay; //Round trip time in seconds
|
||||
double m_LocalClockOffset; //Local clock offset relative to the server
|
||||
};
|
||||
|
||||
//The actual SNTP class
|
||||
class CSNTPClient
|
||||
{
|
||||
public:
|
||||
//Constructors / Destructors
|
||||
CSNTPClient();
|
||||
|
||||
//General functions
|
||||
BOOL GetServerTime(LPCTSTR pszHostName, NtpServerResponse& response, int nPort = 123);
|
||||
DWORD GetTimeout() const { return m_dwTimeout; };
|
||||
void SetTimeout(DWORD dwTimeout) { m_dwTimeout = dwTimeout; };
|
||||
BOOL SetClientTime(const CNtpTime& NewTime);
|
||||
|
||||
protected:
|
||||
BOOL EnableSetTimePriviledge();
|
||||
void RevertSetTimePriviledge();
|
||||
|
||||
DWORD m_dwTimeout;
|
||||
HANDLE m_hToken;
|
||||
TOKEN_PRIVILEGES m_TokenPriv;
|
||||
BOOL m_bTakenPriviledge;
|
||||
};
|
||||
|
||||
#endif //__SNTP_H__
|
||||
@@ -0,0 +1,235 @@
|
||||
// TextProgressCtrl.cpp : implementation file
|
||||
//
|
||||
// Written by Chris Maunder (chrismaunder@codeguru.com)
|
||||
// Copyright 1998.
|
||||
//
|
||||
// Modified : 26/05/98 Jeremy Davis, jmd@jvf.co.uk
|
||||
// Added colour routines
|
||||
//
|
||||
// TextProgressCtrl is a drop-in replacement for the standard
|
||||
// CProgressCtrl that displays text in a progress control.
|
||||
//
|
||||
// This code may be used in compiled form in any way you desire. This
|
||||
// file may be redistributed by any means PROVIDING it is not sold for
|
||||
// profit without the authors written consent, and providing that this
|
||||
// notice and the authors name is included. If the source code in
|
||||
// this file is used in any commercial application then an email to
|
||||
// the me would be nice.
|
||||
//
|
||||
// This file is provided "as is" with no expressed or implied warranty.
|
||||
// The author accepts no liability if it causes any damage to your
|
||||
// computer, causes your pet cat to fall ill, increases baldness or
|
||||
// makes you car start emitting strange noises when you start it up.
|
||||
//
|
||||
// Expect bugs.
|
||||
//
|
||||
// Please use and enjoy. Please let me know of any bugs/mods/improvements
|
||||
// that you have found/implemented and I will fix/incorporate them into this
|
||||
// file.
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "TextProgressCtrl.h"
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define new DEBUG_NEW
|
||||
#undef THIS_FILE
|
||||
static char THIS_FILE[] = __FILE__;
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CTextProgressCtrl
|
||||
|
||||
CTextProgressCtrl::CTextProgressCtrl()
|
||||
{
|
||||
m_nPos = 0;
|
||||
m_nStepSize = 1;
|
||||
m_nMax = 100;
|
||||
m_nMin = 0;
|
||||
m_colFore = ::GetSysColor(COLOR_HIGHLIGHT);
|
||||
m_colBk = 0xFFFFFF;//::GetSysColor(COLOR_MENU);
|
||||
m_colTextFore = 0x98938A;
|
||||
m_colTextBk = 0x056284;
|
||||
m_bShowText = TRUE;
|
||||
|
||||
m_nBarWidth = -1;
|
||||
}
|
||||
|
||||
CTextProgressCtrl::~CTextProgressCtrl()
|
||||
{
|
||||
}
|
||||
|
||||
BEGIN_MESSAGE_MAP(CTextProgressCtrl, CProgressCtrl)
|
||||
//{{AFX_MSG_MAP(CTextProgressCtrl)
|
||||
//ON_WM_ERASEBKGND()
|
||||
ON_WM_PAINT()
|
||||
ON_WM_SIZE()
|
||||
//}}AFX_MSG_MAP
|
||||
ON_WM_NCPAINT()
|
||||
END_MESSAGE_MAP()
|
||||
#include "winuser.h"
|
||||
#include ".\textprogressctrl.h"
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CTextProgressCtrl message handlers
|
||||
|
||||
BOOL CTextProgressCtrl::OnEraseBkgnd(CDC* /*pDC*/)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void CTextProgressCtrl::OnSize(UINT nType, int cx, int cy)
|
||||
{
|
||||
CProgressCtrl::OnSize(nType, cx, cy);
|
||||
|
||||
m_nBarWidth = -1; // Force update if SetPos called
|
||||
}
|
||||
|
||||
void CTextProgressCtrl::OnPaint()
|
||||
{
|
||||
if (m_nMin >= m_nMax)
|
||||
return;
|
||||
|
||||
CRect LeftRect, RightRect, ClientRect;
|
||||
GetClientRect(ClientRect);
|
||||
|
||||
double Fraction = (double)(m_nPos - m_nMin) / ((double)(m_nMax - m_nMin));
|
||||
|
||||
CPaintDC dc(this); // device context for painting (if not double buffering)
|
||||
|
||||
LeftRect = RightRect = ClientRect;
|
||||
|
||||
LeftRect.right = LeftRect.left + (int)((LeftRect.right - LeftRect.left)*Fraction);
|
||||
dc.FillSolidRect(LeftRect, m_colFore);
|
||||
|
||||
RightRect.left = LeftRect.right;
|
||||
dc.FillSolidRect(RightRect, m_colBk);
|
||||
|
||||
if (m_bShowText)
|
||||
{
|
||||
CString str;
|
||||
if (m_strText.GetLength())
|
||||
str = m_strText;
|
||||
else
|
||||
str.Format(_T("%d%%"), (int)(Fraction*100.0));
|
||||
|
||||
dc.SetBkMode(TRANSPARENT);
|
||||
|
||||
CRgn rgn;
|
||||
rgn.CreateRectRgn(LeftRect.left, LeftRect.top, LeftRect.right, LeftRect.bottom);
|
||||
dc.SelectClipRgn(&rgn);
|
||||
dc.SetTextColor(m_colTextBk);
|
||||
|
||||
HFONT hSysFont = ( HFONT )GetStockObject( DEFAULT_GUI_FONT );
|
||||
|
||||
CFont* pFont = CFont::FromHandle( hSysFont );
|
||||
CFont* pOldFont = dc.SelectObject( pFont );
|
||||
|
||||
dc.DrawText(str, ClientRect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
|
||||
|
||||
rgn.DeleteObject();
|
||||
rgn.CreateRectRgn(RightRect.left, RightRect.top, RightRect.right, RightRect.bottom);
|
||||
dc.SelectClipRgn(&rgn);
|
||||
dc.SetTextColor(m_colTextFore);
|
||||
|
||||
dc.DrawText(str, ClientRect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
|
||||
dc.SelectObject( pOldFont );
|
||||
pFont->DeleteObject();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void CTextProgressCtrl::SetForeColour(COLORREF col)
|
||||
{
|
||||
m_colFore = col;
|
||||
}
|
||||
|
||||
void CTextProgressCtrl::SetBkColour(COLORREF col)
|
||||
{
|
||||
m_colBk = col;
|
||||
}
|
||||
|
||||
COLORREF CTextProgressCtrl::GetForeColour()
|
||||
{
|
||||
return m_colFore;
|
||||
}
|
||||
|
||||
COLORREF CTextProgressCtrl::GetBkColour()
|
||||
{
|
||||
return m_colBk;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CTextProgressCtrl message handlers
|
||||
|
||||
void CTextProgressCtrl::SetShowText(BOOL bShow)
|
||||
{
|
||||
if (::IsWindow(m_hWnd) && m_bShowText != bShow)
|
||||
Invalidate();
|
||||
|
||||
m_bShowText = bShow;
|
||||
}
|
||||
|
||||
void CTextProgressCtrl::SetText(LPCTSTR lpszText)
|
||||
{
|
||||
m_strText = lpszText;
|
||||
|
||||
if (::IsWindow(m_hWnd) && m_bShowText)
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
void CTextProgressCtrl::SetRange(int nLower, int nUpper)
|
||||
{
|
||||
m_nMax = nUpper;
|
||||
m_nMin = nLower;
|
||||
}
|
||||
|
||||
int CTextProgressCtrl::SetPos(int nPos, LPCTSTR lpszText)
|
||||
{
|
||||
if (!::IsWindow(m_hWnd))
|
||||
return -1;
|
||||
|
||||
if (lpszText)
|
||||
m_strText = lpszText;
|
||||
|
||||
int nOldPos = m_nPos;
|
||||
m_nPos = nPos;
|
||||
|
||||
CRect rect;
|
||||
GetClientRect(rect);
|
||||
|
||||
double Fraction = (double)(m_nPos - m_nMin) / ((double)(m_nMax - m_nMin));
|
||||
int nBarWidth = (int) (Fraction * rect.Width());
|
||||
|
||||
if (nBarWidth != m_nBarWidth) {
|
||||
m_nBarWidth = nBarWidth;
|
||||
// RedrawWindow();
|
||||
}
|
||||
Invalidate(FALSE);
|
||||
|
||||
return nOldPos;
|
||||
}
|
||||
|
||||
int CTextProgressCtrl::StepIt()
|
||||
{
|
||||
return SetPos(m_nPos + m_nStepSize);
|
||||
}
|
||||
|
||||
int CTextProgressCtrl::OffsetPos(int nPos)
|
||||
{
|
||||
return SetPos(m_nPos + nPos);
|
||||
}
|
||||
|
||||
int CTextProgressCtrl::SetStep(int nStep)
|
||||
{
|
||||
int nOldStep = m_nStepSize;
|
||||
m_nStepSize = nStep;
|
||||
return nOldStep;
|
||||
}
|
||||
|
||||
void CTextProgressCtrl::OnNcPaint()
|
||||
{
|
||||
|
||||
// TODO: 여기에 메시지 처리기 코드를 추가합니다.
|
||||
// 그리기 메시지에 대해서는 CProgressCtrl::OnNcPaint()을(를) 호출하지 마십시오.
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
#if !defined(AFX_TEXTPROGRESSCTRL_H__4C78DBBE_EFB6_11D1_AB14_203E25000000__INCLUDED_)
|
||||
#define AFX_TEXTPROGRESSCTRL_H__4C78DBBE_EFB6_11D1_AB14_203E25000000__INCLUDED_
|
||||
|
||||
#if _MSC_VER >= 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER >= 1000
|
||||
|
||||
// TextProgressCtrl.h : header file
|
||||
//
|
||||
// Written by Chris Maunder (chrismaunder@codeguru.com)
|
||||
// Copyright 1998.
|
||||
//
|
||||
// Modified : 26/05/98 Jeremy Davis, jmd@jvf.co.uk
|
||||
// Added colour routines
|
||||
//
|
||||
// TextProgressCtrl is a drop-in replacement for the standard
|
||||
// CProgressCtrl that displays text in a progress control.
|
||||
//
|
||||
// This code may be used in compiled form in any way you desire. This
|
||||
// file may be redistributed by any means PROVIDING it is not sold for
|
||||
// profit without the authors written consent, and providing that this
|
||||
// notice and the authors name is included. If the source code in
|
||||
// this file is used in any commercial application then an email to
|
||||
// the me would be nice.
|
||||
//
|
||||
// This file is provided "as is" with no expressed or implied warranty.
|
||||
// The author accepts no liability if it causes any damage to your
|
||||
// computer, causes your pet cat to fall ill, increases baldness or
|
||||
// makes you car start emitting strange noises when you start it up.
|
||||
//
|
||||
// Expect bugs.
|
||||
//
|
||||
// Please use and enjoy. Please let me know of any bugs/mods/improvements
|
||||
// that you have found/implemented and I will fix/incorporate them into this
|
||||
// file.
|
||||
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CTextProgressCtrl window
|
||||
|
||||
class CTextProgressCtrl : public CProgressCtrl
|
||||
{
|
||||
// Construction
|
||||
public:
|
||||
CTextProgressCtrl();
|
||||
|
||||
// Attributes
|
||||
public:
|
||||
|
||||
// Operations
|
||||
public:
|
||||
int SetPos(int nPos, LPCTSTR lpszText = NULL);
|
||||
int StepIt();
|
||||
void SetRange(int nLower, int nUpper);
|
||||
int OffsetPos(int nPos);
|
||||
int SetStep(int nStep);
|
||||
void SetForeColour(COLORREF col);
|
||||
void SetBkColour(COLORREF col);
|
||||
COLORREF GetForeColour();
|
||||
COLORREF GetBkColour();
|
||||
|
||||
void SetShowText(BOOL bShow);
|
||||
void SetText(LPCTSTR lpszText);
|
||||
|
||||
// Overrides
|
||||
// ClassWizard generated virtual function overrides
|
||||
//{{AFX_VIRTUAL(CTextProgressCtrl)
|
||||
//}}AFX_VIRTUAL
|
||||
|
||||
// Implementation
|
||||
public:
|
||||
virtual ~CTextProgressCtrl();
|
||||
|
||||
// Generated message map functions
|
||||
protected:
|
||||
int m_nPos,
|
||||
m_nStepSize,
|
||||
m_nMax,
|
||||
m_nMin;
|
||||
CString m_strText;
|
||||
BOOL m_bShowText;
|
||||
int m_nBarWidth;
|
||||
COLORREF m_colFore,
|
||||
m_colBk,
|
||||
m_colTextFore,
|
||||
m_colTextBk;
|
||||
|
||||
//{{AFX_MSG(CTextProgressCtrl)
|
||||
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
|
||||
afx_msg void OnPaint();
|
||||
afx_msg void OnSize(UINT nType, int cx, int cy);
|
||||
//}}AFX_MSG
|
||||
|
||||
DECLARE_MESSAGE_MAP()
|
||||
public:
|
||||
afx_msg void OnNcPaint();
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//{{AFX_INSERT_LOCATION}}
|
||||
// Microsoft Developer Studio will insert additional declarations immediately before the previous line.
|
||||
|
||||
#endif // !defined(AFX_TEXTPROGRESSCTRL_H__4C78DBBE_EFB6_11D1_AB14_203E25000000__INCLUDED_)
|
||||
@@ -0,0 +1,21 @@
|
||||
#include "stdafx.h"
|
||||
#include "TimedMsgBox.h"
|
||||
|
||||
void CTimedMsgBox::Do(PCTSTR pszCaption, LPCTSTR pszTitle, UINT nType)
|
||||
{
|
||||
CMsgBoxThread *pthread = new CMsgBoxThread(pszCaption, pszTitle, nType);
|
||||
if (!thread)
|
||||
return;
|
||||
|
||||
thread->Start();
|
||||
|
||||
Sleep(MSGBOX_DELAY);
|
||||
|
||||
try
|
||||
{
|
||||
delete pthread;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
class CTimedMsgBox;
|
||||
|
||||
#ifndef _TIMEDMSGBOX_H_
|
||||
#define _TIMEDMSGBOX_H_
|
||||
|
||||
#pragma once
|
||||
|
||||
#define MSGBOX_DELAY 4000
|
||||
|
||||
class CTimedMsgBox
|
||||
{
|
||||
protected:
|
||||
class CMsgBoxThread : public CWizThread
|
||||
{
|
||||
public:
|
||||
CMsgBoxThread(LPCTSTR pszCaption, LPCTSTR pszTitle, UINT nType) {
|
||||
m_pszCaption = strdup(pszCaption);
|
||||
m_pszTitle = strdup(pszTitle);
|
||||
m_nType = nType;
|
||||
};
|
||||
|
||||
virtual ~CMsgBoxThread()
|
||||
{
|
||||
if (m_pszCaption)
|
||||
free(m_pszCaption);
|
||||
|
||||
if (m_pszTitle)
|
||||
free(m_pszTitle);
|
||||
};
|
||||
|
||||
virtual void Run(LPVOID)
|
||||
{
|
||||
// Create the desired dialog box
|
||||
if (!m_pszCaption)
|
||||
return;
|
||||
|
||||
MessageBox(NULL, m_pszCaption, m_pszTitle, MB_OK | m_nType);
|
||||
};
|
||||
|
||||
LPSTR m_pszCaption;
|
||||
LPSTR m_pszTitle;
|
||||
UINT m_nType;
|
||||
};
|
||||
|
||||
public:
|
||||
static void Do(LPCTSTR pszCaption, LPCTSTR pszTitle, UINT nType);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,87 @@
|
||||
#include "stdafx.h"
|
||||
#include "TransLogger.h"
|
||||
|
||||
CTransLogger::CTransLogger()
|
||||
{
|
||||
}
|
||||
|
||||
CTransLogger::~CTransLogger()
|
||||
{
|
||||
}
|
||||
|
||||
HANDLE CTransLogger::m_hFile = INVALID_HANDLE_VALUE;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// Operations
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool CTransLogger::Create(LPCTSTR lpszPathName, bool bOverwrite)
|
||||
{
|
||||
if(m_hFile != INVALID_HANDLE_VALUE)
|
||||
return true;
|
||||
|
||||
m_hFile = ::CreateFile(lpszPathName, GENERIC_WRITE, FILE_SHARE_READ, NULL, bOverwrite ? CREATE_ALWAYS : OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
if(m_hFile == INVALID_HANDLE_VALUE)
|
||||
return false;
|
||||
|
||||
if(!bOverwrite)
|
||||
::SetFilePointer(m_hFile, 0, NULL, FILE_END);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CTransLogger::Close()
|
||||
{
|
||||
if(m_hFile == INVALID_HANDLE_VALUE)
|
||||
return false;
|
||||
|
||||
bool bClose = ::CloseHandle(m_hFile) ? true :false;
|
||||
m_hFile = INVALID_HANDLE_VALUE;
|
||||
|
||||
return bClose;
|
||||
}
|
||||
|
||||
bool CTransLogger::Flush()
|
||||
{
|
||||
if(m_hFile == INVALID_HANDLE_VALUE)
|
||||
return false;
|
||||
|
||||
return ::FlushFileBuffers(m_hFile) ? true : false;
|
||||
}
|
||||
|
||||
DWORD CTransLogger::Write(LPCTSTR lpszFormat, ...)
|
||||
{
|
||||
if(m_hFile == INVALID_HANDLE_VALUE)
|
||||
return -1;
|
||||
|
||||
TCHAR* pszMessage = NULL;
|
||||
DWORD dwSize = 0;
|
||||
|
||||
va_list listArgument;
|
||||
va_start(listArgument, lpszFormat);
|
||||
dwSize = (DWORD)::_vsctprintf(lpszFormat, listArgument) + 1;
|
||||
|
||||
pszMessage = new TCHAR[dwSize];
|
||||
::memset(pszMessage, NULL, dwSize);
|
||||
|
||||
dwSize = (DWORD)::_vstprintf(pszMessage, lpszFormat, listArgument);
|
||||
va_end(listArgument);
|
||||
|
||||
if(dwSize < 0)
|
||||
{
|
||||
delete [] pszMessage;
|
||||
return -1;
|
||||
}
|
||||
|
||||
DWORD dwWritten = 0;
|
||||
bool bWritten = false;
|
||||
|
||||
bWritten = ::WriteFile(m_hFile, pszMessage, dwSize, &dwWritten, NULL) ? true : false;
|
||||
if(bWritten)
|
||||
Flush();
|
||||
|
||||
delete [] pszMessage;
|
||||
|
||||
return bWritten ? dwWritten : -1;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
#include <tchar.h>
|
||||
|
||||
class CTransLogger
|
||||
{
|
||||
public:
|
||||
CTransLogger();
|
||||
~CTransLogger();
|
||||
|
||||
// Operations
|
||||
public:
|
||||
static bool Create(LPCTSTR lpszPathName, bool bOverwrite = true);
|
||||
static bool Close();
|
||||
static bool Flush();
|
||||
|
||||
static DWORD Write(LPCTSTR lpszFormat, ...);
|
||||
|
||||
// Data Members
|
||||
private:
|
||||
static HANDLE m_hFile;
|
||||
};
|
||||
@@ -0,0 +1,493 @@
|
||||
// 컴퓨터에서 Microsoft Visual C++를 사용하여 생성한 IDispatch 래퍼 클래스입니다.
|
||||
|
||||
// 참고: 이 파일의 내용을 수정하지 마십시오. Microsoft Visual C++에서
|
||||
// 이 클래스를 다시 생성할 때 수정한 내용을 덮어씁니다.
|
||||
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "WebBrowser2.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CExplorer
|
||||
|
||||
IMPLEMENT_DYNCREATE(CWebBrowser2, CWnd)
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CExplorer 속성입니다.
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CExplorer 작업입니다.
|
||||
|
||||
BOOL CWebBrowser2::PreTranslateMessage(MSG* pMsg)
|
||||
{
|
||||
switch (pMsg->message) {
|
||||
case WM_RBUTTONDOWN:
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return CWnd::PreTranslateMessage(pMsg);
|
||||
}
|
||||
|
||||
void CWebBrowser2::GoBack()
|
||||
{
|
||||
InvokeHelper(0x64, DISPATCH_METHOD, VT_EMPTY, NULL, NULL);
|
||||
}
|
||||
|
||||
void CWebBrowser2::GoForward()
|
||||
{
|
||||
InvokeHelper(0x65, DISPATCH_METHOD, VT_EMPTY, NULL, NULL);
|
||||
}
|
||||
|
||||
void CWebBrowser2::GoHome()
|
||||
{
|
||||
InvokeHelper(0x66, DISPATCH_METHOD, VT_EMPTY, NULL, NULL);
|
||||
}
|
||||
|
||||
void CWebBrowser2::GoSearch()
|
||||
{
|
||||
InvokeHelper(0x67, DISPATCH_METHOD, VT_EMPTY, NULL, NULL);
|
||||
}
|
||||
|
||||
void CWebBrowser2::Navigate(LPCTSTR URL, VARIANT* Flags, VARIANT* TargetFrameName, VARIANT* PostData, VARIANT* Headers)
|
||||
{
|
||||
static BYTE parms[] =
|
||||
VTS_BSTR VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT;
|
||||
InvokeHelper(0x68, DISPATCH_METHOD, VT_EMPTY, NULL, parms,
|
||||
URL, Flags, TargetFrameName, PostData, Headers);
|
||||
}
|
||||
|
||||
void CWebBrowser2::Refresh()
|
||||
{
|
||||
InvokeHelper(DISPID_REFRESH, DISPATCH_METHOD, VT_EMPTY, NULL, NULL);
|
||||
}
|
||||
|
||||
void CWebBrowser2::Refresh2(VARIANT* Level)
|
||||
{
|
||||
static BYTE parms[] =
|
||||
VTS_PVARIANT;
|
||||
InvokeHelper(0x69, DISPATCH_METHOD, VT_EMPTY, NULL, parms,
|
||||
Level);
|
||||
}
|
||||
|
||||
void CWebBrowser2::Stop()
|
||||
{
|
||||
InvokeHelper(0x6a, DISPATCH_METHOD, VT_EMPTY, NULL, NULL);
|
||||
}
|
||||
|
||||
LPDISPATCH CWebBrowser2::GetApplication()
|
||||
{
|
||||
LPDISPATCH result;
|
||||
InvokeHelper(0xc8, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
|
||||
LPDISPATCH CWebBrowser2::GetParent()
|
||||
{
|
||||
LPDISPATCH result;
|
||||
InvokeHelper(0xc9, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
|
||||
LPDISPATCH CWebBrowser2::GetContainer()
|
||||
{
|
||||
LPDISPATCH result;
|
||||
InvokeHelper(0xca, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
|
||||
LPDISPATCH CWebBrowser2::GetDocument()
|
||||
{
|
||||
LPDISPATCH result;
|
||||
InvokeHelper(0xcb, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
|
||||
BOOL CWebBrowser2::GetTopLevelContainer()
|
||||
{
|
||||
BOOL result;
|
||||
InvokeHelper(0xcc, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
|
||||
CString CWebBrowser2::GetType()
|
||||
{
|
||||
CString result;
|
||||
InvokeHelper(0xcd, DISPATCH_PROPERTYGET, VT_BSTR, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
|
||||
long CWebBrowser2::GetLeft()
|
||||
{
|
||||
long result;
|
||||
InvokeHelper(0xce, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
|
||||
void CWebBrowser2::SetLeft(long nNewValue)
|
||||
{
|
||||
static BYTE parms[] =
|
||||
VTS_I4;
|
||||
InvokeHelper(0xce, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,
|
||||
nNewValue);
|
||||
}
|
||||
|
||||
long CWebBrowser2::GetTop()
|
||||
{
|
||||
long result;
|
||||
InvokeHelper(0xcf, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
|
||||
void CWebBrowser2::SetTop(long nNewValue)
|
||||
{
|
||||
static BYTE parms[] =
|
||||
VTS_I4;
|
||||
InvokeHelper(0xcf, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,
|
||||
nNewValue);
|
||||
}
|
||||
|
||||
long CWebBrowser2::GetWidth()
|
||||
{
|
||||
long result;
|
||||
InvokeHelper(0xd0, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
|
||||
void CWebBrowser2::SetWidth(long nNewValue)
|
||||
{
|
||||
static BYTE parms[] =
|
||||
VTS_I4;
|
||||
InvokeHelper(0xd0, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,
|
||||
nNewValue);
|
||||
}
|
||||
|
||||
long CWebBrowser2::GetHeight()
|
||||
{
|
||||
long result;
|
||||
InvokeHelper(0xd1, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
|
||||
void CWebBrowser2::SetHeight(long nNewValue)
|
||||
{
|
||||
static BYTE parms[] =
|
||||
VTS_I4;
|
||||
InvokeHelper(0xd1, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,
|
||||
nNewValue);
|
||||
}
|
||||
|
||||
CString CWebBrowser2::GetLocationName()
|
||||
{
|
||||
CString result;
|
||||
InvokeHelper(0xd2, DISPATCH_PROPERTYGET, VT_BSTR, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
|
||||
CString CWebBrowser2::GetLocationURL()
|
||||
{
|
||||
CString result;
|
||||
InvokeHelper(0xd3, DISPATCH_PROPERTYGET, VT_BSTR, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
|
||||
BOOL CWebBrowser2::GetBusy()
|
||||
{
|
||||
BOOL result;
|
||||
InvokeHelper(0xd4, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
|
||||
void CWebBrowser2::Quit()
|
||||
{
|
||||
InvokeHelper(0x12c, DISPATCH_METHOD, VT_EMPTY, NULL, NULL);
|
||||
}
|
||||
|
||||
void CWebBrowser2::ClientToWindow(long* pcx, long* pcy)
|
||||
{
|
||||
static BYTE parms[] =
|
||||
VTS_PI4 VTS_PI4;
|
||||
InvokeHelper(0x12d, DISPATCH_METHOD, VT_EMPTY, NULL, parms,
|
||||
pcx, pcy);
|
||||
}
|
||||
|
||||
void CWebBrowser2::PutProperty(LPCTSTR Property_, const VARIANT& vtValue)
|
||||
{
|
||||
static BYTE parms[] =
|
||||
VTS_BSTR VTS_VARIANT;
|
||||
InvokeHelper(0x12e, DISPATCH_METHOD, VT_EMPTY, NULL, parms,
|
||||
Property_, &vtValue);
|
||||
}
|
||||
|
||||
VARIANT CWebBrowser2::GetProperty_(LPCTSTR Property_)
|
||||
{
|
||||
VARIANT result;
|
||||
static BYTE parms[] =
|
||||
VTS_BSTR;
|
||||
InvokeHelper(0x12f, DISPATCH_METHOD, VT_VARIANT, (void*)&result, parms,
|
||||
Property_);
|
||||
return result;
|
||||
}
|
||||
|
||||
CString CWebBrowser2::GetName()
|
||||
{
|
||||
CString result;
|
||||
InvokeHelper(0x0, DISPATCH_PROPERTYGET, VT_BSTR, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
|
||||
long CWebBrowser2::GetHwnd()
|
||||
{
|
||||
long result;
|
||||
InvokeHelper(DISPID_HWND, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
|
||||
CString CWebBrowser2::GetFullName()
|
||||
{
|
||||
CString result;
|
||||
InvokeHelper(0x190, DISPATCH_PROPERTYGET, VT_BSTR, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
|
||||
CString CWebBrowser2::GetPath()
|
||||
{
|
||||
CString result;
|
||||
InvokeHelper(0x191, DISPATCH_PROPERTYGET, VT_BSTR, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
|
||||
BOOL CWebBrowser2::GetVisible()
|
||||
{
|
||||
BOOL result;
|
||||
InvokeHelper(0x192, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
|
||||
void CWebBrowser2::SetVisible(BOOL bNewValue)
|
||||
{
|
||||
static BYTE parms[] =
|
||||
VTS_BOOL;
|
||||
InvokeHelper(0x192, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,
|
||||
bNewValue);
|
||||
}
|
||||
|
||||
BOOL CWebBrowser2::GetStatusBar()
|
||||
{
|
||||
BOOL result;
|
||||
InvokeHelper(0x193, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
|
||||
void CWebBrowser2::SetStatusBar(BOOL bNewValue)
|
||||
{
|
||||
static BYTE parms[] =
|
||||
VTS_BOOL;
|
||||
InvokeHelper(0x193, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,
|
||||
bNewValue);
|
||||
}
|
||||
|
||||
CString CWebBrowser2::GetStatusText()
|
||||
{
|
||||
CString result;
|
||||
InvokeHelper(0x194, DISPATCH_PROPERTYGET, VT_BSTR, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
|
||||
void CWebBrowser2::SetStatusText(LPCTSTR lpszNewValue)
|
||||
{
|
||||
static BYTE parms[] =
|
||||
VTS_BSTR;
|
||||
InvokeHelper(0x194, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,
|
||||
lpszNewValue);
|
||||
}
|
||||
|
||||
long CWebBrowser2::GetToolBar()
|
||||
{
|
||||
long result;
|
||||
InvokeHelper(0x195, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
|
||||
void CWebBrowser2::SetToolBar(long nNewValue)
|
||||
{
|
||||
static BYTE parms[] =
|
||||
VTS_I4;
|
||||
InvokeHelper(0x195, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,
|
||||
nNewValue);
|
||||
}
|
||||
|
||||
BOOL CWebBrowser2::GetMenuBar()
|
||||
{
|
||||
BOOL result;
|
||||
InvokeHelper(0x196, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
|
||||
void CWebBrowser2::SetMenuBar(BOOL bNewValue)
|
||||
{
|
||||
static BYTE parms[] =
|
||||
VTS_BOOL;
|
||||
InvokeHelper(0x196, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,
|
||||
bNewValue);
|
||||
}
|
||||
|
||||
BOOL CWebBrowser2::GetFullScreen()
|
||||
{
|
||||
BOOL result;
|
||||
InvokeHelper(0x197, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
|
||||
void CWebBrowser2::SetFullScreen(BOOL bNewValue)
|
||||
{
|
||||
static BYTE parms[] =
|
||||
VTS_BOOL;
|
||||
InvokeHelper(0x197, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,
|
||||
bNewValue);
|
||||
}
|
||||
|
||||
void CWebBrowser2::Navigate2(VARIANT* URL, VARIANT* Flags, VARIANT* TargetFrameName, VARIANT* PostData, VARIANT* Headers)
|
||||
{
|
||||
static BYTE parms[] =
|
||||
VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT;
|
||||
InvokeHelper(0x1f4, DISPATCH_METHOD, VT_EMPTY, NULL, parms,
|
||||
URL, Flags, TargetFrameName, PostData, Headers);
|
||||
}
|
||||
|
||||
long CWebBrowser2::QueryStatusWB(long cmdID)
|
||||
{
|
||||
long result;
|
||||
static BYTE parms[] =
|
||||
VTS_I4;
|
||||
InvokeHelper(0x1f5, DISPATCH_METHOD, VT_I4, (void*)&result, parms,
|
||||
cmdID);
|
||||
return result;
|
||||
}
|
||||
|
||||
void CWebBrowser2::ExecWB(long cmdID, long cmdexecopt, VARIANT* pvaIn, VARIANT* pvaOut)
|
||||
{
|
||||
static BYTE parms[] =
|
||||
VTS_I4 VTS_I4 VTS_PVARIANT VTS_PVARIANT;
|
||||
InvokeHelper(0x1f6, DISPATCH_METHOD, VT_EMPTY, NULL, parms,
|
||||
cmdID, cmdexecopt, pvaIn, pvaOut);
|
||||
}
|
||||
|
||||
void CWebBrowser2::ShowBrowserBar(VARIANT* pvaClsid, VARIANT* pvarShow, VARIANT* pvarSize)
|
||||
{
|
||||
static BYTE parms[] =
|
||||
VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT;
|
||||
InvokeHelper(0x1f7, DISPATCH_METHOD, VT_EMPTY, NULL, parms,
|
||||
pvaClsid, pvarShow, pvarSize);
|
||||
}
|
||||
|
||||
long CWebBrowser2::GetReadyState()
|
||||
{
|
||||
long result;
|
||||
InvokeHelper(DISPID_READYSTATE, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
|
||||
BOOL CWebBrowser2::GetOffline()
|
||||
{
|
||||
BOOL result;
|
||||
InvokeHelper(0x226, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
|
||||
void CWebBrowser2::SetOffline(BOOL bNewValue)
|
||||
{
|
||||
static BYTE parms[] =
|
||||
VTS_BOOL;
|
||||
InvokeHelper(0x226, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,
|
||||
bNewValue);
|
||||
}
|
||||
|
||||
BOOL CWebBrowser2::GetSilent()
|
||||
{
|
||||
BOOL result;
|
||||
InvokeHelper(0x227, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
|
||||
void CWebBrowser2::SetSilent(BOOL bNewValue)
|
||||
{
|
||||
static BYTE parms[] =
|
||||
VTS_BOOL;
|
||||
InvokeHelper(0x227, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,
|
||||
bNewValue);
|
||||
}
|
||||
|
||||
BOOL CWebBrowser2::GetRegisterAsBrowser()
|
||||
{
|
||||
BOOL result;
|
||||
InvokeHelper(0x228, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
|
||||
void CWebBrowser2::SetRegisterAsBrowser(BOOL bNewValue)
|
||||
{
|
||||
static BYTE parms[] =
|
||||
VTS_BOOL;
|
||||
InvokeHelper(0x228, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,
|
||||
bNewValue);
|
||||
}
|
||||
|
||||
BOOL CWebBrowser2::GetRegisterAsDropTarget()
|
||||
{
|
||||
BOOL result;
|
||||
InvokeHelper(0x229, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
|
||||
void CWebBrowser2::SetRegisterAsDropTarget(BOOL bNewValue)
|
||||
{
|
||||
static BYTE parms[] =
|
||||
VTS_BOOL;
|
||||
InvokeHelper(0x229, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,
|
||||
bNewValue);
|
||||
}
|
||||
|
||||
BOOL CWebBrowser2::GetTheaterMode()
|
||||
{
|
||||
BOOL result;
|
||||
InvokeHelper(0x22a, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
|
||||
void CWebBrowser2::SetTheaterMode(BOOL bNewValue)
|
||||
{
|
||||
static BYTE parms[] =
|
||||
VTS_BOOL;
|
||||
InvokeHelper(0x22a, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,
|
||||
bNewValue);
|
||||
}
|
||||
|
||||
BOOL CWebBrowser2::GetAddressBar()
|
||||
{
|
||||
BOOL result;
|
||||
InvokeHelper(0x22b, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
|
||||
void CWebBrowser2::SetAddressBar(BOOL bNewValue)
|
||||
{
|
||||
static BYTE parms[] =
|
||||
VTS_BOOL;
|
||||
InvokeHelper(0x22b, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,
|
||||
bNewValue);
|
||||
}
|
||||
|
||||
BOOL CWebBrowser2::GetResizable()
|
||||
{
|
||||
BOOL result;
|
||||
InvokeHelper(0x22c, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
|
||||
return result;
|
||||
}
|
||||
|
||||
void CWebBrowser2::SetResizable(BOOL bNewValue)
|
||||
{
|
||||
static BYTE parms[] =
|
||||
VTS_BOOL;
|
||||
InvokeHelper(0x22c, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,
|
||||
bNewValue);
|
||||
}
|
||||
@@ -0,0 +1,222 @@
|
||||
#pragma once
|
||||
|
||||
// 컴퓨터에서 Microsoft Visual C++를 사용하여 생성한 IDispatch 래퍼 클래스입니다.
|
||||
|
||||
// 참고: 이 파일의 내용을 수정하지 마십시오. Microsoft Visual C++에서
|
||||
// 이 클래스를 다시 생성할 때 수정한 내용을 덮어씁니다.
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CExplorer 래퍼 클래스입니다.
|
||||
|
||||
class CWebBrowser2 : public CWnd
|
||||
{
|
||||
protected:
|
||||
DECLARE_DYNCREATE(CWebBrowser2)
|
||||
public:
|
||||
CLSID const& GetClsid()
|
||||
{
|
||||
static CLSID const clsid
|
||||
= { 0x8856F961, 0x340A, 0x11D0, { 0xA9, 0x6B, 0x0, 0xC0, 0x4F, 0xD7, 0x5, 0xA2 } };
|
||||
return clsid;
|
||||
}
|
||||
virtual BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle,
|
||||
const RECT& rect, CWnd* pParentWnd, UINT nID,
|
||||
CCreateContext* pContext = NULL)
|
||||
{
|
||||
return CreateControl(GetClsid(), lpszWindowName, dwStyle, rect, pParentWnd, nID);
|
||||
}
|
||||
|
||||
BOOL Create(LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd,
|
||||
UINT nID, CFile* pPersist = NULL, BOOL bStorage = FALSE,
|
||||
BSTR bstrLicKey = NULL)
|
||||
{
|
||||
return CreateControl(GetClsid(), lpszWindowName, dwStyle, rect, pParentWnd, nID,
|
||||
pPersist, bStorage, bstrLicKey);
|
||||
}
|
||||
|
||||
// 특성
|
||||
public:
|
||||
enum
|
||||
{
|
||||
CSC_UPDATECOMMANDS = -1,
|
||||
CSC_NAVIGATEFORWARD = 1,
|
||||
CSC_NAVIGATEBACK = 2
|
||||
}CommandStateChangeConstants;
|
||||
enum
|
||||
{
|
||||
OLECMDID_OPEN = 1,
|
||||
OLECMDID_NEW = 2,
|
||||
OLECMDID_SAVE = 3,
|
||||
OLECMDID_SAVEAS = 4,
|
||||
OLECMDID_SAVECOPYAS = 5,
|
||||
OLECMDID_PRINT = 6,
|
||||
OLECMDID_PRINTPREVIEW = 7,
|
||||
OLECMDID_PAGESETUP = 8,
|
||||
OLECMDID_SPELL = 9,
|
||||
OLECMDID_PROPERTIES = 10,
|
||||
OLECMDID_CUT = 11,
|
||||
OLECMDID_COPY = 12,
|
||||
OLECMDID_PASTE = 13,
|
||||
OLECMDID_PASTESPECIAL = 14,
|
||||
OLECMDID_UNDO = 15,
|
||||
OLECMDID_REDO = 16,
|
||||
OLECMDID_SELECTALL = 17,
|
||||
OLECMDID_CLEARSELECTION = 18,
|
||||
OLECMDID_ZOOM = 19,
|
||||
OLECMDID_GETZOOMRANGE = 20,
|
||||
OLECMDID_UPDATECOMMANDS = 21,
|
||||
OLECMDID_REFRESH = 22,
|
||||
OLECMDID_STOP = 23,
|
||||
OLECMDID_HIDETOOLBARS = 24,
|
||||
OLECMDID_SETPROGRESSMAX = 25,
|
||||
OLECMDID_SETPROGRESSPOS = 26,
|
||||
OLECMDID_SETPROGRESSTEXT = 27,
|
||||
OLECMDID_SETTITLE = 28,
|
||||
OLECMDID_SETDOWNLOADSTATE = 29,
|
||||
OLECMDID_STOPDOWNLOAD = 30,
|
||||
OLECMDID_ONTOOLBARACTIVATED = 31,
|
||||
OLECMDID_FIND = 32,
|
||||
OLECMDID_DELETE = 33,
|
||||
OLECMDID_HTTPEQUIV = 34,
|
||||
OLECMDID_HTTPEQUIV_DONE = 35,
|
||||
OLECMDID_ENABLE_INTERACTION = 36,
|
||||
OLECMDID_ONUNLOAD = 37,
|
||||
OLECMDID_PROPERTYBAG2 = 38,
|
||||
OLECMDID_PREREFRESH = 39,
|
||||
OLECMDID_SHOWSCRIPTERROR = 40,
|
||||
OLECMDID_SHOWMESSAGE = 41,
|
||||
OLECMDID_SHOWFIND = 42,
|
||||
OLECMDID_SHOWPAGESETUP = 43,
|
||||
OLECMDID_SHOWPRINT = 44,
|
||||
OLECMDID_CLOSE = 45,
|
||||
OLECMDID_ALLOWUILESSSAVEAS = 46,
|
||||
OLECMDID_DONTDOWNLOADCSS = 47,
|
||||
OLECMDID_UPDATEPAGESTATUS = 48,
|
||||
OLECMDID_PRINT2 = 49,
|
||||
OLECMDID_PRINTPREVIEW2 = 50,
|
||||
OLECMDID_SETPRINTTEMPLATE = 51,
|
||||
OLECMDID_GETPRINTTEMPLATE = 52,
|
||||
OLECMDID_PAGEACTIONBLOCKED = 55,
|
||||
OLECMDID_PAGEACTIONUIQUERY = 56,
|
||||
OLECMDID_FOCUSVIEWCONTROLS = 57,
|
||||
OLECMDID_FOCUSVIEWCONTROLSQUERY = 58,
|
||||
OLECMDID_SHOWPAGEACTIONMENU = 59
|
||||
}OLECMDID;
|
||||
enum
|
||||
{
|
||||
OLECMDF_SUPPORTED = 1,
|
||||
OLECMDF_ENABLED = 2,
|
||||
OLECMDF_LATCHED = 4,
|
||||
OLECMDF_NINCHED = 8,
|
||||
OLECMDF_INVISIBLE = 16,
|
||||
OLECMDF_DEFHIDEONCTXTMENU = 32
|
||||
}OLECMDF;
|
||||
enum
|
||||
{
|
||||
OLECMDEXECOPT_DODEFAULT = 0,
|
||||
OLECMDEXECOPT_PROMPTUSER = 1,
|
||||
OLECMDEXECOPT_DONTPROMPTUSER = 2,
|
||||
OLECMDEXECOPT_SHOWHELP = 3
|
||||
}OLECMDEXECOPT;
|
||||
enum
|
||||
{
|
||||
READYSTATE_UNINITIALIZED = 0,
|
||||
READYSTATE_LOADING = 1,
|
||||
READYSTATE_LOADED = 2,
|
||||
READYSTATE_INTERACTIVE = 3,
|
||||
READYSTATE_COMPLETE = 4
|
||||
}tagREADYSTATE;
|
||||
enum
|
||||
{
|
||||
secureLockIconUnsecure = 0,
|
||||
secureLockIconMixed = 1,
|
||||
secureLockIconSecureUnknownBits = 2,
|
||||
secureLockIconSecure40Bit = 3,
|
||||
secureLockIconSecure56Bit = 4,
|
||||
secureLockIconSecureFortezza = 5,
|
||||
secureLockIconSecure128Bit = 6
|
||||
}SecureLockIconConstants;
|
||||
enum
|
||||
{
|
||||
SWC_EXPLORER = 0,
|
||||
SWC_BROWSER = 1,
|
||||
SWC_3RDPARTY = 2,
|
||||
SWC_CALLBACK = 4
|
||||
}ShellWindowTypeConstants;
|
||||
enum
|
||||
{
|
||||
SWFO_NEEDDISPATCH = 1,
|
||||
SWFO_INCLUDEPENDING = 2,
|
||||
SWFO_COOKIEPASSED = 4
|
||||
}ShellWindowFindWindowOptions;
|
||||
|
||||
protected:
|
||||
virtual BOOL PreTranslateMessage(MSG* pMsg);
|
||||
|
||||
// 작업
|
||||
public:
|
||||
void GoBack();
|
||||
void GoForward();
|
||||
void GoHome();
|
||||
void GoSearch();
|
||||
void Navigate(LPCTSTR URL, VARIANT* Flags, VARIANT* TargetFrameName, VARIANT* PostData, VARIANT* Headers);
|
||||
void Refresh();
|
||||
void Refresh2(VARIANT* Level);
|
||||
void Stop();
|
||||
LPDISPATCH GetApplication();
|
||||
LPDISPATCH GetParent();
|
||||
LPDISPATCH GetContainer();
|
||||
LPDISPATCH GetDocument();
|
||||
BOOL GetTopLevelContainer();
|
||||
CString GetType();
|
||||
long GetLeft();
|
||||
void SetLeft(long nNewValue);
|
||||
long GetTop();
|
||||
void SetTop(long nNewValue);
|
||||
long GetWidth();
|
||||
void SetWidth(long nNewValue);
|
||||
long GetHeight();
|
||||
void SetHeight(long nNewValue);
|
||||
CString GetLocationName();
|
||||
CString GetLocationURL();
|
||||
BOOL GetBusy();
|
||||
void Quit();
|
||||
void ClientToWindow(long* pcx, long* pcy);
|
||||
void PutProperty(LPCTSTR Property_, const VARIANT& vtValue);
|
||||
VARIANT GetProperty_(LPCTSTR Property_);
|
||||
CString GetName();
|
||||
long GetHwnd();
|
||||
CString GetFullName();
|
||||
CString GetPath();
|
||||
BOOL GetVisible();
|
||||
void SetVisible(BOOL bNewValue);
|
||||
BOOL GetStatusBar();
|
||||
void SetStatusBar(BOOL bNewValue);
|
||||
CString GetStatusText();
|
||||
void SetStatusText(LPCTSTR lpszNewValue);
|
||||
long GetToolBar();
|
||||
void SetToolBar(long nNewValue);
|
||||
BOOL GetMenuBar();
|
||||
void SetMenuBar(BOOL bNewValue);
|
||||
BOOL GetFullScreen();
|
||||
void SetFullScreen(BOOL bNewValue);
|
||||
void Navigate2(VARIANT* URL, VARIANT* Flags, VARIANT* TargetFrameName, VARIANT* PostData, VARIANT* Headers);
|
||||
long QueryStatusWB(long cmdID);
|
||||
void ExecWB(long cmdID, long cmdexecopt, VARIANT* pvaIn, VARIANT* pvaOut);
|
||||
void ShowBrowserBar(VARIANT* pvaClsid, VARIANT* pvarShow, VARIANT* pvarSize);
|
||||
long GetReadyState();
|
||||
BOOL GetOffline();
|
||||
void SetOffline(BOOL bNewValue);
|
||||
BOOL GetSilent();
|
||||
void SetSilent(BOOL bNewValue);
|
||||
BOOL GetRegisterAsBrowser();
|
||||
void SetRegisterAsBrowser(BOOL bNewValue);
|
||||
BOOL GetRegisterAsDropTarget();
|
||||
void SetRegisterAsDropTarget(BOOL bNewValue);
|
||||
BOOL GetTheaterMode();
|
||||
void SetTheaterMode(BOOL bNewValue);
|
||||
BOOL GetAddressBar();
|
||||
void SetAddressBar(BOOL bNewValue);
|
||||
BOOL GetResizable();
|
||||
void SetResizable(BOOL bNewValue);
|
||||
};
|
||||
@@ -0,0 +1,523 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 1998 by J?g K?ig
|
||||
// All rights reserved
|
||||
//
|
||||
// This file is part of the completely free tetris clone "CGTetris".
|
||||
//
|
||||
// This is free software.
|
||||
// You may redistribute it by any means providing it is not sold for profit
|
||||
// without the authors written consent.
|
||||
//
|
||||
// No warrantee of any kind, expressed or implied, is included with this
|
||||
// software; use at your own risk, responsibility for damages (if any) to
|
||||
// anyone resulting from the use of this software rests entirely with the
|
||||
// user.
|
||||
//
|
||||
// Send bug reports, bug fixes, enhancements, requests, flames, etc., and
|
||||
// I'll try to keep a version up to date. I can be reached as follows:
|
||||
// J.Koenig@adg.de (company site)
|
||||
// Joerg.Koenig@rhein-neckar.de (private site)
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "dib256.h"
|
||||
#include "dibpal.h"
|
||||
|
||||
|
||||
#define PADWIDTH(x) (((x)*8 + 31) & (~31))/8
|
||||
|
||||
|
||||
CDIBitmap :: CDIBitmap()
|
||||
: m_pInfo(0)
|
||||
, m_pPixels(0)
|
||||
, m_pPal(0)
|
||||
, m_bIsPadded(FALSE)
|
||||
{
|
||||
}
|
||||
|
||||
CDIBitmap :: ~CDIBitmap() {
|
||||
delete [] (BYTE*)m_pInfo;
|
||||
delete [] m_pPixels;
|
||||
delete m_pPal;
|
||||
}
|
||||
|
||||
void CDIBitmap :: DestroyBitmap() {
|
||||
delete [] (BYTE*)m_pInfo;
|
||||
delete [] m_pPixels;
|
||||
delete m_pPal;
|
||||
m_pInfo = 0;
|
||||
m_pPixels = 0;
|
||||
m_pPal = 0;
|
||||
}
|
||||
|
||||
BOOL CDIBitmap :: CreateFromBitmap( CDC * pDC, CBitmap * pSrcBitmap ) {
|
||||
ASSERT_VALID(pSrcBitmap);
|
||||
ASSERT_VALID(pDC);
|
||||
|
||||
try {
|
||||
BITMAP bmHdr;
|
||||
|
||||
// Get the pSrcBitmap info
|
||||
pSrcBitmap->GetObject(sizeof(BITMAP), &bmHdr);
|
||||
|
||||
// Reallocate space for the image data
|
||||
if( m_pPixels ) {
|
||||
delete [] m_pPixels;
|
||||
m_pPixels = 0;
|
||||
}
|
||||
|
||||
DWORD dwWidth;
|
||||
if (bmHdr.bmBitsPixel > 8)
|
||||
dwWidth = PADWIDTH(bmHdr.bmWidth * 3);
|
||||
else
|
||||
dwWidth = PADWIDTH(bmHdr.bmWidth);
|
||||
|
||||
m_pPixels = new BYTE[dwWidth*bmHdr.bmHeight];
|
||||
if( !m_pPixels )
|
||||
throw TEXT("could not allocate data storage\n");
|
||||
|
||||
// Set the appropriate number of colors base on BITMAP structure info
|
||||
WORD wColors;
|
||||
switch( bmHdr.bmBitsPixel ) {
|
||||
case 1 :
|
||||
wColors = 2;
|
||||
break;
|
||||
case 4 :
|
||||
wColors = 16;
|
||||
break;
|
||||
case 8 :
|
||||
wColors = 256;
|
||||
break;
|
||||
default :
|
||||
wColors = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
// Re-allocate and populate BITMAPINFO structure
|
||||
if( m_pInfo ) {
|
||||
delete [] (BYTE*)m_pInfo;
|
||||
m_pInfo = 0;
|
||||
}
|
||||
|
||||
m_pInfo = (BITMAPINFO*)new BYTE[sizeof(BITMAPINFOHEADER) + wColors*sizeof(RGBQUAD)];
|
||||
if( !m_pInfo )
|
||||
throw TEXT("could not allocate BITMAPINFO struct\n");
|
||||
|
||||
// Populate BITMAPINFO header info
|
||||
m_pInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
||||
m_pInfo->bmiHeader.biWidth = bmHdr.bmWidth;
|
||||
m_pInfo->bmiHeader.biHeight = bmHdr.bmHeight;
|
||||
m_pInfo->bmiHeader.biPlanes = bmHdr.bmPlanes;
|
||||
|
||||
|
||||
if( bmHdr.bmBitsPixel > 8 )
|
||||
m_pInfo->bmiHeader.biBitCount = 24;
|
||||
else
|
||||
m_pInfo->bmiHeader.biBitCount = bmHdr.bmBitsPixel;
|
||||
|
||||
m_pInfo->bmiHeader.biCompression = BI_RGB;
|
||||
m_pInfo->bmiHeader.biSizeImage = ((((bmHdr.bmWidth * bmHdr.bmBitsPixel) + 31) & ~31) >> 3) * bmHdr.bmHeight;
|
||||
m_pInfo->bmiHeader.biXPelsPerMeter = 0;
|
||||
m_pInfo->bmiHeader.biYPelsPerMeter = 0;
|
||||
m_pInfo->bmiHeader.biClrUsed = 0;
|
||||
m_pInfo->bmiHeader.biClrImportant = 0;
|
||||
|
||||
// Now actually get the bits
|
||||
int test = ::GetDIBits(pDC->GetSafeHdc(), (HBITMAP)pSrcBitmap->GetSafeHandle(),
|
||||
0, (WORD)bmHdr.bmHeight, m_pPixels, m_pInfo, DIB_RGB_COLORS);
|
||||
|
||||
// check that we scanned in the correct number of bitmap lines
|
||||
if( test != (int)bmHdr.bmHeight )
|
||||
throw TEXT("call to GetDIBits did not return full number of requested scan lines\n");
|
||||
|
||||
CreatePalette();
|
||||
m_bIsPadded = FALSE;
|
||||
#ifdef _DEBUG
|
||||
} catch( TCHAR * psz ) {
|
||||
TRACE1("CDIBitmap::CreateFromBitmap(): %s\n", psz);
|
||||
#else
|
||||
} catch( TCHAR * ) {
|
||||
#endif
|
||||
if( m_pPixels ) {
|
||||
delete [] m_pPixels;
|
||||
m_pPixels = 0;
|
||||
}
|
||||
if( m_pInfo ) {
|
||||
delete [] (BYTE*) m_pInfo;
|
||||
m_pInfo = 0;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
BOOL CDIBitmap :: LoadResource(LPCTSTR pszID) {
|
||||
HBITMAP hBmp = (HBITMAP)::LoadImage(
|
||||
AfxGetInstanceHandle(),
|
||||
pszID, IMAGE_BITMAP,
|
||||
0,0, LR_CREATEDIBSECTION
|
||||
);
|
||||
|
||||
if( hBmp == 0 )
|
||||
return FALSE;
|
||||
|
||||
CBitmap bmp;
|
||||
bmp.Attach(hBmp);
|
||||
CClientDC cdc( CWnd::GetDesktopWindow() );
|
||||
BOOL bRet = CreateFromBitmap( &cdc, &bmp );
|
||||
bmp.DeleteObject();
|
||||
return bRet;
|
||||
}
|
||||
|
||||
|
||||
BOOL CDIBitmap :: Load( CFile* pFile ) {
|
||||
ASSERT( pFile );
|
||||
BOOL fReturn = TRUE;
|
||||
try {
|
||||
delete [] (BYTE*)m_pInfo;
|
||||
delete [] m_pPixels;
|
||||
m_pInfo = 0;
|
||||
m_pPixels = 0;
|
||||
DWORD dwStart = (DWORD)pFile->GetPosition();
|
||||
//
|
||||
// Check to make sure we have a bitmap. The first two bytes must
|
||||
// be 'B' and 'M'.
|
||||
BITMAPFILEHEADER fileHeader;
|
||||
pFile->Read(&fileHeader, sizeof(fileHeader));
|
||||
if( fileHeader.bfType != 0x4D42 )
|
||||
throw TEXT("Error:Unexpected file type, not a DIB\n");
|
||||
|
||||
BITMAPINFOHEADER infoHeader;
|
||||
pFile->Read( &infoHeader, sizeof(infoHeader) );
|
||||
if( infoHeader.biSize != sizeof(infoHeader) )
|
||||
throw TEXT("Error:OS2 PM BMP Format not supported\n");
|
||||
|
||||
// Store the sizes of the DIB structures
|
||||
int cPaletteEntries = GetPalEntries( infoHeader );
|
||||
int cColorTable = 256 * sizeof(RGBQUAD);
|
||||
int cInfo = sizeof(BITMAPINFOHEADER) + cColorTable;
|
||||
int cPixels = fileHeader.bfSize - fileHeader.bfOffBits;
|
||||
//
|
||||
// Allocate space for a new bitmap info header, and copy
|
||||
// the info header that was loaded from the file. Read the
|
||||
// the file and store the results in the color table.
|
||||
m_pInfo = (BITMAPINFO*)new BYTE[cInfo];
|
||||
memcpy( m_pInfo, &infoHeader, sizeof(BITMAPINFOHEADER) );
|
||||
pFile->Read( ((BYTE*)m_pInfo) + sizeof(BITMAPINFOHEADER),
|
||||
cColorTable );
|
||||
//
|
||||
// Allocate space for the pixel area, and load the pixel
|
||||
// info from the file.
|
||||
m_pPixels = new BYTE[cPixels];
|
||||
pFile->Seek(dwStart + fileHeader.bfOffBits, CFile::begin);
|
||||
pFile->Read( m_pPixels, cPixels );
|
||||
CreatePalette();
|
||||
m_bIsPadded = TRUE;
|
||||
#ifdef _DEBUG
|
||||
} catch( TCHAR * psz ) {
|
||||
TRACE( psz );
|
||||
#else
|
||||
} catch( TCHAR * ) {
|
||||
#endif
|
||||
fReturn = FALSE;
|
||||
}
|
||||
return fReturn;
|
||||
}
|
||||
|
||||
BOOL CDIBitmap :: Load( const CString & strFilename ) {
|
||||
CFile file;
|
||||
if( file.Open( strFilename, CFile::modeRead ) )
|
||||
return Load( &file );
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BOOL CDIBitmap :: Save( const CString & strFileName ) {
|
||||
ASSERT(! strFileName.IsEmpty());
|
||||
|
||||
CFile File;
|
||||
|
||||
if( !File.Open(strFileName, CFile::modeCreate|CFile::modeWrite) ) {
|
||||
TRACE1("CDIBitmap::Save(): Failed to open file %s for writing.\n", LPCSTR(strFileName));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return Save( &File );
|
||||
}
|
||||
|
||||
|
||||
// Does not open or close pFile. Assumes
|
||||
// caller will do it.
|
||||
BOOL CDIBitmap :: Save( CFile * pFile ) {
|
||||
ASSERT_VALID( pFile );
|
||||
ASSERT( m_pInfo );
|
||||
ASSERT( m_pPixels );
|
||||
|
||||
BITMAPFILEHEADER bmfHdr;
|
||||
|
||||
DWORD dwPadWidth = PADWIDTH(GetWidth());
|
||||
|
||||
// Make sure bitmap data is in padded format
|
||||
PadBits();
|
||||
|
||||
bmfHdr.bfType = 0x4D42;
|
||||
// initialize to BitmapInfo size
|
||||
DWORD dwImageSize= m_pInfo->bmiHeader.biSize;
|
||||
// Add in palette size
|
||||
WORD wColors = GetColorCount();
|
||||
WORD wPaletteSize = (WORD)(wColors*sizeof(RGBQUAD));
|
||||
dwImageSize += wPaletteSize;
|
||||
|
||||
// Add in size of actual bit array
|
||||
dwImageSize += PADWIDTH((GetWidth()) * DWORD(m_pInfo->bmiHeader.biBitCount)/8) * GetHeight();
|
||||
m_pInfo->bmiHeader.biSizeImage = 0;
|
||||
bmfHdr.bfSize = dwImageSize + sizeof(BITMAPFILEHEADER);
|
||||
bmfHdr.bfReserved1 = 0;
|
||||
bmfHdr.bfReserved2 = 0;
|
||||
bmfHdr.bfOffBits = (DWORD)sizeof(BITMAPFILEHEADER) + m_pInfo->bmiHeader.biSize + wPaletteSize;
|
||||
pFile->Write(&bmfHdr, sizeof(BITMAPFILEHEADER));
|
||||
|
||||
pFile->Write(m_pInfo, sizeof(BITMAPINFO) + (wColors-1)*sizeof(RGBQUAD));
|
||||
pFile->Write(m_pPixels,
|
||||
DWORD((dwPadWidth*(DWORD)m_pInfo->bmiHeader.biBitCount*GetHeight())/8) );
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL CDIBitmap :: CreatePalette() {
|
||||
if( m_pPal )
|
||||
delete m_pPal;
|
||||
m_pPal = 0;
|
||||
ASSERT( m_pInfo );
|
||||
// We only need a palette, if there are <= 256 colors.
|
||||
// otherwise we would bomb the memory.
|
||||
if( m_pInfo->bmiHeader.biBitCount <= 8 )
|
||||
m_pPal = new CBmpPalette(this);
|
||||
return m_pPal ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
void CDIBitmap :: ClearPalette() {
|
||||
if( m_pPal )
|
||||
delete m_pPal;
|
||||
m_pPal = 0;
|
||||
}
|
||||
|
||||
void CDIBitmap :: DrawDIB( CDC* pDC, int x, int y ) {
|
||||
DrawDIB( pDC, x, y, GetWidth(), GetHeight() );
|
||||
}
|
||||
|
||||
//
|
||||
// DrawDib uses StretchDIBits to display the bitmap.
|
||||
void CDIBitmap :: DrawDIB( CDC* pDC, int x, int y, int width, int height ) {
|
||||
ASSERT( pDC );
|
||||
HDC hdc = pDC->GetSafeHdc();
|
||||
|
||||
CPalette * pOldPal = 0;
|
||||
|
||||
if( m_pPal ) {
|
||||
pOldPal = pDC->SelectPalette( m_pPal, FALSE );
|
||||
pDC->RealizePalette();
|
||||
// Make sure to use the stretching mode best for color pictures
|
||||
pDC->SetStretchBltMode(COLORONCOLOR);
|
||||
}
|
||||
|
||||
if( m_pInfo )
|
||||
StretchDIBits( hdc,
|
||||
x,
|
||||
y,
|
||||
width,
|
||||
height,
|
||||
0,
|
||||
0,
|
||||
GetWidth(),
|
||||
GetHeight(),
|
||||
GetPixelPtr(),
|
||||
GetHeaderPtr(),
|
||||
DIB_RGB_COLORS,
|
||||
SRCCOPY );
|
||||
|
||||
if( m_pPal )
|
||||
pDC->SelectPalette( pOldPal, FALSE );
|
||||
}
|
||||
|
||||
int CDIBitmap :: DrawDIB( CDC * pDC, CRect & rectDC, CRect & rectDIB ) {
|
||||
ASSERT( pDC );
|
||||
HDC hdc = pDC->GetSafeHdc();
|
||||
|
||||
CPalette * pOldPal = 0;
|
||||
|
||||
if( m_pPal ) {
|
||||
pOldPal = pDC->SelectPalette( m_pPal, FALSE );
|
||||
pDC->RealizePalette();
|
||||
// Make sure to use the stretching mode best for color pictures
|
||||
pDC->SetStretchBltMode(COLORONCOLOR);
|
||||
}
|
||||
|
||||
int nRet = 0;
|
||||
|
||||
if( m_pInfo )
|
||||
nRet = SetDIBitsToDevice(
|
||||
hdc, // device
|
||||
rectDC.left, // DestX
|
||||
rectDC.top, // DestY
|
||||
rectDC.Width(), // DestWidth
|
||||
rectDC.Height(), // DestHeight
|
||||
rectDIB.left, // SrcX
|
||||
GetHeight() -
|
||||
rectDIB.top -
|
||||
rectDIB.Height(), // SrcY
|
||||
0, // StartScan
|
||||
GetHeight(), // NumScans
|
||||
GetPixelPtr(), // color data
|
||||
GetHeaderPtr(), // header data
|
||||
DIB_RGB_COLORS // color usage
|
||||
);
|
||||
|
||||
if( m_pPal )
|
||||
pDC->SelectPalette( pOldPal, FALSE );
|
||||
|
||||
return nRet;
|
||||
}
|
||||
|
||||
BITMAPINFO * CDIBitmap :: GetHeaderPtr() const {
|
||||
ASSERT( m_pInfo );
|
||||
ASSERT( m_pPixels );
|
||||
return m_pInfo;
|
||||
}
|
||||
|
||||
RGBQUAD * CDIBitmap :: GetColorTablePtr() const {
|
||||
ASSERT( m_pInfo );
|
||||
ASSERT( m_pPixels );
|
||||
RGBQUAD* pColorTable = 0;
|
||||
if( m_pInfo != 0 ) {
|
||||
int cOffset = sizeof(BITMAPINFOHEADER);
|
||||
pColorTable = (RGBQUAD*)(((BYTE*)(m_pInfo)) + cOffset);
|
||||
}
|
||||
return pColorTable;
|
||||
}
|
||||
|
||||
BYTE * CDIBitmap :: GetPixelPtr() const {
|
||||
return m_pPixels;
|
||||
}
|
||||
|
||||
int CDIBitmap :: GetWidth() const {
|
||||
ASSERT( m_pInfo );
|
||||
return m_pInfo->bmiHeader.biWidth;
|
||||
}
|
||||
|
||||
int CDIBitmap :: GetHeight() const {
|
||||
ASSERT( m_pInfo );
|
||||
return m_pInfo->bmiHeader.biHeight;
|
||||
}
|
||||
|
||||
WORD CDIBitmap :: GetColorCount() const {
|
||||
ASSERT( m_pInfo );
|
||||
|
||||
switch( m_pInfo->bmiHeader.biBitCount ) {
|
||||
case 1: return 2;
|
||||
case 4: return 16;
|
||||
case 8: return 256;
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int CDIBitmap :: GetPalEntries() const {
|
||||
ASSERT( m_pInfo );
|
||||
return GetPalEntries( *(BITMAPINFOHEADER*)m_pInfo );
|
||||
}
|
||||
|
||||
int CDIBitmap :: GetPalEntries( BITMAPINFOHEADER& infoHeader ) const {
|
||||
int nReturn;
|
||||
if( infoHeader.biClrUsed == 0 )
|
||||
nReturn = ( 1 << infoHeader.biBitCount );
|
||||
else
|
||||
nReturn = infoHeader.biClrUsed;
|
||||
|
||||
return nReturn;
|
||||
}
|
||||
|
||||
DWORD CDIBitmap :: GetBitsPerPixel() const {
|
||||
ASSERT( m_pInfo );
|
||||
return m_pInfo->bmiHeader.biBitCount;
|
||||
}
|
||||
|
||||
DWORD CDIBitmap :: LastByte( DWORD dwBitsPerPixel, DWORD dwPixels ) const {
|
||||
register DWORD dwBits = dwBitsPerPixel * dwPixels;
|
||||
register DWORD numBytes = dwBits / 8;
|
||||
register DWORD extraBits = dwBits - numBytes * 8;
|
||||
return (extraBits % 8) ? numBytes+1 : numBytes;
|
||||
}
|
||||
|
||||
|
||||
DWORD CDIBitmap :: GetBytesPerLine( DWORD dwBitsPerPixel, DWORD dwWidth ) const {
|
||||
DWORD dwBits = dwBitsPerPixel * dwWidth;
|
||||
|
||||
if( (dwBits % 32) == 0 )
|
||||
return (dwBits/8); // already DWORD aligned, no padding needed
|
||||
|
||||
DWORD dwPadBits = 32 - (dwBits % 32);
|
||||
return (dwBits/8 + dwPadBits/8 + (((dwPadBits % 8) > 0) ? 1 : 0));
|
||||
}
|
||||
|
||||
BOOL CDIBitmap :: PadBits() {
|
||||
if( m_bIsPadded )
|
||||
return TRUE;
|
||||
|
||||
// dwAdjust used when bits per pixel spreads over more than 1 byte
|
||||
DWORD dwAdjust = 1, dwOffset = 0, dwPadOffset=0;
|
||||
BOOL bIsOdd = FALSE;
|
||||
|
||||
dwPadOffset = GetBytesPerLine(GetBitsPerPixel(), GetWidth());
|
||||
dwOffset = LastByte(GetBitsPerPixel(), GetWidth());
|
||||
|
||||
if( dwPadOffset == dwOffset )
|
||||
return TRUE;
|
||||
|
||||
BYTE * pTemp = new BYTE [GetWidth()*dwAdjust];
|
||||
if( !pTemp ) {
|
||||
TRACE1("CDIBitmap::PadBits(): could not allocate row of width %d.\n", GetWidth());
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// enough space has already been allocated for the bit array to
|
||||
// include the padding, so we just need to shift rows around.
|
||||
// This will pad each "row" on a DWORD alignment.
|
||||
|
||||
for( DWORD row = GetHeight()-1 ; row>0 ; --row ) {
|
||||
CopyMemory((void *)pTemp, (const void *)(m_pPixels + (row*dwOffset)), dwOffset );
|
||||
CopyMemory((void *)(m_pPixels + (row*dwPadOffset)), (const void *)pTemp, dwOffset);
|
||||
}
|
||||
delete [] pTemp;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL CDIBitmap::UnPadBits() {
|
||||
if( ! m_bIsPadded )
|
||||
return TRUE;
|
||||
|
||||
DWORD dwAdjust = 1;
|
||||
BOOL bIsOdd = FALSE;
|
||||
|
||||
DWORD dwPadOffset = GetBytesPerLine(GetBitsPerPixel(), GetWidth());
|
||||
DWORD dwOffset = LastByte(GetBitsPerPixel(), GetWidth());
|
||||
|
||||
BYTE * pTemp = new BYTE [dwOffset];
|
||||
if( !pTemp ) {
|
||||
TRACE1("CDIBitmap::UnPadBits() could not allocate row of width %d.\n", GetWidth());
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// enough space has already been allocated for the bit array to
|
||||
// include the padding, so we just need to shift rows around.
|
||||
for( DWORD row=1 ; row < DWORD(GetHeight()); ++row ) {
|
||||
CopyMemory((void *)pTemp, (const void *)(m_pPixels + row*(dwPadOffset)), dwOffset);
|
||||
CopyMemory((void *)(m_pPixels + (row*dwOffset)), (const void *)pTemp, dwOffset);
|
||||
}
|
||||
|
||||
delete [] pTemp;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
// dib256.h
|
||||
//
|
||||
|
||||
#ifndef DIB256_H
|
||||
#define DIB256_H
|
||||
|
||||
#pragma once
|
||||
|
||||
class CDIBitmap
|
||||
{
|
||||
friend class CBmpPalette;
|
||||
|
||||
public:
|
||||
BITMAPINFO* m_pInfo;
|
||||
BYTE* m_pPixels;
|
||||
CBmpPalette* m_pPal;
|
||||
BOOL m_bIsPadded;
|
||||
|
||||
public: //constructors
|
||||
CDIBitmap();
|
||||
virtual ~CDIBitmap();
|
||||
|
||||
private:
|
||||
CDIBitmap(const CDIBitmap& dbmp);
|
||||
|
||||
public:
|
||||
BITMAPINFO* GetHeaderPtr() const;
|
||||
BYTE* GetPixelPtr() const;
|
||||
RGBQUAD* GetColorTablePtr() const;
|
||||
int GetWidth() const;
|
||||
int GetHeight() const;
|
||||
CBmpPalette* GetPalette() { return m_pPal; }
|
||||
|
||||
public: // operations
|
||||
BOOL CreatePalette(); // auto. made by "Load()" and "CreateFromBitmap()"
|
||||
void ClearPalette(); // destroy the palette associated with this image
|
||||
BOOL CreateFromBitmap(CDC*, CBitmap*);
|
||||
BOOL LoadResource(LPCTSTR ID);
|
||||
BOOL LoadResource(UINT ID) { return LoadResource(MAKEINTRESOURCE(ID)); }
|
||||
BOOL LoadBitmap(UINT ID) { return LoadResource(ID); }
|
||||
BOOL LoadBitmap(LPCTSTR ID) { return LoadResource(ID); }
|
||||
void DestroyBitmap();
|
||||
BOOL DeleteObject() { DestroyBitmap(); return TRUE; }
|
||||
|
||||
public: // overridables
|
||||
// draw the bitmap at the specified location
|
||||
virtual void DrawDIB(CDC * pDC, int x=0, int y=0);
|
||||
|
||||
// draw the bitmap and stretch/compress it to the desired size
|
||||
virtual void DrawDIB(CDC * pDC, int x, int y, int width, int height);
|
||||
|
||||
// draw parts of the dib into a given area of the DC
|
||||
virtual int DrawDIB(CDC * pDC, CRect & rectDC, CRect & rectDIB);
|
||||
|
||||
// load a bitmap from disk
|
||||
virtual BOOL Load(CFile* pFile);
|
||||
virtual BOOL Load(const CString&);
|
||||
|
||||
// save the bitmap to disk
|
||||
virtual BOOL Save(CFile* pFile);
|
||||
virtual BOOL Save(const CString&);
|
||||
|
||||
protected:
|
||||
int GetPalEntries() const;
|
||||
int GetPalEntries(BITMAPINFOHEADER& infoHeader) const;
|
||||
DWORD GetBitsPerPixel() const;
|
||||
DWORD LastByte(DWORD BitsPerPixel, DWORD PixelCount) const;
|
||||
DWORD GetBytesPerLine(DWORD BitsPerPixel, DWORD Width) const;
|
||||
BOOL PadBits();
|
||||
BOOL UnPadBits();
|
||||
WORD GetColorCount() const;
|
||||
};
|
||||
|
||||
#include "dibpal.h"
|
||||
|
||||
#endif // DIB256_H
|
||||
@@ -0,0 +1,32 @@
|
||||
// dibpal.cpp
|
||||
//
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "dib256.h"
|
||||
#include "dibpal.h"
|
||||
|
||||
CBmpPalette::CBmpPalette( CDIBitmap* pBmp )
|
||||
{
|
||||
ASSERT( pBmp );
|
||||
int cPaletteEntries = pBmp->GetPalEntries();
|
||||
int cPalette = sizeof(LOGPALETTE) +
|
||||
sizeof(PALETTEENTRY) * cPaletteEntries;
|
||||
// Since the LOGPALETTE structure is open-ended, you
|
||||
// must dynamically allocate it, rather than using one
|
||||
// off the stack.
|
||||
LOGPALETTE* pPal = (LOGPALETTE*)new BYTE[cPalette];
|
||||
RGBQUAD* pColorTab = pBmp->GetColorTablePtr();
|
||||
pPal->palVersion = 0x300;
|
||||
pPal->palNumEntries = cPaletteEntries;
|
||||
// Roll through the color table, and add each color to
|
||||
// the logical palette.
|
||||
for( int ndx = 0; ndx < cPaletteEntries; ndx++ )
|
||||
{
|
||||
pPal->palPalEntry[ndx].peRed = pColorTab[ndx].rgbRed;
|
||||
pPal->palPalEntry[ndx].peGreen = pColorTab[ndx].rgbGreen;
|
||||
pPal->palPalEntry[ndx].peBlue = pColorTab[ndx].rgbBlue;
|
||||
pPal->palPalEntry[ndx].peFlags = NULL;
|
||||
}
|
||||
VERIFY( CreatePalette( pPal ) );
|
||||
delete [] (BYTE*)pPal;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// dibpal.h
|
||||
//
|
||||
|
||||
#ifndef DIBPAL_H
|
||||
#define DIBPAL_H
|
||||
|
||||
#pragma once
|
||||
|
||||
class CBmpPalette : public CPalette
|
||||
{
|
||||
public:
|
||||
CBmpPalette( CDIBitmap* pBmp );
|
||||
};
|
||||
|
||||
#endif // DIBPAL_H
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 4.2 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 4.2 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 92 KiB |
Reference in New Issue
Block a user