有四个类名叫part1-pic-bg的盒子。id分别是part1-iconinfo1,part1-iconinfo2,part1-iconinfo3,part1-iconinfo4,在这个大盒子里面分别有一个类名叫part1-iconinfo的小盒子,,id值分别叫part1-iconinfo1-content,part1-iconinfo2-content,part1-iconinfo3-content,part1-iconinfo4-content,最初类名叫part1-iconinfo的盒子是隐藏状态,当点击大盒子的时候,对应的显示各自的小盒子,再次点击任意地方可以隐藏小盒子的jquery代码
时间: 2024-02-03 17:12:08 浏览: 98
可以使用以下代码实现:
```
$(document).ready(function() {
$('.part1-pic-bg').click(function() {
var id = $(this).attr('id');
$('#' + id + '-content').toggle();
});
$(document).click(function(event) {
if(!$(event.target).closest('.part1-pic-bg').length) {
$('.part1-iconinfo').hide();
}
});
});
```
首先,当用户点击 `.part1-pic-bg` 盒子时,获取其 id 值并在该 id 后面添加 `-content`,得到对应的小盒子的 id 值,然后使用 `toggle()` 函数来显示或隐藏该小盒子。
其次,当用户点击页面中其他地方时,检查是否点击了 `.part1-pic-bg` 盒子或其内部元素,如果没有,则隐藏所有小盒子。
相关问题
我需要在windows下正确的获取word文档“1.docx”的图标原始二进制资源数据,请告诉我详细C语言代码
获取Word文档的图标原始二进制资源数据,可以通过以下步骤完成:
1. 使用Win32 API函数LoadLibraryEx加载shell32.dll库。
2. 使用Win32 API函数LoadIconMetric从shell32.dll库中加载Word文档的图标。
3. 使用Win32 API函数GetIconInfo获取图标的信息。
4. 使用Win32 API函数GetDIBits获取图标的位图信息。
5. 使用Win32 API函数FreeLibrary释放shell32.dll库。
下面是详细的C语言代码:
```c
#include <Windows.h>
#include <Shellapi.h>
#include <Shlwapi.h>
#pragma comment(lib, "Shell32.lib")
#pragma comment(lib, "Shlwapi.lib")
int main() {
HMODULE hModule = LoadLibraryEx("shell32.dll", NULL, LOAD_LIBRARY_AS_DATAFILE);
if (hModule == NULL) {
return 0;
}
HICON hIcon;
HRESULT hr = LoadIconMetric(hModule, MAKEINTRESOURCE(2), LIM_LARGE, &hIcon);
if (FAILED(hr)) {
FreeLibrary(hModule);
return 0;
}
ICONINFO iconInfo;
if (!GetIconInfo(hIcon, &iconInfo)) {
DestroyIcon(hIcon);
FreeLibrary(hModule);
return 0;
}
BITMAP bmp;
if (!GetObject(iconInfo.hbmColor, sizeof(BITMAP), &bmp)) {
DeleteObject(iconInfo.hbmColor);
DeleteObject(iconInfo.hbmMask);
DestroyIcon(hIcon);
FreeLibrary(hModule);
return 0;
}
BITMAPINFOHEADER bmpInfoHeader;
bmpInfoHeader.biSize = sizeof(BITMAPINFOHEADER);
bmpInfoHeader.biWidth = bmp.bmWidth;
bmpInfoHeader.biHeight = bmp.bmHeight;
bmpInfoHeader.biPlanes = bmp.bmPlanes;
bmpInfoHeader.biBitCount = bmp.bmBitsPixel;
bmpInfoHeader.biCompression = BI_RGB;
bmpInfoHeader.biSizeImage = bmp.bmWidthBytes * bmp.bmHeight;
bmpInfoHeader.biXPelsPerMeter = 0;
bmpInfoHeader.biYPelsPerMeter = 0;
bmpInfoHeader.biClrUsed = 0;
bmpInfoHeader.biClrImportant = 0;
LPVOID lpBits = NULL;
HDC hdc = GetDC(NULL);
HBITMAP hBitmap = CreateDIBSection(hdc, (BITMAPINFO*)&bmpInfoHeader, DIB_RGB_COLORS, &lpBits, NULL, 0);
ReleaseDC(NULL, hdc);
if (hBitmap != NULL) {
HDC hMemDC = CreateCompatibleDC(NULL);
HBITMAP hOldBitmap = (HBITMAP)SelectObject(hMemDC, hBitmap);
if (!GetDIBits(hMemDC, iconInfo.hbmColor, 0, bmp.bmHeight, lpBits, (BITMAPINFO*)&bmpInfoHeader, DIB_RGB_COLORS)) {
DeleteDC(hMemDC);
DeleteObject(hBitmap);
DeleteObject(iconInfo.hbmColor);
DeleteObject(iconInfo.hbmMask);
DestroyIcon(hIcon);
FreeLibrary(hModule);
return 0;
}
SelectObject(hMemDC, hOldBitmap);
DeleteDC(hMemDC);
DeleteObject(hBitmap);
}
DeleteObject(iconInfo.hbmColor);
DeleteObject(iconInfo.hbmMask);
DestroyIcon(hIcon);
FreeLibrary(hModule);
return 0;
}
```
在上面的代码中,我们使用了LoadLibraryEx、LoadIconMetric、GetIconInfo、GetDIBits、FreeLibrary等Win32 API函数来获取Word文档的图标原始二进制资源数据。请注意,这里的资源ID是2,如果要获取其他类型的文件图标,请查看相应的资源ID。
Win32 输入exe路径和exe资源id和图标路径,替换exe图标,实现函数
以下是一个实现这个功能的示例函数:
```c++
#include <Windows.h>
#include <Shlwapi.h>
#pragma comment(lib, "Shlwapi.lib")
BOOL ReplaceExeIcon(LPCTSTR lpExePath, DWORD dwIconResourceId, LPCTSTR lpNewIconPath)
{
// 读取exe文件的文件头信息
HANDLE hFile = CreateFile(lpExePath, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE)
{
return FALSE;
}
IMAGE_DOS_HEADER dosHeader;
DWORD dwBytesRead;
if (!ReadFile(hFile, &dosHeader, sizeof(dosHeader), &dwBytesRead, NULL) || dwBytesRead != sizeof(dosHeader))
{
CloseHandle(hFile);
return FALSE;
}
SetFilePointer(hFile, dosHeader.e_lfanew + sizeof(DWORD), NULL, FILE_BEGIN);
IMAGE_FILE_HEADER fileHeader;
if (!ReadFile(hFile, &fileHeader, sizeof(fileHeader), &dwBytesRead, NULL) || dwBytesRead != sizeof(fileHeader))
{
CloseHandle(hFile);
return FALSE;
}
// 根据exe文件头信息找到资源表位置
DWORD dwResourceOffset = dosHeader.e_lfanew + sizeof(DWORD) + sizeof(IMAGE_FILE_HEADER) + fileHeader.SizeOfOptionalHeader;
SetFilePointer(hFile, dwResourceOffset, NULL, FILE_BEGIN);
IMAGE_RESOURCE_DIRECTORY resourceDirectory;
if (!ReadFile(hFile, &resourceDirectory, sizeof(resourceDirectory), &dwBytesRead, NULL) || dwBytesRead != sizeof(resourceDirectory))
{
CloseHandle(hFile);
return FALSE;
}
// 遍历资源表,找到指定的图标资源
IMAGE_RESOURCE_DIRECTORY_ENTRY* pEntry = (IMAGE_RESOURCE_DIRECTORY_ENTRY*)((BYTE*)&resourceDirectory + sizeof(resourceDirectory));
for (WORD i = 0; i < resourceDirectory.NumberOfNamedEntries + resourceDirectory.NumberOfIdEntries; i++, pEntry++)
{
if (pEntry->u1.s1.Id == (WORD)RT_GROUP_ICON)
{
// 找到了图标资源组,进入下一层资源表
DWORD dwNextOffset = dwResourceOffset + pEntry->u2.s2.OffsetToDirectory;
SetFilePointer(hFile, dwNextOffset, NULL, FILE_BEGIN);
IMAGE_RESOURCE_DIRECTORY nextResourceDirectory;
if (!ReadFile(hFile, &nextResourceDirectory, sizeof(nextResourceDirectory), &dwBytesRead, NULL) || dwBytesRead != sizeof(nextResourceDirectory))
{
CloseHandle(hFile);
return FALSE;
}
IMAGE_RESOURCE_DIRECTORY_ENTRY* pNextEntry = (IMAGE_RESOURCE_DIRECTORY_ENTRY*)((BYTE*)&nextResourceDirectory + sizeof(nextResourceDirectory));
for (WORD j = 0; j < nextResourceDirectory.NumberOfNamedEntries + nextResourceDirectory.NumberOfIdEntries; j++, pNextEntry++)
{
if (pNextEntry->u1.s1.Id == dwIconResourceId)
{
// 找到了指定的图标资源
DWORD dwIconOffset = dwResourceOffset + pNextEntry->u2.s2.OffsetToData;
SetFilePointer(hFile, dwIconOffset, NULL, FILE_BEGIN);
IMAGE_RESOURCE_DATA_ENTRY dataEntry;
if (!ReadFile(hFile, &dataEntry, sizeof(dataEntry), &dwBytesRead, NULL) || dwBytesRead != sizeof(dataEntry))
{
CloseHandle(hFile);
return FALSE;
}
// 读取图标资源
BYTE* pIconData = new BYTE[dataEntry.Size];
if (!ReadFile(hFile, pIconData, dataEntry.Size, &dwBytesRead, NULL) || dwBytesRead != dataEntry.Size)
{
delete[] pIconData;
CloseHandle(hFile);
return FALSE;
}
// 替换图标资源
HANDLE hNewIcon = LoadImage(NULL, lpNewIconPath, IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_LOADFROMFILE);
if (hNewIcon == NULL)
{
delete[] pIconData;
CloseHandle(hFile);
return FALSE;
}
ICONINFO iconInfo;
if (!GetIconInfo((HICON)hNewIcon, &iconInfo))
{
delete[] pIconData;
CloseHandle(hFile);
DestroyIcon((HICON)hNewIcon);
return FALSE;
}
DWORD dwNewIconSize = iconInfo.dwBytesInRes;
BYTE* pNewIconData = new BYTE[dwNewIconSize];
if (!GetIconResourceData(iconInfo.hResInfo, pNewIconData, dwNewIconSize))
{
delete[] pIconData;
delete[] pNewIconData;
CloseHandle(hFile);
DestroyIcon((HICON)hNewIcon);
return FALSE;
}
memcpy(pIconData, pNewIconData, dwNewIconSize);
// 写入替换后的图标资源
SetFilePointer(hFile, dwIconOffset + sizeof(IMAGE_RESOURCE_DATA_ENTRY), NULL, FILE_BEGIN);
if (!WriteFile(hFile, pIconData, dataEntry.Size, &dwBytesRead, NULL) || dwBytesRead != dataEntry.Size)
{
delete[] pIconData;
delete[] pNewIconData;
CloseHandle(hFile);
DestroyIcon((HICON)hNewIcon);
return FALSE;
}
delete[] pIconData;
delete[] pNewIconData;
CloseHandle(hFile);
DestroyIcon((HICON)hNewIcon);
return TRUE;
}
}
}
}
CloseHandle(hFile);
return FALSE;
}
```
调用示例:
```c++
ReplaceExeIcon(TEXT("C:\\MyApp.exe"), 101, TEXT("C:\\NewIcon.ico"));
```
其中,`lpExePath` 参数为需要替换图标的exe文件路径,`dwIconResourceId` 参数为需要替换的图标资源的ID,`lpNewIconPath` 参数为新的图标文件路径。如果函数执行成功,则返回 `TRUE`,如果失败,则返回 `FALSE`。
阅读全文