C++ Questions

Pages: 1... 8910111213
Duthomhas
Some people might get intimidated by your knowledge base. Sometimes people have their own pet peeves and anal ways too. For instance, I like your alphabetizing of the include directives, but I like to do them in most to least used in my practice codes, just to make it easier to del the least used ones from the bottom. But on a real and big project I will alpha them.

George
Interesting stuff, but there aren't many people doing winAPI games anymore. Maybe incorporating some of the API's though and I am sure it is good coding practice in general. I know there are a lot of resources online, but is there a winAPI book that you particularly like?

I just posted in the Lounge asking about win gui's.

mbozzi
More reading homework...will do!
Might as well mention my other gripe, while we are on the topic. You know when you hoover over a function/class and it pops a window with the suggested syntax, I wish you can just copy the text and then you can reformat it yourself in a separate text file.

At times those can get disturbing to look at. I can only hope for that future upgrade.
A lot of tools will allow you to paste in the suggested syntax template and edit it to your liking. I think Ctrl+J or Ctrl+Space is the usual shortcut for that...

Also, I’m not always right.
there aren't many people doing winAPI games anymore.

Not to put too fine a point on it, but so what? I do what I do for my own enjoyment and edification.

I honestly don't give a flying rat's turd what others do when it comes to mucking around with games.

You asked, I answered.

The games are very basic yet they still give a semi-decent overview of creating the guts of a game. Yeah, I know the code is old and outdated. Meh.

Trying to update old code to modern coding standards is not something to be sneered at.

If you didn't know all games written for Windows DO use the WinAPI in some form or the other. Hidden by whatever framework used. DirectX, OpenGL, etc.

I just prefer to not let a framework obscure what is done. Raw and ground down to the bare metal.

For that matter ALL apps written for Windows use the WinAPI, hidden by some verdammt framework built upon the bones of the WinAPI.

I am a self-taught and still learning programming hobbyist. I have never tried to say I am something else. I know that I don't know a lot about programming.

/rant

A lot of tools will allow you to paste in the suggested syntax template and edit it to your liking. I think Ctrl+J or Ctrl+Space is the usual shortcut for that...

CTRL+J or CTRL+Space when a source/header file is active in the VS IDE editor pops up a HUUUUUGE list of what at first glance looks like all the C/C++ keywords available. From #define to ~ (dtor) allows you to paste a template version of whatever construct you want.

The issue as I see it you have to already know what you want to paste, so scrolling through such a massive list is a weeeeee bit counter-productive.
You can go to declaration cntrl+F12 or peek at def alt+F12.
is there a winAPI book that you particularly like?

I pointed to two a bit earlier that I like via that GitHub repo, on creating games.

For hard-core and serious old school Windows Desktop programming, "Programming Windows, Fifth Edition" by Charles Petzold. Written when Windows 98 was "da bomb."

https://www.amazon.com/Programming-Windows%C2%AE-Fifth-Developer-Reference/dp/157231995X/

I have the hardcover and paid considerably more than US$14 when I bought a couple of decades ago.

I also have his 6th edition and eeee-yuck! C# and .NET frameworks and the like.

For the most part the code shows that Petzold's WinAPI code still is remarkably backwards compatible, though there are a few features that won't work with modern PC hardware. One chapter expects 256 bit displays.

There are several attempts available at GitHub repos to revise and update the code to work with modern PCs and Windows.

There is also an old yet still good online resource for learning the basics of Windows Desktop programming when Win98 was King. theForger's Win32 API Tutorial.

http://www.winprog.org/tutorial/

Not to "toot my own horn (much)" I have a GitHub repo of that tutorial code updated to what I consider are modern Windows Desktop standards:

https://github.com/GeorgePimpleton/theForger-winapi-tutorial
1
2
3
4
5
#include <fstream>   // I personally prefer to order these alphabetically.
#include <iomanip>   // This makes it so much easier to see whether a
#include <iostream>  // required header is listed
#include <sstream>
#include <string> 

Well, hot diggity! I noticed something interesting in the Visual Studio IDE when editing code that contains header includes. Right click anywhere in the edit window and the pop-up menu has an option "#include Directives" that has a sub-menu to "Sort #include Directives".

So if your includes are something like this:
1
2
3
4
5
6
7
8
#include <windows.h>
#include "Resource.h"
#include "GameEngine.h"
#include "Bitmap.h"
#include "Sprite.h"
#include "Background.h"
#include "AlienSprite.h"
#include <cstdlib> 

can be quickly changed to this:
1
2
3
4
5
6
7
8
#include "AlienSprite.h"
#include "Background.h"
#include "Bitmap.h"
#include "GameEngine.h"
#include "Resource.h"
#include "Sprite.h"
#include <cstdlib>
#include <windows.h> 

Sadly this menu command doesn't work with import directives. :(
There's also flounder.com
http://www.flounder.com/

See MVP tips
Those look like cave paintings


Carve them into a wall of a cave and in a few hundred years you'll have archaeologists spending years trying to decipher them - no Rosetta stone! I wonder what translation they come up with?
Last edited on
You can look at the code and peek, but it is not exactly the same, for instance sometimes omits "inline". It would be nice to just hoover and QUICKLY copy/paste the text and not have to hit anything extra...minor wish.

George, that was a good find! Duthomhas was holding out on us...that's why he likes to alpha them cuz he can do it so easily! The darn IDE is in front of me all the time and I barely experiment with the functions and settings...on the to do list.

You know when you highlight a variable, all the other same named variable get highlighted in grey. Is there a way to more rapidly change ALL of the variables names at the same time while your changing the main highlighted variable name? CNTRL+H using the quick replace is the quickest way I know how.

But it would be nice to, highlight variable (all others get highlighted) then hit a button and all other var's get changed too while your changing the main one...without the quick replace pop up window.
I actually do almost all my programming in Notepad++, lol. It has nice tools to alphabetize based on columns, but honestly, it doesn’t take much to just stick the new #include line in the right spot.

The tougher thing to do is get rid of lines I no longer need. I don’t know of a tool that does that, but I’d be surprised if something like VS couldn’t do it for you.
CNTRL+H using the quick replace is the quickest way I know how.

Put the cursor on the name you want to change and press Ctrl-R twice in a row.

The tougher thing to do is get rid of lines I no longer need. I don’t know of a tool that does that, but I’d be surprised if something like VS couldn’t do it for you.

There is a tool called "Include What You Use".
https://github.com/include-what-you-use/include-what-you-use
I have heard of some projects that use it, but I've also heard a few very unfavorable reviews.

you can hide them in notepad++ or VS. Both allow hidden blocks of code that are 'collapsed' and can be opened or closed if you need to get at it but its not in your way as you work.

If you just want it to not be compiled, switches of course but that gets old.

The aggravation here is why I am a heretic that loathes (even when I use it) that freaking boost. Ill want one microscopic thing from their stuff and the next thing you know there are 10k items being compiled to get it because little thing uses little type that uses common header that uses everything...
The tougher thing to do is get rid of lines I no longer need. I don’t know of a tool that does that, but I’d be surprised if something like VS couldn’t do it for you.

VS requires a free extension to remove multiple blank lines when saving a document.

If you mean actual code lines the only "solution" I know of is highlight what you want to delete and then hit "delete".

I've done that more than a few times when I didn't want to get rid of the lines. :|

Put the cursor on the name you want to change and press Ctrl-R twice in a row

An alternate method for people who aren't keyboard warriors is to again put the cursor over what you want to rename and right-click. Choose the "Rename..." option.

Which also displays the Ctrl+R, Ctrl+R chord keyboard shortcut.
I meant prune #includes that the code doesn’t use.


I’m a HUGE fan of the old Borland “Classic” Modified WordStar command set. That is, I generally prefer to have a more extensive keyset to do stuff.

For example, if the editor doesn’t have an “insert line before current that leaves the cursor at the beginning of the new line” kind of command, I consider it sub-standard garbage for the hoi-polloi.

Hence my loathing of dumb editors like Notepad and gedit.
CNTRL+R, CNTRL+R feels more streamlined than my CNTRL+H, much thanks!

What ever happened to highlight the identifier and hit F2, then a text box comes up where you change the main variable name and like magic++ it changes everywhere? Not that I ever got to use it, but was it removed from VS2022?
I meant prune #includes that the code doesn’t use.

It turns out that can be done in VS.

Configure C/C++ Include Cleanup in Visual Studio
https://learn.microsoft.com/en-us/cpp/ide/include-cleanup-config?view=msvc-170

Enabling it can be configured to assist for removal and addition of #includes.
SubZeroWins wrote:
What ever happened to highlight the identifier and hit F2

MS has quietly removed a few things over the years that cause problems.

Finding and replacing a variable name like that is not actually a simple task. To do it properly would require, essentially, compiling the entire program into an ASL tree, then frobbing the linker in weird ways, then working backwards from there. Anything less leads to surprising errors in places people don’t expect. For large mission-critical projects that’s a no-no.

Various text editors (like Notepad++) can still do it for you, but it is worth your time to look at each change as you make it.
Maybe the F2 could have had dual functionality, act like before when the task is simple enough and the variables all local or else bring up the quick replace window when the variables are spread out. You have to admit though, that it would have felt good to have had it if things went well. I wouldn't even bring up a pop-up with the F2, just force lock you into the main identifier selection and expand/contract it according to new text (esc to cancel change)....oh it would have felt SO GOOD and QUICK!

Another good find George, although I would have preferred a CNTRL+Shift+# key (or CNTRL+3), with window pops that show various warnings and check boxes with a clean up button. Sometimes you have includes that you add to program later or toward the end and want to cleanup others. Constant warnings could distract and you play tug-of-war with varying desires. For me, the CNTRL+Shift+# would have been more streamlined, plus the quick combo keys makes sense.
Last edited on
Various text editors (like Notepad++) can still do it for you, but it is worth your time to look at each change as you make it.

Using Ctrl+R,Ctrl+R in VS pops up a dialog that lets you select how extensive the search will be. At Project or Solution level. You can then preview the changes that are scheduled to happen in all the targeted files, and after reviewing the changes are acceptable hit Apply. The IDE then changes all instances and displays all the items changed in the output window. Save the changed files and you are good to go.

Having to manually type a two command chord to change an identifier name ensures it is less likely to be accidentally activated.

Ctrl+R, Ctrl+R has been a VS standard for rename refactoring since VS 6, there are several different keystroke commands for different preset profiles.

Sure, it is possible to change the shortcut for a rename if someone really wants to.
Pages: 1... 8910111213