SetCursorPos in wxWidgets - c++

I code with visual c++, and i use wxwidget 3.x., Windows 10
I would like to use SetCursorPos (to move my camera, and let the mouse cursor stay in middle of screen), but i got some error message:
canvas.obj : error LNK2019: unresolved external symbol __imp__SetCursorPos#8 referenced in function "public: void __thiscall CanvasFrame::setCursorPos(int,int)" (?setCursorPos#CanvasFrame##QAEXHH#Z)
I m not sure i can use SetCursorPos via wwxwidget, i think wxwidget manage this, but cant find it on google …
Some idea?

My bad …
this->WarpPointer(renderer->GetWidth() / 2, renderer->GetHeight() / 2);
works..
Thanks anyway :)

Related

calling ApplicationView::GetForCurrentView() returns error in uwp app

This is how I call this. to resize window of the app
auto view = ApplicationView::GetForCurrentView();
view.SetPreferredMinSize({ 300, 200 });
Window::Current().Activate();
and the error:
Severity Code Description Project File Line Suppression State
Error LNK2001 unresolved external symbol "public: static struct
winrt::Windows::UI::ViewManagement::ApplicationView __cdecl
winrt::Windows::UI::ViewManagement::ApplicationView::GetForCurrentView(void)"
(?GetForCurrentView#ApplicationView#ViewManagement#UI#Windows#winrt##SA?AU12345#XZ) BluetoothLE C:\Users\berkin1\Desktop\BluetoothLE\cppwinrt\App.obj 1
This is how I call this. to resize window of the app
If you want to resize your app, please call TryResizeView method after setting preferred min Size.
auto view = ApplicationView::GetForCurrentView();
view->SetPreferredMinSize({ 300,200 });
view->TryResizeView({ 300,200 });
And please make sure above code run in the ui thread.

QT: DirectShowPlayerService::doSetUrlSource: Unresolved error code 0x8007007b ()

I am using Qt Version 5.14.1.
When I was trying to play a video(.mp3), the program stopped working
And given error is DirectShowPlayerService::doSetUrlSource: Unresolved error code 0x8007007b ()
AudioPlayer::AudioPlayer(QObject *parent)
: QObject(parent)
, m_backgroundMusic(NULL) //QMediaPlayer * m_backgroundMusic
{
QUrl backgroundMusicUrl = QUrl::fromLocalFile(":/music/8bitDungeonLevel.mp3");
if (QFile::exists(backgroundMusicUrl.toLocalFile()))
{
m_backgroundMusic = new QMediaPlayer(this);
QMediaPlaylist * backgroundMusicList = new QMediaPlaylist();
QMediaContent media(backgroundMusicUrl);
backgroundMusicList->addMedia(media);
backgroundMusicList->setCurrentIndex(0);
backgroundMusicList->setPlaybackMode(QMediaPlaylist::CurrentItemInLoop);
m_backgroundMusic->setPlaylist(backgroundMusicList);
}
}
void AudioPlayer::startBGM()
{
if (m_backgroundMusic)
{
qDebug() << m_backgroundMusic;
m_backgroundMusic->play();
}
}
the output as below
QMediaPlayer(0x3987eb0)
DirectShowPlayerService::doSetUrlSource: Unresolved error code 0x8007007b ()
I search the Internet and add LAV Filters to QT installation directory
, I also restart the computer but nothing changes.So how to fix it?
Your path in QUrl::fromLocalFile(":/music/8bitDungeonLevel.mp3") appears to be off, AFIK there is no (at least not common) path naming scheme that uses : to begin paths.
UPDATE:
I was told that :/ refers to resources that have been compiled into a Qt application, I think using the Qt Resource Compiler (rcc)
Use this code to load mp3 from resources:
m_mediaPlayer.setMedia(QUrl("qrc:/Audio/MouseOver.mp3"));
(do no forget do delete fromLocalFile)

Printing to paper in Qt

I am new to qt. I want to make a simple project that will print text from the printer.
whenever I am using
QPrinter printer;
QPrintDialog *dialog = new QPrintDialog(&printer, this);
dialog->setWindowTitle(tr("Print Document"));
if (editor->textCursor().hasSelection())
dialog->addEnabledOption(QAbstractPrintDialog::PrintSelection);
if (dialog->exec() != QDialog::Accepted)
return;
or this
QPrinter printer(QPrinter::HighResolution);
printer.setOutputFileName("print.ps");
QPainter painter;
painter.begin(&printer);
for (int page = 0; page < numberOfPages; ++page) {
// Use the painter to draw on the page.
if (page != lastPage)
printer.newPage();
}
painter.end();
I just copy pasted this to my mainwindow.cpp(and tried pasting it to main.cpp too),to check if it works. It does not.
I am getting several errors like these
mainwindow.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual _thiscall QPrinter::~QPrinter(void)" (_imp_??1QPrinter##UAE#XZ) referenced in function "private: void __thiscall MainWindow::on_pushButton_clicked(void)" (?on_pushButton_clicked#MainWindow##AAEXXZ).
could someone tell me step by step, how to print to a printer?
I also checked a lot online, but did not get any relevant tutorial , or even an example.
so, PLEASE write it here instead of linking me to another page.
I did some quick research being kind of surprised by your comments. The QtPrintSupport did change, so use for Qt5 (Detailed Description):
In Pro file:
QT += core gui printsupport
In cpp file:
#include <QtPrintSupport>
For printing from your QTextEdit *editor use:
editor->document()->print(&printer);

Finding the length of a song

I want to find the length of a song in seconds so that I can make a playlist with the M3U format, but I don't know how to get that info from the file. I am using id3lib and also Qt.
I've tried:
ID3_Frame* myFrame = myTag.Find(ID3FID_SONGLEN);
ID3_Frame* myFrame = myTag.Find(ID3FID_TIME);
ID3_Frame* myFrame = myTag.Find(ID3FID_SIZE);
but myFrame was NULL. I tried other parameters and worked, like ID3FID_ALBUM. I really don't know what to try. I didn't find anything in the id3lib API.
I know that Qt can give me that info, but can't I use id3lib?
Later edit: I've read that MediaObject::totalTime() gives me the time only if the song is played but I want that info, regarding that the songs are played or not; I need this info to write it in a file.
LATER EDIT:
I am trying to use Phonon from Qt for the length, but i receive a lot of errors.
#include <Phonon/MediaSource>
#include <Phonon/MediaObject>
#include <iostream>
#include <Qstring>
/* stuff */
Phonon::MediaObject *mediaObject = new Phonon::MediaObject();
QString fileName("D:/melodie.mp3");
mediaObject->setCurrentSource(fileName);
cout << mediaObject->totalTime() << endl;
I get a lot of unresolved external symbol
main.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall Phonon::MediaObject::MediaObject(class QObject *)" (_imp??0MediaObject#Phonon##QAE#PAVQObject###Z) referenced in function _main
I am using QCreator, my application is simple, just a window that says hello(it works if i don't use Phonon); i just can't make it run; i've allocated static mediaObject, i've made a MediaSource and tried to pass it, but it doesn't work(here it says that can't covert from MediaSource* to MediaSource &). What could be the problem?
You can use Phonon::MediaObject::totalTime() to get the length of the song in milliseconds.
id3lib does not provide a function to directly find the length of a song because track length is not part of the ID3v1 or ID3v2 "standards". They are merely for tagging. If you're getting a 0 when you try the code in your question, it probably means that those tags haven't been set yet. As noted in the docs, "...the Find() method will return a NULL pointer if no such frame can be found."
Use MediaObject::totalTime after setting correctly the media source
I suggest you to use totalTimeChanged(qint64 newTotalTime) signal. It is more careful way to capture length of the track, because you don't need to manually check state of mediaObject.

Hiding a winform & bringing it back from a DLL

In my DDL, I have the following function defined:
extern "C" __declspec(dllexport) void hideme(HWND h) {
//ShowWindow(h, SW_HIDE);
SendMessage(h, WM_SHOWWINDOW, FALSE, 0);
}
As you can see, I've tried multiple things to get this working...
I have it declared in my winform as followed:
typedef void (*HideMe)(HWND);
In my System::Windows::Forms::Form Load event, I have the following code:
...
HINSTANCE hinst = LoadLibrary(_T("My.dll"));
if (hinst == NULL)
System::Diagnostics::Debug::WriteLine("null hinst");
else
hideme = (HideMe) GetProcAddress(hinst, "hideme");
...
In my System::Windows::Forms::Form Shown event, I have the following code:
...
hideme((HWND)this->Handle.ToPointer());
...
I think the problem must lie in the way I send over the HWND, but I've been searching all day, and can't find an alternative.
I've also tried setting this->Visible = false; but then I can't figure out how to trigger it back to visible from the DLL (abuse sendmessage?).
I'm not a C++ programmer, I normally only program in managed languages, so any help (and patience is appreciated.
Thanks,
Nick.
N.B.
One weird thing I can't explain is that I can't call ShowWindow from the WinForm itself. It will throw up this gem:
Error 2 error LNK2028: unresolved token (0A00001E) "extern "C" int __stdcall ShowWindow(struct HWND__ *,int)" (?ShowWindow##$$J18YGHPAUHWND__##H#Z) referenced in function "private: void __clrcall CheckMSNCpp::frmMain::frmMain_Shown(class System::Object ^,class System::EventArgs ^)" (?frmMain_Shown#frmMain#CheckMSNCpp##$$FA$AAMXP$AAVObject#System##P$AAVEventArgs#4##Z)
Error 3 error LNK2019: unresolved external symbol "extern "C" int __stdcall ShowWindow(struct HWND__ *,int)" (?ShowWindow##$$J18YGHPAUHWND__##H#Z) referenced in function "private: void __clrcall CheckMSNCpp::frmMain::frmMain_Shown(class System::Object ^,class System::EventArgs ^)" (?frmMain_Shown#frmMain#CheckMSNCpp##$$FA$AAMXP$AAVObject#System##P$AAVEventArgs#4##Z)
Error 4 error LNK1120: 2 unresolved externals
[EDIT1]
Hans Passant said:
The linker error message you got on
the ShowWindow() attempt is also a
strong hint why your current code is
not working. You forgot to add error
checking code, GetProcAddress() can
fail and will return a NULL pointer.
It will, the function isn't exported
by the "hideme" name. In a 32-bit
build, it will be exported as
"_hideme", note the underscore. Which
was added to indicate that the
function uses the __cdecl calling
convention. The linker error on
ShowWindow demonstrates C++ name
decoration, you forgot to #include
windows.h and made up your own,
incorrect, declaration for ShowWindow.
This is not the right way to do it,
you should just set the Visible
property to false. Like you tried. Why
you cannot set it back to true is
quite unguessable.
What you said makes no sense to me at all for a few reasons.
1)
The imports for the winform:
#include "stdafx.h"
#include <windows.h>
#include <iostream>
#include <stdio.h>
As you can tell, windows.h is in there.
2) the ShowWindor error is not in the DLL, there I can call it fine, it's in the WinForm code.
3) I never exported ShowWindow, just my own functions.
[/EDIT1]
[EDIT2]
Uwe Keim said:
Why do you need an extra DLL that is
merely just a wrapper to another DLL
function?
I would do it like in e.g. C# by using
PInvoke from your managed C++
application. The signature for
SendMessage would be (in C#):
The PInvoke stuff just doesn't make any sense, like commenters said.
As for the DLL, it needs to be a DLL because i require a global hook to respond to my hotkeys & WH_CBT. In this case, I want the program to start hidden & just show a setting screen when pressing a key combo.
Everything in the program works as expected, the hotkey works like a charm, the only thin I can't get right, is showing the application, triggered from the DLL.
[/EDIT2]
[EDIT3]
Example code at: http://www.nickkusters.com/CPP_PROBLEM_Demo-NOBIN.zip
[/EDIT3]
The linker error message you got on the ShowWindow() attempt is also a strong hint why your current code is not working. You forgot to add error checking code, GetProcAddress() can fail and will return a NULL pointer. It will, the function isn't exported by the "hideme" name. In a 32-bit build, it will be exported as "_hideme", note the underscore. Which was added to indicate that the function uses the __cdecl calling convention. The linker error on ShowWindow demonstrates C++ name decoration, you forgot to #include windows.h and made up your own, incorrect, declaration for ShowWindow.
This is not the right way to do it, you should just set the Visible property to false. Like you tried. Why you cannot set it back to true is quite unguessable.
Why do you need an extra DLL that is merely just a wrapper to another DLL function?
I would do it like in e.g. C# by using PInvoke from your managed C++ application. The signature for SendMessage would be (in C#):
[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern IntPtr SendMessage(
IntPtr hWnd,
UInt32 Msg,
IntPtr wParam,
IntPtr lParam);