[英]USe function from user32.dll in Qt4 application
i am unable to use the function MonitorFromPoint in my Qt application. 我无法在Qt应用程序中使用MonitorMonPoint函数。 I have the latest Qt SDL 2010.05 with mingw on Windows XP
我在Windows XP上使用mingw拥有最新的Qt SDL 2010.05
#include <QtCore/QCoreApplication>
#include<windows.h>
#include <winuser.h>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
POINT pt;
MonitorFromPoint(pt,2);
return a.exec();
}
I added this to the .pro file 我将此添加到.pro文件
LIBS+= -luser32
And the result is 结果是
g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_CORE_LIB -DQT_THREAD_SUPPORT -I"..\include\QtCore" -I"..\include" -I"..\include\ActiveQt" -I"tmp\moc\debug_shared" -I"..\testUser32" -I"." -I"..\mkspecs\win32-g++" -o tmp\obj\debug_shared\main.o ..\testUser32\main.cpp
mingw32-make[1]: Leaving directory `C:/Qt/2010.05/qt/testUser32-build-desktop'
mingw32-make: Leaving directory `C:/Qt/2010.05/qt/testUser32-build-desktop'
..\testUser32\main.cpp: In function 'int main(int, char**)':
..\testUser32\main.cpp:8: error: 'MonitorFromPoint' was not declared in this scope
mingw32-make[1]: *** [tmp/obj/debug_shared/main.o] Error 1
mingw32-make: *** [debug-all] Error 2
The process "C:/Qt/2010.05/mingw/bin/mingw32-make.exe" exited with code %2.
Error while building project testUser32 (target: Desktop)
When executing build step 'Make'
Someone on the IRc said that is a mingw prolem and i should use visualc compiler. IRc上的某人说这是一个问题,我应该使用visualc编译器。 Switching the compiler will take time and maybe i will findother problems.
切换编译器将花费一些时间,也许我会发现其他问题。 I imported functions from wingdi.h and i had no problems.
我从wingdi.h导入了函数,没有问题。 I need a better explanation about the problem, how you figure it out and the solution
我需要对问题,如何解决以及解决方案有更好的解释
PS I am trying to get the screen geometryes in a multi monitor system, QDesktopWidget does not work ,see the topic Capture multiple screens desktop image using Qt4 PS我正在尝试在多监视器系统中获得屏幕几何图形,QDesktopWidget无法正常工作,请参阅使用Qt4捕获多屏幕桌面图像主题。
I found this http://www.mingw.org/wiki/Use_more_recent_defined_functions 我发现了这个http://www.mingw.org/wiki/Use_more_recent_defined_functions
I looked again at the header were the function is defined and i seen this 我再次查看了标头,定义了函数,我看到了
#if (_WIN32_WINNT >= 0x0500 || _WIN32_WINDOWS >= 0x0410)
WINUSERAPI HMONITOR WINAPI MonitorFromPoint(POINT,DWORD);
this means that this methods will not work on old versions of Windows. 这意味着该方法将不适用于旧版本的Windows。 The solution is to define
解决方案是定义
#include <QtCore/QCoreApplication>
#define _WIN32_WINNT 0x0500
#include<windows.h>
#include <winuser.h>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
POINT pt;
MonitorFromPoint(pt,2);
return a.exec();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.