Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

How to paint only child windows

SephirothSephiroth Fayetteville, NC, USAMember Posts: 1,035
Alright, I setup my primary window (the parent window) with the WS_CLIPCHILDREN style so that I could do some custom drawing in four or five of the child windows. The thing is, I only want to paint the child windows at specific times, such as when the user clicks inside of one. How can I tell which child window is sending a message to the parent about what is going on? For instance, I have a static window in the center of the parent window and when the user left-clicks in it, I want to place an image at the location the suer clicked. I know how to place the image and all, but I cannot figure out how to handle clicks in child windows, or how to tell those clicks from ones in the parent window, which should be ignored.

-[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red][/b][/italic]

Comments

  • AsmGuru62AsmGuru62 Member Posts: 6,519
    : Alright, I setup my primary window (the parent window) with the
    : WS_CLIPCHILDREN style so that I could do some custom drawing in four
    : or five of the child windows. The thing is, I only want to paint the
    : child windows at specific times, such as when the user clicks inside
    : of one. How can I tell which child window is sending a message to
    : the parent about what is going on? For instance, I have a static
    : window in the center of the parent window and when the user
    : left-clicks in it, I want to place an image at the location the suer
    : clicked. I know how to place the image and all, but I cannot figure
    : out how to handle clicks in child windows, or how to tell those
    : clicks from ones in the parent window, which should be ignored.
    :
    : -[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/gre
    : en][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h
    : [/red][/b][/italic]

    [color=Blue]Every window object (in Windows) should have a window procedure. This procedure will get te message for drawing when needed. To force the redraw of any window do that (hWnd is a window handle, which needs to be repainted):[/color]
    [color=Black][code]InvalidateRect (hWnd, NULL, TRUE);
    UpdateWindow (hWnd);[/code][/color]
  • SephirothSephiroth Fayetteville, NC, USAMember Posts: 1,035
    : [color=Blue]Every window object (in Windows) should have a window
    : procedure. This procedure will get te message for drawing when
    : needed. To force the redraw of any window do that (hWnd is a window
    : handle, which needs to be repainted):[/color]
    : [color=Black][code]: InvalidateRect (hWnd, NULL, TRUE);
    : UpdateWindow (hWnd);[/code]: [/color]

    Yeah I know that, what I need to do is when the parent window recieves a WM_LBUTTONDOWN message, I need to determine which window the user clicked in. I am doing this because clicking in one window places bitmap images at the mouse location and clicking in the other three causes a load file screen to appear. What I need is to figure out what messages came from what window.

    -[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red][/b][/italic]
  • AsmGuru62AsmGuru62 Member Posts: 6,519
    [color=Blue]Seph,

    You kind of missed my point. If every one of these child windows is written by you and have its own window procedure, then the clicks will come to these procedures accordingly:[/color]

    [code]LRESULT CALLBACK WinProc1 (...)
    {
    if (message == WM_LBUTTONDOWN)
    {
    // you clicked in panel #1
    }
    ...
    }

    LRESULT CALLBACK WinProc2 (...)
    {
    if (message == WM_LBUTTONDOWN)
    {
    // you clicked in panel #2
    }
    ...
    }

    LRESULT CALLBACK WinProc3 (...)
    {
    if (message == WM_LBUTTONDOWN)
    {
    // you clicked in panel #3
    }
    ...
    }[/code]

    [color=Blue]However, if all these panels have same nature, like it is the same functional object. Then you need one window procedure and you need to create it three times everytime passing different parameter as a last parameter in CreateWindow() function. This parameter will come back to you when WM_CREATE is received. You can stamp the HWND with this parameter, so when clicks are coming (to the same single procedure this time) by examining the HWND you will see which one of created panels is sending the messages, so you will know which instance of a panel you clicked on.

    Unfortunately clicks from child window will not come to a parent, unless the child sends it by itself, like it is done by a button and dialog box.

    Also, you can achieve what you need by createing panels as static controls with ability to notify a parent of an event - check the SS_NOTIFY style:

    [link=http://msdn2.microsoft.com/en-us/library/ms651153.aspx]http://msdn2.microsoft.com/en-us/library/ms651153.aspx[/link][/color]
  • SephirothSephiroth Fayetteville, NC, USAMember Posts: 1,035
    Right, but how do I tell a child window what window procedure to use? I did this once eons ago but have since lost the code. I have my main WNDPROC for the main window and most child windows, but there are four windows that need their own so I may do things within them. Will I have to register a unique class for each of the four windows to specify their own WNDPROCs?

    -[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red][/b][/italic]
Sign In or Register to comment.