views:

26

answers:

1

Hi, i am unable to use the function MonitorFromPoint in my Qt application. I have the latest Qt SDL 2010.05 with mingw on Windows XP

#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

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. Switching the compiler will take time and maybe i will findother problems. I imported functions from wingdi.h and i had no problems. I need a better explanation about the problem, how you figure it out and the solution

P.S. I am trying to get the screen geometryes in a multi monitor system, QDesktopWidget does not work ,see the topic http://stackoverflow.com/questions/3966429/capture-multiple-screens-desktop-image-using-qt4

+1  A: 

I found this 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. 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();
}
simion314
It's better to define this environment variable in your project file. It shouldn't differ across source files; you'd end up compiling half your sources for Windows 2000 and the other half for Windows XP. This is especially painful since some types have new members added, so their `sizeof` changes. (That's why such stuctures have a `cb` field - Windows checks it to see what members you used)
MSalters