gtk_window_fullscreen problem - fullscreen

I need in full screen window functional in my gtk+ application. I try to use gtk_window_fullscreen(GtkWindow* Window):
I have function:
static void
full_screen(MainWin *mw)
{
gtk_window_fullscreen((GtkWindow*)mw);
}
When i try to call this function i see error:
Gtk-CRITICAL **: gtk_window_fullscreen: assertion `GTK_IS_WINDOW (window)' failed
Where MainWin:
typedef struct _MainWin MainWin;
typedef struct _MainWin
{
GtkWindow parent;
GtkWidget* scroll;
GtkWidget* box;
GtkWidget *toolbar;
gboolean full_screen;
};
What's wrong?
Thank you

You're (still) trying to weirdly subclass GtkWindow for some reason. You can't do that like that, where did you get this idea?
You need to have a widget pointer:
GtkWindow *window;
Then create the window using gtk_window_new(GTK_WINDOW_TOPLEVEL).

Related

How to capture windows message from the up/down button of a CDateTimeCtrl control?

I am using a CDateTimeCtrl, along with a callback field, in my dialog application. All works well as intended but I want to capture the windows message when the up-down button ( looks a lot like the spin control) of the CDateTimeCtrl is clicked without success. Spy++ reported the class of the up-down button to be msctls_updown32. Spy++ message log offer no clue either. How do I capture the mouse click messages from this up-down control ( looks like an OLE control to me)?
Edited: : I've tried handling the UDN_DELTAPOS message like so but still unable to capture the message from CMyTimeCtrl.
class CMyTimeCtrl : public CDateTimeCtrl
{
DECLARE_DYNAMIC(CMyTimeCtrl)
public:
CMyTimeCtrl();
virtual ~CMyTimeCtrl();
protected:
int m_msec;
DECLARE_MESSAGE_MAP()
public:
virtual void DoDataExchange(CDataExchange* pDX);
afx_msg void OnDtnFormat(NMHDR* pNMHDR, LRESULT* pResult);
afx_msg void OnDtnFormatquery(NMHDR* pNMHDR, LRESULT* pResult);
afx_msg void OnDtnWmkeydown(NMHDR* pNMHDR, LRESULT* pResult);
afx_msg void OnDeltaposSpin(NMHDR* pNMHDR, LRESULT* pResult);
};
BEGIN_MESSAGE_MAP(CMyTimeCtrl, CDateTimeCtrl)
ON_NOTIFY(WM_NOTIFY, UDN_DELTAPOS, &CMyTimeCtrl::OnDeltaposSpin)
ON_NOTIFY_REFLECT(DTN_FORMAT, &CMyTimeCtrl::OnDtnFormat)
ON_NOTIFY_REFLECT(DTN_FORMATQUERY, &CMyTimeCtrl::OnDtnFormatquery)
ON_NOTIFY_REFLECT(DTN_WMKEYDOWN, &CMyTimeCtrl::OnDtnWmkeydown)
END_MESSAGE_MAP()
Thanks, with the guidance from the comment section I manage to resolve my issue. In the message map I made an error, corrected as shown below. Now it's working fine. In my resource section, the IDC_STATIC value is 1000:
BEGIN_MESSAGE_MAP(CMyTimeCtrl, CDateTimeCtrl)
ON_NOTIFY(UDN_DELTAPOS, IDC_STATIC, &CMyTimeCtrl::OnDeltaposSpin)
ON_NOTIFY_REFLECT(DTN_FORMAT, &CMyTimeCtrl::OnDtnFormat)
ON_NOTIFY_REFLECT(DTN_FORMATQUERY, &CMyTimeCtrl::OnDtnFormatquery)
ON_NOTIFY_REFLECT(DTN_WMKEYDOWN, &CMyTimeCtrl::OnDtnWmkeydown)
END_MESSAGE_MAP()

Something for a child window analogous to `this`

I am a newcomer to programming. I am writing a dialog based application which has a static control on it. Using
Using
void CMy1stDlg::OnMouseMove(UINT nFlags, CPoint point)
{
if (this == GetCapture())
{
CClientDC aDC(this);
aDC.SetPixel(point, RGB(255,0,0));
}
}
I can create results like
However what I want is that the locus of mouse is only drawn within the static window. I can't find the reference to this in MSDN and I don't know why the following method fails.
void CMy1stDlg::OnMouseMove(UINT nFlags, CPoint point)
{
CWnd* pMYSTATIC = GetDlgItem (IDC_MYSTATIC); //IDC_MYSTATIC is the ID of the static control
if (pMYSTATIC == GetCapture())
{
CClientDC aDC(pMYSTATIC);
aDC.SetPixel(point, RGB(255,0,0));
}
}
How can I get what I want? Are there any methods to get something for the static window analogous to this? I will appreciate any help with these.
OK, try this:
void CMy1stDlg::OnMouseMove(UINT nFlags, CPoint point)
{
CRect rect;
// Get static control's rectangle
GetDlgItem(IDC_MYSTATIC)->GetWindowRect(&rect);
// Convert it to client coordinates
ScreenToClient(&rect);
// Check if mouse pointer is inside the static window, if so draw the pixel
if (rect.PtInRect(point))
{
CClientDC dc(this);
dc.SetPixel(point.x, point.y, RGB(255,0,0));
}
}
This code may need some fixes too, eg shrink the rectangle (to its client-only area), before checking whether to draw the pixel.
Please note that you don't need to check GetCapture(); if your dialog hasn't captured the mouse it won't be receiving this message anyway.
Also, all these functions are wrappers of Windows SDK ones, eg the ClientDC() class, basically wraps GetDC()/ReleaseDC().

MFC on form create event

I have simple FMC dialog form. Can't find how to manage event that should be called on form create moment. Something like onFormCreate like it is in VB or Delphi.
How to create such functionality?
My simple form header:
#pragma once
// CMFCApplicationUPTDlg dialog
class CMFCApplicationUPTDlg : public CDialog
{
// Construction
public:
CMFCApplicationUPTDlg(CWnd* pParent = NULL); // standard constructor
// Dialog Data
enum { IDD = IDD_MFCAPPLICATIONUPT_DIALOG };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
// Implementation
protected:
HICON m_hIcon;
// Generated message map functions
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnBnClickedOk();
afx_msg void OnBnClickedButton1();
};
You want to handle it in the OnInitDialog() member function. At the point that OnInitDialog() is called, the dialog and all of its child windows will have been created. However, the dialog will still be invisible to the user. After exiting OnInitDialog(), the dialog will be shown to the user.
So, it is the place where you would want to do initialization of your dialog.
You need to implement OnInitDialog in your own derived class.
BOOL CMFCApplicationUPTDlg::OnInitDialog()
{
// this will create the controls you defined in the resources.
BOOL retValue = __super::OnInitDialog();
// initialize (or add new controls to ) your dialog content here.
// ...
return retValue;
}

How to call a slot, that belongs to a QThread, within that same QThread?

I have a QThread that starts an external Linux binary. I use connect() to call a slot(), which is part of the QThread, whenever I get an output from that external Linux binary. This seems not to work for me. Can anyone tell me what is wrong in the below code?
class ThreadPowerSubSystem : public QThread
{
public:
ThreadPowerSubSystem(){ }
private slots:
void checkForTwoSecPress()
{
qWarning("button pressed");
}
private:
void run()
{
QProcess *powerProcess = new QProcess();
powerProcess->start("/home/testApp/button");
connect(powerProcess, SIGNAL(readyRead()), this, SLOT(checkForTwoSecPress()));
exec();
}
};
Also I need to call a function to display a dialog inside that slot. Can anyone show me an example on how to do it?

Image not getting displayed/update in QLabel using SIGNAL-SLOT in ROS node

I am implementing the Qt code in ROS node. I have a header file in which i have defined all the members, Q_SIGNAL and Q_SLOTS. In my .cpp file i want to display an image when i press a button(assignButton). But when i press the button, nothing shows up.
To test whether the connect function is working properly or not, i tried to display an image in the imageLabel which is stored in my laptop..and it worked.
PROBLEM:- I am taking the images from simulator in ROS through the
void SelectionInterface::imageCallback(const sensor_msgs::ImageConstPtr& msg) and i want to display those images in imageLabel by SIGNAL-SLOT..but its not getting displayed..no error
My code is following:-
1. Header file-- SelectionInterface.h
class SelectionInterface : public QMainWindow
{
Q_OBJECT
public:
SelectionInterface(ros::NodeHandle *nh, RosThread *rt, QMainWindow *parent = 0);
~SelectionInterface();
private:
RosThread *rosThread;
ros::NodeHandle *nodeHandle;
// ROS Subscribers
image_transport::Subscriber image_sub;
void imageCallback(const sensor_msgs::ImageConstPtr& msg);
// More Memberfunctions and Variables
QWidget *newCentralWidget;
QPushButton *quitButton;
QPushButton *assignButton;
QVBoxLayout *layout;
QLabel *imageLabel;
QImage image;
// ...
protected:
void closeEvent(QCloseEvent *event);
Q_SIGNALS:
void windowClosedSignal();
private Q_SLOTS:
void quitInterface();
void assignImage();//QImage
};
2. .cpp file
#include "SelectionInterface.h"
#include <iostream>
SelectionInterface::SelectionInterface(ros::NodeHandle *nh, RosThread *rt, QMainWindow *parent): QMainWindow (parent)
{
rosThread = rt;
nodeHandle = nh;
// Subscribing and Publishing
image_transport::ImageTransport it(*nh);
// Setup user interface here
newCentralWidget = new QWidget;
quitButton = new QPushButton("Quit");
assignButton = new QPushButton("Assign Image");
layout = new QVBoxLayout;
imageLabel = new QLabel;
imageLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
layout->addWidget(imageLabel);
layout->addWidget(quitButton);
layout->addWidget(assignButton);
newCentralWidget->setLayout(layout);
this->setCentralWidget(newCentralWidget);
// Signal-Slot Connections
connect(this, SIGNAL(windowClosedSignal()), this, SLOT(quitInterface()));
connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));
connect(assignButton, SIGNAL(clicked()), this, SLOT(assignImage()));
// ...
}
void SelectionInterface::imageCallback(const sensor_msgs::ImageConstPtr& msg)
{
QImage image(&(msg->data[0]), msg->width, msg->height, QImage::Format_RGB888);
}
SelectionInterface::~SelectionInterface()
{
//destructer (leave empty)
}
void SelectionInterface::closeEvent(QCloseEvent *event)
{
Q_EMIT windowClosedSignal();
}
void SelectionInterface::quitInterface()
{
rosThread->stop();
rosThread->wait();
std::cout << "Good bye.\n";
}
void SelectionInterface::assignImage()
{
imageLabel->setPixmap(QPixmap::fromImage(image));
}
I doubt QImage can replace ~ to your home path. Try to specify full path e.g. '/home/user/Pictures/wallpapers/buddha.jpg'.

Resources