Click here to Skip to main content
15,946,342 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
A question on how to create cascading dialog programs. The code below is being used to create multiple versions of the same dialog, only with a command line that is processed. What I would like to do is have them cascade, and according to the MSVC++ V6 documentation, setting the STARTUPINFO bit field STARTF_USEPOSITION should cause the new dialog to be positioned at the location dwX & dwY. No matter what combinations of bit fields used, the new dialog is always positioned where the original one is located - in the center of the screen.

Any suggestions would be appreciated.

Thanks,

-jon
C++
// process initialization
STARTUPINFO	si;
PROCESS_INFORMATION pi;
ZeroMemory (&si, sizeof(si));
si.cb = sizeof(si);
si.wShowWindow = SW_SHOWNORMAL;
si.dwFlags = STARTF_USEPOSITION | STARTF_USESHOWWINDOW;

for ( i = 0, dwX=0, dwY=0; i < lFileMax; i++ ) {
	sprintf(buf,"%s",sFileArray.GetAt(i));
	_splitpath (buf, drive, dir, fname, ext);
	display("processing->%s", fname ) ;
	// check for operation
	if ( iRadioBatchCombine == 1 ) {
		sprintf(cmdLine,"COMBINE %s", buf );
	}
	else if ( iRadioBatchNetInput == 1 ) {
		sprintf(cmdLine,"NET_INPUT %s", buf );
	}
	else if ( iRadioBatchPNNPost == 1 ) {
		sprintf(cmdLine,"PNN_Post %s", buf );
	}
	// spawn new program
	si.dwX = dwX;
	si.dwY = dwY;
	if (CreateProcess(exeFile, cmdLine, NULL, NULL, FALSE,
		CREATE_SUSPENDED | IDLE_PRIORITY_CLASS, NULL, __TEXT("\\"), &si, &pi)) {

		SetThreadPriority(pi.hThread, THREAD_PRIORITY_NORMAL);

		// Raise our priority so that we terminate as quickly as possible.
		SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL);
				SetPriorityClass(GetCurrentProcess(), NORMAL_PRIORITY_CLASS);

		// Allow the batch file to run and clean-up our handles.
		CloseHandle(pi.hProcess);
		ResumeThread(pi.hThread);
		// We want to terminate right away now so that we can be deleted
		CloseHandle(pi.hThread);
	}
	Sleep(100);
	dwX+=50, dwY+=50;		
}
Posted
Updated 17-Mar-14 8:40am
v2

The spawned EXE can ignore your window placement settings. Check the WM_CREATE handler of the spawned program to see if it always does something like CenterWindow() when the frame or dialog window is created.
 
Share this answer
 
The spawned dialog program uses a tabbed dialog class, and am working though the code to see where the override is located. Thanks for the pointer on where to look.
 
Share this answer
 
The SI structure was never found in any of the main app or dialog methods prior to displaying the dialog. As a workaround, the SI dwFlags, dwX & dwY were appended to the command line.Upon entry in the main app, they were extracted and assigned to global variables. The SetWindowPos was then set prior to displaying the dialog as follows:

void CNLPredictDlg::OnShowWindow(BOOL bShow, UINT nStatus) 
{
	CDialog::OnShowWindow(bShow, nStatus);
	
	// TODO: Add your message handler code here
	RECT Rect;
	GetWindowRect(&Rect);

	if ( ( CNLPredictApp::dwFlags != -1 ) && ( CNLPredictApp::dwFlags & STARTF_USEPOSITION ) ) {
		// Change the size
		SetWindowPos(NULL, CNLPredictApp::dwX, CNLPredictApp::dwY, 
			Rect.right - Rect.left, Rect.bottom - Rect.top, SWP_SHOWWINDOW);
	}

}


Multiple spawns of dialog applications are now cascaded properly.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900