PDA

Click to See Complete Forum and Search --> : Is it my breath?


wayneh
Dec 7th, 1999, 09:02 PM
Or do I just ask the hardest questions on this board?
It seems I rarely get any replies.

I asked 2 *simple* questions -

1) How do I dim the screen (on NT) like a screen saver?

2) How do I add an item to a forms system menu (the one you get when you right click the title bar) and how do I get the response when it's chosen?

Any of you gurus out there have the cojones to answer?! :)

Juillet
Dec 7th, 1999, 09:41 PM
Must be your breath!

wayneh
Dec 7th, 1999, 09:59 PM
thanks.

Aaron Young
Dec 7th, 1999, 10:33 PM
What do you mean when you say Dim the Screen? Like when you Select Shutdown? Or do you mean how do you get access to the Screen for Drawing Operations?

If it's Accessing the Screen, Maximize a Borderless Form and use the BitBlt API with the GetDC API to copy the Image of the Desktop to the Form, giving the Illusion of the Desktop on which you can Draw, etc..

Otherwise, do the same as above, then use a loop to draw diagonal black lines every 2 pixels to give the effect of Dimming the Screen.

Here's a quick Example of how to add an Item the the System Menu of a Form and Utilize it..

In a Module..

Private Declare Function GetSystemMenu Lib "user32" (ByVal Hwnd As Long, ByVal bRevert As Long) As Long
Private Declare Function AppendMenu Lib "user32" Alias "AppendMenuA" (ByVal hMenu As Long, ByVal wFlags As Long, ByVal wIDNewItem As Long, ByVal lpNewItem As Any) As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal Hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal Hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Public Const GWL_WNDPROC = (-4)
Private Const MF_ENABLED = &H0&
Private Const MF_STRING = &H0&
Private Const WM_MENUSELECT = &H11F

Private lMenu As Long
Public lPrevProc As Long

Public Sub SetupMenu(ByVal lHwnd As Long)
lMenu = GetSystemMenu(lHwnd, 0)
Call AppendMenu(lMenu, MF_ENABLED Or MF_STRING, 200, ByVal "Happy Happy Joy Joy!")
End Sub

Public Function SubWindowProc(ByVal Hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Static lSelected As Long
Static lSelMenu As Long

If Msg = WM_MENUSELECT Then
If lParam Then
lSelected = wParam And &HFF
lSelMenu = lParam
Else
If lSelected = 200 And lSelMenu = lMenu Then MsgBox "Happy Happy Joy Joy!!!", vbSystemModal, "System Menu Popup"
lSelected = 0
End If
End If
SubWindowProc = CallWindowProc(lPrevProc, Hwnd, Msg, wParam, ByVal lParam)
End Function

In the Form..

Private Sub Form_Load()
Call SetupMenu(Hwnd)
lPrevProc = SetWindowLong(Hwnd, GWL_WNDPROC, AddressOf SubWindowProc)
End Sub

Private Sub Form_Unload(Cancel As Integer)
Call SetWindowLong(Hwnd, GWL_WNDPROC, lPrevProc)
End Sub



------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
adyoung@win.bright.net

wayneh
Dec 7th, 1999, 10:50 PM
Re: Dim the screen - Yes, I mean like when you shutdown. I want to be able to "turn down the brightness" so to speak....on NT.

Also, haven't yet tried your menu code yet but thanks so far...

(I guess using mouthwash helped after all!)

Joacim Andersson
Dec 8th, 1999, 04:41 AM
This was something new:
lDC = GetDC(0)

Why do you get the desktop DC by passing 0 as the hWnd?

------------------
Joacim Andersson
joacim@programmer.net
joacim@yellowblazer.com
www.YellowBlazer.com (http://www.YellowBlazer.com)

Yonatan
Dec 8th, 1999, 04:55 AM
GetDC allocates a Device-Context for the hWnd specified. This hWnd can be either:

0 (Zero) - Currently active desktop.
128 - First desktop (the one created when Windows started).
Any other number - A valid window handle.

------------------
Yonatan
Teenage Programmer
E-Mail: RZvika@netvision.net.il
ICQ: 19552879 (http://www.icq.com/19552879)
AIM: RYoni69

Aaron Young
Dec 8th, 1999, 11:54 AM
A Quick and Effective Method for Reducing the Brightness of the Screen (Dimming it), would be to AND the Image of the Screen with a Dark Solid Background, eg.

In a Form, with the BorderStyle set to 0 - None, and the WindowState set to 2 - Maximized..

Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
Private Const SRCAND = &H8800C6

Private Sub Form_Load()
Dim lDC As Long
Hide
'Set the Background Color to a Dark Grey -
'to use to Dim the Screen Image
BackColor = RGB(80, 80, 80)
AutoRedraw = True
'Get the Desktop Device Context
lDC = GetDC(0)
DoEvents
'Copy the Screen Image to the Form Using AND
BitBlt hdc, 0, 0, Screen.Width / Screen.TwipsPerPixelX, Screen.Height / Screen.TwipsPerPixelY, lDC, 0, 0, SRCAND
Call ReleaseDC(0, lDC)
Picture = Image
Show
End Sub


------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
adyoung@win.bright.net

wayneh
Dec 12th, 1999, 04:33 AM
Aaron -
I have used your code to add a menu item to the system menu of a form and it
seems to work BUT:

1) If I open more than one window, only the most recent window will call my
menu item. The others show my new menu item, but when selected they do
nothing.

2) It seems as though the subwindowproc is being called everytime ANY window
is touched, moved, resized, covered, uncovered, etc. In addition to making
it nearly impossible to step through the code, when I do reach any error VB6
locks up and I have to kill it with the task mgr. Or, it'll crash.

Do you know of any other way to add an item to the system menu???

Phobic
Dec 12th, 1999, 09:38 AM
This is just a cool way to dim the screen without drawing lines everywhere, this one actually dims the screen to a different shade... Use BitBlt along with the raster operation code MERGE, and merge it with a picturebox with a black background. It looks cool!

Aaron Young
Dec 12th, 1999, 08:24 PM
The Code Example I posted was written for a Single Window Instance, you'd need to adapt it to function with Multiple Forms.
You would need to track multiple lMenu and lPrevProc Variables and Each Form would Have to Be Subclassed to check for the Menu Messages.

------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
adyoung@win.bright.net