| 193 | } |
| 194 | |
| 195 | void CDialogEdit::OnFileEditoropen( ) |
| 196 | { |
| 197 | TCHAR szFileName[MAX_PATH + 1024] = _T( "" ); |
| 198 | |
| 199 | // Open file structure |
| 200 | OPENFILENAME ofn; |
| 201 | ZeroMemory( (LPVOID)&ofn, sizeof( OPENFILENAME ) ); |
| 202 | // Fill in open file structure |
| 203 | ofn.lStructSize = sizeof( OPENFILENAME ); |
| 204 | ofn.lpstrFilter = _T( "All Files (*.*)\x0*.*\x0\x0" ); |
| 205 | ofn.lpstrTitle = _T( "Open Source File" ); |
| 206 | ofn.Flags = OFN_HIDEREADONLY | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; |
| 207 | ofn.lpstrFile = szFileName; |
| 208 | ofn.nMaxFile = sizeof( szFileName ); |
| 209 | ofn.lpstrDefExt = _T( "" ); |
| 210 | ofn.hwndOwner = GetSafeHwnd( ); |
| 211 | |
| 212 | // Get user file |
| 213 | if (::GetOpenFileName( &ofn )) |
| 214 | { |
| 215 | // Clear editor text |
| 216 | m_Edit.Clear( ); |
| 217 | |
| 218 | // Ensure it exists |
| 219 | if (::GetFileAttributes( szFileName ) == 0xFFFFFFFF) |
| 220 | { |
| 221 | // Open the file |
| 222 | CFile file; |
| 223 | if (file.Open( szFileName, CFile::modeRead | CFile::shareDenyNone )) |
| 224 | { |
| 225 | // Ensure length |
| 226 | DWORD uSize = (DWORD)(file.GetLength( ) & 0xFFFFFFFF); |
| 227 | if (uSize > 0) |
| 228 | { |
| 229 | // Allocate memory |
| 230 | char* Buffer = new char[uSize + 1]; |
| 231 | if (Buffer) |
| 232 | { |
| 233 | // Read the data |
| 234 | if (file.Read( (void*)Buffer, (UINT)uSize )) |
| 235 | { |
| 236 | // null terminate (probably not needed here) |
| 237 | Buffer[uSize] = '\0'; |
| 238 | // Set editor text |
| 239 | m_Edit.SetText( Buffer ); |
| 240 | } |
| 241 | // Close the file |
| 242 | file.Close( ); |
| 243 | // Release memory |
| 244 | delete[] Buffer; |
| 245 | } |
| 246 | } |
| 247 | } |
| 248 | } |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | |