one window, two handles

This is a discussion on one window, two handles within the Windows Programming forums, part of the Platform Specific Boards category; is there a way to split a singal window to two windows with two handles? what i mean is: to ...

  1. #1
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768

    one window, two handles

    is there a way to split a singal window to two windows with two handles?

    what i mean is: to the user it will look like a singal window, but it will enable me to split the big window into areas, where each area has it's own handle (HWND).



    thank you,
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    no, but you can create a bunch of HRGN's and select them into the window's device context as needed.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  3. #3
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    regions would be an interesting approach, depends on what he's trying to do. It seems to me that it would be better to make two windows to start with. Perhaps docked on a parent window. You can set the parent on the fly to undock it. You can always create new windows and move the stuff over.
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  4. #4
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    FillYourBrain, I don't really understand what you mean?
    can you give me an example please?
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

  5. #5
    Handy Andy andyhunter's Avatar
    Join Date
    Dec 2004
    Posts
    540
    You could use child windows that would appear to be one continuous window yet contained different handles. This approach would probably resolve what you are trying to do. I am going to post a basic app below that uses 2 child windows that change colors when you click on them. Take note that it appears as if it is one window when the colors match. Additionally their size depends on the main window size, ensuring the illusion.

    Code:
    #include <windows.h>
    
    #define numChild 2
    
    LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
    //children window procedure
    LRESULT CALLBACK ChildWndProc(HWND, UINT, WPARAM, LPARAM); 
    
    TCHAR szChildClass [] = TEXT("Children"); //Child class name
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) {
    
    	static TCHAR szAppName[] = TEXT("ChildWindowDemo");
    	WNDCLASS wc;
    	MSG msg;
    	HWND hwnd;
    
    	wc.cbClsExtra = 0;
    	wc.cbWndExtra = 0;
    	wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
    	wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    	wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    	wc.hInstance = hInstance;
    	wc.lpfnWndProc = WndProc;
    	wc.lpszClassName = szAppName;
    	wc.lpszMenuName = NULL;
    	wc.style = CS_HREDRAW | CS_VREDRAW;
    
    	if(!RegisterClass(&wc)) {
    		MessageBox(NULL, TEXT("Could not register class"), szAppName, MB_ICONERROR);
    		return 0;
    	}
    
    	//define and register child window class
    	wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
    	wc.lpfnWndProc = ChildWndProc;
    	wc.hIcon = NULL;
    	wc.lpszClassName = szChildClass;
    	RegisterClass(&wc);
    	//-------------------------------------
    	
    	hwnd = CreateWindow(szAppName,
    					    TEXT("Child Window Demo"),
    						WS_OVERLAPPEDWINDOW,
    						CW_USEDEFAULT,
    						CW_USEDEFAULT,
    						CW_USEDEFAULT,
    						CW_USEDEFAULT,
    						NULL,
    						NULL,
    						hInstance,
    						NULL);
    
    	ShowWindow(hwnd, iCmdShow);
    	UpdateWindow(hwnd);
    
    	while(GetMessage(&msg, NULL, 0, 0)) {
    
    		TranslateMessage(&msg);
    		DispatchMessage(&msg);
    	}
    	return msg.wParam;
    }
    LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
    
    	static HWND hwndChild[numChild]; //create array to hold children
    	int cxBlock, cyBlock, x;
    
    	switch(message) {
    
    		case WM_CREATE:
    			//create our children
    			for(x = 0; x < numChild; x++) {
    				hwndChild[x] = CreateWindow(szChildClass,
    											NULL,
    											WS_CHILDWINDOW | WS_VISIBLE,
    											0,
    											0,
    											0,
    											0,
    											hwnd,
    											(HMENU)(1 << 8 | x), //child window ID
    											(HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE),
    											NULL);
    			}
    			return 0;
    		case WM_SIZE:
    			//each window will be 1/2 width of parent and = height
    			cxBlock = LOWORD(lParam) / numChild;
    			cyBlock = HIWORD(lParam);
    
    			for(x = 0; x < numChild; x++) {
    				MoveWindow(hwndChild[x],
    						   x * cxBlock,
    						   0,
    						   cxBlock,
    						   cyBlock,
    						   TRUE);
    			}
    			return 0;
    		case WM_DESTROY:
    
    			PostQuitMessage(0);
    			return 0;
    	}
    	return DefWindowProc(hwnd, message, wParam, lParam);
    }
    LRESULT CALLBACK ChildWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
    
    	static int iColor;
    	int bkgColor[4] = {WHITE_BRUSH, LTGRAY_BRUSH, DKGRAY_BRUSH, BLACK_BRUSH};
    
    	switch(message) {
    
    		case WM_CREATE:
    
    			iColor = 0;
    			SetWindowLong(hwnd, 0, 0);
    			return 0;
    		case WM_LBUTTONUP:
    
    			SetClassLong(hwnd, GCL_HBRBACKGROUND, (LONG)GetStockObject(bkgColor[iColor]));
    			InvalidateRect(hwnd, NULL, TRUE);
    			if(!(iColor == 3)) {
    				iColor++;
    			}else {
    				iColor = 0;
    			}
    			return 0;
    	}
    	return DefWindowProc(hwnd, message, wParam, lParam);
    }
    Hope this helps. Happy Coding!!
    i don't think most standard compilers support programmers with more than 4 red boxes - Misplaced

    It is my sacred duity to stand in the path of the flood of ignorance and blatant stupidity... - quzah

    Such pointless tricks ceased to be interesting or useful when we came down from the trees and started using higher level languages. - Salem

  6. #6
    Registered User
    Join Date
    May 2002
    Posts
    132
    I use a program for my job that is made up of four separate sections. Separating the four sections is a bar that the mouse allows you to resize the four different sections (either horizontally or vertically depending on how that bar stretches across the screen). I was wondering how this was done. The way this program is designed, it seems like the controls are children of the main program. But the controls change location on the screen based on how you resize the different sections.

    Is this done using four separate windows (like the example above) or is this done using something like Windows Regions?

    Thanks
    Tyouk

  7. #7
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    Those resizeable bars are just another type of control used in Windows Forms. I forget what they're called - but they're predefined in the API (I don't recall seeing them in Win32, but at least as early VS.NET they've been there - most likely much earlier.

  8. #8
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    I think the control called a splitter:

    http://www.catch22.net/tuts/splitter.asp
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

  9. #9
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    andyhunter, your code is exacly what i need, but i don't understand one small thing in your code...

    there are two child windows in that main parent one, but only one ChildWndProc, did you mean that this will control both of the child windows?

    Code:
    //define and register child window class
    	wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
    	wc.lpfnWndProc = ChildWndProc;
    	wc.hIcon = NULL;
    	wc.lpszClassName = szChildClass;
    if so, how can i gain more control over the two child windows?
    Last edited by Devil Panther; 01-15-2005 at 04:45 AM.
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

  10. #10
    Handy Andy andyhunter's Avatar
    Join Date
    Dec 2004
    Posts
    540
    Yes, for the above example both child windows shared the same windows callback procedure. You could decide to register a class for each child window and create a seperate windows procedure for each if you wanted them to be seperate.

    Another approach is to have the child window procedure send a message to the parent window procedure detailing a message and the child window ID. This way you could also have more control over individual windows.

    Happy Coding!!!
    i don't think most standard compilers support programmers with more than 4 red boxes - Misplaced

    It is my sacred duity to stand in the path of the flood of ignorance and blatant stupidity... - quzah

    Such pointless tricks ceased to be interesting or useful when we came down from the trees and started using higher level languages. - Salem

  11. #11
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    thank you very much.
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C or C++
    By AcerN30 in forum Game Programming
    Replies: 41
    Last Post: 05-30-2008, 07:57 PM
  2. WM_CAPTION causing CreateWindowEx() to fail.
    By Necrofear in forum Windows Programming
    Replies: 8
    Last Post: 04-06-2007, 09:23 AM
  3. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 11:06 AM
  4. My Window Class
    By Epo in forum Game Programming
    Replies: 2
    Last Post: 07-10-2005, 03:33 PM
  5. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 01:34 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21