📄 testdlg.cpp
字号:
// testDlg.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "testDlg.h"
#include "testDlgDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTestDlgApp
BEGIN_MESSAGE_MAP(CTestDlgApp, CWinApp)
//{{AFX_MSG_MAP(CTestDlgApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG
ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTestDlgApp construction
CTestDlgApp::CTestDlgApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CTestDlgApp object
CTestDlgApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CTestDlgApp initialization
BOOL CALLBACK EnumResNameProc( HMODULE hModule,
LPCTSTR lpszType,
LPTSTR lpszName,
LONG_PTR lParam
)
{
return true;
}
BOOL CTestDlgApp::InitInstance()
{
AfxEnableControlContainer();
EnumResourceNames(AfxGetInstanceHandle(),RT_ICON,EnumResNameProc,NULL);
LANGID LangID=GetSystemDefaultLangID();
WORD wLangPID=PRIMARYLANGID(GetSystemDefaultLangID());
HINSTANCE h=AfxGetInstanceHandle();
HRSRC hrc= FindResource(h,MAKEINTRESOURCE(7),RT_STRING);
DWORD dw=GetLastError();
HGLOBAL hbal=LoadResource(h,hrc);
if (LANG_CHINESE == PRIMARYLANGID(LangID))
{
if (SUBLANGID(LangID) == SUBLANG_CHINESE_SIMPLIFIED)
{
#define AFX_TARG_CHS
int i=0;
//#pragma code_page(936)
}
if (SUBLANGID(LangID) == SUBLANG_CHINESE_TRADITIONAL)
{
#define AFX_TARG_CHT
int j=0;
//#pragma code_page(950)
}
}
typedef struct A
{
union
{
struct { byte s_b1,s_b2,s_b3,s_b4; } S_un_b;
struct { byte s_w1,s_w2; } S_un_w;
DWORD S_addr;
}
S_un;
#define s_addr S_un.S_addr
/* can be used for most tcp & ip code */
#define s_host S_un.S_un_b.s_b2
/* host on imp */
#define s_net S_un.S_un_b.s_b1
/* network */
#define s_imp S_un.S_un_w.s_w2
/* imp */
#define s_impno S_un.S_un_b.s_b4
/* imp # */
#define s_lh S_un.S_un_b.s_b3
/* logical host */
}B;
B a;
a.s_addr;
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
CTestDlgDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}
doResource();
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
}
char szBuffer[80]; // print buffer for EnumResourceTypes
DWORD cbWritten; // number of bytes written to res. info. file
size_t cbString; // length of string in sprintf
HRESULT hResult;
// Declare callback functions.
BOOL EnumTypesFunc(
HANDLE hModule,
LPTSTR lpType,
LONG lParam);
BOOL EnumNamesFunc(
HANDLE hModule,
LPCTSTR lpType,
LPTSTR lpName,
LONG lParam);
BOOL EnumLangsFunc(
HANDLE hModule,
LPCTSTR lpType,
LPCTSTR lpName,
WORD wLang,
LONG lParam);
HANDLE hFile=NULL;
void CTestDlgApp::doResource()
{
// Load the .EXE whose resources you want to list.
HMODULE hExe = LoadLibrary("testdlg.exe");
if (hExe == NULL)
{
// Add code to fail as securely as possible.
return;
}
// Create a file to contain the resource info.
hFile = CreateFile("resinfo.txt", // name of file
GENERIC_READ | GENERIC_WRITE, // access mode
0, // share mode
(LPSECURITY_ATTRIBUTES) NULL, // default security
CREATE_ALWAYS, // create flags
FILE_ATTRIBUTE_NORMAL, // file attributes
(HANDLE) NULL); // no template
if (hFile == INVALID_HANDLE_VALUE) {
TRACE("Could not open file.");
}
// Find all of the loaded file's resources.
hResult = StringCchPrintf(szBuffer, 80/sizeof(TCHAR),
// cbString = sprintf(szBuffer,
"The file contains the following resources:\n\n");
if (FAILED(hResult))
{
// Add code to fail as securely as possible.
return;
}
hResult = StringCchLength(szBuffer, 80/sizeof(TCHAR), &cbString);
if (FAILED(hResult))
{
// Add code to fail as securely as possible.
return;
}
WriteFile(hFile, // file to hold resource info.
szBuffer, // what to write to the file
(DWORD) cbString, // number of bytes in szBuffer
&cbWritten, // number of bytes written
NULL); // no overlapped I/O
EnumResourceTypes(hExe, // module handle
(ENUMRESTYPEPROC)EnumTypesFunc, // callback function
0); // extra parameter
// Unload the executable file whose resources were
// enumerated and close the file created to contain
// the resource information.
FreeLibrary(hExe);
CloseHandle(hFile);
}
// FUNCTION: EnumTypesFunc(HANDLE, LPSTR, LONG)
//
// PURPOSE: Resource type callback
BOOL EnumTypesFunc(
HANDLE hModule, // module handle
LPTSTR lpType, // address of resource type
LONG lParam) // extra parameter, could be
// used for error checking
{
size_t cbString;
HRESULT hResult;
// Write the resource type to a resource information file.
// The type may be a string or an unsigned decimal
// integer, so test before printing.
if ((ULONG)lpType & 0xFFFF0000)
{
hResult = StringCchPrintf(szBuffer, 80/sizeof(TCHAR), "Type: %s\n", lpType);
if (FAILED(hResult))
{
// Add code to fail as securely as possible.
return true;
}
// cbString = sprintf(szBuffer, "Type: %s\n", lpType);
}
else
{
hResult = StringCchPrintf(szBuffer, 80/sizeof(TCHAR), "Type: %u\n", (USHORT)lpType);
if (FAILED(hResult))
{
// Add code to fail as securely as possible.
return true;
}
// cbString = sprintf(szBuffer, "Type: %u\n", (USHORT)lpType);
}
hResult = StringCchLength(szBuffer, 80/sizeof(TCHAR), &cbString);
if (FAILED(hResult))
{
// Add code to fail as securely as possible.
return true;
}
WriteFile(hFile, szBuffer, (DWORD) cbString,
&cbWritten, NULL);
// Find the names of all resources of type lpType.
EnumResourceNames((HMODULE)hModule,
lpType,
(ENUMRESNAMEPROC)EnumNamesFunc,
0);
return TRUE;
}
// FUNCTION: EnumNamesFunc(HANDLE, LPSTR, LPSTR, LONG)
//
// PURPOSE: Resource name callback
BOOL EnumNamesFunc(
HANDLE hModule, // module handle
LPCTSTR lpType, // address of resource type
LPTSTR lpName, // address of resource name
LONG lParam) // extra parameter, could be
// used for error checking
{
size_t cbString;
HRESULT hResult;
// Write the resource name to a resource information file.
// The name may be a string or an unsigned decimal
// integer, so test before printing.
if ((ULONG)lpName & 0xFFFF0000)
{
hResult = StringCchPrintf(szBuffer, 80/sizeof(TCHAR), "\tName: %s\n", lpName);
if (FAILED(hResult))
{
// Add code to fail as securely as possible.
return true;
}
// cbString = sprintf(szBuffer, "\tName: %s\n", lpName);
}
else
{
hResult = StringCchPrintf(szBuffer, 80/sizeof(TCHAR), "\tName: %u\n", (USHORT)lpName);
if (FAILED(hResult))
{
// Add code to fail as securely as possible.
return true;
}
// cbString = sprintf(szBuffer, "\tName: %u\n",
// (USHORT)lpName);
}
hResult = StringCchLength(szBuffer, 80/sizeof(TCHAR), &cbString);
if (FAILED(hResult))
{
// Add code to fail as securely as possible.
return true;
}
WriteFile(hFile, szBuffer, (DWORD) cbString,
&cbWritten, NULL);
// Find the languages of all resources of type
// lpType and name lpName.
EnumResourceLanguages((HMODULE)hModule,
lpType,
lpName,
(ENUMRESLANGPROC)EnumLangsFunc,
0);
return TRUE;
}
// FUNCTION: EnumLangsFunc(HANDLE, LPSTR, LPSTR, WORD, LONG)
//
// PURPOSE: Resource language callback
BOOL EnumLangsFunc(
HANDLE hModule, // module handle
LPCTSTR lpType, // address of resource type
LPCTSTR lpName, // address of resource name
WORD wLang, // resource language
LONG lParam) // extra parameter, could be
// used for error checking
{
HANDLE hResInfo;
char szBuffer[80];
size_t cbString = 0;
HRESULT hResult;
hResInfo = FindResourceEx((HMODULE)hModule, lpType, lpName, wLang);
// Write the resource language to the resource information file.
hResult = StringCchPrintf(szBuffer, 80/sizeof(TCHAR), "\t\tLanguage: %u\n", (USHORT) wLang);
if (FAILED(hResult))
{
// Add code to fail as securely as possible.
return true;
}
hResult = StringCchLength(szBuffer, 80/sizeof(TCHAR), &cbString);
if (FAILED(hResult))
{
// Add code to fail as securely as possible.
return true;
}
// cbString = sprintf(szBuffer, "\t\tLanguage: %u\n", (USHORT)wLang);
WriteFile(hFile, szBuffer, (DWORD) cbString,
&cbWritten, NULL);
// Write the resource handle and size to buffer.
cbString = StringCchPrintf(szBuffer,80,
"\t\thResInfo == %lx, Size == %lu\n\n",
hResInfo,
SizeofResource((HMODULE)hModule, (HRSRC)hResInfo));
WriteFile(hFile, szBuffer, (DWORD) cbString,
&cbWritten, NULL);
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -