ホーム » 2010 » 10月

月別アーカイブ: 10月 2010

2010年10月
 12
3456789
10111213141516
17181920212223
24252627282930
31  

カテゴリー

アーカイブ

ブログ統計情報

  • 79,653 アクセス



GetLongPathName 存在しないと失敗

http://msdn.microsoft.com/ja-jp/library/cc429335.aspx

簡略化するために HelpAPI.hxx に以下を用意.
inline CString GetLongPathName (LPCTSTR fileName)
{
 CString longPath ;
 UINT size = _MAX_PATH ;
 DWORD len  = ::GetLongPathName(fileName,longPath.GetBuffer(size),size) ;
 longPath.ReleaseBuffer() ;
 if (len == 0) { return fileName ; }
 return longPath ;
 }

ファイルが存在しないと関数が失敗する様なので,
 ::CreateEmptyFile(sFile) ;
 CString  lFile = ::GetLongPathName(sFile) ;
 

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

DImageS の配列で,…

以下の様な DImageS の配列で,要素の表示が 1 回目しかできなかった.
 CString selFile = DImgAry.GetAt(selIndex).GetFileName() ;
 DImgAry[selIndex].Draw(&m_Image) ;

配列を直接使用するのではなく,DImageS にファイル名を取得してからでは OK .
 DImageS dImg ;
 dImg.SetFileName(selFile) ;
 dImg.Draw(&m_ImageMBA) ;
 

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

CEdit::SetSel である位置を選択

SetSel を UpdateData(FALSE) の呼び出しより後に使用すれば良い.
UpdateData(TRUE) ;

// 例えば文字列の最後へ
int pos = m_SelectStr.GetLength() ;
m_CtrlSelectStr.SetSel (pos,pos) ;

// UpdateData(FALSE) ;
または,UpdateData を使用しないで取得,更新する.
CEdit::Setsel の使い方

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

画像付ファイル名のリストボックス

ヘッダファイルへの追加
 #include “DImgS.hxx” または “DImg.hxx”
 #include “ODrawDcM.hxx”

 ListBoxDocMF m_ListDImage;
 CArray <DImageS,DImageS> DImgAry ; または <DImage,…>

OnInitDialog など
 m_ListDImage.SubclassDlgItem(IDC_XXXX_FILE_LIST,this) ;
 m_ListDImage.Init() ;
 m_ListDImage.ResetContent() ;

リストに表示するファイルの設定
 DImgAry.RemoveAll() ;
 for (int dIndex=0 ; dIndex<addFiles.GetSize() ; dIndex++) {
  DImageS dImg ; または DImage
  dImg.SetFileName(addFiles[dIndex]) ;
  DImgAry.Add(dImg) ;
  }
 m_ListDImage.ResetContent() ;
 for (int rIndex=0 ; rIndex<DImgAry.GetSize() ; rIndex++) {
  CString fileName = DImgAry.GetAt(rIndex).GetFileName() ;
  m_ListDImage.AddString(fileName,fileName) ;
   // 以下は登録時に画像を付ける場合
  CString mfName = CacheFile::GetCF_Name(fileName,1000) ;
  if (::FileIsExist(mfName)) {
   m_ListDImage.SetAtDocMF(rIndex,mfName) ;
   }
  else {
   HICON icon = DImageS_GetIcon(fileName) ;
   m_ListDImage.SetAtIcon(rIndex,icon) ;
   }
  }

DImageS クラスでなく DImage クラスを使用した場合は,ImageDMF クラスをサポートする形になる.
DImageS クラスでは,対応付けた EMF での動作になる.
現状の ListBoxDocMF では Shell Extension を利用できないみたい.
別のクラスを用意するか変更が必要.間にListBoxDocSE などを用意するか?
 

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

コントロールをサブクラス化した時のエラー

ダイアログのコントロールをサブクラス化した時の実行時エラーの対応.
m_ListXxx.SubclassDlgItem(IDC_Xxxx_LIST,this) ;
—————————
Microsoft Visual C++ Debug Library
—————————
Debug Assertion Failed!
Program: …\Xxxx\Xxxx\Debug\Xxxx.exe
File: wincore.cpp
Line: 321
For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.
(Press Retry to debug the application)
—————————
中止(A)   再試行(R)   無視(I)
—————————
以前 CListBox として使用していたので,変数として割り付けられていた.
変数を削除してOK.

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

リンクエラーの時のソースとの対応

AlphaBlend MSImg32.lib
SE_ExtractImage HelpEImg.cxx

 

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

FaceA::Search の高速化

データが増えると遅かったので改良
BOOL FaceA::Search(const long edgeS,const long edgeE,long* left_Face,long* rightFace) const
{
  if (left_Face == NULL) { return FALSE ; }
  if (rightFace== NULL) { return FALSE ; }
  *left_Face = *rightFace = -1 ;
  BOOL lfFound = FALSE ;
  BOOL rfFound = FALSE ;
   static long LastFace = 0 ;
  int index = 0 ;
   for (index=LastFace ; index<GetCount() ; index++) {
     Face f = Faces[index] ;
     if (!f.Search(edgeS,edgeE,&lfFound,&rfFound)) { continue ; }
     if (*left_Face<0 && lfFound) { *left_Face = index ; }
     if (*rightFace<0 && rfFound) { *rightFace = index ; }
     if (*left_Face >= 0 && *rightFace>=0) {
       LastFace = min(*left_Face,*rightFace) ;
       return TRUE ;
       }
     }
  for (index=0 ; index<GetCount() ; index++) {
    Face f = Faces[index] ;
    if (!f.Search(edgeS,edgeE,&lfFound,&rfFound)) { continue ; }
    if (*left_Face<0 && lfFound) { *left_Face = index ; }
    if (*rightFace<0 && rfFound) { *rightFace = index ; }
    if (*left_Face >= 0 && *rightFace>=0) {
      LastFace = min(*left_Face,*rightFace) ;
      return TRUE ;
      }
    }
  return FALSE ;
  }

前に検索して一致した所から再検索するコードを追加.

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

CArray の要素のコピー

FaceA::FaceA (const FaceA& other)
{

// ループによるコピー
  Faces.SetSize(other.Faces.GetSize()) ;
  for (int index=0 ; index<other.Faces.GetSize() ; index++) {
    Faces[index] = other.Faces[index] ;
    }

// CArray::Copy
  Faces.Copy(other.Faces) ;

  }

VC 6 リリース版では体感できなかったが,少なくともデバッグ版では Copy の方がはるかに速かった.

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

VC 2010 $(IncludePath)

Microsoft.Cpp.Xxxx.user.props の場所
C:\Users\(UserName)\AppData\Local\Microsoft\MSBuild\v4.0
http://msdn.microsoft.com/ja-jp/library/ee855621.aspx

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

CImage::Draw 部分のメモ

//  AtlImage.h より

inline BOOL CImage::Draw(
  _In_ HDC hDestDC,
  _In_ int xDest,
  _In_ int yDest,
  …
{
  …
#if WINVER >= 0x0500
  if( ((m_iTransparentColor != -1) || (m_clrTransparentColor != (COLORREF)-1)) && IsTransparencySupported() ) {
    bResult = ::TransparentBlt( hDestDC, xDest, yDest, … , GetTransparentRGB() ) ;
    }
  else if( m_bHasAlphaChannel && IsTransparencySupported() ) {
    BLENDFUNCTION bf;
    bf.BlendOp = AC_SRC_OVER;
    bf.BlendFlags = 0;
    bf.SourceConstantAlpha = 0xff;
    bf.AlphaFormat = AC_SRC_ALPHA;
    bResult = ::AlphaBlend( hDestDC, xDest, yDest, … , bf) ;
    }
  else
#endif // WINVER >= 0x0500
  {
    bResult = ::StretchBlt( hDestDC, xDest, yDest, … , SRCCOPY) ;
    }
  …
  return( bResult );
  }

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

VC 6 で GlobalMemoryStatusEx

#if(_MFC_VER >= 0x0700)
  #include	<WinBase.h>
#else

#include	<Windows.h>
#include	<TChar.h>

//  WinBase.h より
typedef struct _MEMORYSTATUSEX {
  DWORD    dwLength;
  DWORD    dwMemoryLoad;
  DWORDLONG  ullTotalPhys;
  DWORDLONG  ullAvailPhys;
  DWORDLONG  ullTotalPageFile;
  DWORDLONG  ullAvailPageFile;
  DWORDLONG  ullTotalVirtual;
  DWORDLONG  ullAvailVirtual;
  DWORDLONG  ullAvailExtendedVirtual;
  } MEMORYSTATUSEX, *LPMEMORYSTATUSEX;

typedef	BOOL	(WINAPI *PFnGlobalMemoryStatusEx)	(LPMEMORYSTATUSEX lpBuffer) ;

////
//*******************************************************************************
//	クラス名:Kernel32.DLL ラッパー
//	作成日	:’10/09/16
//*******************************************************************************
class	WrapKernel32	{
public:
      WrapKernel32	() ;
  virtual ~WrapKernel32	() ;
public:
  virtual	BOOL	GlobalMemoryStatusEx(LPMEMORYSTATUSEX lpBuffer) ;
protected:
  HMODULE   HLibrary ;
  PFnGlobalMemoryStatusEx  FnGlobalMemoryStatusEx ;
  } ;

////
//*******************************************************************************
//	関数名	:コンストラクタ/デストラクタ
//	作成日	:’10/09/16
//*******************************************************************************
inline
WrapKernel32::WrapKernel32	()
{
  HLibrary = NULL ;
  FnGlobalMemoryStatusEx = NULL ;
  HLibrary = ::LoadLibrary	(TEXT("Kernel32.DLL")) ;
  if (HLibrary == NULL)	{	return ;	}
  FnGlobalMemoryStatusEx = (PFnGlobalMemoryStatusEx) GetProcAddress(HLibrary,("GlobalMemoryStatusEx")) ;
  }

inline
WrapKernel32::~WrapKernel32	()
{
  if (HLibrary != NULL) {
    FreeLibrary(HLibrary) ;
    }
  }

////
//*******************************************************************************
//	関数名	:それぞれの呼び出し
//	作成日	:’10/09/16
//*******************************************************************************
inline
BOOL	WrapKernel32::GlobalMemoryStatusEx	(LPMEMORYSTATUSEX lpBuffer)
{
  if (FnGlobalMemoryStatusEx != NULL)	{
    return	FnGlobalMemoryStatusEx	(lpBuffer) ;
    }
  return	FALSE ;
  }

inline
BOOL	WINAPI	GlobalMemoryStatusEx(LPMEMORYSTATUSEX lpBuffer)
{
  if (lpBuffer->dwLength != sizeof(MEMORYSTATUSEX)) {
    #ifdef	_DEBUG
      afxDump << _T("GlobalMemoryStatusEx ... dwLength != ") << sizeof(MEMORYSTATUSEX)
            << _T("  ") << lpBuffer->dwLength << _T("\r\n") ;
    #endif
    }
  WrapKernel32	wk32 ;
  return	wk32.GlobalMemoryStatusEx(lpBuffer) ;
  }

#endif	//	(_MFC_VER >= 0x0700)

WrpKrnl3.hxx

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

EMF への保存

Displaying a Picture and Storing It in an Enhanced Metafile
http://msdn.microsoft.com/en-us/library/dd183568.aspx


2020/12
E_MF.hxx
EMF_fnc.hxx

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

DIB の縮小表示

サイズの大きな画像を縮小して表示すると汚くなる

SetStretchBltMode の指定が必要.
http://msdn.microsoft.com/ja-jp/library/cc428734.aspx

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.