我试图在Windows中使用winapi获取当前窗口或活动窗口以及该窗口的进程名称.
所以,我能够获得活动窗口GetForegroundWindow()并且我正在使用OpenProcess()以获取进程,问题是OpenProcess需要进程ID,所以我虽然我可以使用GetProcessId()但是这个接收窗口的HANDLE类型我有HWND类型的当前窗口.
我尝试了几件事,但无法使其发挥作用.所以任何人都可以告诉我如何在HWND中获取窗口的进程ID?或者获取当前窗口的句柄?
我将代码保留在这里,以防有些人看到可能对我有帮助的解决方案.我正在使用Qt和C++
char wnd_title[256];
HWND hwnd=GetForegroundWindow(); // get handle of currently active window
GetWindowText(hwnd,wnd_title,sizeof(wnd_title));
HANDLE Handle = OpenProcess(
PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,
FALSE,
GetProcessId(hwnd) // GetProcessId is returning 0
);
if (Handle)
{
TCHAR Buffer[MAX_PATH];
if (GetModuleFileNameEx(Handle, 0, Buffer, MAX_PATH))
{
printf("Paht: %s", Buffer);
// At this point, buffer contains the full path to the executable
}
CloseHandle(Handle);
}
Run Code Online (Sandbox Code Playgroud) 我一直在尝试使用windows xp在虚拟机中安装clang,首先我从这个页面尝试使用Windows的clang for Preng Built Binaries:LLVM下载,我收到此错误:
Failed to find MSBuild toolset directory
Run Code Online (Sandbox Code Playgroud)
所以,我尝试按照这个问题中的步骤解释编译clang:在Windows中编译Clang,但我也遇到错误:
In file included from C:\llvm-3.7.0.src\lib\Support\DynamicLibrary.cpp:40:0:
C:\llvm-3.7.0.src\lib\Support\Windows/DynamicLibrary.inc:34:56: error: 'PENUMLOA
DED_MODULES_CALLBACK64' has not been declared
typedef BOOL (WINAPI *fpEnumerateLoadedModules)(HANDLE,PENUMLOADED_MODULES_CALL
BACK64,PVOID);
^
C:\llvm-3.7.0.src\lib\Support\Windows/DynamicLibrary.inc: In static member funct
ion 'static llvm::sys::DynamicLibrary llvm::sys::DynamicLibrary::getPermanentLib
rary(const char*, std::string*)':
C:\llvm-3.7.0.src\lib\Support\Windows/DynamicLibrary.inc:70:65: error: invalid conversion from 'BOOL (__attribute__((__stdcall__)) *)(PSTR, DWORD64, ULONG, PVOID) {aka int (__attribute__((__stdcall__)) *)(char*, long long unsigned int, long
unsigned int, void*)}' to 'int' [-fpermissive]
fEnumerateLoadedModules(GetCurrentProcess(), ELM_Callback, 0);
^
lib\Support\CMakeFiles\LLVMSupport.dir\build.make:1912: recipe …Run Code Online (Sandbox Code Playgroud) 我有一个例行程序,可以使用 gdi plus 和 c++ 在 Windows 平台上截取屏幕截图,它仅适用于一台显示器,但当我在一台带有 2 台显示器的 VM 机器上运行它时,它只拍摄一张照片。
这就是我正在做的:
#include <stdlib.h>
#include <windows.h>
#include <iostream>
#include <GdiPlus.h>
#include <wingdi.h>
#include <fstream>
#include <unistd.h>
#pragma comment(lib, "gdiplus.lib")
#pragma comment(lib, "ws2_32.lib")
using namespace std;
// Se encarga de configurar, por asi decirlo, el formato
// de la imagen, este metodo es llamado en gdiscreen al
// momento de guardar la imagen.
int GetEncoderClsid(const WCHAR* format, CLSID* pClsid)
{
using namespace Gdiplus;
UINT num = 0; // number of …Run Code Online (Sandbox Code Playgroud)