NO

Author Topic: Dialog in two sizes  (Read 2116 times)

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
Dialog in two sizes
« on: November 18, 2017, 08:22:38 PM »
I wanted to have a dialog that can maximize to screen.
Let me know other ways to do that.
Code: [Select]
#define WIN32_LEAN_AND_MEAN
#include <windows.h>

#ifndef DLG_MAIN
#define DLG_MAIN 1001
#endif

LRESULT CALLBACK MainDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);

#define MAXCTRLS 3
RECT aRect[MAXCTRLS]; // normal
RECT aRect2[MAXCTRLS]; // maximized

int __cdecl WinMainCRTStartup(void)
{
HINSTANCE hInstance = GetModuleHandle(NULL);
//int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
//{
return DialogBox(hInstance, MAKEINTRESOURCE(DLG_MAIN), NULL, (DLGPROC)MainDlgProc);
}

LRESULT CALLBACK MainDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_INITDIALOG:
{
RECT rect;
RECT rect2;
GetClientRect(hwndDlg, &rect);
GetClientRect(GetDesktopWindow(), &rect2);
float iAspectRatio = (float)rect2.bottom / (float)rect.bottom;
for (int iC = 0; iC < MAXCTRLS; iC++) {
HWND hWnd = GetDlgItem(hwndDlg, 4001+iC);
GetWindowRect(GetDlgItem(hwndDlg, 4001+iC), &rect);
ScreenToClient(hwndDlg, (POINT*)&rect.left);
ScreenToClient(hWnd, (POINT*)&rect.right);
MoveWindow(GetDlgItem(hwndDlg, 4001+iC), rect.left, rect.top, rect.right, rect.bottom, TRUE);
CopyRect(&aRect[iC], &rect);
aRect2[iC].left = rect.left * iAspectRatio;
aRect2[iC].top = rect.top * iAspectRatio;
aRect2[iC].right = rect.right * iAspectRatio;
aRect2[iC].bottom = rect.bottom * iAspectRatio;
}
}
return TRUE;
case WM_SIZE:
for (int iC = 0; iC < MAXCTRLS; iC++) {
if (wParam == SIZE_MAXIMIZED)
MoveWindow(GetDlgItem(hwndDlg, 4001+iC), aRect2[iC].left, aRect2[iC].top, aRect2[iC].right, aRect2[iC].bottom, TRUE);
else
MoveWindow(GetDlgItem(hwndDlg, 4001+iC), aRect[iC].left, aRect[iC].top, aRect[iC].right, aRect[iC].bottom, TRUE);
}
return TRUE;
case WM_CLOSE:
EndDialog(hwndDlg, 0);
return TRUE;
}
return FALSE;
}
Code: [Select]
#include <windows.h>

LANGUAGE LANG_ENGLISH,SUBLANG_ENGLISH_US

1001 DIALOG DISCARDABLE 6, 18, 118, 86
STYLE WS_POPUP|WS_CAPTION|WS_SYSMENU|WS_MAXIMIZEBOX
CAPTION "Test"
FONT 8, "Tahoma"
{
  CONTROL "OK", 4001, "Button", WS_TABSTOP, 1, 2, 100, 20
  CONTROL "Cancel", 4002, "Button", WS_TABSTOP, 1, 24, 100, 20
  CONTROL "Forget", 4003, "Button", WS_TABSTOP, 1, 46, 100, 20
}
EDIT: to avoid __ftoll and crt
Code: [Select]
#define WIN32_LEAN_AND_MEAN
#include <windows.h>

#ifndef DLG_MAIN
#define DLG_MAIN 1001
#endif

LRESULT CALLBACK MainDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
int ScaleInt(int a, float f);

#define MAXCTRLS 3
RECT aRect[MAXCTRLS]; // normal
RECT aRect2[MAXCTRLS]; // maximized

int __cdecl WinMainCRTStartup(void)
{
HINSTANCE hInstance = GetModuleHandle(NULL);
//int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
//{
return DialogBox(hInstance, MAKEINTRESOURCE(DLG_MAIN), NULL, (DLGPROC)MainDlgProc);
}

LRESULT CALLBACK MainDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_INITDIALOG:
{
RECT rect;
RECT rect2;
GetClientRect(hwndDlg, &rect);
GetClientRect(GetDesktopWindow(), &rect2);
float fScale2 = (float)rect2.bottom / (float)rect.bottom;
for (int iC = 0; iC < MAXCTRLS; iC++) {
HWND hWnd = GetDlgItem(hwndDlg, 4001+iC);
GetWindowRect(GetDlgItem(hwndDlg, 4001+iC), &rect);
ScreenToClient(hwndDlg, (POINT*)&rect.left);
ScreenToClient(hWnd, (POINT*)&rect.right);
MoveWindow(GetDlgItem(hwndDlg, 4001+iC), rect.left, rect.top, rect.right, rect.bottom, TRUE);
CopyRect(&aRect[iC], &rect);
#ifndef _WIN64
aRect2[iC].left = ScaleInt(rect.left, fScale2);
aRect2[iC].top = ScaleInt(rect.top, fScale2);
aRect2[iC].right = ScaleInt(rect.right, fScale2);
aRect2[iC].bottom = ScaleInt(rect.bottom, fScale2);
#else
aRect2[iC].left = rect.left * fScale2;
aRect2[iC].top = rect.top * fScale2;
aRect2[iC].right = rect.right * fScale2;
aRect2[iC].bottom = rect.bottom * fScale2;
#endif
}
}
return TRUE;
case WM_SIZE:
for (int iC = 0; iC < MAXCTRLS; iC++) {
if (wParam == SIZE_MAXIMIZED)
MoveWindow(GetDlgItem(hwndDlg, 4001+iC), aRect2[iC].left, aRect2[iC].top, aRect2[iC].right, aRect2[iC].bottom, TRUE);
else
MoveWindow(GetDlgItem(hwndDlg, 4001+iC), aRect[iC].left, aRect[iC].top, aRect[iC].right, aRect[iC].bottom, TRUE);
}
return TRUE;
case WM_CLOSE:
EndDialog(hwndDlg, 0);
return TRUE;
}
return FALSE;
}

int ScaleInt(int a, float f)
{
int b;
__asm {
fld f
fimul a
fistp b
}
return b;
}
« Last Edit: November 19, 2017, 09:48:15 PM by TimoVJL »
May the source be with you