What is the opposite of LVM_SORTITEMS?
A customer was using the LVM_SORTITEMS message to sort the items in a classic Win32 ListView control in response to the user checking a box called “Show sorted by date”. That part worked great. They...
View ArticleOn catching exceptions in PPL tasks
Say you want to catch exceptions that emerge from the Parallel Patterns Library (PPL) task class. Your initial inclination might be to write something like this: extern concurrency::task<int>...
View ArticleSpeeding up the insertion of a sorted (or mostly-sorted) key list into a...
Suppose you want to insert or emplace a bunch of items into a std::map, std::multimap, std::set, or std::multiset (collectively known as ordered associative containers), and you have the items in...
View ArticleOn creating (and using) a transforming iterator
The C++20 ranges library come with the ability to transform a view; that is, to provide a unary function that is applied to each element of a view, producing a new view. std::array<int, 2> a = {...
View ArticleDon’t name your header file security.h either
A customer found that the GetUserNameExW function suddenly disappeared. error C2065: 'NameSamCompatible': undeclared identifier error C3861: 'GetUserNameExW': identifier not found What happened? These...
View ArticleHow can I trigger a recalc of the mouse cursor after I changed some of my...
Some time ago, I described how to trigger a recalc of the mouse cursor after changing internal application state. In the bonus chatter, I noted that the cursor you set with SetCursor is used only when...
View ArticleGetting a strong reference from the this pointer too late
It is a standard pattern for functions that are coroutines to promote the this pointer to a strong reference (either a COM strong reference or a shared_ptr), so that the object won’t be destructed...
View ArticleOn writing functions that accept any specialization of a C++ template type
Suppose you want to write a template function that accepts any specialization of std::vector. Your first try would probably be something like this: template<typename Value> void...
View ArticleHow do I change the directory Windows uses for user profiles? revisited
Some time ago, I noted that you can use the ProfilesDirectory setting in your unattend file to move the directory that Windows uses for user profiles. The classic documentation has been updated to...
View ArticleC++/WinRT event handlers that are lambdas with weak pointers to the parent...
C++/WinRT provides multiple ways of auto-implementing delegates. // Function pointer e.add(&MyClass::StaticMemberFunction); // Raw pointer + non-static member function pointer e.add({ this,...
View Article