   Find the right Hwnd & send a COLORREF var to it
  HelloI have something to do that is a little complex to explain but I'll try to explain it as clearly as possible. But I REALLY need some help with this, I have been trying to find a solution for ages. I have a Win32 control that I have made that right now is similar to a list box(its a white rectangle ,with cells & text inside the cells). When the 'list box' is created I do the normal thing of creating a class object 'listBoxObject'(called 'LBO') & hook/link it to the window. When I right click the control a new window opens which is called the 'property dialog' & this has its own WNDPROC. This dialog is very simple, it allows the user to change the background colour of the 'list box'. There is a button on the 'property dialog' called "Change Bk Colour". When this button is clicked a standard colour dialog appears & the user selects a new background colour for the 'list box'. So now my 'property dialog' knows the new background colour(COLORREF variable) the user wants for the 'list box' background. But my 'list box' WNDPROC doesn't know what this color is yet. And my 'list box's linked object 'LBO' doesnt know this new COLORREF value? How can I pass this COLORREF variable from the 'property dialog' to the 'list box' window, so I can then set the 'LBO's member variable bkColour to this COLORREF variable (change the background colour)? Possible solution?: - From the 'Property Dialog' can I get obtain the handle to the 'listbox' window- Suppose I have created a constant called #define LB_CHANGEBKCOL 11 & I store the new background colour in thios variable COLORREF newBKCol; - Then I send a message to the 'listbox' window SendMessage(listboxHWND,WM_COMMAND,(WPARAM)LB_CHANGEBKCOL,(LPARAM)newBKCol);- From the 'list box' WNDPROC, when I receive a WM_COMMAND & the wParam equals LB_CHANGEBKCOL I change the objects background colour by doing this:LBO->bkColour = lParam;InvalidateRect(hwnd,NULL,true);UpdateWindow(hwnd);Is this how I can achieve what I want to do? If not, can you suggest how I can do this. If you think my solution will work, how do I get a handle to the 'list box' window? Can I send a COLORREF variable as a LPARAM parameter?Any advice & code examples would be extremely helpful.   
  When you create the property dialog with CreateWindowEx, pass a pointer to a structure, call it, say, PropertyDialogInfo, that has any data that this window needs including the HWND of the corresponding list box and/or a pointer to the listBoxObject associated with the list box window. You can do this by using the LPVOID lpParam parameter of the CreateWindowEx call. Whatever you pass in the lpParam parameter of CreateWindowEx will show up in the lpCreateParams field of the CREATESTRUCT pointed to by the LPARAM of the WM_CREATE message of the property dialog window. So handle WM_CREATE in the WndProc of the property dialog, cast its LPARAM to a CREATESTRUCT*, dereference the CREATESTRUCT*, and cast its lpCreateParams field to a PropertyDialogInfo*, then store the HWND to the list box somewhere, wherever you are storing the state of a property dialog.Once you have the HWND of the list box associated with a property dialog accessible by the property dialog, you can tell a list box which color to use with a custom message. Don't use WM_COMMAND. Define something like#define WM_CHANGE_LBO_COLOR (WM_APP + 1) (or whatever) and thenSendMessage(list_box, WM_CHANGE_LBO_COLOR, 0, (LPARAM) new_color) from wherever you need to in the property dialog window procedure and handle WM_CHANGE_LBO_COLOR in the window procedure of the list box window.   ;  Thanks very much. Thats exactly what I wanted to do, pass the hwnd of the list box to the new window as a parent, but I had no idea how to. :D I always wondered what the last param for CreateWindowEx was for, I should really read msdn more carefully :PThanks again.I just have some questions..Quote:...So handle WM_CREATE in the WndProc of the property dialog, cast its LPARAM to a CREATESTRUCT*, dereference the CREATESTRUCT*, and cast its lpCreateParams field to a PropertyDialogInfo*, then store the HWND to the list box somewhere, wherever you are storing the state of a property dialog.I am unsure what you mean by dereference?would this code be correct?// Send the hwnd of the listbox like this?CreateWindowEx(0,"PropDialog","",WS_VISIBLE,10,10,100,100,hwnd,NULL,gInstance,(LPVOID lpParam)hwnd);// Or do I create a whole CREATESTRUCT*CREATESTRUCT* me;me.lpCreateParams = hwnd;CreateWindowEx(0,"PropDialog","",WS_VISIBLE,10,10,100,100,hwnd,NULL,gInstance,(LPVOID lpParam)me);class PropertyDialogInfo {public:   PropertyDialogInfo(HWND parent);   HWND myParent;};case WM_CREATE: PropertyDialogInfo* pdi = NULL;   CREATESTRUCT* windowObj = lParam;   // Dereference ?   windowObj.lpCreateParams = pdi // To access the parent to send message I just say   HWND listboxHwnd = pdi->myParent;break;  By "dereference" I just mean "use the thing the pointer is pointing to".Anyway, I think you have the right idea but you got the syntax a little bit wrong. windowObj.lpCreateParams will be the PropertyDialogInfo* so you don't want to assign it to anything. It would be more like this:HWND CreatePropertyDialog(HWND parent, int x, int y, int wd, int hgt, HWND list_box) {    PropertyDialogInfo pdi;    pdi.myParent = list_box;    HWND prop_dialog = CreateWindowEx(0, "PropDialog", "", WS_VISIBLE | WS_POPUP,   x, y, wd, hgt, parent, NULL, gInstance, (LPVOID) &pdi);    return prop_dialog;}and then in porperty dialog's WndProc:case WM_CREATE: {    CREATESTRUCT* windowObj = (CREATESTRUCT*) lParam;    PropertyDialogInfo* pdi = (PropertyDialogInfo*) windowObj->lpCreateParams;    HWND listboxHwnd = pdi->myParent;    // do something with listboxHwnd    // ...}(You should actually use C++-style static_casts if you're not writing in straight C, but you get the idea)Also if PropertyDialogInfo is only going to contain the HWND you could just pass the HWND itself as the final parameter to CreateWindowEx, casting appropriately. I was just suggesting passing a pointer to a structure in case there is anything else that the property dialog is going to need.[Edited by - jwezorek on May 6, 2010 5:40:58 AM];  Thanks :D this has been extremely helpful. Gonna get coding.   