Jump to content
  • Advertisement
Sign in to follow this  
XVincentX

Moving an external window

This topic is 3623 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

Hello to all! I've got a program that every time i run it, it positiones itself in a very owful way. So i thought to create a little program, getting HWND of the windows and move it with SetWindowPos. I wrote this code with notepad.exe, to make some tries:
	
	HWND desktop = GetDesktopWindow();
	HWND childwindow;
	DWORD ProcessID;
	PROCESS_INFORMATION ProcInfo;
	STARTUPINFO si;
	int x;
	int y;

	ZeroMemory(&si,sizeof(STARTUPINFO));
	si.cb = sizeof(STARTUPINFO);

	CreateProcess(NULL,"notepad.exe",NULL,NULL,false,0,NULL,NULL,&si,&ProcInfo);
	
	
	childwindow = GetWindow(desktop,GW_CHILD);

	while (childwindow != NULL)
		{
			GetWindowThreadProcessId(childwindow,&ProcessID);

				if ( ProcessID == ProcInfo.dwProcessId )
					break;

			childwindow = GetWindow(childwindow,GW_HWNDNEXT);
		}

	if (childwindow == NULL)
		return;				//Il software non è stato aperto. Non dovrebbe mai accadere.

	ShowWindow(childwindow,SW_MINIMIZE);
	CloseHandle(ProcInfo.hProcess);
	CloseHandle(ProcInfo.hThread);
	
	x = GetSystemMetrics(SM_CXSCREEN);
	y = GetSystemMetrics(SM_CYSCREEN);

	SetWindowText(childwindow,"Jada jada jada");
	SetWindowPos(childwindow,HWND_TOP,0,0,x,y,SWP_SHOWWINDOW);


I'm able to find process, but the window looks like ignore SetWindowText and SetWindowPos, beyond ShowWindow. After SetWindowPos, if i open again notepad, appears also a little window in the top left of the screen, sometimes with my title, sometimes not. Is this the right way? Have you got other methods?

Share this post


Link to post
Share on other sites
Advertisement
Update:
I did a GetWindowText on childwindow, i received MSCTFIME UI and not the notepad titlebar text.

Advices?

Share this post


Link to post
Share on other sites
An easier and more successful method would be to use FindWindow() or FindWindowEx() (assuming you know the window's caption or class). The window's class can be found using Spy++.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!