MSDN is awkward to navigate. The cryptic URLs don’t help either.
This is a listing of refs that I don’t want to lose or spend time looking for again:
- how do I get the width and height of a window?
RECT r ; GetClientRect( hwnd, &r ) ; int width = r.right - r.left ; // OR GetWindowRect( hwnd, &r ) ; width = r.right - r.left ;
- Given the mouse click coords in wparam, how do I get the click coordinates INSIDE my window, relative to ITS top corner?
- How do I keep the user’s mouse from exiting my window?
- Given a HWND, how do I get all of its child windows?
EnumChildWindows(). Use is a bit complicated (callbacks and all), but it works.
You can hittest using PtInRect()
Here’s a GDI+ hit test ref as well
How do I get the HWND of the window the user clicked on?
Very useful are:
How do I change the z-order of my window?
- What’s the difference between HWND_TOP and HWND_TOPMOST?
How can I SIMULATE an input event to the Windows O/S?
- secrets of the system tray
Straight msdn refs
Mar 2 09
GetCurrentDirectory, kind of cool, and SetCurrentDirectory, which sets the running directory of the calling process, something I must label as “cooler still”.
- GetDiBits function, which lets you get the “internal” data of a HBITMAP that you have. Very handy if trying to save some image from the clipboard to disk.
Mar 1 09
PrintWindow for taking a screenshot
- How Do I in Visual C++. Amazingly complete article about how to USE visual studio
- SHUT ‘EM DOWN!. How to shut down or restart windows from your program.
- FormatMessage(), used to get text description of error codes from GetLastError()
- Winsock error codes
- Synchronization for multithreaded programming
- LocalAlloc(), a function I stumbled upon but haven’t used yet, and Heap functions.
- All about the Console: including AttachConsole() function
- Root of the “Windowing” tree
- The CreateWindow() function
- All of the WS_ Window styles
WS_BORDER WS_CAPTION WS_CHILDWINDOW WS_MAXIMIZEBOX WS_MINIMIZEBOX WS_OVERLAPPED WS_OVERLAPPEDWINDOW WS_POPUP WS_POPUPWINDOW (and more!)
- The CreateWindowEx() function
- All of the EXtended window styles such as WS_EX_ACCEPTFILES (just scroll down a bit when you get to the article)
- All of the CS_ class styles
CS_BYTEALIGNCLIENT CS_BYTEALIGNWINDOW CS_CLASSDC CS_DBLCLKS CS_DROPSHADOW CS_GLOBALCLASS CS_HREDRAW CS_NOCLOSE CS_OWNDC CS_PARENTDC CS_SAVEBITS CS_VREDRAW
- A particular article on The Old New Thing that explains CS_OWNDC really well.
Listing of Windows macros
GET_X_LPARAM GET_Y_LPARAM HIBYTE HIWORD LOBYTE LOWORD MAKELONG MAKELPARAM MAKELRESULT MAKEWORD MAKEWPARAM
Also don’t forget about the MAKEPOINTS macro.
- All of the WINDOW related WM_ notifications
WM_ACTIVATEAPP WM_CANCELMODE WM_CHILDACTIVATE WM_CLOSE WM_COMPACTING WM_CREATE WM_DESTROY WM_ENABLE WM_ENTERSIZEMOVE WM_EXITSIZEMOVE WM_GETICON WM_GETMINMAXINFO WM_INPUTLANGCHANGE WM_INPUTLANGCHANGEREQUEST WM_MOVE WM_MOVING WM_NCACTIVATE WM_NCCALCSIZE WM_NCCREATE WM_NCDESTROY WM_NULL WM_PARENTNOTIFY WM_QUERYDRAGICON WM_QUERYOPEN WM_SHOWWINDOW WM_SIZE WM_SIZING WM_STYLECHANGED WM_STYLECHANGING WM_THEMECHANGED WM_USERCHANGED WM_WINDOWPOSCHANGED WM_WINDOWPOSCHANGING
SC_CLOSE SC_CONTEXTHELP SC_DEFAULT SC_HOTKEY SC_HSCROLL SC_KEYMENU SC_MAXIMIZE SC_MINIMIZE SC_MONITORPOWER SC_MOUSEMENU SC_MOVE SC_NEXTWINDOW SC_PREVWINDOW SC_RESTORE SC_SCREENSAVE SC_SIZE SC_TASKLIST SC_VSCROLL
Menu notifications, such as WM_COMMAND
WM_COMMAND WM_CONTEXTMENU WM_ENTERMENULOOP WM_EXITMENULOOP WM_GETTITLEBARINFOEX WM_MENUCOMMAND WM_MENUDRAG WM_MENUGETOBJECT WM_MENURBUTTONUP WM_NEXTMENU WM_UNINITMENUPOPUP
Keyboard input notifications WM_
WM_ACTIVATE WM_APPCOMMAND WM_CHAR WM_DEADCHAR WM_HOTKEY WM_KEYDOWN WM_KEYUP WM_KILLFOCUS WM_SETFOCUS WM_SYSDEADCHAR WM_SYSKEYDOWN WM_SYSKEYUP WM_UNICHAR
Mouse input notifications WM_
WM_CAPTURECHANGED WM_LBUTTONDBLCLK WM_LBUTTONDOWN WM_LBUTTONUP WM_MBUTTONDBLCLK WM_MBUTTONDOWN WM_MBUTTONUP WM_MOUSEACTIVATE WM_MOUSEHOVER WM_MOUSEHWHEEL WM_MOUSELEAVE WM_MOUSEMOVE WM_MOUSEWHEEL WM_NCHITTEST WM_NCLBUTTONDBLCLK WM_NCLBUTTONDOWN WM_NCLBUTTONUP WM_NCMBUTTONDBLCLK WM_NCMBUTTONDOWN WM_NCMBUTTONUP WM_NCMOUSEHOVER WM_NCMOUSELEAVE WM_NCMOUSEMOVE WM_NCRBUTTONDBLCLK WM_NCRBUTTONDOWN WM_NCRBUTTONUP WM_NCXBUTTONDBLCLK WM_NCXBUTTONDOWN WM_NCXBUTTONUP WM_RBUTTONDBLCLK WM_RBUTTONDOWN WM_RBUTTONUP WM_XBUTTONDBLCLK WM_XBUTTONDOWN WM_XBUTTONUP
Each of those has descriptions of constants
MK_CONTROL MK_LBUTTON MK_MBUTTON MK_RBUTTON MK_SHIFT MK_XBUTTON1 MK_XBUTTON2
- The LoadImage() function, used to load an icon, cursor, animated cursor, or bitmap.
- Error handling functions, including functions like Beep() and FlashWindow()
- Control Library – use the menus at the left to find docs on Button, ComboBox, Trackbar, etc.
The predefined window classes, including
ANIMATE_CLASS DATETIMEPICK_CLASS HOTKEY_CLASS LINK_CLASS MONTHCAL_CLASS NATIVEFNTCTL_CLASS PROGRESS_CLASS REBARCLASSNAME STANDARD_CLASSES STATUSCLASSNAME TOOLBARCLASSNAME TOOLTIPS_CLASS TRACKBAR_CLASS UPDOWN_CLASS WC_BUTTON WC_COMBOBOX WC_COMBOBOXEX WC_EDIT WC_HEADER WC_LISTBOX WC_IPADDRESS WC_LINK WC_LISTVIEW WC_NATIVEFONTCTL WC_PAGESCROLLER WC_SCROLLBAR WC_STATIC WC_TABCONTROL WC_TREEVIEW
(MUST #include <commctrl.h> to use!)
Common Controls demo
zetcode has a good lesson on trackbar
sunjapan has a GREAT page on trackbars. Although this page is dated 1994, its still perfectly 100% relevant!
- PhysicalToLogicalPoint() function
- MSDN OpenGL examples from 1994!
Functions that GET things
- GetWindowLong(): For getting a property of a Window given its HWND.
- GetSysColor() function
- GetDlgCtrlID Function You can retrieve the identifier for a control by calling the GetDlgCtrlID function.
- Getting the HWND of a parent of a child control window using the GetParent() function
- Nate Robins’ SIGGRAPH 1997 Windows /OGL course notes
- C++ __try/__catch
- Keyboard input functions
- Winspector win 32 application inspector – like Spy++, only EXCELLENT!!
- Win32 hooks – this article is a bit of a clearer and more thorough explanation of what a hook is, and what it does.
- The SetWindowsHookEx() function
- The LISTING of all the hook functions YOU can write – (these are the HOOKPROC functions YOU’RE supposed to write, depending on what you’re hooking.)
- GetCurrentThreadId() – gets you the id of the thread that’s currently running THIS piece of code
TO DISCARD A MESSAGE THAT YOU’VE CAPTURED IN YOUR HOOK PROCEDURE: “The hook procedure returns FALSE to pass a message to the default dialog box procedure or TRUE to discard the message.”
I couldn’t find similar instruction in the SetWindowsHookEx() “HELP” file, nor in the “Win32 Hooks” article (all that article says is “Filters can tell Windows to discard the message.”) WHY DON’T THEY JUST SAY “Filters can tell Windows to discard the message BY RETURNING TRUE”? That would have saved me the minutes wasted searching.
- Hooks in ASSEMBLY LANGUAGE!. Now you’ve seen it all.
- All about DLL’s from C, C++ and C#
- Create your own cursor manually, in code (no use of “resources”).
- all about bitmap file storage, the BITMAPFILEHEADER struct, and the BITMAPINFOHEADER struct.
Recommended books for Win32 programming:
- “The Petzold”
- First few chapters of Mason McCuskey’s DirectX 8.0 book (the DirectX part is good too – slightly out of date for Direct3D, but it is still worth getting, in my opinion!) Try a gettextbooks.com search.
- First few chapters of Ernest Pazera’s “Isometric Game Programming with DirectX 7.0”*** THIS BOOK is severely outdated when it comes to DirectX, but the Win32 part is really well written and still relevant. It goes for as low as $3.70 right now on Amazon.com (used book sellers!). Try a gettextbooks.com search!
Another good book is Jeffrey Richter’s Windows via C/C++.
This is the 5th edition of a book that was formerly called “Programming Applications For Microsoft Windows” (in its 4th edition) and “Advanced Windows” (in its 3rd edition). Same book, different title each edition that comes out.
This is kind of what happened with Jeff Prosise’s Programming Windows with MFC — going for outrageous prices like $200.00 and such. Copies of the Windows 95 edition of the MFC book are available on Thriftbooks.com right now for $0.39!
- OpenGL functions on msdn.