What’s an alternative to GWL_USERDATA for storing an object pointer?

SetWindowLongPtr was created to replace SetWindowLong in these instances. It’s LONG_PTR parameter allows you to store a pointer for 32-bit or 64-bit compilations. LONG_PTR SetWindowLongPtr( HWND hWnd, int nIndex, LONG_PTR dwNewLong ); Remember that the constants have changed too, so usage now looks like: SetWindowLongPtr(hWnd, GWLP_USERDATA, this); Also don’t forget that now to retrieve the … Read more

Programming In C + Win API: How To Get Windows 7 Look For Controls?

That’s how the controls looked back in the 1990s, before themes (visual styles) were invented. As you’ve noticed, modern buttons are now painted all fancy-pants with gradients and throbbing and all that. But for backwards-compatibility reasons, you have to specifically request that your controls get that treatment, or they’ll fall back to the legacy style. … Read more

RegSvr32 exit codes documentation?

The exit codes are not documented. The documentation is here: https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/regsvr32 However, the source code for a version REGSVR32.EXE is shipped with Visual Studio 2008. This gives its version as 4.0.0, so is not the same as the one shipped with windows, which reports version 6. http://msdn.microsoft.com/en-us/library/ms177531(v=vs.90).aspx A quick look shows these: #define FAIL_ARGS 1 … Read more

How do I find position of a Win32 control/window relative to its parent window?

The solution is using the combined power of GetWindowRect() and MapWindowPoints(). GetWindowRect() retrieves the coordinates of a window relative to the entire screen area you see on your monitor. We need to convert these absolute coordinates into relative coordinates of our main window area. The MapWindowPoints() transforms the coordinates given relative to one window into … Read more

How do you programmatically resize and move windows with the Windows API?

For flicker-free, simultaneously positioning two (or more) windows, your best bet is to use BeginDeferWindowPos(), DeferWindowPos() and EndDeferWindowPos(). In your case, since you’re moving two at the same time, this is your best bet. Three older, simpler functions you might also consider are SetWindowPos(), MoveWindow() and AdjustWindowRectEx().

Should I use _T or _TEXT on C++ string literals?

A simple grep of the SDK shows us that the answer is that it doesn’t matter—they are the same. They both turn into __T(x). C:\…\Visual Studio 8\VC>findstr /spin /c:”#define _T(” *.h crt\src\tchar.h:2439:#define _T(x) __T(x) include\tchar.h:2390:#define _T(x) __T(x) C:\…\Visual Studio 8\VC>findstr /spin /c:”#define _TEXT(” *.h crt\src\tchar.h:2440:#define _TEXT(x) __T(x) include\tchar.h:2391:#define _TEXT(x) __T(x) And for completeness: C:\…\Visual Studio … Read more

How to change menu hover color

You are using the MenuStrip class. You can override its renderer. Here’s an example, pick your own colors please. public partial class Form1 : Form { public Form1() { InitializeComponent(); menuStrip1.Renderer = new MyRenderer(); } private class MyRenderer : ToolStripProfessionalRenderer { public MyRenderer() : base(new MyColors()) {} } private class MyColors : ProfessionalColorTable { public … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)