我有一个只有一个按钮的简单QWidgets应用程序。这是标题
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include "Windows.h"
//#include "Winuser.h"
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void on_pushButton_clicked();
private:
Ui::MainWindow *ui;
bool changed;
};
#endif // MAINWINDOW_H
实施
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
changed = false;
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
if (!changed){
// DEVMODE *dm = new DEVMODE();
// EnumDisplaySettings(NULL,ENUM_CURRENT_SETTINGS,dm);
// dm->dmPelsWidth = (unsigned long) 1024;
// dm->dmPelsHeight = (unsigned long) 768;
// ChangeDisplaySettings(dm,CDS_FULLSCREEN);
DEVMODE desiredMode = { 0 };
desiredMode.dmSize = sizeof(DEVMODE);
desiredMode.dmPelsWidth = 1024;
desiredMode.dmPelsHeight = 768;
desiredMode.dmFields = DM_PELSHEIGHT | DM_PELSWIDTH;
LONG res = ChangeDisplaySettings(&desiredMode,CDS_UPDATEREGISTRY | CDS_GLOBAL | CDS_RESET );
}
else{
ChangeDisplaySettings(NULL,0);
}
changed = !changed;
}
我的.pro文件
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = ChangeResolution
TEMPLATE = app
# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
LIBS += -luser32
SOURCES += \
main.cpp \
mainwindow.cpp
HEADERS += \
mainwindow.h
FORMS += \
mainwindow.ui
我需要开发一个需要更改显示分辨率的应用程序,仅在显示某些图像时,才能达到1024x768,然后再恢复正常。为了测试如何做到这一点,我正在尝试上面的代码,我在这里或者发现。但是,在尝试编译上面的代码时,我收到以下链接错误:
mainwindow.obj:-1: error: LNK2019: unresolved external symbol __imp_ChangeDisplaySettingsW referenced in function "private: void __cdecl MainWindow::on_pushButton_clicked(void)" (?on_pushButton_clicked@MainWindow@@AEAAXXZ)
根据我的研究,这似乎与编译器没有找到lib有关,这就是为什么我将LIBS行添加到.pro文件中,但没有任何改变。
我的项目设置表明我使用的是Qt 5.10.0 MSVC2017 64位编译器。
有关如何编译的任何帮助吗?