我正在尝试在winapi中制作图像查看器, 所以基本上它加载并绘制我的第一个图像,但然后我点击按钮浏览给定目录中的.bmp图像并且它们没有被绘制。
如果你能帮助我并告诉我在哪里犯错误,我将不胜感激。
以下是我的WndProc变量:
WIN32_FIND_DATA file;
HBITMAP img;
std::vector<WIN32_FIND_DATA> vFiles;
std::vector<WIN32_FIND_DATA>::iterator it;
HANDLE hFile = FindFirstFile(L"C:\\Users\\eclip7e\\Pictures\\*.bmp", &file);
if (hFile != INVALID_HANDLE_VALUE)
{
it = vFiles.begin();
it = vFiles.insert(it, file);
while (FindNextFile(hFile, &file))
{
it = vFiles.insert(it, file);
}
it = vFiles.begin();
}
这是我的按钮点击:
case WM_COMMAND:
{
switch (LOWORD(wParam))
{
case IDC_RIGHT_BUTTON:
{
if (it<vFiles.end())
{
it++;
InvalidateRect(hWnd, NULL, TRUE);
}
else if (it == vFiles.end())
{
it = vFiles.begin();
InvalidateRect(hWnd, NULL, TRUE);
}
}
break;
}
}
break;
这是我的WM_PAINT:
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd, &ps);
HDC hdcMem;
LPCWSTR d = L"C:\\Users\\eclip7e\\Pictures\\";
WIN32_FIND_DATA filex;
filex = *(it);
std::wstring df = std::wstring(d) + filex.cFileName;
LPCWSTR dfc = df.c_str();
img = (HBITMAP)LoadImage(NULL, dfc, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
hdcMem = CreateCompatibleDC(hdc);
// Get the bitmap's parameters and verify the get
BITMAP qBitmap;
int iReturn = GetObject(reinterpret_cast<HGDIOBJ>(img), sizeof(BITMAP),
reinterpret_cast<LPVOID>(&qBitmap));
SelectObject(hdcMem, img);
BOOL bb =BitBlt(hdc, 0, 0, qBitmap.bmWidth, qBitmap.bmHeight, hdcMem, 0, 0, SRCCOPY);
DeleteDC(hdcMem);
DeleteObject(img);
EndPaint(hWnd, &ps);
}
break;