In MDI mode, Dynamic change menu caption which without ID - menu

The old question, is for menu on dialog, to change the menu caption which no id
How do I dynamic change MENU text which without ID
the code is
////////////////////////////////////////////////////////
//CMenu* pMenu = CMenu::FromHandle(GetSkinMenu(m_pMainWnd->m_hWnd))->GetSubMenu(1);
HMENU hMenu;
hMenu=LoadMenu(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDR_MENU_S8521));
//CMenu* pMenu = CMenu::FromHandle(hMenu);
CMenu* pMenu = GetMenu();
int i, nCou = pMenu->GetMenuItemCount();
UINT uID;
CString strMenu;
for (i = 0; i < nCou; i++)
{
uID = pMenu->GetMenuItemID(i);
if (uID == 0) // separator
{
//TRACE(_T("----------------------\n"));
continue;
}
//pMenu->GetMenuString(i, ss, MF_BYPOSITION);
if (uID == (UINT)-1)
{
//TRACE(_T("Popup '%s' "), ss);
if(i == 0)
{
strMenu = theApp.mLang.structMenuLang.strMenuFile;
}
if(i == 1)
{
strMenu = theApp.mLang.structMenuLang.strMenuSet;
}
if(i == 2)
{
strMenu = theApp.mLang.structMenuLang.strMenuLanguage;
}
if(i == 3)
{
strMenu = theApp.mLang.structMenuLang.strMenuHelp;
}
pMenu->ModifyMenu(i, MF_BYPOSITION|MF_STRING|MF_ENABLED, 0, strMenu);
//TRACE(_T("modified to '%s' "), ss);
}
//else
// TRACE(_T("Item '%s', ID=%d "), ss, uID);
//TRACE(_T("\n"));
}
//Invalidate(true);
//UpdateWindow();
this->SetMenu(pMenu);
Now I want to change the MID menu caption which also no id,
the keyword code is
this->SetMenu(pMenu);
then the menu will reflash. My question is On MDI Menu, how do I reflash the menu caption
, In out command window i find the TRACE message is right, but the UI no change.

ok, I get method to solve it using
CMenu menu;
menu.LoadMenu(IDR_MENU_MAIN);
AfxGetMainWnd()->SetMenu(pMenu);
AfxGetMainWnd()->DrawMenuBar();
pMenu->Detach();

Related

In MFC how to increase the time tooltips remain Visible

I am using below code to create tooltips.
m_ctrlToolTip.Create(this, TTS_ALWAYSTIP|TTS_BALLOON);
m_ti.cbSize = sizeof(TOOLINFO);
m_ti.uFlags = TTF_IDISHWND|TTF_TRACK|TTF_TRANSPARENT|TTF_ABSOLUTE;
m_ti.hwnd = m_hWnd;
m_ti.hinst = NULL;
m_ti.uId = (UINT)1;
m_ti.lpszText = "";;
m_ti.rect=CRect(0,0,0,0);
m_ctrlToolTip.SetMaxTipWidth(SHRT_MAX);
m_ctrlToolTip.SetDelayTime(TTDT_AUTOPOP,5000);
m_ctrlToolTip.Activate(TRUE);
void CLadIOView::OnMouseMove(UINT nFlags, CPoint point)
{
static CPoint prevPoint =0;
static CLadRemoteIOModule* pLastIO=NULL;
CLadRemoteIOModule* pLastIO1=pLastIO;
pLastIO=NULL;
bool bToolTipSet = false;
// Go thru each module already added
POSITION pos = gobjEztouchApp.m_objLadderLogic.m_objSysAttr.m_objRemoteIOModuleLst.GetHeadPosition();
for( ; pos != NULL; )
{
CLadRemoteIOModule* pIO = gobjEztouchApp.m_objLadderLogic.m_objSysAttr.m_objRemoteIOModuleLst.GetNext(pos);
// Get the rectangle for the module
CRect rectModule = GetIOModuleRect(pIO->m_nModulePosition);
if(!rectModule.PtInRect(pt)) continue;
pLastIO=pIO;
if(pLastIO1==pIO) break;
if(!m_bMouseDown && !m_bPlacingANewModule && prevPoint != pt)
{
CString sDescription, sPartNumber, sAddressRange;
GetIOModuleText2(pIO,sDescription, sPartNumber, sAddressRange);
sPartNumber.Remove('[');
sPartNumber.Remove(']');
CString sModuleDetails;
sModuleDetails.Format(_T("Position: M%d\nModule Type: %s\nModule Part No: %s"), pIO->m_nModulePosition+1, sDescription,sPartNumber);
if(pIO->GetIPSize() > 0)
sModuleDetails+=_T("\nInput Address: ")+ pIO->GetInputAdr()+_T(" - ")+pIO->GetEndInputAdr();
if(pIO->GetOPSize() > 0)
sModuleDetails+=_T("\nOutput Address: ")+ pIO->GetOutputAdr()+_T(" - ")+pIO->GetEndOutputAdr();
CPoint pp = pt-GetScrollPosition();
ClientToScreen(&pp);
m_ctrlToolTip.UpdateTipText(sModuleDetails,this,1);
m_ctrlToolTip.SendMessage(TTM_TRACKPOSITION, 0, (LPARAM)MAKELPARAM(pp.x, pp.y+16));//+16 to move the tooltip stem down
m_ctrlToolTip.SendMessage(TTM_TRACKACTIVATE, TRUE, (LPARAM)&m_ti);
//to track mouse leave abd there we can remove tooltip
TRACKMOUSEEVENT tk;
tk.cbSize = sizeof(tk);
tk.dwFlags = TME_LEAVE;
tk.hwndTrack = m_hWnd;
_TrackMouseEvent(&tk);
prevPoint = pt;
bToolTipSet = true;
}
bToolTipSet = true;
break;
}
if(!bToolTipSet)
{
m_ctrlToolTip.SendMessage(TTM_TRACKACTIVATE, FALSE, (LPARAM)&m_ti);
m_ctrlToolTip.UpdateTipText("",this,1);
m_ctrlToolTip.Pop();
}
The tooltip remains visible for very few seconds and then they disappear. I find this time too short to read some of the longer tooltips. Is there a way to increase the time they remain visible?
I tried to increase the time using setdelaytime function but it doesn't help me.
Thanks in advance.

Windows phone:Do not allow more than one dot in a textbox?

I am writing application in windows phone 8.
I need to provide a textbox which will allow user to enter only "Numbers" and if required, only one dot ".
I set <TextBox InputScope="Number" /> but it allow multiple dot.
How can i set single dot in textbox of windows phone?
Set an event that triggers everytime a text has change like this:
<TextBox x:Name="textBox1" TextChanged="textBox1_TextChanged" />
And then in the event function loop through the text, count the dots and if the dot count is higher than 1, delete the said dot.
EDIT: you said if I could provide a sample algorithm:
string str = textBox1.Text;
int dotCount = 0;
for (int i = 0; i < str.Length; i++)
{
if (str[i] == '.')
{
dotCount++;
if (dotCount > 1)
{
str.Remove(i, 1);
i--;
dotCount--;
}
}
}
This code is not working as it should so I made some improvements.. hope it helps! I'm using KeyUp but TextChange is also OK to use.
private void tbMainText_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
{
TextBox tb = (TextBox)sender; //Getting the textbox which fired the event if you assigned many textboxes to the same event.
string str = tb.Text;
int dotCount = 0;
for (int i = 0; i < str.Length; i++)
{
if (str[i] == '.')
{
dotCount++;
if (dotCount > 1)
{
str = str.Remove(i, 1); //Assigning the new value.
i--;
dotCount--;
}
}
}
tb.Text = str;
tb.Select(tb.Text.Length, 0); //Positioning the cursor at end of textbox.
}

As3 Text Manipulation - How to say "if charAt == Carriage Return"?

I currently have a form that disables a send button based on two textfields. The one field is a message box. I want to have it so that a person can't just put in a bunch of enters and spaces. I currently ahve a check for spaces, but charAt just returns a space :/ Here is what I want it to look like:
_sendComposeBtn.visible = true;
// if the length of the message is zero, don't let people send it
if (_messageLength == 0)
{
trace("hiding");
_sendComposeBtn.visible = false;
_realMessage = false;
}
_allSpaces = true;
// start with allSpaces true. If there is a nonspace (or non-enter character then hide send button
for (i = 0; i < _bigMessageTextField.length; i++)
{
if (_bigMessageTextField.text.charAt(i) != " " && _bigMessageTextField.text.charAt(i) != (ENTER_CHARACTER))
{
trace("not a space");
_allSpaces = false;
}
}
if (_allSpaces == true)
{
_sendComposeBtn.visible = false;
}
You can say:
_bigMessageTextField.text.charAt(i) != String.fromCharCode(13)

Read Check Box, Radio Button Name and values from PDF using iText Sharp

I have a fillable PDF contains CheckBoxes and RadioButtons and TextBox.
How do i get the CheckBox Name and its value also how do we know that it is a checkbox / Radio Button?
i'm using iTextSharp and have look at my below code
PdfReader pdfReader = new PdfReader(FileName);
pdfReader.SelectPages("37");
MemoryStream oStream = new MemoryStream();
PdfStamper stamper = new PdfStamper(pdfReader, oStream);
AcroFields form = stamper.AcroFields;
if (form.Fields.Count() > 0)
{
IDictionary<string,AcroFields.Item> oDic= form.Fields;
foreach (string FieldName in oDic.Keys)
{
//FieldName - CheckBox name; i need to confirm that is a Checkbox...
}
foreach (AcroFields.Item oItem in oDic.Values)
{
// how do we get check box values
}
}
The following code may help you out, if you still need it. It only works for AcroForms
int BUTTON = 1;
int CHECK_BOX = 2;
int RADIO_BUTTON = 3;
int TEXT_FIELD = 4;
int LIST_BOX = 5;
int COMBO_BOX = 6;
PdfReader pdfReader = new PdfReader(path);
AcroFields af = pdfReader.AcroFields;
foreach (var field in af.Fields)
{
bool isRadio = RADIO_BUTTON == af.GetFieldType(field.Key));
}
Edit:
Also, field.Key is the name of the field and field.Value is the value at it.
For checkboxes, if(field.Value == "Yes") then it is selected... if it is anything else, it is not selected.
Edit:
And I just found how tro get Radio Button options, if you are needing them.
myKey k = new myKey(field.Key, af.GetField(field.Key), af.GetFieldType(field.Key));
if (k.isRadio())
{
try { k.options.AddRange(af.GetAppearanceStates(k.key)); }
catch { }
}
Keys.Add(k);
Radio buttons, checkbox and buttons are all actually the same type of field but with different flags set. You can see the flags in the PDF Spec section 12.7.4.2.1 Table 226.
int ffRadio = 1 << 15; //Per spec, 16th bit is radio button
int ffPushbutton = 1 << 16; //17th bit is push button
For a given Field you want to get the Widgets associated with it. Usually this is just one but can be more so you should account for this.
PdfDictionary w = f.Value.GetWidget(0);
Button fields will have their field type (/Ft) set to /Btn so check for that
if (!w.Contains(PdfName.FT) || !w.Get(PdfName.FT).Equals(PdfName.BTN)) {continue;/*Skipping non-buttons*/ }
For the current Widget get the optional field flags (/Ff) value or use zero if it doesn't exist.
int ff = (w.Contains(PdfName.FF) ? w.GetAsNumber(PdfName.FF).IntValue : 0);
Then just some simple math:
if ((ff & ffRadio) == ffRadio) {
//Is Radio
} else if (((ff & ffRadio) != ffRadio) && ((ff & ffPushbutton) != ffPushbutton)) {
//Is Checkbox
} else {
//Regular button
}
Below is a full-working C# WinForm 2011 app targeting iTextSharp 5.2.0 that shows off all of the above looking at a file called Test.pdf living on your desktop. Just add some logic to the conditionals to handle each button type.
using System;
using System.IO;
using System.Windows.Forms;
using iTextSharp.text.pdf;
namespace WindowsFormsApplication3 {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e) {
var testFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Test.pdf");
PdfReader reader = new PdfReader(testFile);
var fields = reader.AcroFields;
int ffRadio = 1 << 15; //Per spec, 16th bit is radio button
int ffPushbutton = 1 << 16; //17th bit is push button
int ff;
//Loop through each field
foreach (var f in fields.Fields) {
//Get the widgets for the field (note, this could return more than 1, this should be checked)
PdfDictionary w = f.Value.GetWidget(0);
//See if it is a button-like object (/Ft == /Btn)
if (!w.Contains(PdfName.FT) || !w.Get(PdfName.FT).Equals(PdfName.BTN)) { continue;/*Skipping non-buttons*/ }
//Get the optional field flags, if they don't exist then just use zero
ff = (w.Contains(PdfName.FF) ? w.GetAsNumber(PdfName.FF).IntValue : 0);
if ((ff & ffRadio) == ffRadio) {
//Is Radio
} else if (((ff & ffRadio) != ffRadio) && ((ff & ffPushbutton) != ffPushbutton)) {
//Is Checkbox
} else {
//Regular button
}
}
this.Close();
}
}
}
C# with System.Linq included
for radio buttons , get which option is selected from all the options in radio form, print also all the choice options by their specified name in Adobe Acrobat Pro
AcroFields fields = reader.AcroFields;
List<string> fldNames = new List<string>(fields.Fields.Keys);
if (fldNames.Count > 0) //am gasit cel putin un acroform
{
foreach (string fldname in fldNames)
{
int tip = fields.GetFieldType(fldname);
if (tip == 3) //choice / radio
{
Console.WriteLine("radio form");
string[] valori = fields.GetListSelection(fldname);
foreach (string s in valori)
Console.WriteLine(s + " ");
Console.WriteLine("selected from radio form options");
string[] valori2 = fields.GetAppearanceStates(fldname);
//Console.WriteLine(valori2.Length);
var val2 = (from string c in valori2
where (c.ToLower().CompareTo("off") != 0)
select c).ToList();
if (val2.Count > 0)
foreach (string s2 in val2)
Console.WriteLine(s2 + " ");
}
}
}

Is there a way to use normal ASCII characters (like a comma) as wxWidgets menu accelerators?

I want a few menu entries that show accelerators that are normal keys, like the space-bar or comma key, but I don't want wxWidgets to make those accelerators itself (because then they can't be used anywhere in the program, including in things like edit boxes).
Unfortunately, wxWidgets insists on always making anything it recognizes in that column into an accelerator under its control, and simply erases anything it doesn't recognize.
I'm looking for some way to either put arbitrary text into the accelerator column (which I don't think exists, I've looked at the source code), or get 'hold of the accelerator table used for the menus so I can modify it myself (haven't found it yet). Can anyone point me in the right direction?
You can try wxKeyBinder. It allows you to bind hotkeys to commands (usually menu entries), save/load/add/remove/modify ... them easily
I couldn't find a way to access the menu's accelerator keys directly, but modifying the accelerator menu text works just as well. Here's the code I came up with:
In a header file:
class accel_t {
public:
// If idcount == -1, idlist must be null or terminated with a -1 entry.
accel_t(): mMenu(0) { }
accel_t(wxMenuBar *m, int *idlist = 0, int idcount = -1);
void reset(wxMenuBar *m, int *idlist = 0, int idcount = -1);
void restore() const;
void remove() const;
private: //
struct accelitem_t {
accelitem_t(int _id, wxAcceleratorEntry _key): id(_id), hotkey(_key) { }
int id;
wxAcceleratorEntry hotkey;
};
typedef std::vector<accelitem_t> data_t;
void noteProblemMenuItems(wxMenu *m);
static bool isProblemAccelerator(wxAcceleratorEntry *a);
wxMenuBar *mMenu;
data_t mData;
};
In a cpp file:
accel_t::accel_t(wxMenuBar *m, int *idlist, int idcount) {
reset(m, idlist, idcount);
}
void accel_t::reset(wxMenuBar *m, int *idlist, int idcount) {
mMenu = m;
mData.clear();
if (idlist == 0) {
for (int i = 0, ie = m->GetMenuCount(); i != ie; ++i)
noteProblemMenuItems(m->GetMenu(i));
} else {
if (idcount < 0) {
int *i = idlist;
while (*i != -1) ++i;
idcount = (i - idlist);
}
for (int *i = idlist, *ie = i + idcount; i != ie; ++i) {
wxMenuItem *item = mMenu->FindItem(*i);
if (item) {
wxAcceleratorEntry *a = item->GetAccel();
if (a != 0) mData.push_back(accelitem_t(*i, *a));
}
}
}
}
bool accel_t::isProblemAccelerator(wxAcceleratorEntry *a) {
if (a == 0) return false;
int flags = a->GetFlags(), keycode = a->GetKeyCode();
// Normal ASCII characters, when used with no modifier or Shift-only, would
// interfere with editing.
if ((flags == wxACCEL_NORMAL || flags == wxACCEL_SHIFT) &&
(keycode >= 32 && keycode < 127)) return true;
// Certain other values, when used as normal accelerators, could cause
// problems too.
if (flags == wxACCEL_NORMAL) {
if (keycode == WXK_RETURN ||
keycode == WXK_DELETE ||
keycode == WXK_BACK) return true;
}
return false;
}
void accel_t::noteProblemMenuItems(wxMenu *m) {
// Problem menu items have hotkeys that are ASCII characters with normal or
// shift-only modifiers.
for (size_t i = 0, ie = m->GetMenuItemCount(); i != ie; ++i) {
wxMenuItem *item = m->FindItemByPosition(i);
if (item->IsSubMenu())
noteProblemMenuItems(item->GetSubMenu());
else {
wxAcceleratorEntry *a = item->GetAccel();
if (isProblemAccelerator(a))
mData.push_back(accelitem_t(item->GetId(), *a));
}
}
}
void accel_t::restore() const {
if (mMenu == 0) return;
for (data_t::const_iterator i = mData.begin(), ie = mData.end(); i != ie;
++i)
{
wxMenuItem *item = mMenu->FindItem(i->id);
if (item) {
wxString text = item->GetItemLabel().BeforeFirst(wxT('\t'));
wxString hotkey = i->hotkey.ToString();
if (hotkey.empty()) {
// The wxWidgets authors apparently don't expect ASCII
// characters to be used for accelerators, because
// wxAcceleratorEntry::ToString just returns an empty string for
// them. This code deals with that.
int flags = i->hotkey.GetFlags(), key = i->hotkey.GetKeyCode();
if (flags == wxACCEL_SHIFT) hotkey = wx("Shift-") + wxChar(key);
else hotkey = wxChar(key);
}
item->SetItemLabel(text + '\t' + hotkey);
}
}
}
void accel_t::remove() const {
if (mMenu == 0) return;
for (data_t::const_iterator i = mData.begin(), ie = mData.end(); i != ie;
++i)
{
wxMenuItem *item = mMenu->FindItem(i->id);
if (item) {
wxString text = item->GetItemLabel().BeforeFirst(wxT('\t'));
item->SetItemLabel(text);
}
}
}
The easiest way to use it is to create your menu-bar as normal, with all accelerator keys (including the problematic ones) in place, then create an accel_t item from it something like this:
// mProblemAccelerators is an accel_t item in the private part of my frame class.
// This code is in the frame class's constructor.
wxMenuBar *menubar = _createMenuBar();
SetMenuBar(menubar);
mProblemAccelerators.reset(menubar);
It will identify and record the accelerator keys that pose problems. Finally, call the remove and restore functions as needed, to remove or restore the problematic accelerator keys. I'm calling them via messages passed to the frame whenever I open a window that needs to do standard editing.

Resources