Click here to Skip to main content
12,357,929 members (68,225 online)
Click here to Skip to main content

Stats

177.3K views
6.5K downloads
80 bookmarked
Posted

Easy dialog control resizer

, 22 Sep 2003
Simple implementation of "anchors" and "docking" features implemented in .NET forms
#include "windows.h"
#include "commctrl.h"
#include "windowsx.h"
#include "resource.h"
#include "../anchor.h"
#include "../dlgman.h"

CDlgAnchor dlgAnchor;
CDlgMan    dlgMan;    // class that help to load/save size and position of dialog
                      // window and all child controls

static BOOL CALLBACK DialogFunc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
  switch (msg) {

  case WM_INITDIALOG:
    /* anchor code */
    dlgAnchor.Init(hwndDlg);
    dlgAnchor.Add(IDOK, ANCHOR_BOTTOM);
    dlgAnchor.Add(IDCANCEL, ANCHOR_BOTTOM);
    dlgAnchor.Add(IDC_LIST1, ANCHOR_TOPLEFT | ANCHOR_BOTTOM);
    dlgAnchor.Add(IDC_LIST2, ANCHOR_BOTTOMLEFT | ANCHOR_RIGHT);
    dlgAnchor.Add(IDC_EDIT1, ANCHOR_ALL);
    dlgAnchor.Add(
      CreateWindow("msctls_statusbar32", "Docking: left right bottom", WS_VISIBLE|WS_CHILD, 0, 0, 0, 0, hwndDlg, NULL, NULL, 0),
      DOCK_LEFT | DOCK_BOTTOM | DOCK_RIGHT
    );
    ListBox_AddString(GetDlgItem(hwndDlg, IDC_LIST1), "Anchor:");
    ListBox_AddString(GetDlgItem(hwndDlg, IDC_LIST1), "top");
    ListBox_AddString(GetDlgItem(hwndDlg, IDC_LIST1), "left");
    ListBox_AddString(GetDlgItem(hwndDlg, IDC_LIST1), "bottom");
    ListBox_AddString(GetDlgItem(hwndDlg, IDC_LIST2), "Anchor: left right bottom");
    SetDlgItemText(hwndDlg, IDC_EDIT1, "Anchor: top left right bottom");

    // load dialog window position and position of all controls inside
    dlgMan.Load(hwndDlg, "Software\\CodeProject\\AnchorExample");

    // update position of all docked controls
    dlgAnchor.OnSize();
    return TRUE;

  case WM_SIZE:
    /* anchor code */
    dlgAnchor.OnSize();
    InvalidateRect(hwndDlg, NULL, FALSE);
    break;

  case WM_COMMAND:
    switch (LOWORD(wParam)) {
      case IDOK:
      case IDCANCEL:
        EndDialog(hwndDlg,LOWORD(wParam));
        return TRUE;
    }
    break;

  case WM_CLOSE:
    EndDialog(hwndDlg,0);
    return TRUE;

  case WM_DESTROY:
    // save pos/sizes
    dlgMan.Save();
  }
  return FALSE;
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
  InitCommonControls();
  return DialogBox(hInstance, (LPCTSTR)IDD_DIALOG1, NULL, (DLGPROC) DialogFunc);
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

uemaker
Web Developer
Slovakia Slovakia
No Biography provided

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160621.1 | Last Updated 23 Sep 2003
Article Copyright 2003 by uemaker
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid