/************************************************* * srcproc.c * * * * Copyright (C) 1992-1999 Microsoft Inc. * * * *************************************************/ #include "chnuconv.h" #include "resource.h" INT_PTR SourceTabProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam ) { TCHAR szBuffer[50]; int i; switch( message ) { case WM_INITDIALOG: { RECT rcTab; //GetTab window size // first get the size of the tab control if (GetWindowRect( hMainTabControl, &rcTab )){ // adjust it to compensate for the tabs TabCtrl_AdjustRect( hMainTabControl, FALSE , &rcTab); // convert the screen coordinates to client coordinates MapWindowPoints( HWND_DESKTOP, GetParent(hMainTabControl), (LPPOINT)&rcTab, 2); } SetWindowPos(hWnd, HWND_TOP, rcTab.left, rcTab.top, rcTab.right - rcTab.left, rcTab.bottom - rcTab.top, SWP_NOACTIVATE ); LoadString(_hModule, IDS_BUT_OPEN, szBuffer, EXTENSION_LENGTH); SetDlgItemText(hWnd,IDC_OPENORSAVEAS, szBuffer); LoadString(_hModule, IDS_BUT_FROMCLIPBOARD,szBuffer,EXTENSION_LENGTH); SetDlgItemText(hWnd, IDC_PASTEORCOPY, szBuffer); for (i=0;i 2^32 * If it is OK, write the file size in hwndSize0 */ { DWORD dwHigh; DWORD dwLow; dwLow = GetFileSize(hFile,&dwHigh); if ((dwHigh > 0) || (dwLow == 0xFFFFFFFF && GetLastError() != NO_ERROR)) { LoadString(_hModule,IDS_FILETOOBIG,MBMessage,EXTENSION_LENGTH); MessageBox (hWnd, MBMessage,MBTitle, MBFlags); CloseHandle (hFile); return 0; } nBytesSource= dwLow; } /* Allocate space for string, including potential UNICODE_NULL */ pSourceData = ManageMemory (MMALLOC, MMSOURCE, nBytesSource +2, pSourceData); if (pSourceData == NULL) { CloseHandle (hFile); return 0; } /* first read two bytes and look for BOM */ if (!ReadFile (hFile, pSourceData,SIZEOFBOM, &nBytesRead, NULL)) { LoadString(_hModule,IDS_READERROR,MBMessage,EXTENSION_LENGTH); MessageBox (hWnd, MBMessage,MBTitle, MBFlags); CloseHandle (hFile); pSourceData = ManageMemory (MMFREE, MMSOURCE, 0, pSourceData); return 0; } /* If file begins with BOM, then we know the type, * we'll decrement the number of bytes by two, * and read the rest of the data. */ if (IsBOM (pSourceData)) { gTypeSource = TYPEUNICODE; gTypeSourceID = IDC_RBUNICODE1-CODEPAGEBASE; gTypeDest = TYPECODEPAGE; gTypeDestID = giRBInit-CODEPAGEBASE; nBytesSource -=SIZEOFBOM; /* If file begins with Reverse BOM, then we know the type, * we'll decrement the number of bytes by two, * and read the rest of the data, and post a message so * that we know to swap the order later. */ } else if (IsRBOM (pSourceData)) { gTypeSource = TYPEUNICODE; gTypeSourceID = IDC_RBUNICODE1-CODEPAGEBASE; gTypeDest = TYPECODEPAGE; gTypeDestID = giRBInit-CODEPAGEBASE; nBytesSource -=SIZEOFBOM; LoadString(_hModule,IDS_BYTEORDER,MBMessage,EXTENSION_LENGTH); MessageBox (hWnd, MBMessage,MBTitle, MBFlags); SwapSource(TRUE); /* Oops, does not begin with BOM. * Reset file pointer, and read data. */ } else { gTypeSource = TYPEUNKNOWN; SetFilePointer (hFile, -SIZEOFBOM, NULL, FILE_CURRENT); } /* try to read all of it into memory */ if (!ReadFile (hFile, pSourceData,nBytesSource, &nBytesRead, NULL)) { LoadString(_hModule,IDS_READERROR,MBMessage,EXTENSION_LENGTH); MessageBox (hWnd, MBMessage,MBTitle, MBFlags); CloseHandle (hFile); pSourceData = ManageMemory (MMFREE, MMSOURCE, 0, pSourceData); return 0; } CloseHandle (hFile); /* If we don't know the file type at this point, * try to determine if it is unicode. */ if (gTypeSource == TYPEUNKNOWN) { gTypeSource = TYPECODEPAGE; gTypeSourceID = giRBInit-CODEPAGEBASE; gTypeDest = TYPEUNICODE; gTypeDestID = IDC_RBUNICODE1-CODEPAGEBASE; pSourceData[nBytesSource] = 0; } SendMessage (hWnd, WMU_ADJUSTFORNEWSOURCE, 0, (LPARAM)szFile); break; } /**********************************************************************\ * WM_COMMAND, IDC_CLEAR * * Clear the SOURCE information. May cause data to be lost. \**********************************************************************/ case IDC_CLEAR: { SetDlgItemText (hWnd, IDC_NAMETEXT, szBlank); SetDlgItemText (hWnd, IDC_SIZETEXT, szBlank); for(i=0;i