0

How can I add syntax highlight for windows.h C/C++ apis and types?

All I've found is a tiny winapi syntax file here.

3

You've already found how to highlight these types from the link you've posted in your question; by adding these lines to after/syntax/c/winapi.vim (see How can I add additional syntax highlighting rules in my local vimrc? for more details on that):

syn keyword cppWINAPI SetWindowLong
syn keyword cppWINAPIConst WM_CREATE
syn keyword cppWINAPItype HGLOBAL

hi def link cppWINAPI Identifier
hi def link cppWINAPItype Type
hi def link cppWINAPIConst Constant

So all we need to do now is to populate this list with additional function, constants, and types.

For example, I found this Alphabetical list of Win32 and COM API in Windows 8.x apps. With some JS-fu in my console I got a space-separated list of all the functions:

$('#mainSection li a strong')
    .map(function() { return $(this).html() })
    .toArray()
    .join(' ')

Which I then copied & pasted in the after/syntax/c/winapi.vim file:

syn keyword cppWINAPI _IRDPSessionEvents AcquireSRWLockExclusive [..etc..]

This doesn't separate out functions, constants, and types though; and I have no idea how complete it is. But this is the basic procedure to make such a file.


If you want a more complete list then you can perhaps try using one of the answers in Win32 API to enumerate dll export functions? to export the information from the WinAPI libraries.

There is also the Windows API Index. It's split over a whole bunch of pages, but the layout seems fairly consistent. Extracting that would require a script and some work, but is probably doable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.