Results 1 to 11 of 11

Thread: Is it my breath?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 1999
    Location
    Sunny Southern Weather
    Posts
    406

    Post

    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?!

  2. #2
    Member
    Join Date
    Jul 1999
    Posts
    40

    Post

    Must be your breath!

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    May 1999
    Location
    Sunny Southern Weather
    Posts
    406

    Post

    thanks.

  4. #4
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    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..
    Code:
    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..
    Code:
    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
    [email protected]
    [email protected]

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    May 1999
    Location
    Sunny Southern Weather
    Posts
    406

    Post

    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!)

  6. #6
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Post

    This was something new:
    lDC = GetDC(0)

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

    ------------------
    Joacim Andersson
    [email protected]
    [email protected]
    www.YellowBlazer.com



  7. #7
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892

    Post

    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: [email protected]
    ICQ: 19552879
    AIM: RYoni69

  8. #8
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    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..
    Code:
    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
    [email protected]
    [email protected]

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    May 1999
    Location
    Sunny Southern Weather
    Posts
    406

    Post

    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???

  10. #10
    Hyperactive Member
    Join Date
    Sep 1999
    Location
    Cleveland, Ohio
    Posts
    263

    Post

    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!

  11. #11
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    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
    [email protected]
    [email protected]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width