in tools/ExeView/main.cpp [106:313]
LRESULT CALLBACK MainWndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
DLGPROC lpProc;
HWND hLB = GetDlgItem( hWnd, IDL_EXEHDR );
switch (msg)
{
case WM_COMMAND:
switch ( LOWORD(wParam) )
{
case IDM_OPEN:
{
OPENFILENAME of;
char szFile[120];
memset( &of, 0, sizeof(OPENFILENAME) );
szFile[0] = 0;
of.lStructSize = sizeof(OPENFILENAME);
of.hwndOwner = ghWndMain;
of.hInstance = ghInst;
of.lpstrFilter = (LPSTR)"EXE file\0*.EXE\0DLL library\0*.DLL\0Font\0*.FON\0\0";
of.nFilterIndex = 0;
of.lpstrFile = (LPSTR)szFile;
of.nMaxFile = (DWORD)256;
of.lpstrTitle = (LPSTR)"Enter File";
of.Flags = OFN_HIDEREADONLY|OFN_FILEMUSTEXIST;
of.lpstrDefExt = (LPSTR)"EXE";
if( GetOpenFileName( &of ) )
{
// Kill the old exe info if it exists
if (gpExeInfo)
{
FreeExeInfoMemory( gpExeInfo );
gpExeInfo = NULL;
}
gpExeInfo = LoadExeInfo( szFile );
switch ( (int)gpExeInfo )
{
case LERR_OPENINGFILE:
MessageBox(hWnd,"Error opening file!",
"ExeView Error", MB_ICONSTOP|MB_OK );
SetWindowText( hWnd, "Windows Executable Viewer" );
gpExeInfo = NULL;
break;
case LERR_NOTEXEFILE:
MessageBox(hWnd,"Not a valid EXE file!",
"ExeView Error", MB_ICONSTOP|MB_OK );
SetWindowText( hWnd, "Windows Executable Viewer" );
gpExeInfo = NULL;
break;
case LERR_READINGFILE:
MessageBox(hWnd,"Error reading file!",
"ExeView Error", MB_ICONSTOP|MB_OK );
SetWindowText( hWnd, "Windows Executable Viewer" );
gpExeInfo = NULL;
break;
case LERR_MEMALLOC:
MessageBox(hWnd,"Memory allocation denied!",
"ExeView Error", MB_ICONSTOP|MB_OK );
SetWindowText( hWnd, "Windows Executable Viewer" );
gpExeInfo = NULL;
break;
default:
{
char szBuff[120];
if (gpExeInfo->NewHdr.wNewSignature)
FillLBWithNewExeHeader(hLB, gpExeInfo );
else
FillLBWithOldExeHeader( hLB, gpExeInfo );
wsprintf( szBuff, "ExeView - %s", (LPSTR)szFile );
SetWindowText( hWnd, szBuff );
SetFocus( hLB );
}
break;
}
EnableChildWindows( hWnd, gpExeInfo );
if (!gpExeInfo)
SendMessage( hLB, LB_RESETCONTENT, 0, 0L );
}
}
break;
case IDM_ABOUT:
lpProc = MakeProcInstance(About, ghInst);
DialogBox(ghInst, "AboutBox", hWnd, lpProc);
FreeProcInstance(lpProc);
break;
case IDM_EXIT:
PostMessage( hWnd, WM_SYSCOMMAND, SC_CLOSE, 0L );
break;
case IDB_OLDHDR:
FillLBWithOldExeHeader(hLB, gpExeInfo );
SetFocus( hLB );
break;
case IDB_NEWHDR:
FillLBWithNewExeHeader(hLB, gpExeInfo );
SetFocus( hLB );
break;
case IDB_ENTRYTABLE:
FillLBWithEntryTable(hLB, gpExeInfo );
SetFocus( hLB );
break;
case IDB_SEGMENTS:
FillLBWithSegments(hLB, gpExeInfo );
SetFocus( hLB );
break;
case IDB_RESOURCES:
FillLBWithResources(hLB, gpExeInfo );
SetFocus( hLB );
break;
case IDB_RESIDENTNAMES:
FillLBWithResidentNames(hLB, gpExeInfo );
SetFocus( hLB );
break;
case IDB_IMPORTEDNAMES:
FillLBWithImportedNames(hLB, gpExeInfo );
SetFocus( hLB );
break;
case IDB_NONRESIDENTNAMES:
FillLBWithNonResidentNames(hLB, gpExeInfo );
SetFocus( hLB );
break;
case IDL_EXEHDR:
{
int nItem = (int)SendMessage( hLB, LB_GETCURSEL,0,0L );
LONG lData;
if (HIWORD(wParam)!=LBN_DBLCLK)
break;
if (nItem<0)
break;
lData = SendMessage( hLB, LB_GETITEMDATA,nItem,0L );
if (lData==NULL)
break;
return (LONG)DisplayResource(gpExeInfo, ((PRESINFO)lData)->pResType, (PRESINFO)lData);
}
break;
case IDM_SAVERES:
{
OPENFILENAME of;
char szFile[120];
memset( &of, 0, sizeof(OPENFILENAME) );
szFile[0] = 0;
of.lStructSize = sizeof(OPENFILENAME);
of.hwndOwner = ghWndMain;
of.hInstance = ghInst;
of.lpstrFilter = (LPSTR)"Resource file\0*.rc\0\0";
of.nFilterIndex = 0;
of.lpstrFile = (LPSTR)szFile;
of.nMaxFile = (DWORD)sizeof(szFile);
of.lpstrTitle = (LPSTR)"Resource File";
of.Flags = OFN_HIDEREADONLY|OFN_PATHMUSTEXIST;
of.lpstrDefExt = (LPSTR)"rc";
if (GetSaveFileName(&of))
{
SaveResources(hWnd, gpExeInfo, szFile);
}
}
break;
}
break;
case WM_SIZE:
ResizeChildWindows( hWnd );
break;
case WM_DESTROY:
if (gpExeInfo)
{
FreeExeInfoMemory( gpExeInfo );
gpExeInfo = NULL;
}
PostQuitMessage(0);
break;
}
return (DefWindowProc(hWnd, msg, wParam, lParam));
} //*** MainWndProc()