windows_programming_notes.nbk: Home | Index | Next Page: DefDlgProc | Previous Page: Creating Threads
Custom windows are windows you design. They can be either something generally useful, such as a grid; or something specific to a single program.
You will need a way to transfer data between your program as a whole and the window. It's possible to create custom messages with which to communicate with a custom window, mimicing the behaviour of the built in windows. It seems like a good idea because it's consistent with the native windows, but I doubt whether it's really worth the effort. It's easier and more efficient to create methods that communicate directly with the class holding the window's data.
Your windows will require a way to keep track of their state. If the window falls into the 'generally useful' catagory, you probably should have a way to associate separate state information with each window so you can have multiple instances of the window without them interacting.
If your window is for a specific purpose, why not just store the state information in global variables? This is generally poo-poo'ed, but unless you think you might want to go to a MDI interface, why not? KISS.
When you create a custom window, you can allocate extra bytes for that window:
// Register the window class. wc.cbWndExtra = sizeof( CustCtrl * );
In the above example, we've allocated enough extra bytes to store a single pointer. We can then save a pointer to a struct or class instance that holds all the custom data needed for this window:
CustCtrl * GetCustCtrl(HWND hwnd) { return (CustCtrl *)GetWindowLong(hwnd, 0); }
void SetCustCtrl(HWND hwnd, CustCtrl *ccp) { SetWindowLong(hwnd, 0, (LONG)ccp); }
windows_programming_notes.nbk: Home | Index | Next Page: DefDlgProc | Previous Page: Creating Threads
Notebook exported on Monday, 7 July 2008, 18:56:50 PM Eastern Daylight Time