I have a dialog box displayed when I press a menu item in the SDI window. In the Dialog box When i press OK button it should display "SUCESS" in the SDI window... In ONVIEW() i have to use pDC->TEXTOUT() but how to execute that statement on pressing OK button.. I am using visual C++ 6
you should define a user defined message and use PostMessage to call your method in SDI Window.
I am working on assumption that your dialog is modal.
You do not have to define or send any messages.
Retrieve data from the dialog.
Presumably you store 2D vector data in some kind of an array declared as a member variable of the dialog.
When OK button is pushed and copy data to a view’s member variable of the same type. Use it to draw whatever you desire.
void CSDIPopupSampleView::OnViewDialog()
{
CSimpleDlg dlg;
int iResponse = dlg.DoModal();
if(IDOK == iResponse)
{
//Copy data from a dialog here.
}
Invalidate(); // this will cause redraw
}
Related
I have a window which has a CTreeCtrl. A user can right-click any element and display a context menu. From there they can choose to delete the entry. Something like this:
Here is a snippet of the context menu item handler:
void CAssignHistoryDlg::OnDeleteFromAssignmentHistory()
{
CString strINI = theApp.GetAssignHistoryPath();
HTREEITEM hItem = m_treeHistory.GetSelectedItem();
CString strName, strDeletedName, strEntry;
if (m_treeHistory.GetParentItem(hItem) != nullptr)
{
// The user has picked one of the history dates.
// So the parent should be the actual name.
hItem = m_treeHistory.GetParentItem(hItem);
// Now OK to proceed
}
strName = ExtractName(hItem);
GetParent()->EnableWindow(FALSE);
strEntry.Format(IDS_TPL_SURE_DELETE_FROM_ASSIGN_HIST, strName);
if (AfxMessageBox(strEntry, MB_YESNO | MB_ICONQUESTION) == IDNO)
{
The image shows my problem. If I first click on Test, so that it is selected and bright blue and then right-click, it shows Test in the popup message. This is fine. But ...
If the first name is initially selected, and I go ahead and directly right-click Test, even though it seems to go blue (as if selected), m_treeHistory.GetSelectedItem() is returning the original, first name. I think I am describing it not very well.
In short, I want to guarantee that I get the HTREEITEM for the item that the user right-clicked on. What I have is not 100% fool-proof.
If it helps, this is how I display the context menu:
void CAssignHistoryDlg::OnNMRclickTreeHistory(NMHDR *pNMHDR, LRESULT *pResult)
{
CMenu mnuContext, *pMnuEdit = nullptr;
CPoint ptLocal;
LPNMTREEVIEW pNMTreeView = reinterpret_cast<LPNMTREEVIEW>(pNMHDR);
GetCursorPos(&ptLocal);
mnuContext.LoadMenu( IDR_MENU_SM_ASSIGN_HIST_POPUP );
pMnuEdit = mnuContext.GetSubMenu( 0 );
if (pMnuEdit != nullptr)
{
pMnuEdit->TrackPopupMenu( TPM_LEFTALIGN|TPM_LEFTBUTTON,
ptLocal.x, ptLocal.y, this, nullptr );
}
*pResult = 0;
}
So to recap, at the moment the user must physically left click on a item in the tree to select it. Then they can right-click and it will offer to delete this person. But if they go ahead and just right-click on anyone, it will not offer to delete THAT person.
You can get the actual tree item at any given point using the HitTest() member of the CTreeCtrl class. Exactly how and where you do this will depend on your code design but, if you have a pointer to your CTreeCtrl (pwTree in the code below), then you can do something like this:
CPoint ptLocal;
GetCursorPos(&ptLocal);
pWTree->ScreenToClient(&ptLocal); // May not be required in certain handlers?
HTREEITEM hItem = pWTree->HitTest(ptLocal); // Remember to check for NULL return!
You can then either use the returned hItem directly, or use it to explicitly set the tree's selection (to that item), before doing any further processing.
The MS doc: https://learn.microsoft.com/en-us/cpp/mfc/reference/cwnd-class?view=vs-2019 doesn't have a "click" handler, it has CWnd::OnRButtonDblClk, CWnd::OnRButtonDown and CWnd::OnRButtonUp. Which one are you handling?
The reason for your defect might be that you don't let the tree control handle that right button event (to select that new item).
I would suggest to use CWnd::OnContextMenu instead.
I am not sure if there may be a memory leak here - its about quitting a simple popup window in GTK.
if (alertWindow == NULL) {
alertWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
alertLabel = gtk_label_new (" wrong input! connection should be either s,S,p or P.\n All other data as floating numbers" );
gtk_container_add(GTK_CONTAINER(alertWindow), alertLabel);
g_signal_connect (alertWindow, "destroy", G_CALLBACK (destroyAlert), NULL); //avslutar applikation
}
and the callback
static void destroyAlert(GtkWidget *widget, gpointer data) {
alertWindow = NULL;
}
I set the alertWindow to NULL so it can be created once again next time the user enters wrong input.
That should not leak memory. The window assumes a reference to the label, so the label will get destroyed and freed with the window. The window will get destroyed and freed when you click on the window title bar's close button (which is the only way to close that window according to the code that you have.)
However, I'd suggest doing it a different way:
GtkWidget *alertWindow = gtk_message_dialog_new(parentWindow,
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_USE_HEADER_BAR,
GTK_MESSAGE_WARNING, GTK_BUTTONS_CLOSE,
"Wrong input! Connection should be either s, S, p or P.\n"
"All other data as floating point numbers.");
gtk_dialog_run(GTK_DIALOG(alertWindow));
gtk_widget_destroy(alertWindow);
This has a few advantages; first, you get a more full-featured dialog with a friendly button for closing it. Second, you don't have to use a global variable that you then have to worry about whether it is NULL or not. Third, the dialog is modal (the rest of the application is disabled while the dialog is open), which is appropriate for an error message like this.
Even better would be to detect the wrong input as the user types, and use something like a GtkPopover to inform them of what kind of input belongs in each field.
I have dropped ComboBox on dialog form. Also I have added some text to it:
BOOL CMyAppDlg::OnInitDialog()
{
CComboBox *combo= (CComboBox *)GetDlgItem(IDC_COMBO_TT);
combo->AddString("s1");
combo->AddString("s2");
//...
return TRUE;
}
When I drop down ComboBox it shows only one selection line and adds arrows to select other items. How to increase dropdown size?
Click the combo button in dialog editor. You can now drag down to set the open size.
I have a listctrl with CheckBox in it(LVS_EX_CHECKBOXES) .It is a single column List Control . My Problem is when I Click on the CheckBox the particular item is getting selected/UnSelected. But when I click on the Item text the corresponding Checkbox is not getting Selected/UnSelected . How to handle both the Scenarios.
To check the item when the user clicks on the item text, you'll have to handle the NM_CLICK message, which is sent whenever the user clicks on the item.
Something along the lines of:
CYourListCtrl::OnNMClick(NMHDR* pNMHDR, LRESULT* pResult)
{
LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
int nItemIndex = pNMItemActivate->iItem;
BOOL bCurrentCheckState = GetCheck(nItemIndex);
SetCheck(nItemIndex, !bCurrentCheckState);
*pResult = 0;
}
I'm writing this without testing though, so you'll have to make sure that it doesn't conflict with the handler for clicks on the check box iteself.
How can I make the command button in my VC++ 6.0 dialog visible or invisible on load?
From the resource editor once you select the button, you can see its properties in the properties window. Here you can set the visible property to true / false. (assuming this functionality is present in 6.0 - i use 2003 now and cannot remember if this used to be present in 6.0)
Add CButton variable
If you want to dynamically change the buttons visibility during load, add a variable for your button using the MFC class wizard. (you are lucky to have this - this wizard seems to have been removed from Visual Studio .NET)
Override CDialog InitDialog
Next override the initdialog function of your dialog box and then once the base InitDialog function has been successfully called, set the buttons showwindow property to SW_HIDE / before showing the dialog box.
Code
BOOL CMyDialog::OnInitDialog()
{
CDialog::OnInitDialog();
if (ConditionShow)
m_MyButton.ShowWindow(SW_SHOW);
else
m_MyButton.ShowWindow(SW_HIDE);
return TRUE;
}
You can also do it without adding a CButton variable - just call
In the OnInitDialog method of the window containing the button/control, put in code:
CWnd *wnd = GetDlgItem (YOUR_RESOURCE_NAME_OF_THE_BUTTON)
wnd->ShowWindow(SW_SHOW) or SW_HIDE
What do you mean by 'commnad button' exactly ?
Anyway, you need to obtain the handle of the button then call ShowWindow function:
BOOL prevState = ShowWindow( itemHandle, SW_HIDE );
Only use
ShowDlgItem(Your_DLG_ITEM_ID,1); // visible = true
ShowDlgItem(Your_DLG_ITEM_ID,0); // visible = false