When I hover my cursor on a function called in my code in Visual studio 2012, a small box pops up to show its declaration. How let this work for constructors?
Function(1, 2); // Hover on Function
MyClass a(1, 2); // Hover on a or MyClass or use any shortcut key
The problem is C++'s syntax for constructor calls. It works fine with normal methods because they look like method calls. Constructor calls are all mixed up with the object declaration, and when you hover over them, VS just gives you a tooltip with the object's declaration because it assumes that's what you want.
Hovering over the text gets you the same tooltip as if you had invoked the "Display Quick Info" command (Ctrl+K, Ctrl+I).
But there is also the "Display Parameter Info" command, invoked with Ctrl+Shift+Space, that will display the information you're interested in for constructors.
The trick is that you have to invoke the command with the caret inside of the parentheses. It won't work when the caret is somewhere within the identifier.
Related
Is there a quicker way to copypaste C++ pointers from Visual Studio's Watch window into a conditional breakpoint?
Context: My pointer values change each time I restart my application, so I need to update the address in my conditional breakpoint.
If I have a watch for this, copypasting it gives something like this:
+ this 0x000001287234a8c0 {mTick=2994 mTime=0.00000000 ...} AnimComponent *
When I right click on this, there's a "Copy Value" option, but it copies that {} block too:
0x000001287234a8c0 {mTick=2994 mTime=0.00000000 ...}
So my current process to copy my this watch's pointer value:
Click on this
Ctrl-C
Edit conditional breakpoint
Ctrl-v, remove the {} block, and add a == after this
I'm using C++, so I can't use the "Make Object ID" feature.
Watch Window
Use (void*)this in the watch window to prevent the {} block and make "Copy Value" copy only the number.
Keyboard Shortcut
Open Tools > Customize > Keyboard
Search for "CopyValue" and you should find DebuggerContextMenus.AutosWindow.CopyValue. Map a keyboard shortcut to it and you can copy values with only two steps: click + keyboard.
If you use Ctrl-Shift-C to copy, be sure to remove that shortcut from View.ClassView or it will interrupt your copying.
I am making a Visual Studio MFC C++ App, and I am having a (hopefully) small problem.
I have an Edit Control text box with ID txtInputBox, and it has a value C-String variable m_inputText assigned to it. After I do a SetDlgItemText(txtInputBox, L"Hello World"); the cursor moves to the front of the text, before the 'H'. How would I get the cursor to be at the end (after the 'd') right after doing a SetDlgItemText?
I read of a SetSel method, but don't know how to implement it if that's the right one.
CEdit control MFC, placing cursor to end of string after SetWindowText
What I have is:
someDlg::someFunction() //this is used in an EN_CHANGE event
{
//some logic stuff to get a result string
SetDlgItemText(txtInputBox, L"Hello World");
//need it to set the cursor to the end
//I tried these, but it didn't recognize (expression must have class type?)
//txtInputBox.SetSel(0, -1);
//txtInputBox.SetSel(-1);
}
void someDlg::EnChangetxtinputbox()
{
someFunction();
}
you said txtInputBox is the ID to your edit control (which should be written like so: IDC_NAME), you can pass IDs to SetDlgItemText.
what they are refering to in the link you posted is a member variable, you can't pass a member variable to SetDlgItemText. you can add a variable to a control by right clicking it in editor and clicking "Add variable".
I'm porting an MFC application from VC6 (MFC42.dll) to Visual Studio 2017. Everything else built just fine except the calls to the fn CWnd::SubclassCtl3d(). I googled to get this fn's documentation but could not get anything useful.
With which API/member fn in VS2017's MFC I can replace the calls to this fn?
The descriptive comment about this calls says this:
// Since this window is really an edit control but does not
// have "edit" as its class name, to make it work correctly
// with CTL3D, we have to tell CTL3D that is "really is" an
// edit control. This uses a relatively new API in CTL3D
// called Ctl3dSubclassCtlEx.
and then the call is made like so:
pEdit->SubclassCtl3d(CTL3D_EDIT_CTL);
pEdit is a pointer to a CEdit object (and CEdit derives from CWnd).
I have a CDialog contains many CEdit objects. They all have to do similar operations when kill focus (for example: when focus is killed the edit box text's is changed).
I can define the dialog's message map this way:
ON_EN_KILLFOCUS(ID1, kf1)
ON_EN_KILLFOCUS(ID2, kf2)
ON_EN_KILLFOCUS(ID3, kf3)
ON_EN_KILLFOCUS(ID4, kf4)
and all kf function will call a common function:
CommonFunction(CEdit* editBox)
But is there a way to transfer the edit box in the kf function itself? I mean to define it this way:
ON_EN_KILLFOCUS(ID1, kf(ID1))
ON_EN_KILLFOCUS(ID2, kf(ID2))
ON_EN_KILLFOCUS(ID3, kf(ID3))
ON_EN_KILLFOCUS(ID4, kf(ID4))
or another way.
NOTE: I use Visual C++ 6.0 ('98 edition)
You can use ON_CONTROL_RANGE in the message map to dispatch all of the messages to the same function. To do this it is necessary to assure that the IDs are in a continuous range. (Edit resource.h if necessary.)
ON_CONTROL_RANGE(BN_CLICKED, IDC_RADIO_DRAWALL, IDC_RADIO_DRAWBEST, OnRadioBtnDraw)
void CVisualPPView::OnRadioBtnDraw(UINT nID)
{
}
After working in C# for years, I've returned to an old MFC application I wrote. But it looks like I need a refresher on a few things.
I added a check box control to an existing dialog box. I then used Class Wizard to add a non-control variable of type bool. The variable was created as expected.
However, I see no entry was added to the DoDataExchange() method. And when I tried adding it manually:
DDX_Check(pDX, IDC_PRINT_SUMMARY, m_bPrintSummary);
I get the IntelliSense error:
a reference of type "int &" (not const-qualified) cannot be initialized with a value of type "bool"
1. Why wasn't an entry in DoDataExchange() created for me when I added the variable?
2. If DDX_Check() expects and int &, why did Class Wizards default to type bool for a checkbox value?
A check box can be one of three values, hence the need for the int.
BST_CHECKED - Button is checked.
BST_INDETERMINATE - Button is grayed, indicating an indeterminate state (applies only if the button has the BS_3STATE or BS_AUTO3STATE style).
BST_UNCHECKED - Button is cleared
As to why it's not auto editing the DoDataExchange, it's probably an issue with the C++ formatting of your class.