はみ出しRAPTの戯言

- a day after yesterday -

目次

Blog 利用状況

ニュース

書庫

日記カテゴリ

コミュニティ リンク

INI 編集ツール IniModifier を作成してみる (3)

INI 編集ツール IniModifier を作成してみる (3)

過去の記事へのリンク:
INI 編集ツール IniModifier を作成してみる (1)
INI 編集ツール IniModifier を作成してみる (2)

まずは、WTL::CRichEditCtrl のヘッダを見てみることにする。
WTL は SDK のラッパであり、MFC とほぼ同機能のメソッドを持っているので迷ったら、MSDN で MFC と SDK のヘルプを見るのが常套手段。

WTL::CRichEditCtrl

// WTL::CRichEditCtrl (CRichEditCtrlT<ATL::CWindow>) の宣言
// Constructors
    CRichEditCtrl( HWND hWnd = NULL );
    CRichEditCtrl& operator =( HWND hWnd );
    HWND Create( HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
            DWORD dwStyle = 0, DWORD dwExStyle = 0,
            ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL );

// Attributes
    static LPCTSTR GetWndClassName();
    static LPCTSTR GetLibraryName();

    int GetLineCount() const;
    BOOL GetModify() const;
    void SetModify( BOOL bModified = TRUE );
    void GetRect( LPRECT lpRect ) const;
    DWORD GetOptions() const;
    DWORD SetOptions( WORD wOperation, DWORD dwOptions );

    // NOTE: first word in lpszBuffer must contain the size of the buffer!
    int GetLine( int nIndex, LPTSTR lpszBuffer ) const;

    int GetLine( int nIndex, LPTSTR lpszBuffer, int nMaxLength ) const;
    BOOL CanUndo() const;
    BOOL CanPaste( UINT nFormat = 0 ) const;
    void GetSel( LONG& nStartChar, LONG& nEndChar ) const;
    void GetSel( CHARRANGE &cr ) const;
    int SetSel( LONG nStartChar, LONG nEndChar );
    int SetSel( CHARRANGE &cr );
    int SetSelAll();
    int SetSelNone();
    DWORD GetDefaultCharFormat( CHARFORMAT& cf ) const;
    DWORD GetSelectionCharFormat( CHARFORMAT& cf ) const;
    DWORD GetEventMask() const;
    LONG GetLimitText() const;
    DWORD GetParaFormat( PARAFORMAT& pf ) const;

#if ( _RICHEDIT_VER >= 0x0200 )
    LONG GetSelText( LPTSTR lpstrBuff ) const;
#else
    // RichEdit 1.0 EM_GETSELTEXT is ANSI only
    LONG GetSelText( LPSTR lpstrBuff ) const;
#endif

#ifndef _ATL_NO_COM
    BOOL GetSelTextBSTR( BSTR& bstrText ) const;
#endif

#if defined( _WTL_USE_CSTRING ) || defined( __ATLSTR_H__ )
    LONG GetSelText( _CSTRING_NS::CString& strText ) const;
#endif

    WORD GetSelectionType() const;
    COLORREF SetBackgroundColor( COLORREF cr );
    COLORREF SetBackgroundColor();    // sets to system background
    BOOL SetCharFormat( CHARFORMAT& cf, WORD wFlags );
    BOOL SetDefaultCharFormat( CHARFORMAT& cf );
    BOOL SetSelectionCharFormat( CHARFORMAT& cf );
    BOOL SetWordCharFormat( CHARFORMAT& cf );
    DWORD SetEventMask( DWORD dwEventMask );
    BOOL SetParaFormat( PARAFORMAT& pf );
    BOOL SetTargetDevice( HDC hDC, int cxLineWidth );
    int GetTextLength() const;
    BOOL SetReadOnly( BOOL bReadOnly = TRUE );
    int GetFirstVisibleLine() const;
    EDITWORDBREAKPROCEX GetWordBreakProcEx() const;
    EDITWORDBREAKPROCEX SetWordBreakProcEx( EDITWORDBREAKPROCEX pfnEditWordBreakProcEx );
    int GetTextRange( TEXTRANGE* pTextRange ) const;

#if ( _RICHEDIT_VER >= 0x0200 )
    int GetTextRange( LONG nStartChar, LONG nEndChar, LPTSTR lpstrText ) const;
#else
    int GetTextRange( LONG nStartChar, LONG nEndChar, LPSTR lpstrText ) const;
#endif

#if ( _RICHEDIT_VER >= 0x0200 )
    DWORD GetDefaultCharFormat( CHARFORMAT2& cf ) const;
    BOOL SetCharFormat( CHARFORMAT2& cf, WORD wFlags );
    BOOL SetDefaultCharFormat( CHARFORMAT2& cf );
    DWORD GetSelectionCharFormat( CHARFORMAT2& cf ) const;
    BOOL SetSelectionCharFormat( CHARFORMAT2& cf );
    BOOL SetWordCharFormat( CHARFORMAT2& cf );
    DWORD GetParaFormat( PARAFORMAT2& pf ) const;
    BOOL SetParaFormat( PARAFORMAT2& pf );
    TEXTMODE GetTextMode() const;
    BOOL SetTextMode( TEXTMODE enumTextMode );
    UNDONAMEID GetUndoName() const;
    UNDONAMEID GetRedoName() const;
    BOOL CanRedo() const;
    BOOL GetAutoURLDetect() const;
    BOOL SetAutoURLDetect( BOOL bAutoDetect = TRUE );

    // this method is deprecated, please use SetAutoURLDetect
    BOOL EnableAutoURLDetect( BOOL bEnable = TRUE );

    UINT SetUndoLimit( UINT uUndoLimit );
    void SetPalette( HPALETTE hPalette );
    int GetTextEx( GETTEXTEX* pGetTextEx, LPTSTR lpstrText ) const;
    int GetTextEx( LPTSTR lpstrText, int nTextLen, DWORD dwFlags = GT_DEFAULT, UINT uCodePage = CP_ACP, LPCSTR lpDefaultChar = NULL, LPBOOL lpUsedDefChar = NULL ) const;
    int GetTextLengthEx( GETTEXTLENGTHEX* pGetTextLengthEx ) const;
    int GetTextLengthEx( DWORD dwFlags = GTL_DEFAULT, UINT uCodePage = CP_ACP ) const;
#endif

#if ( _RICHEDIT_VER >= 0x0300 )
    int SetTextEx( SETTEXTEX* pSetTextEx, LPCTSTR lpstrText );
    int SetTextEx( LPCTSTR lpstrText, DWORD dwFlags = ST_DEFAULT, UINT uCodePage = CP_ACP );
    int GetEditStyle() const;
    int SetEditStyle( int nStyle, int nMask = -1 );
    BOOL SetFontSize( int nFontSizeDelta );
    void GetScrollPos( LPPOINT lpPoint ) const;
    void SetScrollPos( LPPOINT lpPoint );
    BOOL GetZoom( int& nNum, int& nDen ) const;
    BOOL SetZoom( int nNum, int nDen );
    BOOL SetZoomOff();
#endif

// Operations
    void LimitText( LONG nChars = 0 );
    int LineFromChar( LONG nIndex ) const;
    POINT PosFromChar( LONG nChar ) const;
    int CharFromPos( POINT pt ) const;
    void EmptyUndoBuffer();
    int LineIndex( int nLine = -1 ) const;
    int LineLength( int nLine = -1 ) const;
    BOOL LineScroll( int nLines, int nChars = 0 );
    void ReplaceSel( LPCTSTR lpszNewText, BOOL bCanUndo = FALSE );
    void SetRect( LPCRECT lpRect );
    BOOL DisplayBand( LPRECT pDisplayRect );
    LONG FindText( DWORD dwFlags, FINDTEXT& ft ) const;
    LONG FindText( DWORD dwFlags, FINDTEXTEX& ft ) const;
    LONG FormatRange( FORMATRANGE& fr, BOOL bDisplay = TRUE );
    LONG FormatRange( FORMATRANGE* pFormatRange, BOOL bDisplay = TRUE );
    void HideSelection( BOOL bHide = TRUE, BOOL bChangeStyle = FALSE );
    void PasteSpecial( UINT uClipFormat, DWORD dwAspect = 0, HMETAFILE hMF = 0 );
    void RequestResize();
    LONG StreamIn( UINT uFormat, EDITSTREAM& es );
    LONG StreamOut( UINT uFormat, EDITSTREAM& es );
    DWORD FindWordBreak( int nCode, LONG nStartChar );

    // Additional operations
    void ScrollCaret();
    int InsertText( long nInsertAfterChar, LPCTSTR lpstrText, BOOL bCanUndo = FALSE );
    int AppendText( LPCTSTR lpstrText, BOOL bCanUndo = FALSE );

    // Clipboard operations
    BOOL Undo();
    void Clear();
    void Copy();
    void Cut();
    void Paste();

    // OLE support
    IRichEditOle* GetOleInterface() const;
    BOOL SetOleCallback( IRichEditOleCallback* pCallback );

#if ( _RICHEDIT_VER >= 0x0200 )
    BOOL Redo();
    void StopGroupTyping();
    void ShowScrollBar( int nBarType, BOOL bVisible = TRUE );
#endif

#if ( _RICHEDIT_VER >= 0x0300 )
    BOOL SetTabStops( int nTabStops, LPINT rgTabStops );
    BOOL SetTabStops();
    BOOL SetTabStops( const int& cxEachStop );    // takes an 'int'
#endif

これで大体何ができるか分かった。 あとは、実際に使用しそうで使ったことがないメソッドについて詳しくみていくことにする。

GetLibraryName

リッチエディットコントロールを使用するには、最初にリッチエディットコントロールの DLL をロードしておかなければいけないらしい。
リッチエディットコントロールの DLL 名はバージョンによって異なるので(Ver1.0 は RICHED32.DLL で、Ver2.0 以降は RICHED20.DLL)、このメソッドを使うことでその違いを CRichEditCtrl がプリプロセス時点で解決してくれる。

// IniModifier.cpp
int WINAPI _tWinMain( HINSTANCE, HINSTANCE, LPTSTR, int )
{
    HMODULE hRich = ::LoadLibrary( CRichEditCtrl::GetLibraryName() );

    // snip

    ::FreeLibrary( hRich );

    return nRet;
}

SetSelectionCharFormat

現在の選択のテキストの文字書式属性を設定する。
なお、選択範囲がない場合は、以降の入力についての設定となる。

// CRichEditCtrl m_rich;

// テキストを青色太字にして保護にする
CHARFORMAT cf;
cf.dwMask = CFM_PROTECTED | CFM_COLOR | CFM_BOLD;
cf.dwEffects = CFE_PROTECTED | CFE_BOLD;
cf.crTextColor = RGB( 0, 0, 255 );
m_rich.SetSelectionCharFormat( cf );

SetEventMask

親ウィンドウに送る通知メッセージを指定する。

ENM_PROTECTED
保護領域を編集しようとした時に WM_NOTIFY メッセージで EN_PROTECTED が通知されるようにする。
0 を返すと変更許可、非0 を返すと変更禁止とする。
ENPROTECTED* pProtected = reinterpret_cast< ENPROTECTED* >( reinterpret_cast< LPNMHDR >( lParam ) ); としたとき、
pProtected->msg に、この通知発生原因のメッセージ ID が入っている。
pProtected->chrg.cpMinpProtected->chrg.cpMax に、この通知発生元のインデックス(リッチエディットコントロール先頭位置からのオフセット)が入っている。
ENM_KEYEVENTS
キーボードイベントが発生した時に WM_NOTIFY メッセージで EN_MSGFILTER が通知されるようにする。
0 を返すと通常のイベントを処理する。非0 を返すと以降のイベント処理を無視する。
MSGFILTER* pFilter = reinterpret_cast< MSGFILTER* >( reinterpret_cast< LPNMHDR >( lParam ) ); としたとき、
pFilter->msg に、この通知発生原因のメッセージ ID が入っている。
ENM_MOUSEEVENTS
マウスイベントが発生した時に WM_NOTIFY メッセージで EN_MSGFILTER が通知されるようにする。
EN_MSGFILTER の動作については、ENM_KEYEVENTS と同じ。
m_rich.SetEventMask( ENM_PROTECTED | ENM_KEYEVENTS | ENM_MOUSEEVENTS );

投稿日時 : 2008年8月17日 16:20

コメントを追加

# KleGljVaIzey 2019/06/29 1:18 https://www.suba.me/

A9ZvnZ You should participate in a contest for the most effective blogs on the web. I will suggest this web site!

# BlkqJUpRPYgQO 2019/07/01 17:58 http://africanrestorationproject.org/social/blog/v

So cool The information provided in the article are some of the best available

# YUWJJJAxrBJYE 2019/07/02 19:00 https://www.youtube.com/watch?v=XiCzYgbr3yM

It as not that I want to copy your web page, but I really like the style and design. Could you tell me which theme are you using? Or was it custom made?

# SArgDiYRuYTNYiCJ 2019/07/04 14:55 http://hubstubticketsworldtour.com

Really enjoyed this post, is there any way I can get an alert email when you make a new post?

# xeijkcOkaEvfXmtIv 2019/07/04 17:39 https://bookmarkingworld.review/story.php?title=1z

Wow, great article post.Really looking forward to read more. Great.

# lzDsrxOzKwPFt 2019/07/05 1:52 https://www.jomocosmos.co.za/members/chardflag38/a

Very good blog article.Much thanks again. Keep writing.

# HGeDfqFpoRezedmjUO 2019/07/07 18:50 https://eubd.edu.ba/

Major thankies for the blog post.Really looking forward to read more. Really Great.

# NkfgWSRrpttlYmRvjw 2019/07/07 20:16 http://i-4-media.net/__media__/js/netsoltrademark.

This is a really good tip especially to those fresh to the blogosphere. Short but very precise information Thanks for sharing this one. A must read post!

# KeUBZxDczcCWRkiG 2019/07/08 23:44 http://chase2929vm.recmydream.com/5-2-and-ababa-wh

The Birch of the Shadow I feel there may become a several duplicates, but an exceedingly helpful list! I have tweeted this. Quite a few thanks for sharing!

# SiOdeNgkJT 2019/07/09 1:10 http://nikitaponynp.biznewsselect.com/positive-cas

Perfectly written content, thanks for selective information.

# PGOYzfAIhRYlUGGgv 2019/07/09 4:03 http://seniorsreversemortej3.tubablogs.com/that-re

Thanks, I have recently been searching for facts about this subject for ages and yours is the best I ave found so far.

# tupkTOLWOUQDuO 2019/07/09 5:30 http://sherondatwylervid.metablogs.net/as-with-any

When I look at your website in Ie, it looks fine but when opening in Internet Explorer, it has some overlapping.

# vYtOoOhhwTYJv 2019/07/10 17:41 http://dailydarpan.com/

I wouldn at mind creating a post or elaborating on many of the subjects you write concerning here. Again, awesome weblog!

# KfgpZzyuoMSlnFs 2019/07/11 6:34 http://www.magcloud.com/user/IzabelleReilly

You may have some real insight. Why not hold some kind of contest for your readers?

# CKxZbuYzIAibyAVH 2019/07/15 6:24 https://www.nosh121.com/42-off-honest-com-company-

Your style is unique compared to other folks I have read stuff from. I appreciate you for posting when you have the opportunity, Guess I will just book mark this site.

# yDWtLCCOJkg 2019/07/15 14:14 https://www.kouponkabla.com/white-castle-coupons-2

Many thanks an additional superb write-up. The site else might anyone obtain that types of facts in such an easy way of writing? I get a display in the future, and I am within the hunt for like info.

# yoYlpSYZfUBIvsKIsHq 2019/07/15 15:48 https://www.kouponkabla.com/orange-theory-promo-co

simply how much time I had spent for this info! Thanks!

# YYSWofXKlsO 2019/07/15 22:14 https://www.kouponkabla.com/poster-my-wall-promo-c

Well I definitely enjoyed reading it. This information offered by you is very effective for good planning.

# JSvmWjsXEnYFMArrggO 2019/07/16 1:50 http://all4webs.com/grapepaper10/xxyayhqjtw565.htm

Your style is very unique in comparison to other people I ave read stuff from. Many thanks for posting when you ave got the opportunity, Guess I will just book mark this page.

# PZBfrPCYaW 2019/07/16 4:57 https://goldenshop.cc/

Regards for this rattling post, I am glad I observed this website on yahoo.

# rUyweRvvZkb 2019/07/16 23:40 https://www.prospernoah.com/wakanda-nation-income-

Very informative blog post.Really looking forward to read more. Really Great.

# kFpiZclbpZx 2019/07/17 3:12 https://www.prospernoah.com/winapay-review-legit-o

I truly appreciate this article post.Really looking forward to read more. Keep writing.

# fKMhGbVjETDZTMwtZGW 2019/07/17 6:41 https://www.prospernoah.com/clickbank-in-nigeria-m

I value the article post.Thanks Again. Keep writing.

# BpRbwYDARFsvcEev 2019/07/17 8:23 https://www.prospernoah.com/how-can-you-make-money

Woman of Alien Perfect get the job done you have got completed, this site is de facto great with great data. Time is God as strategy for maintaining every little thing from going on directly.

# QcldrbzJIUYDa 2019/07/17 10:01 https://www.prospernoah.com/how-can-you-make-money

I was able to find good information from your content.

# HNnHjyWBippkv 2019/07/17 14:29 http://vicomp3.com

Wow, superb blog layout! How long have you ever been blogging for? you make running a blog glance easy. The whole glance of your website is magnificent, let alone the content material!

# qwRQjzjYtjKpQBA 2019/07/17 18:25 http://donn3953xz.wallarticles.com/kitchen-decorat

Major thankies for the blog article. Keep writing.

# CGeKChbsPGYBILjkup 2019/07/17 21:59 http://biznetworkingnowhnb.basinperlite.com/to-get

when I have time I will be back to read much more, Please do keep up the superb jo.

# oONtiurVZakj 2019/07/18 3:52 https://hirespace.findervenue.com/

Thorn of Girl Superb data is usually located on this web blog site.

# qUznxMvffiJWKw 2019/07/18 5:35 http://www.ahmetoguzgumus.com/

Just to let you know your webpage appears a little bit strange in Safari on my notebook using Linux.

# ExFCydnVAwlouWDvP 2019/07/18 9:03 https://softfay.com/windows-browser/microsoft-word

I think other site proprietors should take this web site as an model, very clean and wonderful user genial style and design, as well as the content. You are an expert in this topic!

# tOQEMXjfxLVlTjZAq 2019/07/18 15:52 http://www.hotxxxasia.com/click.php?id=20927&s

very good publish, i actually love this website, carry on it

# SbRDKPzLpQkLgxY 2019/07/18 19:16 https://richnuggets.com/hard-work-smart-work/

Your website offered us with valuable info to work on.

# OqRIQXtXZWmLySvxf 2019/07/19 17:20 https://ageshirt1.bladejournal.com/post/2019/07/18

pretty handy stuff, overall I consider this is well worth a bookmark, thanks

# UKUMFJASFJvYdZj 2019/07/19 19:03 https://www.quora.com/How-can-I-find-the-full-anim

Wow! This could be one particular of the most helpful blogs We ave ever arrive across on this subject. Actually Excellent. I am also an expert in this topic so I can understand your effort.

タイトル  
名前  
URL
コメント