Change Screen Resolution in Windows using C++
主要使用 Windows API
ChangeDisplaySettings
及
EnumDisplaySettings
首先使用 EnumDisplaySettings 取得目前的螢幕設定值
然後修改解析度的寬高
最後使用 ChangeDisplaySettings 更新螢幕設定值
=== 程式範例
#include "windows.h"
#include <string>
#include <iostream>
int main(int argc, char* argv[])
{
if (argc == 3)
{
try
{
unsigned long width = std::stoul(argv[1]);
unsigned long height = std::stoul(argv[2]);
DEVMODE *dm = new DEVMODE();
EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, dm);
dm->dmPelsWidth = width;
dm->dmPelsHeight = height;
ChangeDisplaySettings(dm, CDS_UPDATEREGISTRY);
}
catch (std::invalid_argument e)
{
std::cout << e.what() << std::endl;
}
}
return 0;
}
=== 資料來源
How to change screen resolution using QT, OpenGL, C++, and Linux?
http://stackoverflow.com/questions/11387724/how-to-change-screen-resolution-using-qt-opengl-c-and-linux
How to change screen resolution in Windows using Qt
http://eastfist.com/qt_tutorials/how-to-change-screen-resolution-in-windows-using-qt/
ChangeDisplaySettings function
https://msdn.microsoft.com/en-us/library/dd183411(VS.85).aspx
2015年10月10日 星期六
2015年10月4日 星期日
Qt 如何將 UTF-8 檔案轉存為 UTF-16
之前的文章介紹如何讀取 UTF-8 檔案。
Qt 如何從檔案讀取 UTF-8 的中文
這次介紹如何將 UTF-8 檔案轉存為 UTF-16。
使用 QFile 開啟檔案,
使用 QTextStream 處理編碼,
=== 完整範例
QFile fileIn("input.txt");
if (!fileIn.open(QIODevice::ReadOnly | QIODevice::Text))
{
qDebug() << "fileIn opne fail.";
return;
}
QFile fileOut("output.txt");
if (!fileOut.open(QIODevice::WriteOnly | QIODevice::Text))
{
qDebug() << "fileOut opne fail.";
return;
}
QTextStream in(&fileIn);
in.setCodec("UTF-8");
QTextStream out(&fileOut);
out.setCodec("UTF-16");
while (!in.atEnd()) {
QString line = in.readLine();
out << changeText(line);
}
fileIn.close();
fileOut.close();
qDebug() << "done";
=== 資料來源
Qt Documentation - QTextStream Class
http://doc.qt.io/qt-5/qtextstream.html
Qt 如何從檔案讀取 UTF-8 的中文
這次介紹如何將 UTF-8 檔案轉存為 UTF-16。
使用 QFile 開啟檔案,
使用 QTextStream 處理編碼,
=== 完整範例
QFile fileIn("input.txt");
if (!fileIn.open(QIODevice::ReadOnly | QIODevice::Text))
{
qDebug() << "fileIn opne fail.";
return;
}
QFile fileOut("output.txt");
if (!fileOut.open(QIODevice::WriteOnly | QIODevice::Text))
{
qDebug() << "fileOut opne fail.";
return;
}
QTextStream in(&fileIn);
in.setCodec("UTF-8");
QTextStream out(&fileOut);
out.setCodec("UTF-16");
while (!in.atEnd()) {
QString line = in.readLine();
out << changeText(line);
}
fileIn.close();
fileOut.close();
qDebug() << "done";
=== 資料來源
Qt Documentation - QTextStream Class
http://doc.qt.io/qt-5/qtextstream.html
2015年10月1日 星期四
Qt PostgreSQL 範例
Qt PostgreSQL 範例
=== 測試環境
OS: Windows 7
Qt Verstion: 5.5.0
Compiler: Visual Studio 2013
OS: Arch Linux 4.1.6
Qt Version: 5.5.0
Compiler: GCC 5.2.0
=== 程式範例
=== 錯誤訊息
QSqlDatabase: QPSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7
在 Windows,確認下列檔案
MyAppDir\sqldrivers\qsqlpsql.dll
MyAppDir\libpq.dll
MyAppDir\libeay32.dll
MyAppDir\ssleay32.dll
在 linux,確認 qt project file 加上
INCLUDEPATH+=/usr/include/pgsql
LIBS+=-L/usr/lib -lpq
=== 資料來源
Qt Documentation - SQL Database Drivers
http://doc.qt.io/qt-5/sql-driver.html
Qt: SELECT-Query to PostgreSQL-Server always responses with NULL
http://stackoverflow.com/questions/13633055/qt-select-query-to-postgresql-server-always-responses-with-null
QT5: Failed to load psql driver in windows
http://stackoverflow.com/questions/20884010/qt5-failed-to-load-psql-driver-in-windows
=== 測試環境
OS: Windows 7
Qt Verstion: 5.5.0
Compiler: Visual Studio 2013
OS: Arch Linux 4.1.6
Qt Version: 5.5.0
Compiler: GCC 5.2.0
=== 程式範例
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL"); | |
db.setHostName("127.0.0.1"); | |
db.setDatabaseName("FirstDB"); | |
db.setUserName("demo"); | |
db.setPassword("password"); | |
bool ok = db.open(); | |
if (ok) | |
{ | |
QSqlQuery query("SELECT \"SID\", \"Account\", \"CreateDate\", \"LoginTimes\" FROM \"Account\""); | |
while (query.next()) | |
{ | |
qWarning() << query.value(0).toString(); | |
qWarning() << query.value(1).toString(); | |
qWarning() << query.value(2).toString(); | |
qWarning() << query.value(3).toString(); | |
} | |
qDebug() << query.lastError().text(); | |
} |
QSqlDatabase: QPSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7
在 Windows,確認下列檔案
MyAppDir\sqldrivers\qsqlpsql.dll
MyAppDir\libpq.dll
MyAppDir\libeay32.dll
MyAppDir\ssleay32.dll
在 linux,確認 qt project file 加上
INCLUDEPATH+=/usr/include/pgsql
LIBS+=-L/usr/lib -lpq
=== 資料來源
Qt Documentation - SQL Database Drivers
http://doc.qt.io/qt-5/sql-driver.html
Qt: SELECT-Query to PostgreSQL-Server always responses with NULL
http://stackoverflow.com/questions/13633055/qt-select-query-to-postgresql-server-always-responses-with-null
QT5: Failed to load psql driver in windows
http://stackoverflow.com/questions/20884010/qt5-failed-to-load-psql-driver-in-windows
訂閱:
文章 (Atom)