Add line to comment in Visual Studio C++ - c++

I'm looking for something rather specific.
Let's say I define something like a variable, and add a comment to it.
#define ARDUINO_READ_Q0 //Read pins 22-29
Now, any time I start typing ARDUINO_READ_Q0, it pops up in Visual Studio's list of available values, and when you hover over it, it comes up with a tooltip saying "Read pins 22-29"
Is there any way to add a line to this tooltip? I thought of something like this:
#define ARDUINO_READ_Q0 /* Read pins 22-29
Return 1B */
However, I would prefer for it to remain on a single line when I define it.
To give you an idea of what I'm trying to do, imagine something looking like this:
#define ARDUINO_READ_Q0 // Read pins 22-29 /n Return 1B
This way I can say "next line" without making the mess of having two lines per #define.
It's sort of a formatting preference. I'm about to have a lot of #defines.

If you are using Visual Studio 2013 there are special XML tags that you can use to do this.
/// <summary>Read pins 22-29</summary>
#define ARDUINO_READ_Q0
This will display "Read pins 22-29" in the Intellisense tooltip when you hover the ARDUINO_READ_Q0.
You can find more documentation details on MSDN:
http://msdn.microsoft.com/en-us/library/ms177227.aspx
http://msdn.microsoft.com/en-us/library/ms177226.aspx
Note: This may work on older version of Visual Studio but I only have 2013 have on my laptop at the moment.

Related

Make/trick Visual C++ into indenting macros structure properly

Consider these macros
#define BEGIN(Parent) void Process(){
#define ELEMENT(Elem) RegisterElement(Elem);
#define END }
When using them, Visual Studio will not recognize ELEMENT as part of a child code block and thus not indent it properly
BEGIN(ParentClass) <--- hit ENTER here and carret will go below `B` in begin, with no indentation
ELEMENT(m_member)
END
Is there a way to trick Visual Studio, as in a way I could code my macros or maybe some helpful pragmas so that Visual Studio recognizes the opening and closing scope of RegisterElement function and thus indend ELEMENT entries properly? Thanks
Use Code alignment extension for VS 2013/12/10
Here's url: https://visualstudiogallery.msdn.microsoft.com/7179e851-a263-44b7-a177-1d31e33c84fd
From Edit->Code Alignment menu, select 'Align from caret'

Resource.rc Windres Syntax Error (Mingw)

I got a project from MS VS, and at the moment I'm migrating it to compile using gcc for Windows.
The C code is completely ported, but I'm having a problem using windres to compile the projet resources.
I'm having a syntax error, reported by windres, at those single lines:
CONTROL "Tab1",IDC_FILETAB,"SysTabControl32",TCS_BOTTOM,0,1,336,194
CONTROL "Tab1",IDC_KEYS,"SysTabControl32",TCS_BOTTOM,27,111,73,6
All others use of Control, with similar syntax, works as expected...
According with http://cygwin.com/cygwin-ug-net/windres.html , the follow syntax is used for CONTROL:
CONTROL ["name",] id, class, style, x,y,w,h [,exstyle] [data]
CONTROL ["name",] id, class, style, x,y,w,h, exstyle, helpid [data]
At top of resource.rc I'm including afxres.h,winuser.h and windows.h .
Can any one give me a help? I don't have a clue about what to do....
BTW, if I comment those lines, all ends with no errors, but the executable cannot works properly.
Thanks
Edit: After more search on the internet.. I found that windres already had many problems with syntax accepted on windows resource compiler, mainly because some classes aren't visible for windres. So if any one know an alternative classes/id, or where it are defined to include, I can workaround it.
You might have copied the code happens all the time just open the code in a textviewer and change the format to plain text or edit and replace characters like " , ' etc.

Win32 C++ getting text from elements

While this question has probably been asked a thousand times before (pretty sure of it I have read a thousand answers). I still don't get it.
Lets say I have a function that creates a ComboBox like this:
scopeComboSelector=CreateCombobox(hwnd,
GetModuleHandle(0),
CBS_DROPDOWNLIST,
re,
IDCC_DROPDOWNLIST_SCOPE_SELECTOR,
_T("Scopes"));
Where "re" is a positioning rectangle. And IDCC_DROPDOWNLIST_SCOPE_SELECTOR (pretty long name) is the id of the combobox. Now the point is, I can actually fill this "drop down select list" but I have no clue as how I can simply get the currently selected value as a string.
I have seen about 10 ways to do it, which all give errors straight away (need to Convert to LPWSTR -> fixing results in more terror).
Maybe I'm just to used to Java where one can simply say:
textfield.getText();
How would one achieve this in Win32 C++ (microsoft visual studio)?
Edit
Code I've used:
char userName[_MAX_PATH+1];
GetDlgItemTextW(scopeComboSelector,
IDCC_DROPDOWNLIST_SCOPE_SELECTOR,
(LPWSTR)userName,
200);
Returns: userName == empty
Update
Now using: GetDlgItemText(). Debugger tells me the value of userName = ""
The documentation has a C style Windows 9x code example.
You need simply to replace C with C++ and Windows 9x silly T macros with wchar_t and friends.
It's always a good idea to read the documentation.

Creating Visual Studio Error List Messages

Is there any way to create a custom message in the Visual Studio error list? I'm looking at VS 2010 and 2012.
For generating errors, it's a simple #error text.
For generating warnings it's #pragma warning ("text").
For printing a message to the Output window, it's #pragma message("text")
There's little or no documentation on how to create a information message in the Error List. Anyone know if it is possible?
I'd prefer if no VS addons would be used, but if there is a way with those, that would be fine too.
Possibly this may help: Formatting the Output of a Custom Build Step or Build Event
or https://learn.microsoft.com/en-us/visualstudio/msbuild/msbuild-diagnostic-format-for-tasks?view=vs-2022
Formatting the Output of a Custom Build Step or Build Event
If the output of a custom build step or build event is formatted
correctly, users get the following benefits:
Warnings and errors are counted in the Output window.
Output appears in the Task List window.
Clicking on the output in the Output window displays the appropriate topic.
F1 operations are enabled in the Task List window or Output window.
The format of the output should be:
{filename (line# [, column#]) | toolname} :
[any text] {error | warning} code####: localizable string
And this macro is a possible implementation of what Rost linked to :
#define COMBINE_NAMES_HELPER_6(a,b,c,d,e,f) a##b##c##d##e##f
#define COMBINE_NAMES_6(a,b,c,d,e,f) COMBINE_NAMES_HELPER_6(a,b,c,d,e,f)
#define FILE_LINE_FUNC_STR(msg) ( COMBINE_NAMES_6(__FILE__, "(",STRING( __LINE__), "): ", __FUNCTION__, " "msg) )
#define COMPILER_MSG(msg) message FILE_LINE_FUNC_STR(msg)

Visual Studio 2010 C++ code formatter

I'm new to coding C++ programs in Visual Studio. When I am coding C# programs in VS, code formatter changes code that looked like this
for(int i= 0; i<(n+ m) ; i++){
}
into
for(int i = 0; i < (n + m); i++)
{
}
which is way easier to read. When I write the same thing in C++, nothing happens. I tried to select the text and press Ctrl+E, F, but that didn't work. Is there a way to improve the C++ code formatter in visual studio?
Visual Studio can't format C++-Code. Maybe there is a VS extension. I searched a long time, but never found a suitable one for free.
A very good, free, but not easy to use code formatter is GreatCode. Its a command line tool.
You can configure it as "External Tool":
After unpacking GreatCode on your HD just go Tools->External Tools->Add and insert the following settings...
Whenever you call that Tool, the actual opened file is being formatted.
You can configure GreatCode as you like in the gc.cfg. I tried many options, some are easy, some are complex.
If you want a Microsoft-like looking, just use my settings as a template and fine tune yourself:
-code_constructor_style-1
-code_split_fctdef_style-5
-code_split_decl_style-2
-overwrite_read_only-
-verbose-
-tab_out-
-space_if-
-space_return-
-space_fctcall_inparam-
-no-space_fctcall_firstparam-
-no-space_cast_after-
-space_affect_style-0
-space_autoaffect_style-0
-code_len-180
-code_keep_more_empty_lines-
-code_decl_access_to_type-
-code_decl_break_template-
-code_remove_return_paren-
-code_align_max_blanks-80
-code_class_access_eol_after-1
-code_class_access_eol_before-1
-code_split_fctcall_style-1
-code_constructor_style-1
-no-code_split_bool_before-
-no-stmt_concat_else_if-
-no-stmt_decl_remove_empty-
-no-stmt_concat_if_remove_empty-
-no-stmt_concat_else_if-
-stmt_force_brace-1
-stmt_break_dowhile-
-stmt_switch_style-1
-stmt_switch_eol-0
-stmt_class_indent-0
-stmt_static_init_style-2
-stmt_concat_inline_class-
-pp_align_to_code-
-pp_style-1
-pp_align_breakline-
-no-cmt_first_space_cpp-
-cmt_dont_modify-
-no-cmt_add_class_access-
-no-cmt_add_gc_tag-
-no-cmt_add_fct_def_class-
-no-cmt_decl_before-
-no-cmt_decl-
-no-cmt_first_line_break_first-
-no-cmt_first_line_break_last-
-no-code_split_bool_before-
-catch_eol_before-1
-no-stmt_decl_remove_empty-
-no-cmt_add_fct_def_class-
-no-cmt_add_class_access-
-no-stmt_break_alone-
-stmt_concat_inline_class-
-cmt_keep_cpp-
Good luck!
I use exactly the same approach as DirkMausF except the formatting tool itself. I would suggest you to use Artistic Style formatter:
http://astyle.sourceforge.net/
It is well documented and comes with a lot of predefined formatting styles so it is very easy to use.
If you have cash to spend, you might want to look in to Visual Assist. See also, this question.
For a long time, I was writing all the C++ code in Netbeans and I was compiling it in Visual Studio. Netbeans is formatting code perfectly (with ALT+SHIFT+F) and there are many formatting options.