//resource.h
//{
{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by PE.rc
//
#define IDD_DIALOG 101
#define IDR_MENU1 102
#define IDI_ICON 103
#define IDC_EDIT1 1001
#define IDC_EDIT 1001
#define ID_40001 40001
#define ID_40002 40002
#define IDC_OPEN 40003
#define IDC_EXIT 40004
#define ID_40005 40005
#define ID_40006 40006
#define ID_40007 40007
#define IDC_BASE 40008
#define IDC_IMPORT 40009
#define IDC_EXPORT 40010
#define ID_40011 40011
#define ID_40012 40012
#define IDC_RELOC 40013
#define IDC_RES 40014
#define ID_40015 40015
#define IDC_ABOUT 40016
#define IDC_ICON 40017
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 104
#define _APS_NEXT_COMMAND_VALUE 40018
#define _APS_NEXT_CONTROL_VALUE 1003
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
//popfile.h
/*------------------------------------------
POPFILE.C -- Popup Editor File Functions
------------------------------------------*/
#ifndef POPFILE_H
#define POPFILE_H
#include <windows.h>
#include <commdlg.h>
static OPENFILENAME ofn ;
void PopFileInitialize (HWND hwnd)
{
static TCHAR szFilter[] = TEXT ("PE Files \0*.exe;*.dll;*.scr;*.fon;*.drv\0") \
TEXT ("All Files (*.*)\0*.*\0\0") ;
ofn.lStructSize = sizeof (OPENFILENAME) ;
ofn.hwndOwner = hwnd ;
ofn.hInstance = NULL ;
ofn.lpstrFilter = szFilter ;
ofn.lpstrCustomFilter = NULL ;
ofn.nMaxCustFilter = 0 ;
ofn.nFilterIndex = 0 ;
ofn.lpstrFile = NULL ; // Set in Open and Close functions
ofn.nMaxFile = MAX_PATH ;
ofn.lpstrFileTitle = NULL ; // Set in Open and Close functions
ofn.nMaxFileTitle = MAX_PATH ;
ofn.lpstrInitialDir = NULL ;
ofn.lpstrTitle = NULL ;
ofn.Flags = 0 ; // Set in Open and Close functions
ofn.nFileOffset = 0 ;
ofn.nFileExtension = 0 ;
ofn.lpstrDefExt = TEXT ("txt") ;
ofn.lCustData = 0L ;
ofn.lpfnHook = NULL ;
ofn.lpTemplateName = NULL ;
}
BOOL PopFileOpenDlg (HWND hwnd, PTSTR pstrFileName, PTSTR pstrTitleName)
{
ofn.hwndOwner = hwnd ;
ofn.lpstrFile = pstrFileName ;
ofn.lpstrFileTitle = pstrTitleName ;
ofn.Flags = OFN_HIDEREADONLY | OFN_CREATEPROMPT ;
return GetOpenFileName (&ofn) ;
}
BOOL PopFileSaveDlg (HWND hwnd, PTSTR pstrFileName, PTSTR pstrTitleName)
{
ofn.hwndOwner = hwnd ;
ofn.lpstrFile = pstrFileName ;
ofn.lpstrFileTitle = pstrTitleName ;
ofn.Flags = OFN_OVERWRITEPROMPT ;
return GetSaveFileName (&ofn) ;
}
BOOL PopFileRead (HWND hwndEdit, PTSTR pstrFileName)
{
BYTE bySwap ;
DWORD dwBytesRead ;
HANDLE hFile ;
int i, iFileLength, iUniTest ;
PBYTE pBuffer, pText, pConv ;
// Open the file.
if (INVALID_HANDLE_VALUE ==
(hFile = CreateFile (pstrFileName, GENERIC_READ, FILE_SHARE_READ,
NULL, OPEN_EXISTING, 0, NULL)))
return FALSE ;
// Get file size in bytes and allocate memory for read.
// Add an extra two bytes for zero termination.
iFileLength = GetFileSize (hFile, NULL) ;
pBuffer = (PBYTE)malloc (iFileLength + 2) ;
// Read file and put terminating zeros at end.
ReadFile (hFile, pBuffer, iFileLength, &dwBytesRead, NULL) ;
CloseHandle (hFile) ;
pBuffer[iFileLength] = '\0' ;
pBuffer[iFileLength + 1] = '\0' ;
// Test to see if the text is unicode
iUniTest = IS_TEXT_UNICODE_SIGNATURE | IS_TEXT_UNICODE_REVERSE_SIGNATURE ;
if (IsTextUnicode (pBuffer, iFileLength, &iUniTest))
{
pText = pBuffer + 2 ;
iFileLength -= 2 ;
if (iUniTest & IS_TEXT_UNICODE_REVERSE_SIGNATURE)
{
for (i = 0 ; i < iFileLength / 2 ; i++)
{
bySwap = ((BYTE *) pText) [2 * i] ;
((BYTE *) pText) [2 * i] = ((BYTE *) pText) [2 * i + 1] ;
((BYTE *) pText) [2 * i + 1] = bySwap ;
}
}
// Allocate memory for possibly converted string
pConv = (PBYTE)malloc (iFileLength + 2) ;
// If the edit control is not Unicode, convert Unicode text to
// non-Unicode (ie, in general, wide character).
#ifndef UNICODE
WideCharToMultiByte (CP_ACP, 0, (PWSTR) pText, -1, pConv,
iFileLength + 2, NULL, NULL) ;
// If the edit control is Unicode, just copy the string
#else
lstrcpy ((PTSTR) pConv, (PTSTR) pText) ;
#endif
}
else // the file is not Unicode
{
pText = pBuffer ;
// Allocate memory for possibly converted string.
pConv = (PBYTE)malloc (2 * iFileLength + 2) ;
// If the edit control is Unicode, convert ASCII text.
#ifdef UNICODE
MultiByteToWideChar (CP_ACP, 0, (LPCSTR)pText, -1, (PTSTR) pConv,
iFileLength + 1) ;
// If not, just copy buffer
#else
lstrcpy ((PTSTR) pConv, (PTSTR) pText) ;
#endif
}
SetWindowText (hwndEdit, (PTSTR) pConv) ;
free (pBuffer) ;
free (pConv) ;
return TRUE ;
}
BOOL PopFileWrite (HWND hwndEdit, PTSTR pstrFileName)
{
DWORD dwBytesWritten ;
HANDLE hFile ;
int iLength ;
PTSTR pstrBuffer ;
WORD wByteOrderMark = 0xFEFF ;
// Open the file, creating it if necessary
if (INVALID_HANDLE_VALUE ==
(hFile = CreateFile (pstrFileName, GENERIC_WRITE, 0,
NULL, CREATE_ALWAYS, 0, NULL)))
return FALSE ;
// Get the number of characters in the edit control and allocate
// memory for them.
iLength = GetWindowTextLength (hwndEdit) ;
pstrBuffer = (PTSTR) malloc ((iLength + 1) * sizeof (TCHAR)) ;
if (!pstrBuffer)
{
CloseHandle (hFile) ;
return FALSE ;
}
// If the edit control will return Unicode text, write the
// byte order mark to the file.