记事本自动换行代码

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

/*Word Wrap*/

case M_WW:

style= (!fWrap) ? ES_STD : (ES_STD | WS_HSCROLL);

if( NpReCreate( style ) )

{

fWrap= !fWrap;

}

...

/* ** Recreate notepad edit window, get text from old window and put in new window. Called when user changes style from wrap on/off */ BOOL FAR NpReCreate( long style )

{

RECT rcT1;

HWND hwndT1;

HANDLE hT1;

int cchTextNew;

TCHAR* pchText;

BOOL fWrap = ((style & WS_HSCROLL) == 0);

HCURSOR hPrevCursor;

BOOL bModified; // modify flag from old edit buffer

/* if wordwrap, remove soft carriage returns */

hPrevCursor= SetCursor( hWaitCursor ); // this may take some time... if (!fWrap)

SendMessage(hwndEdit, EM_FMTLINES, FALSE, 0L);

bModified= (SendMessage( hwndEdit, EM_GETMODIFY, 0,0 ) != 0);

cchTextNew= (int)SendMessage( hwndEdit, WM_GETTEXTLENGTH, 0, 0L ); hT1= LocalAlloc( LMEM_MOVEABLE, ByteCountOf(cchTextNew + 1) );

if( !hT1 )

{

/* failed, was wordwrap; insert soft carriage returns */

if (!fWrap)

SendMessage(hwndEdit, EM_FMTLINES, TRUE, 0L);

SetCursor( hPrevCursor );

return FALSE;

}

GetClientRect( hwndNP, (LPRECT)&rcT1 );

/*

* save the current edit control text.

*/

pchText= LocalLock (hT1);

SendMessage( hwndEdit, WM_GETTEXT, cchTextNew+1, (LPARAM)pchText );

hwndT1= CreateWindowEx( WS_EX_CLIENTEDGE,

TEXT("Edit"),

TEXT(""), // pchText

style,

0,

0,

rcT1.right,

rcT1.bottom,

hwndNP,

(HMENU)ID_EDIT,

hInstanceNP, NULL );

if( !hwndT1 )

{

SetCursor( hPrevCursor );

if (!fWrap)

SendMessage( hwndEdit, EM_FMTLINES, TRUE, 0L );

LocalUnlock(hT1);

LocalFree(hT1);

return FALSE;

}

//

// The user can "add" styles to the edit window after it is

// created (like WS_EX_RTLREADING) when language packs are installed.

// Preserve these styles when changing the word wrap.

//

SetWindowLong( hwndT1 ,

GWL_EXSTYLE ,

GetWindowLong( hwndEdit , GWL_EXSTYLE )|WS_EX_CLIENTEDGE ) ;

// Set font before set text to save time calculating

SendMessage( hwndT1, WM_SETFONT, (WPARAM)hFont, MAKELPARAM(TRUE, 0) );

if (!SendMessage (hwndT1, WM_SETTEXT, 0, (LPARAM) pchText))

{

SetCursor( hPrevCursor );

if (!fWrap)

SendMessage( hwndEdit, EM_FMTLINES, TRUE, 0L );

DestroyWindow( hwndT1 );

LocalUnlock( hT1 );

LocalFree( hT1 );

return FALSE;

}

LocalUnlock(hT1);

DestroyWindow( hwndEdit ); // out with the old

hwndEdit = hwndT1; // in with the new

/*

* Win32s does not support the EM_SETHANDLE message, so just do * the assignment. hT1 already contains the edit control text.

*/

/* free the earlier allocated memory in hEdit */

if (hEdit)

LocalFree(hEdit);

hEdit = hT1;

/* limit text for safety's sake. */

PostMessage( hwndEdit, EM_LIMITTEXT, (WPARAM)CCHNPMAX, 0L );

ShowWindow(hwndNP, SW_SHOW);

SetTitle( fUntitled ? szUntitled : szFileName );

SendMessage( hwndEdit, EM_SETMODIFY, bModified, 0L );

SetFocus(hwndEdit);

SetCursor( hPrevCursor ); // restore cursor

return TRUE;

}

相关文档
最新文档