Is there some way to get all control IDs of current MFC dialog box? (to change WindowText of all controls)
You can do something like that:
for(CWnd* pWnd = GetWindow(GW_CHILD); pWnd != NULL; pWnd = pWnd->GetWindow(GW_HWNDNEXT))
{
pWnd->SetWindowText(_T("MyText"));
}
Of course, you can check ID or type of control id if you need.
Related
I want to create a simple MFC application which uses the RTL property to display a tooltip with the given Arabic text content for an edit box in the application dialog.
My code looks like this:
HWND CMFCApplicationDlg::CreateToolTip(HWND hWnd, LPCTSTR szText){
hWndTT = CreateWindowEx(NULL, TOOLTIPS_CLASS, NULL,
WS_POPUP | TTS_ALWAYSTIP | TTS_BALLOON,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
m_hWnd,
NULL,
GetModuleHandle(NULL),
NULL);
if(!hWndTT)
{
return NULL;
}
if (szText == NULL)
{
::DestroyWindow(hWndTT);
hWndTT = NULL;
return NULL;
}
// Set up the tool information. In this case, the "tool" is the entire parent window
toolItem.cbSize = sizeof(toolItem);
toolItem.uFlags = TTF_IDISHWND | TTF_SUBCLASS | TTF_RTLREADING;//Setting RTL flag here
toolItem.hwnd = m_hWnd;
toolItem.hinst = GetModuleHandle(NULL);
toolItem.lpszText = (wchar_t *)szText;
toolItem.uId = (UINT_PTR)hWnd;
::GetClientRect(hWnd, &toolItem.rect);
// Associate the tooltip with the tool window
LRESULT result = ::SendMessage(hWndTT, TTM_ADDTOOL, 0, (LPARAM)&toolItem);
return hWndTT;
}
I'm calling this function from OnInitDialog() method this way:
CreateToolTip((HWND)GetDlgItem(IDC_EDIT_DUMMY), L".استخدم 2 من المرات في اليوم");
Here IDC_EDIT_DUMMY is the ID for the edit box that I am trying to attach the tooltip with. But for some reason, the application doesn't display the tooltip at all. Where am I going wrong?
The MFC has it's own tooltip implementation. May be it is easier to use this instead of using the plain Win32 tooltips.
You can use CWnd::EanableTooltips to activate it. The MSDN doku (see link contains a full sample)
Also code project has a sample for it.
im trying to follow this, but got no luck. I'm using treeItem or Choicegroup and it can be selected but can't be clicked, like when clicked, it will go to the next page.
I don't wanna use X and Y coz my Item is dynamic which it was generated through XML. therefore, the item location will be changed. I want a touch pointer for a specific item like the choice group that Im using.
http://www.enough.de/products/j2me-polish/documentation/lush-ui/touch-support.html#gesture-click
You have Choicegroup and you want that on click of item it should go to next page then:
you can use :
choicegroupname.addCommand(command of Command.OK type, say commandOpen);
then,you can set setItemCommandListener to commandOpen and in commandAction you can traverse choicegroup so that you can get focused index and you do your code there,then break.Hope this helps.
you can do this like:
commandOpen.setItemCommandListener(new ItemCommandListener() {
public void commandAction(Command cmd, Item arg1) {
//size will be count of items
for(int i=0 ; i < size ; i++){
if(choicegroupname.focusedIndex== i){
//Do your code
return;
}
}
}
});
I am trying to disable the user's ability to alter the state of a checkbox in a List Control. I am currently changing the state pragmatically. I already handle the LVN_ITEMCHANGED message, and trying to alter the state there isn't an option due to the layout of the rest of the program. I have also tried doing a HitTest when the user clicks in the List Control and simply resetting the checkbox there but that isn't giving me the exact results I am looking for.
Is there a specific message sent or a function I can override when the user clicks the checkbox itself? I would just like to override the handler or catch the message so that it doesn't go anywhere.
Solution:
I ended up removing the LVS_EX_CHECKBOXES flag and created my own implementation. That way the there is only one way to change the icons. Reading the link from the previous question gave me an idea to set a "busy" flag, otherwise I would get stack overflow errors.
// In my dialog class
m_CListCtrl.SetImageList(&m_ImgList, LVSIL_SMALL); // Custom checkboxes (only two images)
// ...
void CMyDialog::OnLvnItemchangedList(NMHDR *pNMHDR, LRESULT *pResult)
{
if(busy) { return; }
// ....
}
// When calling the SetCheck function:
busy = TRUE; // Avoid stack overflow errors
m_CListCtrl.SetCheck(index, fCheck);
busy = FALSE;
// I derived a class from CListCtrl and did an override on the get/set check:
class CCustomListCtrl : public CListCtrl
{
BOOL CCustomListCtrl::SetCheck(int nItem, BOOL fCheck)
{
TCHAR szBuf[1024];
DWORD ccBuf(1024);
LVITEM lvi;
lvi.iItem = nItem;
lvi.iSubItem = 0;
lvi.mask = LVIF_TEXT | LVIF_IMAGE;
lvi.pszText = szBuf;
lvi.cchTextMax = ccBuf;
GetItem(&lvi);
lvi.iImage = (int)fCheck;
SetItem(&lvi);
return TRUE;
}
// Just need to determine which image is set in the list control for the item
BOOL CCustomListCtrl::GetCheck(int nItem)
{
LVITEM lvi;
lvi.iItem = nItem;
lvi.iSubItem = 0;
lvi.mask = LVIF_IMAGE;
GetItem(&lvi);
return (BOOL)(lvi.iImage);
}
}
This is not as elegant as I had hoped, but it works flawlessly.
I was creating vs++ code using MFC framework .I have a Cedit Box named "IDC_EDIT1" in the form.Can anybody tell me how to check if the edit box is empty or not?
CEdit *editBox = (CEdit *) GetDlgItem(IDC_EDIT1);
if(editBox == NULL)
return;
CString str;
editBox->GetWindowTextW(str);
if(str.IsEmpty())
{
}
You can use the WM_GETTEXTLENGTH message:
int length = SendMessage(hwnd,WM_GETTEXTLENGTH,0,0);
if(length == 0)
{
MessageBox(0,"The edit box is empty.",0,0);
}
it's a calculator programme and I was checking on button press whether edit box control is empty or not.
The IDC_Display(Edit control) is connected to variable m_Display(cEdit Type)
I took another variable cString Type (m_TrialString). declare this on class definition just below m_Display.
on Button click event you write:
void CNewCalculatorDlg::OnBnClickedButton1()
{
m_Display.GetWindowText(m_TrialString);
if (m_TrialString.IsEmpty())
AfxMessageBox(_T("The CString is EMPTY"),MB_OK);
else
AfxMessageBox(_T("The CString is NOT EMPTY"), MB_OK);
}
Using Windows Forms or WPF I can open a dialog window by calling ShowDialog. How can I do that using Gtk#?
I tried just making the Window modal, but although it prevents the user from interacting with the calling window it does not wait for the user to close the dialog before running the code after ShowAll().
Instead of using a Gtk.Window, use Gtk.Dialog, then call dialog.Run (). This returns an integer value corresponding to the ID of the button the user used to close the dialog.
e.g.
Dialog dialog = null;
ResponseType response = ResponseType.None;
try {
dialog = new Dialog (
"Dialog Title",
parentWindow,
DialogFlags.DestroyWithParent | DialogFlags.Modal,
"Overwrite file", ResponseType.Yes,
"Cancel", ResponseType.No
);
dialog.VBox.Add (new Label ("Dialog contents"));
dialog.ShowAll ();
response = (ResponseType) dialog.Run ();
} finally {
if (dialog != null)
dialog.Destroy ();
}
if (response == ResponseType.Yes)
OverwriteFile ();
Note that Dispose()ing a widget in GTK# doesn't Destroy() it in GTK# -- a historical design accident, preserved for backwards-compatibility. However, if you use a custom dialog subclass you can override Dispose to also Destroy the dialog. If you also add the child widgets and the ShowAll() call in the constructor, you can write nicer code like this:
ResponseType response = ResponseType.None;
using (var dlg = new YesNoDialog ("Title", "Question", "Yes Button", "No Button"))
response = (ResponseType) dialog.Run ();
if (response == ResponseType.Yes)
OverwriteFile ();
Of course, you could take it a step further and write an equivalent of ShowDialog.
I'm trying to create a more complex dialog, one that doesn't have windows - it's a search dialog with a completion treeview nested in a scrollview, and is closed with Enter or Escape.
Here's how I've figured you put together the mechanics of a modal dialog manually:
Define a property on your dialog that indicates whether it is completed or not. I'm calling mine ModalResult, an enum with values None, OK and Cancel.
Ensure you have the parent window of the dialog handy (dialogParent below)
Sample code:
// assuming Dispose properly written per #mhutch
using (window = new MyDialogWindow())
{
window.TransientFor = dialogParent;
window.Modal = true;
window.Show();
while (window.ModalResult == ModalResult.None)
Application.RunIteration(true);
// now switch on value of modal result
}
Note however this Ubuntu bug with overlay scrollbars. I don't use them and my app is for personal use, but YMMV.
I implemented the following method on my Gtk.Dialog:
public ResponseType ShowDialog()
{
List<ResponseType> responseTypes = new List<ResponseType>
{
// list all the ResponseTypes that you have buttons for
// or that you call this.Respond(...) with
ResponseType.Ok,
ResponseType.Cancel
};
this.Modal = true;
// start with any ResponseType that isn't contained in responseTypes
ResponseType response = ResponseType.None;
while (!responseTypes.Contains(response))
{
response = (ResponseType)this.Run();
}
this.Destroy();
return response;
}