Getting the position of a dialog without parent on the screen

This is a discussion on Getting the position of a dialog without parent on the screen within the Windows Programming forums, part of the Platform Specific Boards category; hi i have a little program that just displays a dialog. now i want to remember the position of the ...

  1. #1
    Registered User stormbringer's Avatar
    Join Date
    Jul 2002
    Posts
    90

    Getting the position of a dialog without parent on the screen

    hi

    i have a little program that just displays a dialog. now i want to remember the position of the dialog, wenn the user presses next to reach the next dialog and place the new dialog at the same place on the screen. here's my question: how can i get the curent position of the dialog on the screen?

    here's some parts of my code:
    Code:
    #include "installer.h"
    #include "dialogs.h"
    
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
    {
    	struct DlgStatus	sStatus;
    	
    	//sStatus vorbereiten
    	sStatus.xScreen=GetSystemMetrics(SM_CXSCREEN);
    	sStatus.yScreen=GetSystemMetrics(SM_CYSCREEN);
    	sStatus.pointDlgPos.x=sStatus.xScreen/2;
    	sStatus.pointDlgPos.y=sStatus.yScreen/2;
    	
    	//Create Dialog Chain
    	Dialog = (struct DlgChain *)malloc(sizeof(struct DlgChain));
    
    	
    	Dialog->Name = TEXT("Installer_Title");
    	Dialog->Last = NULL;
    	Dialog->Next = (struct DlgChain *)malloc(sizeof(struct DlgChain));
    	Dialog->Next->Name = TEXT("Installer_Contract");
    	Dialog->Next->Last = Dialog;
    	Dialog->Next->Next = NULL;
    
    	//Installer routine
    	while(TRUE) {
    		DialogBoxParam(hInstance,Dialog->Name,NULL,InstallerDlgProc,&sStatus);
    		if(sStatus.iButton==NEXT) {
    			//Call Next Dialog
    			if(Dialog->Next != NULL)
    				Dialog = Dialog->Next;
    		}
    		else if(sStatus.iButton==LAST) {
    			//Call Last Dialog
    			if(Dialog->Last != NULL)
    				Dialog = Dialog->Last;
    		}
    		else if(sStatus.iButton==CANCEL) {
    			//Abort
    			break;
    		}
    	}
    
    	return 0;
    }
    
    
    
    BOOL CALLBACK InstallerDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
    {
    	static struct DlgStatus	*psStatus, sStatus;
    
    	
    	switch(message) {
    	case WM_INITDIALOG:
    		psStatus=(struct DlgStatus *)lParam;
    		sStatus=*psStatus;
    
    		GetClientRect(hDlg,&(sStatus.rectDialog));
    		
    		MoveWindow(hDlg,sStatus.pointDlgPos.x-sStatus.rectDialog.right/2, sStatus.pointDlgPos.y-sStatus.rectDialog.bottom/2,
    			sStatus.rectDialog.right,sStatus.rectDialog.bottom,FALSE);
    
    		break;
    
    
    	case WM_COMMAND:
    		
    		sStatus.xScreen=GetSystemMetrics(SM_CXSCREEN);
    		sStatus.yScreen=GetSystemMetrics(SM_CYSCREEN);
    		
    
    		switch(LOWORD(wParam)) {
    		
    		case ID_NEXT:
    			sStatus.iButton=NEXT;
    			*psStatus=sStatus;
    			EndDialog(hDlg,TRUE);
    			break;
    
    		case ID_LAST:
    			sStatus.iButton=LAST;
    			*psStatus=UpdateStatus(hDlg, sStatus);
    			EndDialog(hDlg,TRUE);
    			break;
    
    		case ID_CANCEL:
    			sStatus.iButton=CANCEL;
    			*psStatus=UpdateStatus(hDlg, sStatus);
    			EndDialog(hDlg,FALSE);
    			break;
    
    		case ID_END:
    			sStatus.iButton=CANCEL;
    			*psStatus=UpdateStatus(hDlg, sStatus);
    			EndDialog(hDlg,FALSE);
    			break;
    		}
    		break;
    	}
    	return 0;
    }
    
    struct DlgStatus UpdateStatus(HWND hDlg, struct DlgStatus sStatus)
    {
    
    	sStatus.xScreen=GetSystemMetrics(SM_CXSCREEN);
    	sStatus.yScreen=GetSystemMetrics(SM_CYSCREEN);
    	//ClientToScreen(hDlg,&(sStatus.pointDlgPos));
    	//Does not work. Get cur pos of dialog here, but how?
    
    	return sStatus;
    }
    thank you

  2. #2
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    GetWindowRect() should do the trick.
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Button handler
    By Nephiroth in forum Windows Programming
    Replies: 8
    Last Post: 03-12-2006, 05:23 AM
  2. Feedback: Functional Specification Wording
    By Ragsdale85 in forum C++ Programming
    Replies: 0
    Last Post: 01-18-2006, 03:56 PM
  3. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  4. MFC Dialog App Screen Refresh Question
    By Scotth10 in forum Windows Programming
    Replies: 2
    Last Post: 10-18-2002, 02:07 PM
  5. Replies: 4
    Last Post: 10-17-2002, 03:54 PM

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