Click here to Skip to main content
14,271,874 members

C / C++ / MFC

 
GeneralRe: Dialog box margins Pin
speedbump9922-Feb-19 10:01
memberspeedbump9922-Feb-19 10:01 
AnswerRe: Dialog box margins Pin
Maximilien22-Feb-19 4:23
memberMaximilien22-Feb-19 4:23 
GeneralRe: Dialog box margins Pin
leon de boer22-Feb-19 5:39
memberleon de boer22-Feb-19 5:39 
GeneralRe: Dialog box margins Pin
Maximilien23-Feb-19 1:49
memberMaximilien23-Feb-19 1:49 
GeneralRe: Dialog box margins Pin
leon de boer23-Feb-19 4:30
memberleon de boer23-Feb-19 4:30 
AnswerRe: Dialog box margins Pin
leon de boer22-Feb-19 5:37
memberleon de boer22-Feb-19 5:37 
GeneralRe: Dialog box margins Pin
Alexander Kindel22-Feb-19 9:04
memberAlexander Kindel22-Feb-19 9:04 
GeneralRe: Dialog box margins Pin
leon de boer22-Feb-19 10:00
memberleon de boer22-Feb-19 10:00 
There are two parts to things positioning and scaling

Let me formally centre the dialog at runtime to it's parent in WM_INITDIALOG .. it is this simple
RECT R1, R2;
GetClientRect(GetParent(Wnd), &R1);      // Parent client area
GetWindowRect(Wnd, &R2);                 // Dialog area
SetWindowPos(Wnd, 0, 
             (R1.right+R1.left)/2 - (R2.right-R2.left)/2 ,  // Parent x centre - half dialog width
             (R1.top+R1.Bottom)/2 - (R2.bottom-R2.top)/2,   // Parent y centre - half  dialog height
              0, 0,                                         // No size data
              SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER);

Now if you want to centre and rescale generally you do the scale as a fraction to avoid floats
so (numerator/denominator) where denominator must not be zero
This usually works well because you have ( desired size / current size ) being the exact fraction
int Wth, Ht;
RECT R1, R2;
GetClientRect(GetParent(Wnd), &R1);          // Parent client area
GetWindowRect(Wnd, &R2);                     // Dialog area
Wth = (R2.right-R2.left) * numerator;        // Multiply dialog width by numerator
Wth /= denominator;                          // Divide dialog width by denominator
Ht = (R2.bottom-R2.top) * numerator;         // Multiply dialog height by numerator
Ht /= denominator;                           // Divide dialog height by denominator
SetWindowPos(Wnd, 0, 
             (R1.right+R1.left)/2 - Wth/2 ,  // Parent x centre - half scaled dialog width
             (R1.top+R1.Bottom)/2 - Ht/2,    // Parent y centre - half  dialog height
              Wth, Ht,                       // New sizes
              SWP_NOACTIVATE | SWP_NOZORDER);// Do not change order or activate

/* so if you want to scale the children windows you need to scale and move them */
/* now go thru each child by id (shown as xxx) and scale and move them with this */
RECT R3;
HWND cWnd = GetDlgItem(Wnd, xxxx);           // Fetch and hold child handle from xxxx id
GetWindowRect(cWnd, &R3);                    // Fetch the child area
R3.left *= numerator;                        // Multiply child window left by numerator
R3.left /= denominator;                      // Divide child window left by denominator
R3.right *= numerator;                       // Multiply child window right by numerator
R3.right /= denominator;                     // Divide child window right by denominator
R3.top *= numerator;                         // Multiply child window top by numerator
R3.top /= denominator;                       // Divide child window top by denominator
R3.bottom *= numerator;                      // Multiply child window bottom by numerator
R3.bottom /= denominator;                    // Divide child window bottom by denominator
SetWindowPos(cWnd, 0, 
             R3.left,                        // New child left
             R3.top,                         // New child top
             R3.right - R3.left,             // New child width
             R3.bottom - R3.top,             // New child height
             SWP_NOACTIVATE | SWP_NOZORDER); // Do not change order or activate

**Note you may also need to pass a scaled font (numerator/denominator) to some types of child window because you want the text bigger (you do that via WM_SETFONT).

Is that what you are trying to do???
In vino veritas


modified 22-Feb-19 16:13pm.

SuggestionRe: Dialog box margins Pin
David Crow24-Feb-19 16:23
memberDavid Crow24-Feb-19 16:23 
QuestionTraceability of Dynamic Memory Allocation Faults Pin
HS_C_Student16-Feb-19 22:24
memberHS_C_Student16-Feb-19 22:24 
AnswerRe: Traceability of Dynamic Memory Allocation Faults Pin
leon de boer17-Feb-19 20:53
memberleon de boer17-Feb-19 20:53 
AnswerRe: Traceability of Dynamic Memory Allocation Faults Pin
Stefan_Lang18-Feb-19 0:15
memberStefan_Lang18-Feb-19 0:15 
AnswerRe: Traceability of Dynamic Memory Allocation Faults Pin
jschell23-Feb-19 10:41
memberjschell23-Feb-19 10:41 
QuestionCeratingNameePipe Server Application Using C++ Classes Pin
Member 1271142615-Feb-19 0:23
memberMember 1271142615-Feb-19 0:23 
AnswerRe: CeratingNameePipe Server Application Using C++ Classes Pin
Victor Nijegorodov15-Feb-19 1:03
memberVictor Nijegorodov15-Feb-19 1:03 
GeneralRe: CeratingNameePipe Server Application Using C++ Classes Pin
Member 1271142615-Feb-19 4:53
memberMember 1271142615-Feb-19 4:53 
GeneralRe: CeratingNameePipe Server Application Using C++ Classes Pin
Richard Andrew x6415-Feb-19 13:48
professionalRichard Andrew x6415-Feb-19 13:48 
GeneralRe: CeratingNameePipe Server Application Using C++ Classes Pin
Victor Nijegorodov15-Feb-19 13:53
memberVictor Nijegorodov15-Feb-19 13:53 
GeneralRe: CeratingNameePipe Server Application Using C++ Classes Pin
Richard Andrew x6415-Feb-19 14:11
professionalRichard Andrew x6415-Feb-19 14:11 
GeneralRe: CeratingNameePipe Server Application Using C++ Classes Pin
Victor Nijegorodov15-Feb-19 14:18
memberVictor Nijegorodov15-Feb-19 14:18 
AnswerRe: CeratingNameePipe Server Application Using C++ Classes Pin
Richard MacCutchan15-Feb-19 3:18
protectorRichard MacCutchan15-Feb-19 3:18 
GeneralRe: CeratingNameePipe Server Application Using C++ Classes Pin
Member 1271142615-Feb-19 4:55
memberMember 1271142615-Feb-19 4:55 
QuestionWants guidance. Pin
Member 1415146014-Feb-19 23:46
memberMember 1415146014-Feb-19 23:46 
AnswerRe: Wants guidance. Pin
CPallini15-Feb-19 1:45
mveCPallini15-Feb-19 1:45 
QuestionSelected Row while updating in CListCtrl in MFC Pin
Anu_Bala13-Feb-19 22:29
memberAnu_Bala13-Feb-19 22:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.