How to center window title

How can I align the title of a window to the center using the Win32 API (Windows.h)?, not MFC.
This is a code snippet I used to center the"about" dialog in a window application:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
case WM_INITDIALOG:
		{
		RECT rc, rcDlg, rcOwner; 
		HWND hWnd = GetParent(hDlg);
		GetWindowRect(hWnd, &rcOwner); 
		GetWindowRect(hDlg, &rcDlg); 
		CopyRect(&rc, &rcOwner); 

		// Offset the owner and dialog box rectangles so that right and bottom 
		// values represent the width and height, and then offset the owner again 
		// to discard space taken up by the dialog box. 

		OffsetRect(&rcDlg, -rcDlg.left, -rcDlg.top); 
		OffsetRect(&rc, -rc.left, -rc.top); 
		OffsetRect(&rc, -rcDlg.right, -rcDlg.bottom); 

		// The new position is the sum of half the remaining space and the owner's 
		// original position. 

		SetWindowPos(hDlg, 
			HWND_TOP, 
			rcOwner.left + (rc.right / 2), 
			rcOwner.top + (rc.bottom / 2), 
			0, 0,          // Ignores size arguments. 
			SWP_NOSIZE); 


You need to change the code to your needs and use desktop resolution instead of GetParent() and friends ...
Thanks a lot for this code. I will try out and let you know if I got it correct.
Topic archived. No new replies allowed.