All pastes #164491 Raw Edit

ResOptDlg

public text v1 · immutable
·published 2006-09-08 17:48 UTC
rendered paste body
/*
Resizable options dialog plugin for Miranda IM

Copyright © 2006 Cristian Libotean

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

#include "dlg_handlers.h"
#include "commctrl.h"

#define DIALOG_CLASS "#32770"

static int MIN_OPTIONS_WIDTH = 320;
static int MIN_OPTIONS_HEIGHT = 200;
static int MAX_OPTIONS_WIDTH = 1200;
static int MAX_OPTIONS_HEIGHT = 1200;

static HWND hFirstChildDlg = NULL;

WNDPROC oldOptDlgProc;

void HookOptionsProc(HWND hOptDlg)
{
	oldOptDlgProc = (WNDPROC) SetWindowLong(hOptDlg, GWL_WNDPROC, (LONG) DlgProcOptions);
}

void UnhookOptionsProc(HWND hOptDlg)
{
	SetWindowLong(hOptDlg, GWL_WNDPROC, (LONG) oldOptDlgProc);
}

int OptionsDialogResizer(HWND hWnd, LPARAM lParam, UTILRESIZECONTROL *urc)
{
	switch (urc->wId)
	{
		case IDC_EXPERT:
		{
			return RD_ANCHORX_LEFT | RD_ANCHORY_BOTTOM;
		
			break;
		}
		
		case IDC_PAGETREE:
		{
			return RD_ANCHORX_WIDTH | RD_ANCHORY_TOP;
		
			break;
		}
		
		case IDOK:
		case IDCANCEL:
		case IDC_APPLY:
		{
			return RD_ANCHORX_RIGHT | RD_ANCHORY_BOTTOM;
			
			break;
		}
	}
	
	return RD_ANCHORX_RIGHT | RD_ANCHORY_TOP; //default value
}

int CALLBACK DlgProcOptions(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch (msg)
	{
		case WM_DESTROY:
		{
			UnhookOptionsProc(hWnd);
			
			break;
		}
		
		case WM_SIZE:
		{
			if (IsIconic(hWnd))
			{
				break;
			}
			
			UTILRESIZEDIALOG urd = {0};
			urd.cbSize = sizeof(UTILRESIZEDIALOG);
			urd.hInstance = GetModuleHandle(NULL);
			urd.lpTemplate = MAKEINTRESOURCE(IDD_OPTIONS);
			urd.pfnResizer = OptionsDialogResizer;
			
			CallService(MS_UTILS_RESIZEDIALOG, 0, (LPARAM) &urd);
			
			break;
		}
		
		case WM_USER + 10:
		{
			//todo
			
			break;
		}
		
		case RODM_HOOKED:
		{
			RECT r;
			
			GetWindowRect(hWnd, &r);
			
			MIN_OPTIONS_WIDTH = r.right - r.left;
			MAX_OPTIONS_WIDTH = 1200;
			MIN_OPTIONS_HEIGHT = MAX_OPTIONS_HEIGHT = r.bottom - r.top;
			
			hFirstChildDlg = FindWindowEx(hWnd, NULL, DIALOG_CLASS, NULL);
			
			ULONG style = GetWindowLong(hWnd, GWL_STYLE);
			style = style | WS_SIZEBOX & (~WS_MINIMIZEBOX);
			SetWindowLong(hWnd, GWL_STYLE, style);
			
			break;
		}
	}
	
	return CallWindowProc(oldOptDlgProc, hWnd, msg, wParam, lParam);
}