caret.cpp
上传用户:starrett
上传日期:2020-11-17
资源大小:1474k
文件大小:24k
- // 记事本.cpp : Defines the entry point for the application.
- //
- #include "stdafx.h"
- #include <windows.h>
- #include <stdlib.h>
- #include "resource.h"
- #include <commdlg.h>
- #include <windowsx.h>
- #include "func.h"
- #include <commctrl.h>
- #include "shlwapi.h"
- #define STRSIZE1 300
- #define STRSIZE2 30
- #define FILEPATHSIZE 2048
- #define FILENAMESIZE 280
- #define MAXPATTERNLEN 200
- char * strFileName;
- char * strFilePath;
- TCHAR strWindowTitle[STRSIZE2];
- LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
- void OpenFileProc(HWND);
- BOOL OpenFileDlg(HWND,char *,char *);
- void SaveFileProc(HWND,PTSTR,PTSTR);
- static TCHAR szAppName[] = TEXT ("记事本") ;
- TCHAR szDefaultText[] = TEXT ("welcome to use this") ;
- #define CF_TCHAR CF_UNICODETEXT
- static HWND hDlgModeless;
- PTSTR text=NULL;
- PTSTR Text=NULL;
- PTSTR GetText(HWND);
- HWND FindFindDlg (HWND) ;
- HWND FindReplaceDlg (HWND) ;
- BOOL FindFindText (HWND, int *, LPFINDREPLACE) ;
- BOOL FindReplaceText (HWND, int *, LPFINDREPLACE) ;
- BOOL FindValidFind (void) ;
- int APIENTRY WinMain(HINSTANCE hInstance,
- HINSTANCE hPrevInstance,
- LPSTR lpCmdLine,
- int nCmdShow)
- {
- // TODO: Place code here.
- HWND hwnd ;
- MSG msg ;
- WNDCLASS wndclass ;
- wndclass.style = CS_HREDRAW | CS_VREDRAW ;
- wndclass.lpfnWndProc = WndProc ;
- wndclass.cbClsExtra = 0 ;
- wndclass.cbWndExtra = 0 ;
- wndclass.hInstance = hInstance ;
- wndclass.hIcon = LoadIcon (hInstance,"记事本") ;
- wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
- wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
- wndclass.lpszMenuName = "记事本" ;
- wndclass.lpszClassName = szAppName ;
-
- if (!RegisterClass (&wndclass))
- return 0 ;
-
-
- hwnd = CreateWindow (szAppName, TEXT ("记事本"),
- WS_OVERLAPPEDWINDOW,
- CW_USEDEFAULT, CW_USEDEFAULT,
- CW_USEDEFAULT, CW_USEDEFAULT,
- NULL, NULL, hInstance, NULL) ;
-
- ShowWindow (hwnd, nCmdShow) ;
- UpdateWindow (hwnd) ;
- // SendMessage(GetDlgItem(hwnd,IDC_EDIT1),WM_SETFONT,(WPARAM)hFont,TRUE);
-
- while (GetMessage (&msg, NULL, 0, 0))
- {
- TranslateMessage (&msg) ;
- DispatchMessage (&msg) ;
- }
- return msg.wParam ;
- }
- LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
- {
- static int cxChar, cyChar, cxClient, cyClient, cxBuffer, cyBuffer,
- xCaret, yCaret , iVertPos, iHorzPos, xFocu;
- // static TCHAR * pBuffer = NULL ;
- static TCHAR szFileName[MAX_PATH], szTitleName[MAX_PATH] ;
- static RowNode* PRow[ROWSMAX];
- HDC hdc ;
- int x=0, y=0, i=0 ;
- PAINTSTRUCT p;
- TEXTMETRIC tm ;
- POINT point ;
- int iSelect, iEnable, iPaintBeg, iPaintEnd ;
- static DWORD dwCharSet = DEFAULT_CHARSET ;
- static CHOOSEFONT cf ;
- static LOGFONT lf ;
- static int iOffset ;
- int row=0,cols=0;
- static PTSTR pText ;//用来保存需要复制,剪切,删除的内容
- BOOL bEnable ;
- HGLOBAL hGlobal ;
- PTSTR pGlobal ;
- switch (message)
- {
- case WM_INPUTLANGCHANGE:
- dwCharSet = wParam ;
- return 0;
- case WM_CREATE:
- InsertRow(PRow,ROWSMAX);
- hdc = GetDC (hwnd) ;
- SetFont(hdc, dwCharSet) ;
- GetTextMetrics (hdc, &tm) ;
- cxChar =tm.tmAveCharWidth ;
- cyChar =tm.tmHeight+ tm.tmInternalLeading ;
-
- DeleteObject (SelectObject (hdc, GetStockObject (SYSTEM_FONT))) ;
- ReleaseDC (hwnd, hdc) ;
- return 0 ;
- // fall through
- case WM_SIZE:
- // obtain window size in pixels
- cxClient = LOWORD (lParam) ;
- cyClient = HIWORD (lParam) ;
-
- // calculate window size in characters
- cxBuffer = max (1, cxClient / cxChar) ;
- cyBuffer = max (1, cyClient / cyChar) ;
- InvalidateRect (hwnd, NULL, TRUE) ;
- return 0;
-
- case WM_LBUTTONDOWN :
- point.x = LOWORD (lParam) ;
- point.y = HIWORD (lParam) ;
-
- //xFocu=point.y;
- //xFocu=point.x;
- return 0;
- case WM_LBUTTONUP ://左键放开后操作
- point.x = LOWORD (lParam) ;//得到此点的坐标
- point.y = HIWORD (lParam) ;
- xFocu=(point.x/cxChar)*cxChar;
- yCaret=point.y/cyChar;//转换成一个字节的高度和宽度,即不出现在字符里面
- xCaret=point.x/cxChar;
- SetCaretPos (xFocu, yCaret*cyChar) ;//显示鼠标
- return 0;
- case WM_SETFOCUS:
- // create and show the caret
-
- CreateCaret (hwnd, NULL, 1, cyChar) ;
- SetCaretPos (xFocu, (yCaret-iVertPos) * cyChar) ;
- // SetCaretPos (xFocu, yCaret * cyChar) ;
- ShowCaret (hwnd) ;
- return 0 ;
- case WM_KILLFOCUS:
- // hide and destroy the caret
- HideCaret (hwnd) ;
- DestroyCaret () ;
- return 0 ;
- case WM_KEYDOWN:
- for (i = 0 ; i < (int) LOWORD (lParam) ; i++)
- {
- switch (wParam)
- {
- case VK_LEFT:
- if(xCaret == 0 && yCaret != 0)
- {
- yCaret-- ;
- xCaret=PRow[yCaret]->number ;
- xFocu=PRow[yCaret]->width ;
- }
- else
- {
- if((xCaret - 1)>=0)
- {
- xCaret-- ;
- if((PRow[yCaret]->date[xCaret] >> 8)>0)
- xFocu -= cxChar*2 ;
- else
- xFocu -= cxChar ;
- }
- }
- break ;
-
- case VK_RIGHT:
- if(xCaret == PRow[yCaret]->number && yCaret != RowSum-1)
- {
- yCaret++;
- xFocu=xCaret=0;
- }
- else
- {
- if((xCaret + 1)<=PRow[yCaret]->number)
- {
- if((PRow[yCaret]->date[xCaret] >> 8)>0)
- xFocu += cxChar*2 ;
- else
- xFocu += cxChar ;
- xCaret++ ;
- }
- }
- break ;
-
- case VK_UP:
- yCaret = max (yCaret - 1, 0) ;
- if(xFocu >= PRow[yCaret]->width)
- {
- xCaret=PRow[yCaret]->number ;
- xFocu=PRow[yCaret]->width ;
- }
- else
- {
- while(x<xFocu)
- {
- x+=CharWidth(PRow[yCaret]->date[i])*cxChar ;
- i++ ;
- }
- xCaret=i ;
- xFocu=x ;
- SetCaretPos (xFocu, (yCaret-iVertPos) * cyChar) ;
- }
- break ;
-
- case VK_DOWN:
- yCaret = min (yCaret + 1, RowSum - 1) ;
- if(xFocu >= PRow[yCaret]->width)
- {
- xCaret=PRow[yCaret]->number ;
- xFocu=PRow[yCaret]->width ;
- }
- else
- {
- while(x<xFocu)
- {
- x+=CharWidth(PRow[yCaret]->date[i])*cxChar ;
- i++ ;
- }
- xCaret=i ;
- xFocu=x ;
- }
- break ;
- case VK_DELETE:
- if(xCaret<PRow[yCaret]->number)
- {
- DeleteChar(PRow,yCaret,xCaret);
- HideCaret (hwnd) ;
- hdc = GetDC (hwnd) ;
- SetFont(hdc, dwCharSet) ;
- ClsChar(hdc , xFocu, (yCaret-iVertPos-iVertPos) * cyChar, min(cxBuffer*cxChar,PRow[yCaret-iVertPos]->width)+1, (yCaret-iVertPos+1) * cyChar) ;
- TextOut (hdc, xFocu, (yCaret-iVertPos-iVertPos) * cyChar,PRow[yCaret-iVertPos]->date+xCaret, PRow[yCaret-iVertPos]->number-xCaret) ;
- DeleteObject (SelectObject (hdc, GetStockObject (SYSTEM_FONT))) ;
- if((PRow[yCaret]->date[xCaret] >> 8)>0)
- PRow[yCaret]->width -= cxChar*2;
- else
- PRow[yCaret]->width -= cxChar ;
- ReleaseDC (hwnd, hdc) ;
- ShowCaret (hwnd) ;
- }
- return 0;
- }
- SetCaretPos (xFocu, (yCaret-iVertPos) * cyChar) ;
- return 0 ;
- }
-
- case WM_CHAR:
- for (i = 0 ; i < (int) LOWORD (lParam) ; i++)
- {
- switch (wParam)
- {
- case 'b': // backspace
- if (xCaret > 0)
- {
- xCaret-- ;
- if((PRow[yCaret]->date[xCaret] >> 8)>0)
- xFocu -= cxChar*2 ;
- else
- xFocu -= cxChar ;
- SendMessage (hwnd, WM_KEYDOWN, VK_DELETE, 1) ;
- }
- else if(xCaret == 0 && yCaret != 0)
- {
- x=PRow[yCaret-1]->number ;
- xFocu=PRow[yCaret-1]->width ;
- CopyRow(PRow,yCaret,xCaret,yCaret-1,PRow[yCaret-1]->number);
- PRow[yCaret-1]->width=xFocu + PRow[yCaret]->width;
- DeleteRow(PRow,yCaret);
- xCaret=x;yCaret--;
- HideCaret (hwnd) ;
- hdc = GetDC (hwnd) ;
- SetFont(hdc, dwCharSet) ;
- ClsChar(hdc , 0 , (yCaret-iVertPos) * cyChar , cxBuffer*cxChar, (RowSum-iVertPos+1) * cyChar);
- for (y = yCaret ; y < RowSum ; y++)
- TextOut (hdc, 0, (y-iVertPos) * cyChar,PRow[y]->date, PRow[y]->number) ;
- DeleteObject (SelectObject (hdc, GetStockObject (SYSTEM_FONT))) ;
- ReleaseDC (hwnd, hdc) ;
- ShowCaret (hwnd) ;
- SendMessage(hwnd, WM_VSCROLL, SB_LINEUP, 0);
- }
- break ;
-
- case 't': // tab
- do
- {
- SendMessage (hwnd, WM_CHAR, ' ', 1) ;
- }
- while (xCaret % 8 != 0) ;
- break ;
-
- case 'n': // line feed
- break ;
-
- case 'r': // 回车换行
- xFocu = 0 ;
- InsertRow(PRow,yCaret+1); //插入一行
- HideCaret (hwnd) ;
- hdc = GetDC (hwnd) ;
- SetFont(hdc, dwCharSet) ;
- if(xCaret < PRow[yCaret]->number)//判断是否为在已输入字符间换行
-
- CopyRow(PRow,yCaret,xCaret,yCaret+1,0);//如果是需将后面字符连接到下一行
-
- ClsChar(hdc , 0 , (yCaret-iVertPos) * cyChar , cxBuffer*cxChar, (RowSum-iVertPos) * cyChar); //将后面字符用背景色覆盖
- for (y = yCaret ; y < RowSum ; y++)
- TextOut (hdc, 0, (y-iVertPos) * cyChar,PRow[y]->date, PRow[y]->number) ;//重新输出
- DeleteObject (SelectObject (hdc, GetStockObject (SYSTEM_FONT))) ;
- yCaret++;
- ReleaseDC (hwnd, hdc) ;
- ShowCaret (hwnd) ;
- xCaret=0;
- break ;
-
- case 'x1B':
- break ;
-
- default: // character codes
- InputChar(PRow,yCaret,xCaret,(TCHAR)wParam);
- HideCaret (hwnd) ;
- hdc = GetDC (hwnd) ;
- SetFont(hdc, dwCharSet) ;
- TextOut (hdc, xFocu, (yCaret-iVertPos) * cyChar,PRow[yCaret-iVertPos]->date+xCaret, PRow[yCaret-iVertPos]->number-xCaret) ;
- DeleteObject (SelectObject (hdc, GetStockObject (SYSTEM_FONT))) ;
- ReleaseDC (hwnd, hdc) ;
- ShowCaret (hwnd) ;
- xCaret++ ;
- if((wParam >> 8)>0)
- {
- PRow[yCaret]->width += cxChar*2 ;
- xFocu += cxChar*2 ;
- }
- else
- {
- PRow[yCaret]->width += cxChar ;
- xFocu += cxChar ;
- }
- break;
- }
- }
- if(yCaret >= cyBuffer+iVertPos)
- {
- x=yCaret-cyBuffer+1 ;
- SendMessage(hwnd, WM_VSCROLL, SB_THUMBTRACK, x+1);
- return 0;
- }
- else if(yCaret < iVertPos)
- {
- SendMessage(hwnd, WM_VSCROLL, SB_THUMBTRACK, yCaret+1);
- return 0;
- }
- SetCaretPos (xFocu, (yCaret-iVertPos) * cyChar) ;
- return 0 ;
-
- case WM_PAINT:
- hdc = BeginPaint (hwnd, &p) ;
- SetFont(hdc, dwCharSet) ;
- SetWindowOrgEx(hdc,cxChar * iHorzPos,cyChar * iVertPos,NULL);
- iPaintBeg = max (0, iVertPos + p.rcPaint.top / cyChar) ;
- iPaintEnd = min (RowSum - 1, iVertPos + p.rcPaint.bottom / cyChar) ;
- for (y = iPaintBeg ; y <= iPaintEnd ; y++)
- TextOut (hdc, 0, y * cyChar,PRow[y]->date, PRow[y]->number) ;
- DeleteObject (SelectObject (hdc, GetStockObject (SYSTEM_FONT))) ;
- if(text!=NULL)
- {
- HideCaret (hwnd) ;
- for(int i=0;i<strlen(text);i++)
- {
- if(text[i]=='r'&&text[i+1]=='n')//处理回车换行符
- {
- row+=cyChar;
- cols=0;
- i++; //跳过回车换行符
- }
- else if(text[i]=='t') //处理制表符
- {
- cols+=8*cxChar;
- }
- else if(IsDBCSLeadByte(text[i]))
- {
- TextOut(hdc,cols,row,&text[i],2);
- cols+=cxChar*2;
- i++;
- }
- else
- {
- TextOut(hdc,cols,row,&text[i],1);
- cols+=cxChar;
- }
- }
-
- }
- EndPaint (hwnd, &p) ;
- return 0 ;
- case WM_INITMENUPOPUP:
- if (lParam == 1)
- {
- /* EnableMenuItem ((HMENU) wParam, IDM_EDIT_UNDO,
- SendMessage (hwnd, EM_CANUNDO, 0, 0) ?
- MF_ENABLED : MF_GRAYED) ;
-
- EnableMenuItem ((HMENU) wParam, IDM_EDIT_PASTE,
- IsClipboardFormatAvailable (CF_TEXT) ?
- MF_ENABLED : MF_GRAYED) ;
-
- iSelect = SendMessage (hwnd, EM_GETSEL, 0, 0) ;
-
- if (HIWORD (iSelect) == LOWORD (iSelect))
- iEnable = MF_GRAYED ;
- else
- iEnable = MF_ENABLED ;
-
- EnableMenuItem ((HMENU) wParam, IDM_EDIT_CUT, iEnable) ;
- EnableMenuItem ((HMENU) wParam, IDM_EDIT_COPY, iEnable) ;
- EnableMenuItem ((HMENU) wParam, IDM_EDIT_CLEAR, iEnable) ;
- break;*/
- EnableMenuItem ((HMENU) wParam, IDM_EDIT_PASTE,
- IsClipboardFormatAvailable (CF_TCHAR) ? MF_ENABLED : MF_GRAYED) ;
- bEnable = pText ? MF_ENABLED : MF_GRAYED ;
- EnableMenuItem ((HMENU) wParam, IDM_EDIT_CUT, bEnable) ;
- EnableMenuItem ((HMENU) wParam, IDM_EDIT_COPY, bEnable) ;
- EnableMenuItem ((HMENU) wParam, IDM_EDIT_CLEAR, bEnable) ;
- break ;
- }
- else
- { iEnable = hwnd == NULL ?
- MF_ENABLED : MF_GRAYED ;
-
- EnableMenuItem ((HMENU) wParam, IDM_SEARCH_FIND, iEnable) ;
- EnableMenuItem ((HMENU) wParam, IDM_SEARCH_REPLACE, iEnable) ;
- break ;
- }
- return 0;
- case WM_COMMAND:
- // Messages from edit control
- switch (LOWORD (wParam))
- {
-
- case IDM_FILE_OPEN:
- OpenFileProc(hwnd);
- text=GetText(hwnd);
- InvalidateRect (hwnd, NULL, TRUE) ;
- break;
- case IDM_FILE_SAVE:
- if (szFileName[0])
- SaveFileProc(hwnd,szFileName,text);
- else MessageBox(hwnd,"zenmehuishi?",strWindowTitle,MB_ICONEXCLAMATION);
- break;
- case IDM_FILE_SAVE_AS:
- break;
- case IDM_APP_EXIT:
- SendMessage (hwnd, WM_CLOSE, 0, 0) ;
- return 0 ;
-
- // Messages from Edit menu
-
- case IDM_EDIT_UNDO:
- if (pText)
- {
- free (pText) ;
- pText = NULL ;
- }
- InvalidateRect (hwnd, NULL, TRUE) ;
- return 0 ;
-
- case IDM_EDIT_CUT:
- SendMessage (hwnd, WM_CUT, 0, 0) ;
- return 0 ;
-
- case IDM_EDIT_COPY:
- if (!pText)
- return 0 ;
- hGlobal = GlobalAlloc (GHND | GMEM_SHARE,
- (lstrlen (pText) + 1) * sizeof (TCHAR)) ;
- pGlobal =(char *) GlobalLock (hGlobal) ;
- lstrcpy (pGlobal, pText) ;
- GlobalUnlock (hGlobal) ;
- OpenClipboard (hwnd) ;
- EmptyClipboard () ;
- SetClipboardData (CF_TCHAR, hGlobal) ;
- CloseClipboard () ;
- if (LOWORD (wParam) == IDM_EDIT_COPY)
- return 0 ;
-
-
- case IDM_EDIT_PASTE:
- OpenClipboard (hwnd) ;
- if (hGlobal = GetClipboardData (CF_TCHAR))
- {
- pGlobal = (char *)GlobalLock (hGlobal) ;
- if (pText)
- {
- free (pText) ;
- pText = NULL ;
- }
- pText = (char *)malloc (GlobalSize (hGlobal)) ;
- lstrcpy (pText, pGlobal) ;
- InvalidateRect (hwnd, NULL, TRUE) ;
- }
- CloseClipboard () ;
- return 0 ;
-
- case IDM_EDIT_CLEAR:
- SendMessage (hwnd, WM_CLEAR, 0, 0) ;
- return 0 ;
-
- case IDM_EDIT_SELECT_ALL:
- SendMessage (hwnd, EM_SETSEL, 0, -1) ;
- return 0 ;
-
- // Messages from Search menu
-
- case IDM_SEARCH_FIND:
- SendMessage (hwnd, EM_GETSEL, 0, (LPARAM) &iOffset) ;
- //hDlgModeless = FindFindDlg (hwnd) ;
- return 0 ;
-
-
- case IDM_SEARCH_REPLACE:
- SendMessage (hwnd, EM_GETSEL, 0, (LPARAM) &iOffset) ;
- //hDlgModeless = FindReplaceDlg (hwnd) ;
- return 0 ;
- case IDM_APP_ABOUT:
- MessageBox (hwnd, TEXT ("created by ll,2010_3"),
- szAppName, MB_OK | MB_ICONINFORMATION) ;
- return 0 ;
- case IDM_FORMAT_FONT:
- if (ChooseFont (&cf))
- InvalidateRect (hwnd, NULL, TRUE) ;
- return 0 ;
- }
- break ;
-
- case WM_DESTROY:
- PostQuitMessage (0) ;
- return 0 ;
- }
- return DefWindowProc (hwnd, message, wParam, lParam) ;
- }
- BOOL OpenFileDlg(HWND hWnd,PTSTR pstrFileName, PTSTR pstrTitleName)
- {
- OPENFILENAME ofn;
-
- ZeroMemory(&ofn, sizeof(ofn));
- ofn.lStructSize = sizeof(ofn);
- ofn.hwndOwner = hWnd;
- ofn.lpstrFile = pstrFileName;
- ofn.lpstrFile[0] = ' ';
- ofn.nMaxFile = FILEPATHSIZE;
- ofn.lpstrFilter = "文本文档(*.txt) *.txt 所有文件 *.*";
- ofn.nFilterIndex = 1;
- ofn.lpstrFileTitle = pstrTitleName;
- ofn.nMaxFileTitle = FILENAMESIZE;
- ofn.lpstrInitialDir = NULL;
- ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
- if ( GetOpenFileName(&ofn) )
- return TRUE;
- return FALSE;
- }
- void OpenFileProc(HWND hwnd)
- {
- int MsgBoxRst;
- HDC hdc;
- char *str1=NULL,*strFileNameTemp,*strFilePathTemp;
- HANDLE hFile;
- int filesize;
- BOOL IsSaved=TRUE;
- hdc = GetDC (hwnd) ;
- DWORD dwRead;
- PBYTE pConv;
- if(!IsSaved)
- {
- str1=(char *)calloc(FILENAMESIZE+30,sizeof(char));
- strcpy(str1,"文件 ");
- strcat(str1,strFileName);
- strcat(str1," 的文字已经改变。nn想保存文件吗?");
- MsgBoxRst=MessageBox(hwnd,str1,strWindowTitle,MB_YESNOCANCEL|MB_ICONEXCLAMATION );
- free(str1);
- if(MsgBoxRst==IDYES)
- SendMessage(hwnd,WM_COMMAND,IDM_FILE_SAVE,0);
- }
- if(IsSaved|| MsgBoxRst==IDNO)
- {
- strFileNameTemp=(char *)calloc(FILENAMESIZE,sizeof(char));
- strFilePathTemp=(char *)calloc(FILEPATHSIZE,sizeof(char));
- if(OpenFileDlg(hwnd,strFilePathTemp,strFileNameTemp))
- {
- hFile = CreateFile(strFilePathTemp, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
- if (hFile == INVALID_HANDLE_VALUE)
- MessageBox(hwnd,"打开文件失败!",strWindowTitle,MB_ICONEXCLAMATION);
- else
- {
- filesize=GetFileSize(hFile,NULL);//得到文件长度
- str1=(char *)calloc(filesize+1,sizeof(char));//分配内存
- memset(str1,0,filesize+1); //初始化为空
-
- if(ReadFile(hFile,str1,filesize,&dwRead,NULL))
- {
-
- str1[dwRead]=0;
- CloseHandle(hFile);
- pConv =(PBYTE) malloc (2 *filesize + 2) ;
-
- // If the edit control is Unicode, convert ASCII text.
-
- #ifdef UNICODE
-
- MultiByteToWideChar (CP_ACP, 0, str1, -1, (PTSTR) pConv, filesize + 1) ;
-
- // If not, just copy buffer
- #else
-
- lstrcpy ((PTSTR) pConv, str1) ;
-
- #endif
- Text=(char *)pConv;
- //TextOut (hdc, 0, 0,str1,filesize) ;
- }
- else
- MessageBox(hwnd,"读取文件失败!",strWindowTitle,MB_ICONEXCLAMATION);
- free(str1);
- CloseHandle(hFile);
- }
- }
- free(strFileNameTemp);
- free(strFilePathTemp);
- }
- }
- void SaveFileProc(HWND hwnd, PTSTR pstrFileName, PTSTR pstrtext)
- //(HWND hwnd)
- {
- char *str1=NULL;
- HANDLE hFile;
- int filesize;
- BOOL IsSaved;
- DWORD dwWrite ;
- WORD wByteOrderMark = 0xFEFF ;
-
- hFile = CreateFile(pstrFileName, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
- if (hFile == INVALID_HANDLE_VALUE)
- {
- //str1=(char *)calloc(FILEPATHSIZE+30,sizeof(char));
- //strcpy(str1,"不能创建文件 ");
- //strcat(str1,strFilePath);
- //strcat(str1,"。nn请确认路径和文件名是否正确。");
- // MessageBox(hwnd,str1,strWindowTitle,MB_ICONEXCLAMATION);
- MessageBox(hwnd,"不能创建文件",strWindowTitle,MB_ICONEXCLAMATION);
- free(str1);
- SendMessage(hwnd,WM_COMMAND,IDM_FILE_SAVE_AS,0);
- }
- else
- {
- filesize=strlen(pstrtext);
- str1=(char*)calloc(filesize+1,sizeof(char));
-
- //if(WriteFile(hFile,str1,filesize+1,&num1,NULL))
-
- #ifdef UNICODE
-
- WriteFile (hFile, &wByteOrderMark, 2, &dwWrite, NULL) ;
- IsSaved=TRUE;
-
- #endif
-
- // Get the edit buffer and write that out to the file.
- str1=pstrtext;
-
- WriteFile (hFile, str1, filesize* sizeof (TCHAR),
-
- &dwWrite, NULL) ;
-
-
- MessageBox(hwnd,"保存文件失败!",strWindowTitle,MB_ICONEXCLAMATION);
- free(str1);
- CloseHandle(hFile);
- }
- }
- PTSTR GetText(HWND hwnd)
- {
- return Text;
- }