How to handle TreeView double or right mouse click in WinProc?
i have tried this:
if(LOWORD(wParam) == GetWindowID(g_hWndTV &&
HIWORD(wParam) == WM_RBUTTONUP)
......
but this does not work.
Thanks for answers
Both these events will come via a WM_NOTIFY message sent to the tree control's parent window. You'll get NM_RCLICK for a right-click, and NM_DBLCLK for a double-click.
case WM_NOTIFY:
if (reinterpret_cast<LPNMHDR>(lParam)->hwndFrom == g_hWndTV)
{
if (reinterpret_cast<LPNMHDR>(lParam)->code == NM_RCLICK)
{
// right-click
}
else
if (reinterpret_cast<LPNMHDR>(lParam)->code == NM_DBLCLK)
{
// double-click
}
}
break;
Related
I have a dialog based MFC application which I want to close/terminate only using the X(close) button given in title bar and disabling other shortcuts to do so.
for example: pressing the Esc key. Can someone help?
Override the PreTranslateMessage function and catch the use of VK_ESCAPE for capturing Esc key. Similar way you can catch other messages and bypass closing of dialog
BOOL CMyDialog::PreTranslateMessage(MSG* pMsg)
{
if (pMsg->message == WM_KEYDOWN)
{
if ((pMsg->wParam == VK_RETURN) || (pMsg->wParam == VK_ESCAPE))
return TRUE;
}
return CDialog::PreTranslateMessage(pMsg);
}
I am having a propertysheet and it has three pages (page1, page2, page3) respectively.For which I added as messagebox whenever Cancel button is pressed or [X] is clicked or Esc is pressed.
Steps followed:
1.Ran the application.
Pressed Cancel button and message box is popped up. (Did not cancel the messagebox).
Now go to the taskbar and right click on the application icon and click "close window". Exactly here the problem arose; i.e, one more message box window is popped up.
Actually this should not happen, right? It should be restricted to only one message box.
//This is being triggered when close window or cancel button is pressed.
BOOL OnQueryCancel()
{
if(IDOK == ::MessageBox(m_hWnd, L"Closing the application",
L"Warning", MB_OKCANCEL | MB_ICONWARNING))
{
return TRUE;
}
return FALSE;
}
How can I prevent from not displaying multiple messagebox's? I should show focus to the already opened messagebox.
First, you should use AfxMessageBox, which makes it easier in MFC. Second, this is normal operation in Windows -- it's just responding to the close messages. I would add a variable to indicate the box is displayed already:
//Part of your class
BOOL m_bIsPromptActive;
BOOL OnQueryCancel()
{
if( !m_bIsPromptActive)
{
m_bIsPromptActive = TRUE;
if(IDOK == ::MessageBox(m_hWnd, L"Closing the application",
L"Warning", MB_OKCANCEL | MB_ICONWARNING))
{
return TRUE;
}
m_bIsPromptActive = FALSE;
}
else
{
// Message is already displayed. Set the focus to this window
::SetFocus( m_hWnd ); // or this->SetFocus();
// You can also look at ::BringWindowToFront()
}
return FALSE;
}
I would like to know how to respond to a mouse scroll event in C++ only from the user's mouse wheel. I don't really care whether the user scrolls in or out as long as I catch the event that they indeed did scroll with the mouse. Can anyone show me how I can use this for an event?
You need to implement the glutMouseFunc callback like this:
void mouse(int button, int state, int x, int y)
{
// Wheel reports as button 3(scroll up) and button 4(scroll down)
if ((button == 3) || (button == 4))
{
if (state == GLUT_UP) return; // Disregard redundant GLUT_UP events
(button == 3) ? DO_ACTION : DO_SOMETHING_ELSE;
}
glutPostRedisplay();
}
I'm using a QTableView where I show a list of Icons, the user can select some icons with mouse and control key button, and I'm able to handle these selections. But I want to disable the use of shift+left mouse key over the QTableView.
Is there any way to totally disable the shift key button during the process when GUI is being run? I am able to detect the shift key pressing using the eventFilter that is installed on the viewport of QTableView, but I cannot find any way to totally make the shift key inactive when the user presses shift key and the left mouse button together.
My event filter is as below:
bool MainWindow::eventFilter(QObject* obj, QEvent *ev)
{
if(obj == ui->listOfImages->viewport())
{
if(ev->type() == QEvent::MouseButtonPress)
{
QMouseEvent * mouseEv = static_cast<QMouseEvent*>(ev);
if((mouseEv->buttons() & Qt::LeftButton) && (QApplication::keyboardModifiers().testFlag(Qt::ControlModifier) == true) && (QApplication::keyboardModifiers().testFlag(Qt::ShiftModifier) == false))
{
controlButtonCounter++;
fetch = true;
//I use these variables for some purposes.
return QObject::eventFilter(obj,ev);
}
else if((mouseEv->buttons() & Qt::LeftButton) && (QApplication::keyboardModifiers().testFlag(Qt::ControlModifier) == false) && (QApplication::keyboardModifiers().testFlag(Qt::ShiftModifier) == false))
{
if(selectedImages.size()>0)
{
ui->listOfImages->clearSelection();
selectedImages.clear();
selectedList.clear();
ui->selectedFiles->clear();
ui->selectedFiles->show();
}
fetch = false;
controlButtonCounter = 0;
//I use these variables for some purposes.
}
else if((mouseEv->buttons() & Qt::LeftButton) && (QApplication::keyboardModifiers().testFlag(Qt::ControlModifier) == false) && (QApplication::keyboardModifiers().testFlag(Qt::ShiftModifier) == true) )
{
qDebug()<<"Shift button pressed!";
// Don't how to prevent shift button from selecting multiple icon.
}
}
}
return QObject::eventFilter(obj,ev);
}
Regarding your code, I believe you want to change the way you select things in the QTableView and disabling the shift-button would be just a work around.
You can disable multi-selections with:
QAbstractItemView::selectionMode(QAbstractItemView::SingleSelection);
See: http://qt-project.org/doc/qt-4.8/qabstractitemview.html#SelectionMode-enum: for more info
I will handle mouse clicks and button state in the following way:
bool MyWidget::eventFilter(QObject *obj, QEvent *event)
{
[..]
if (event->type() == QEvent::MouseButtonPress ||
event->type() == QEvent::MouseButtonRelease) {
Qt::KeyboardModifiers modifiers = QApplication::keyboardModifiers();
if (modifiers & Qt::ShiftModifier) {
// Filter the event, when mouse pressed/released
// with the shift key pressed.
return true;
}
}
[..]
return false;
}
I have a simple test script, which it meant to change a boolean when the user clicks within the dimensions of the button but it is not working.
I approached it like so:
while( SDL_PollEvent( &event ) ) {
switch( event.type ){
case SDL_QUIT: quit = true; break;
case SDL_MOUSEMOTION: mouseX = event.motion.x; mouseY = event.motion.y; break;
case SDL_MOUSEBUTTONDOWN: click = true;
}
}
Button btn_settings(btn_x,btn_y);
if(btn_settings.IsIn(mouseX,mouseY)){
btn_settings.RenderImg(menu,screen,"button_on.png","Settings");
if(click){
quit = true;
}
} else {
btn_settings.RenderImg(menu,screen,"button.png","Settings");
}
The problem is if i click any where then click equals true, then if the mouse is over the quit button it exits even if the button wasn't pressed when over the button.
I'm confused how i can make it work properly.
Try handling your "click" event on mouse button up instead. I've never used SDL but I suspect there is a SDL_MOUSEBUTTONUP defined. Otherwise you don't know if they want to perform a drag operation or if they moved the mouse someplace else before letting go of the mouse button.