CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Sep 2003
    Posts
    280

    Create two window with the same toolbar,but only one window's toolbar enable.

    Hello,
    I create two window with the same toolbar:
    Code:
    // ********************************************************
    // INITIALIZATION
    // ********************************************************
    int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrevInst,
                        PSTR szCmdLine, int iCmdShow)
    {
    	MSG	msg ;
    	HWND 	hMainWindow1,hMainWindow2 ;
    
    	if(!Register(hInst))
    		return FALSE ;
    
    	// create the main window
    	hMainWindow1 = Create(hInst, iCmdShow) ;
    	hMainWindow2 = Create(hInst, iCmdShow) ;
    	if(!hMainWindow1)
    		return FALSE ;
    	if(!hMainWindow2)
    		return FALSE ;
    
    
    	while(GetMessage(&msg, NULL, 0, 0)){
            if(!IsDialogMessage(hDlgFrameRate, &msg)){
                TranslateMessage (&msg) ;
                DispatchMessage (&msg) ;
            }
        }
    
        return msg.wParam ;
    }
    But the second window 's toolbar is not enabled.
    When you execute the program,you will [File]->[Open]:Select the qcif sequence.
    The qcif sequence could be download following:
    http://trace.eas.asu.edu/yuv/qcif.html
    After the two window open the qcif sequence,i find the only one winodw 's toolbar is enabled.But i would like to enable two window's toolbars.
    How do I to modify???
    ---
    The whole project is attacted.
    Attached Images Attached Images  
    Attached Files Attached Files

  2. #2
    Join Date
    Sep 2002
    Posts
    924
    You can only have one top-level window as the active window at any time. This is normal Window's behavior. I do not think there is any way to do what you want using two seperate windows. I haven't looked at your code, but you might try using one top level window that contains two of whatever control you are using for the video, with one toolbar that contains two sets of buttons (one set of video playback controls for each video control, etc).

  3. #3
    Join Date
    Sep 2003
    Posts
    280
    Quote Originally Posted by RussG1
    You can only have one top-level window as the active window at any time. This is normal Window's behavior. I do not think there is any way to do what you want using two seperate windows. I haven't looked at your code, but you might try using one top level window that contains two of whatever control you are using for the video, with one toolbar that contains two sets of buttons (one set of video playback controls for each video control, etc).
    I use one top-level window.
    But only one of two windows's toolbar is enabled,and the other one's toolabr never enable.
    How could i to do???
    Thanks!

  4. #4
    Join Date
    Sep 2002
    Posts
    924
    Ok, I mis-understood your problem as it is not completley apparent from the pictures and source code snippet you posted. I have downloaded the project and now I can understand what you are saying. Your problem is your "hToolbar" global variable. You are trying to use one global HWND variable for both toolbars. What is happening is that you are creating two windows, and when each is created, the HWND of it's toolbar is assigned to the global "hToolbar" variable, Thus "hToolbar" is always going to be the HWND of whichever window is created second. So when you open the file, and in-turn enable the toolbar (using the "hToolbar" variable), only the second toolbar is enabled (same thing goes with later enabling/disabling buttons). Since you are enabling the toolbar using it's HWND, you are going to need to store the HWND of each toolbar in it's own varaible and enable/disable both of them whenver you enable/disable one of them, etc.

  5. #5
    Join Date
    Sep 2002
    Posts
    924
    BTW: That is not your only problem. You are gonna have similair problems with the menu items. When you select one of the playback controls (either from the menu or the toolbar), you are only enabling/disabling the corresponding menu items for the currently active window, thus when you choose play from the menu (or toolbar), the stop button menu item will only be enabled for that window, etc. You will need to correct this as well by enabling/disabling the correspnding menu items for both windows, whenever you do the same for either window, same as with the toolbar. Again, you might try creating one main window and have one menu and one toolbar within that window that offers control for the two child windows.

  6. #6
    Join Date
    Sep 2002
    Posts
    924
    I was thinking about it, and again think I may have mis-understood how you want the program to function and thus my previous reply may not be correct. I was thinking you wanted both windows to be sync'd with each other (because if you choose file open from the menu, it loads the video into both windows), but now that I think about, I am not sure what the purpose would be with doing that, so that is probably not what you wanted. In any case, my reply about the "hToolbar" HWND variable is still relevant. (My current thinking is that you want to load the same video into both windows, but to be able to control the video in each window seperatley, it would help if you could clarify exactly how the program should function). You will need a HWND variable for each toolbar (as I indicated previously), and will need to enable the appropriate buttons for both toolbars, when a valid file is opened from either window. Then (since you are using the same window procedure for both windows) when a toolbar button (or menu-item is selected) to control video playback, you will need to determine which window generated the event, and then update the toolbar for that window. You may want to make you hMainWindow1 and hMainWindow2 variables global/static as well and use a seperate HWND variable within your message handlers to make it easier to update the appropriate toolbar.
    i.e.
    static HWND variables:
    hMainWindow1, hMainWindow1, hToolbar1, hToolbar2

    Then within you event handlers you can do something like this:
    Code:
    if (hwnd == hMainWindow1)
        hToolbar = hToolbar1;
    else
        hToolbar = hToolbar2;
    ...
    SendMessage( hToolbar, TB_ENABLEBUTTON, ID_TOOLBAR_BUTTON_PLAY, TRUE );
    ... etc

  7. #7
    Join Date
    Sep 2003
    Posts
    280
    Quote Originally Posted by RussG1
    I was thinking about it, and again think I may have mis-understood how you want the program to function and thus my previous reply may not be correct. I was thinking you wanted both windows to be sync'd with each other (because if you choose file open from the menu, it loads the video into both windows), but now that I think about, I am not sure what the purpose would be with doing that, so that is probably not what you wanted. In any case, my reply about the "hToolbar" HWND variable is still relevant. (My current thinking is that you want to load the same video into both windows, but to be able to control the video in each window seperatley, it would help if you could clarify exactly how the program should function). You will need a HWND variable for each toolbar (as I indicated previously), and will need to enable the appropriate buttons for both toolbars, when a valid file is opened from either window. Then (since you are using the same window procedure for both windows) when a toolbar button (or menu-item is selected) to control video playback, you will need to determine which window generated the event, and then update the toolbar for that window. You may want to make you hMainWindow1 and hMainWindow2 variables global/static as well and use a seperate HWND variable within your message handlers to make it easier to update the appropriate toolbar.
    i.e.
    static HWND variables:
    hMainWindow1, hMainWindow1, hToolbar1, hToolbar2

    Then within you event handlers you can do something like this:
    Code:
    if (hwnd == hMainWindow1)
        hToolbar = hToolbar1;
    else
        hToolbar = hToolbar2;
    ...
    SendMessage( hToolbar, TB_ENABLEBUTTON, ID_TOOLBAR_BUTTON_PLAY, TRUE );
    ... etc
    Thanks for your explain and correct for me!
    I will follow your correction and thinking.
    Thanks!

  8. #8
    Join Date
    Sep 2003
    Posts
    280
    Quote Originally Posted by RussG1
    I was thinking about it, and again think I may have mis-understood how you want the program to function and thus my previous reply may not be correct. I was thinking you wanted both windows to be sync'd with each other (because if you choose file open from the menu, it loads the video into both windows), but now that I think about, I am not sure what the purpose would be with doing that, so that is probably not what you wanted. In any case, my reply about the "hToolbar" HWND variable is still relevant. (My current thinking is that you want to load the same video into both windows, but to be able to control the video in each window seperatley, it would help if you could clarify exactly how the program should function). You will need a HWND variable for each toolbar (as I indicated previously), and will need to enable the appropriate buttons for both toolbars, when a valid file is opened from either window. Then (since you are using the same window procedure for both windows) when a toolbar button (or menu-item is selected) to control video playback, you will need to determine which window generated the event, and then update the toolbar for that window. You may want to make you hMainWindow1 and hMainWindow2 variables global/static as well and use a seperate HWND variable within your message handlers to make it easier to update the appropriate toolbar.
    i.e.
    static HWND variables:
    hMainWindow1, hMainWindow1, hToolbar1, hToolbar2

    Then within you event handlers you can do something like this:
    Code:
    if (hwnd == hMainWindow1)
        hToolbar = hToolbar1;
    else
        hToolbar = hToolbar2;
    ...
    SendMessage( hToolbar, TB_ENABLEBUTTON, ID_TOOLBAR_BUTTON_PLAY, TRUE );
    ... etc
    Hi,
    There is another astonishing problem.
    I just want to show the sequence,if the window open file.
    If i don't open the file in that window,the winodw has nothing on it.
    After executing the program,I select [File] to open some qcif sequences in the top-level window.I move the top-level window anywhere,but I find the bottom-level window would image on it.It is so astonishing to me.
    What shall I modify it???
    Where the problem is???
    Thanks!
    Attached Images Attached Images   
    Attached Files Attached Files

  9. #9
    Join Date
    Sep 2002
    Posts
    924
    Yeah, I had noticed that as well. That is trickier to track down as I do not know much about Video For Windows, and you use GetDC in one function and use ReleaseDC in seperate functions and it is tough for me to quickly trace the program flow just by looking at it. I suspect that the problem is that when you open a file, you call one of the VFW functions with the HWND of that window only, and within those functions that window is initially painted. This is not done for the second window. The second window is only initially painted when forced to redraw itself (by dragging another window over it, etc), and a WM_PAINT message is then generated which then calls one of the VFW functions for that window as well, and then the video is displayed in that window. Anytime you want to do something in both windows, upon an event firing in either window (i.e. displaying the initial starting frame after opening a file (from either window), etc), you will need to make sure that you call the same functions for both windows within that event, etc.
    i.e.
    in your file open message handler you have:
    Code:
    DrawFrame(hwnd);
    When you probably need:
    Code:
    DrawFrame(hMainWindow1);
    DrawFrame(hMainWindow2);
    It may be a bit more complicated than that, as again, it is tough to quicky trace your program flow through all the function calls, but hopefully it will provide a starting point for you. Personnaly, I would try and organize the code and design the functions to make it a bit easier to follow the program logic, and such that the GetDC calls, have the corresponding ReleaseDC calls (and other similair matching functions) within the same function (call the functions that use the DC in between, but within one function) whenever possible, etc. This just makes tracking down problems easier in the long run.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured