Jump to content
  • Advertisement
Sign in to follow this  
yewbie

[Solved][Win32] Creating 2 windows and locking them to each other

This topic is 3545 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Well what I am doing is creating a main window for my map editor, and making another window that I want to lock to the outside edge of my main window... basically if I move my main window my secondary window moves in tandem with it... I have tried just about everything I can think of and have found out that maybe its something simple, some simple little command that I dont know! im using VS express 2008. here is how I create my 2 windows
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)
{
	hInstMain=hInstance;//assign instance to global variable
	WNDCLASSEX wcx;//create window class
	wcx.cbSize=sizeof(WNDCLASSEX);//set the size of the structure
	wcx.style=CS_OWNDC | CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;//class style
	wcx.lpfnWndProc=TheWindowProc;//window procedure
	wcx.cbClsExtra=0;//class extra
	wcx.cbWndExtra=0;//window extra
	wcx.hInstance=hInstMain;//application handle
	wcx.hIcon=LoadIcon(NULL,IDI_APPLICATION);//icon
	wcx.hCursor=LoadCursor(NULL,IDC_ARROW);//cursor
	wcx.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);//background color
	wcx.lpszMenuName=(LPCTSTR)IDR_MENU1;//menu
	wcx.lpszClassName="WINXCLASS";//class name
	wcx.hIconSm=NULL;//small icon
	//register the window class, return 0 if not successful
	if(!RegisterClassEx(&wcx)) return(0);
	hmenu = LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU1));
	
	//create main window
	hWndMain=CreateWindowEx(NULL,"WINXCLASS","Main Window", WS_VISIBLE | WS_SYSMENU | WS_MINIMIZEBOX | WS_CAPTION ,0,0,MainWindowX,MainWindowY,NULL,hmenu,hInstMain,NULL);

	//error check returns true if our main window failed to create
	if(!hWndMain) return(0);
	

	//Create our buttons window
	WNDCLASSEX wcx2;//create window class
	wcx2.cbSize=sizeof(WNDCLASSEX);//set the size of the structure
	wcx2.style=CS_DBLCLKS | CS_NOCLOSE;//class style
	wcx2.lpfnWndProc=CommandWindowProc;//window procedure
	wcx2.cbClsExtra=0;//class extra
	wcx2.cbWndExtra=0;//window extra
	wcx2.hInstance=hInstMain;//application handle
	wcx2.hIcon=LoadIcon(NULL,IDI_APPLICATION);//icon
	wcx2.hCursor=LoadCursor(NULL,IDC_ARROW);//cursor
	wcx2.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);//background color
	wcx2.lpszMenuName=(LPCTSTR)IDR_MENU2;//menu
	wcx2.lpszClassName="WinXButtons";//class name
	wcx2.hIconSm=NULL;//small icon
	//register the window class, return 0 if not successful
	if(!RegisterClassEx(&wcx2)) return(0);
	hmenu2 = LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU2));
	//Create our buttons
	hWndCommand=CreateWindowEx(NULL,"WinXButtons","Commands Window", WS_VISIBLE| WS_CAPTION | WS_EX_TOOLWINDOW,MainWindowX + 10,0,300,MainWindowY,hWndCommand,hmenu2,hInstMain,NULL);
	
now this works great both windows function how I want them to, now I tried putting some code in my windows procs for the two windows as such: anytime the main window is moved the position is stored and the secondary window is moved to where it should be but it just ends up disappearing most of the time... I use and take the .left and .top parameters and add my main windows length to .left (its 800)
GetWindowRect(hWndMain, &rect);// get the Main windows rect
SetWindowPos(hWndCommand, HWND_TOP, rect.left+800,rect.top,NULL,NULL,SWP_NOSIZE)
ugh I just wish there was some way I could tell windows to lock this secondary window to my main one... Also another problem, my second window pops up on my task bar this is undesirable but I can live with that, anyone know a solution to either of these problems, or maybe a link to something I can look at. Thanks in advance! [Edited by - yewbie on January 9, 2009 9:35:41 PM]

Share this post


Link to post
Share on other sites
Advertisement
Nm I solved this problem, it was updating my variable every move with addition instead of replacing the variable with the new one FTL!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!