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

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

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)
{
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.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);//background color
wcx.lpszClassName="WINXCLASS";//class name
wcx.hIconSm=NULL;//small icon
//register the window class, return 0 if not successful
if(!RegisterClassEx(&wcx)) return(0);

//create main window

//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.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);//background color
wcx2.lpszClassName="WinXButtons";//class name
wcx2.hIconSm=NULL;//small icon
//register the window class, return 0 if not successful
if(!RegisterClassEx(&wcx2)) return(0);
//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 on other sites
Nm I solved this problem, it was updating my variable every move with addition instead of replacing the variable with the new one FTL!

1. 1
2. 2
3. 3
Rutin
15
4. 4
khawk
14
5. 5
frob
12

• 9
• 11
• 11
• 23
• 12
• Forum Statistics

• Total Topics
633662
• Total Posts
3013229
×