Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access main window color (MDI color)

Status
Not open for further replies.

barrymelson

Technical User
Jun 16, 2006
5
US
Hi:
I would like to determine the color of the Access main window. You know, if you open access before any database is opened. I want to set the detail section of a form to the main window color so that it appears transparent (without borders, control boxes etc.). I have looked at the Windows color IDs but, can't find one that matches the Access main window color. Any help is greatly appreciated.
Thanks,
Barry
 
For that, I'd imagine you need to use an image editor. So maybe what you could do is take a screen capture/grab of the database portion you want the color from. Then open that image in an image editor that includes a color dropper (I think that's the term). Then use that tool to view what the color code is....

Then go back, and try using the color code from the image program in your database design.

By the way, this hardly sounds like a VBA question. Sounds more like either a Form Design question, or probably just fits best in the "Other" category. So, for future reference, I'd suggest posting in forum181.
 
Dear kjv1611:
Not at all what I had in mind. I wanted to programatically find the value of the main Access window. Then I could apply it to a form that I wanted to appear "transparent" and it would work independent of individual system color settings. There was an example by Lebans however, it was over my head. The closest thing I have found is an example of an actual transparent form, which I have included below. The detail section is transparent while the controls remain in their original state. I am sorry that I don't recall where I found it to give proper credit to the author.

So, I do believe that this is a VBA question, having to deal directly with API calls for finding the backcolor of the main window. I hope that you all enjoy the attachment, it worked quite nicely for me.
Thank you,
Barry

Here is the code: Call the function MakeTransparent(FormName)

Option Compare Database
Option Explicit

Public Const RGN_AND = 1
Public Const RGN_COPY = 5
Public Const RGN_DIFF = 4
Public Const RGN_OR = 2
Public Const RGN_XOR = 3

Public Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Public Declare Function GetClientRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Public Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long
Public Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Public Declare Function ScreenToClient Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
Public Declare Function SetWindowRgn Lib "user32" (ByVal hwnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long

Public Type POINTAPI
tLng_Xloc As Long
tLng_YLoc As Long
End Type

Public Type RECT
tLng_Left As Long
tLng_Top As Long
tLng_Right As Long
tLng_Bottom As Long
End Type

Public Sub MakeTransparent(rFrm_TheForm As Form)

Dim lCtl_Control As Control
Dim lRct_WinFrame As RECT
Dim lRct_ClientArea As RECT
Dim lRct_ControlArea As RECT
Dim lPnt_TopLeft As POINTAPI
Dim lPnt_BottRight As POINTAPI
Dim lLng_CntlHandle As Long
Dim lLng_ClientHandle As Long
Dim lLng_FrameHandle As Long

GetWindowRect rFrm_TheForm.hwnd, lRct_WinFrame
GetClientRect rFrm_TheForm.hwnd, lRct_ClientArea

lPnt_TopLeft.tLng_Xloc = lRct_WinFrame.tLng_Left
lPnt_TopLeft.tLng_YLoc = lRct_WinFrame.tLng_Top
lPnt_BottRight.tLng_Xloc = lRct_WinFrame.tLng_Right
lPnt_BottRight.tLng_YLoc = lRct_WinFrame.tLng_Bottom

ScreenToClient rFrm_TheForm.hwnd, lPnt_TopLeft
ScreenToClient rFrm_TheForm.hwnd, lPnt_BottRight

With lRct_WinFrame
.tLng_Left = lPnt_TopLeft.tLng_Xloc
.tLng_Top = lPnt_TopLeft.tLng_YLoc
.tLng_Right = lPnt_BottRight.tLng_Xloc
.tLng_Bottom = lPnt_BottRight.tLng_YLoc
End With

With lRct_ClientArea
.tLng_Left = Abs(lRct_WinFrame.tLng_Left)
.tLng_Top = Abs(lRct_WinFrame.tLng_Top)
.tLng_Right = .tLng_Right + Abs(lRct_WinFrame.tLng_Left)
.tLng_Bottom = .tLng_Bottom + Abs(lRct_WinFrame.tLng_Top)
End With

With lRct_WinFrame
.tLng_Right = .tLng_Right + Abs(.tLng_Left)
.tLng_Bottom = .tLng_Bottom + Abs(.tLng_Top)
.tLng_Top = 0
.tLng_Left = 0
End With

With lRct_ClientArea
lLng_ClientHandle = CreateRectRgn(.tLng_Left, .tLng_Top, .tLng_Right, .tLng_Bottom)
End With

With lRct_WinFrame
lLng_FrameHandle = CreateRectRgn(.tLng_Left, .tLng_Top, .tLng_Right, .tLng_Bottom)
End With

CombineRgn lLng_FrameHandle, lLng_ClientHandle, lLng_FrameHandle, RGN_XOR

For Each lCtl_Control In rFrm_TheForm.Controls
lRct_ControlArea.tLng_Left = lCtl_Control.Left \ 15
lRct_ControlArea.tLng_Top = lCtl_Control.Top \ 15
lRct_ControlArea.tLng_Right = (lCtl_Control.Left + lCtl_Control.Width - 15) \ 15
lRct_ControlArea.tLng_Bottom = (lCtl_Control.Top + lCtl_Control.Height - 15) \ 15

With lRct_ControlArea
.tLng_Left = .tLng_Left + lRct_ClientArea.tLng_Left
.tLng_Top = .tLng_Top + lRct_ClientArea.tLng_Top
.tLng_Right = .tLng_Right + lRct_ClientArea.tLng_Left
.tLng_Bottom = .tLng_Bottom + lRct_ClientArea.tLng_Top
lLng_CntlHandle = CreateRectRgn(.tLng_Left, .tLng_Top, .tLng_Right, .tLng_Bottom)
End With

CombineRgn lLng_FrameHandle, lLng_CntlHandle, lLng_FrameHandle, RGN_OR
Next lCtl_Control

SetWindowRgn rFrm_TheForm.hwnd, lLng_FrameHandle, True

End Sub
 
I guess the reason I thought it was not a coding question is this: why would you need to code the solution? Isn't the base Access color the same, regardless? I know that in Access 2007, you can tell Access to use Windows styling on forms and buttons, but I was under the impression that the main Access window was non-customizable. At least I've never seen or heard any examples of changing that.
 
As I understand it (and I may be wrong), the back color of the Access main window is dependant upon the system color settings. Again, as I understand, the color is the following system color.

VBA Constant - vbApplicationWorkspace
System Color - AppWorkspace
Hex value - &H8000000C
Long Value - -2147483636
Description - Background color of multiple document interface (MDI) applications.

Here is the link to one of the articles for VB6, but I believe it's the same in vba.

I tried to get the color as close to my backcolor as possible, then put the form on another machine and it was not even close. The solution above works very nicely. The buttons on my form stay and the background is absolutely transparent. And it looks the same on any machine it's running on. Cool!!

Thanks,
Barry
 
Barry,
1) Can you get Lebans code to work? I ran it in 2007 and nothing happens.
2) I got the transparent code to work. It is cool, and I have no idea how that works. Not sure if I would ever actually use it.
3) Looking at Leban's code the following APIs get and set the system colors
Code:
Public Declare Function SetSysColors Lib "user32" (ByVal nChanges As Long, lpSysColor As Long, _
lpColorValues As Long) As Long

Public Declare Function GetSysColor Lib "user32" (ByVal nIndex As Long) As Long

Public Const COLOR_SCROLLBAR = 0 'The Scrollbar colour
Public Const COLOR_BACKGROUND = 1 'Colour of the background with no wallpaper
Public Const COLOR_ACTIVECAPTION = 2 'Caption of Active Window
Public Const COLOR_INACTIVECAPTION = 3 'Caption of Inactive window
Public Const COLOR_MENU = 4 'Menu
Public Const COLOR_WINDOW = 5 'Windows background
Public Const COLOR_WINDOWFRAME = 6 'Window frame
Public Const COLOR_MENUTEXT = 7 'Window Text
Public Const COLOR_WINDOWTEXT = 8 '3D dark shadow (Win95)
Public Const COLOR_CAPTIONTEXT = 9 'Text in window caption
Public Const COLOR_ACTIVEBORDER = 10 'Border of active window
Public Const COLOR_INACTIVEBORDER = 11 'Border of inactive window
Public Const COLOR_APPWORKSPACE = 12 'Background of MDI desktop
Public Const COLOR_HIGHLIGHT = 13 'Selected item background
Public Const COLOR_HIGHLIGHTTEXT = 14 'Selected menu item
Public Const COLOR_BTNFACE = 15 'Button
Public Const COLOR_BTNSHADOW = 16 '3D shading of button
Public Const COLOR_GRAYTEXT = 17 'Grey text, of zero if dithering is used.
Public Const COLOR_BTNTEXT = 18 'Button text
Public Const COLOR_INACTIVECAPTIONTEXT = 19 'Text of inactive window
Public Const COLOR_BTNHIGHLIGHT = 20 '3D highlight of button
Public Const COLOR_2NDACTIVECAPTION = 27 'Win98 only: 2nd active window color
Public Const COLOR_2NDINACTIVECAPTION = 28 'Win98 only: 2nd inactive window color
So
getSysColor(COLOR_WINDOW)
gets the window background color

These values are RGB values as decimal. If you want to set the form's color to that, you need to turn them into seperate RGB values. Something like

Code:
Public Function get_rgb(ByVal dec As Long) As String
  Dim red As Long
  Dim green As Long
  Dim blue As Long

  red = dec And &HFF
  green = (dec And &HFF00&) \ 256
  blue = dec \ 65536

  get_rgb = CStr(red) & "," & CStr(green) & "," & CStr(blue)
End Function

Public Function getRed(strRGB As String) As Long
  getRed = CInt(Nz(Split(strRGB, ",")(0), 0))
End Function

Public Function getGreen(strRGB As String) As Long
  getGreen = CInt(Nz(Split(strRGB, ",")(1), 0))
End Function

Public Function getBlue(strRGB As String) As Long
  getBlue = CInt(Nz(Split(strRGB, ",")(2), 0))
End Function

With that said, here is the bad news. None of those values are the Access MDI background color. To test it. I built a list box with the values of the constants (1-19, 20,27,28)

Code:
Private Sub lstColor_AfterUpdate()
    Dim decimalColor As Long
    Dim strRGB As String
    decimalColor = GetSysColor(Me.lstColor)
    strRGB = get_rgb(decimalColor)
    Me.Detail.BackColor = RGB(getRed(strRGB), getGreen(strRGB), getBlue(strRGB))
   ' SetSysColors 1, COLOR_WINDOW, decimalColor
End Sub

And this will set my form to any of the system colors. However, none of them are the container background. However, if I use the SetSysColor I can change most of the container colors such as the ribbon, vbe environment, and the navigation pane. Bottom line using the above in A2007 you can get and set the colors of just about everything except the dang background. So, there is something more to getting the background then the Windows system colors.
 
Leban's code is way over my head. I know that he changes the main access window to a bitmap or different color and then back but, I can't follow. The transparent form is quite sufficient for now and I am off to other aspects of this project. Thanks for all the input, it's certainly appreciated.

Barry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top