Skip to content

Commit 585d9ba

Browse files
committed
Added utils.setbackgroundcolour function
1 parent cc55da4 commit 585d9ba

File tree

5 files changed

+94
-1
lines changed

5 files changed

+94
-1
lines changed

MDIClientWnd.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#include "stdafx.h"
2+
#include "MUSHclient.h"
3+
#include "mainfrm.h"
4+
5+
#include "MDIClientWnd.h"
6+
7+
// CMDIClientWnd
8+
9+
IMPLEMENT_DYNAMIC(CMDIClientWnd, CWnd)
10+
11+
CMDIClientWnd::CMDIClientWnd()
12+
{
13+
}
14+
15+
CMDIClientWnd::~CMDIClientWnd()
16+
{
17+
}
18+
19+
20+
BEGIN_MESSAGE_MAP(CMDIClientWnd, CWnd)
21+
ON_WM_ERASEBKGND()
22+
END_MESSAGE_MAP()
23+
24+
25+
26+
// CMDIClientWnd message handlers
27+
28+
// utils.setbackgroundcolour (ColourNameToRGB ("yellow") )
29+
30+
BOOL CMDIClientWnd::OnEraseBkgnd(CDC* pDC)
31+
{
32+
33+
// if colour is 0xFFFFFFFF then use Windows default (same as before)
34+
if (Frame.m_backgroundColour == 0xFFFFFFFF)
35+
return CWnd::OnEraseBkgnd(pDC);
36+
37+
// Set brush to desired background color
38+
CBrush backBrush(Frame.m_backgroundColour);
39+
40+
// Save old brush
41+
CBrush* pOldBrush = pDC->SelectObject(&backBrush);
42+
43+
CRect rect;
44+
pDC->GetClipBox(&rect); // Erase the area needed
45+
pDC->PatBlt(rect.left, rect.top, rect.Width(), rect.Height(), PATCOPY);
46+
47+
// put brush back
48+
pDC->SelectObject(pOldBrush);
49+
50+
return TRUE;
51+
}

MDIClientWnd.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// MDIClientWnd.h : sub-classed MDI frame
2+
//
3+
/////////////////////////////////////////////////////////////////////////////
4+
5+
#pragma once
6+
7+
class CMDIClientWnd : public CWnd
8+
{
9+
DECLARE_DYNAMIC(CMDIClientWnd)
10+
11+
public:
12+
CMDIClientWnd();
13+
virtual ~CMDIClientWnd();
14+
15+
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
16+
17+
protected:
18+
DECLARE_MESSAGE_MAP()
19+
};

mainfrm.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ int ActivityToolBarResourceNames [6] = {
6464
BEGIN_MESSAGE_MAP(CMyToolBar, CToolBar)
6565
//{{AFX_MSG_MAP(CMyToolBar)
6666
ON_WM_NCPAINT()
67-
//}}AFX_MSG_MAP
67+
//}}AFX_MSG_MAP
6868
END_MESSAGE_MAP()
6969

7070
void CMyToolBar::OnNcPaint()
@@ -257,6 +257,7 @@ m_wDeviceID = 0; // no MCI device yet
257257
m_bFullScreen = false;
258258
m_bFlashingWindow = false;
259259
m_iTabsCount = 0;
260+
m_backgroundColour = 0xFFFFFFFF; // use default background colour
260261

261262
ZeroMemory(&m_niData,sizeof(NOTIFYICONDATA));
262263
m_niData.cbSize = sizeof(NOTIFYICONDATA);
@@ -282,6 +283,12 @@ int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
282283
return -1;
283284
}
284285

286+
if (!m_wndMDIClient.SubclassWindow(m_hWndMDIClient))
287+
{
288+
TRACE ("Failed to subclass MDI client window\n");
289+
return (-1);
290+
}
291+
285292
if (!m_wndToolBar.CreateEx(this, iToolbarFlags, WS_CHILD | WS_VISIBLE | CBRS_TOP
286293
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
287294
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
@@ -2332,3 +2339,4 @@ void CMainFrame::CheckTimerFallback ()
23322339
ProcessTimers ();
23332340

23342341
} // end of CMainFrame::CheckTimerFallback
2342+

mainfrm.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#pragma once
66

7+
#include "MDIClientWnd.h"
78
#include "MyStatusBar.h"
89
#include "MDITabs.h"
910

@@ -126,8 +127,12 @@ class CMainFrame : public CMDIFrameWnd
126127

127128
CHARFORMAT m_defaultInfoBarFormat;
128129

130+
COLORREF m_backgroundColour; // MDI frame background colour, 0xFFFFFFFF for the default
131+
129132
protected: // control bar embedded members
130133

134+
CMDIClientWnd m_wndMDIClient;
135+
131136
bool m_bActive; // is app active or not?
132137

133138
// Generated message map functions

scripting/lua_utils.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2106,6 +2106,15 @@ static int menufontsize (lua_State *L)
21062106
return 1; // return old size
21072107
} // end of menufontsize
21082108

2109+
// See: http://forums.codeguru.com/showthread.php?383142-change-background-color-of-mainframe
2110+
2111+
static int setbackgroundcolour (lua_State *L)
2112+
{
2113+
Frame.m_backgroundColour = luaL_optnumber (L, 1, 0);
2114+
Frame.InvalidateRect(NULL);
2115+
return 0; // return nothing
2116+
} // end of setbackgroundcolour
2117+
21092118
#if 0
21102119
static int registry (lua_State *L)
21112120
{
@@ -2155,6 +2164,7 @@ static const struct luaL_Reg xmllib [] =
21552164
{"msgbox", msgbox}, // msgbox - not Unicode
21562165
{"multilistbox", multilistbox},
21572166
{"reload_global_prefs", reload_global_prefs},
2167+
{"setbackgroundcolour", setbackgroundcolour},
21582168
{"showdebugstatus", showdebugstatus},
21592169
{"sendtofront", send_to_front},
21602170
{"shellexecute", shell_execute},

0 commit comments

Comments
 (0)