Announcement

Collapse
No announcement yet.

GUI- catch taskbar right click on program and negate the action to close the window

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • GUI- catch taskbar right click on program and negate the action to close the window

    This program is an effort to catch the right click on a taskbar program window and stop the context menu that shows in windows 7.
    This gui is a testing stage for a program to run in the background with no GUI to negate any right click context menu from appearing to the user.
    I really do not know what i am doing but i am making an error to stop the "close window" from appearing along with all other context menu items and that is ok with me.
    I believe if i can send an escape key to the window that may work.
    But i am having a hard time sending an escape key to the window "htry" and i need some help to do that.

    This program assumes that the taskbar is on the bottom and is not hidden or auto hidden.
    In gpedit, you can force the location of the taskbar to the bottom and it not be hidden.

    I do not want to go this with this method, but we have console and other programs that cannot be rewritten.
    I really hate what Microsoft did but offering up a "close window" and to restart another instance of a program in the context menu of windows 7.

    I hate to ask for help and i know i have seen where people can send text and other stuff to other windows and i just cannot find those post on the forum.
    Give it a go if nothing else.

    Code:
    'compiled with PBWIN 9
    '
    #PBFORMS CREATED V2.01
    '------------------------------------------------------------------------------
    ' The first line in this file is a PB/Forms metastatement.
    ' It should ALWAYS be the first line of the file. Other
    ' PB/Forms metastatements are placed at the beginning and
    ' end of "Named Blocks" of code that should be edited
    ' with PBForms only. Do not manually edit or delete these
    ' metastatements or PB/Forms will not be able to reread
    ' the file correctly.  See the PB/Forms documentation for
    ' more information.
    ' Named blocks begin like this:    #PBFORMS BEGIN ...
    ' Named blocks end like this:      #PBFORMS END ...
    ' Other PB/Forms metastatements such as:
    '     #PBFORMS DECLARATIONS
    ' are used by PB/Forms to insert additional code.
    ' Feel free to make changes anywhere else in the file.
    '------------------------------------------------------------------------------
    
    #COMPILE EXE
    #DIM ALL
    
    '------------------------------------------------------------------------------
    '   ** Includes **
    '------------------------------------------------------------------------------
    #PBFORMS BEGIN INCLUDES
    #RESOURCE "mousetest3.pbr"
    #INCLUDE ONCE "WIN32API.INC"
    #INCLUDE ONCE "COMMCTRL.INC"
    #INCLUDE ONCE "PBForms.INC"
    #PBFORMS END INCLUDES
    '------------------------------------------------------------------------------
    
    
    '------------------------------------------------------------------------------
    '   ** Constants **
    '------------------------------------------------------------------------------
    #PBFORMS BEGIN CONSTANTS
    %IDD_DIALOG1  =  101
    %IDC_TEXTBOX1 = 1001
    %IDC_TEXTBOX2 = 1002
    %IDC_TEXTBOX3 = 1003
    %IDC_TEXTBOX4 = 1004
    %IDC_TEXTBOX5 = 1005
    %IDC_TEXTBOX6 = 1006
    %IDC_TEXTBOX7 = 1007
    
    #PBFORMS END CONSTANTS
    '------------------------------------------------------------------------------
    
    
      GLOBAL hDlg, hMouseHook  AS LONG
      GLOBAL MPt, lpPoint AS POINTAPI, OldMPt AS POINTAPI, dwRet AS DWORD
      GLOBAL hInst,dwcounter AS DWORD
    
    
    
    '------------------------------------------------------------------------------
    '   ** Declarations **
    '------------------------------------------------------------------------------
    DECLARE CALLBACK FUNCTION ShowDIALOG1Proc()
    DECLARE FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
    #PBFORMS DECLARATIONS
    
    FUNCTION iscursorintaskbar() AS LONG
        LOCAL Retval AS LONG
        LOCAL rc,rcwindow AS RECT
        GetCursorPos( lpPoint )
        SystemParametersInfo %SPI_GETWORKAREA, 0, BYVAL VARPTR(rc), 0
        IF lpPoint.y > (rc.nbottom+1&) THEN FUNCTION=1&
        CONTROL SET TEXT hDlg, %IDC_TEXTBOX5,"workarea bottom = "+STR$(rc.nbottom)+"  mouse vertical at = "+STR$(lpPoint.y)
    
    END FUNCTION
    
    
      '----------------------------------------------------------------------------------------------------------------------
      ' Callback for mouse hook proc.
      '----------------------------------------------------------------------------------------------------------------------
    
     FUNCTION MouseHookProc(BYVAL nCode AS LONG, BYVAL wParam AS LONG, BYVAL lParam AS LONG) EXPORT AS LONG
        LOCAL MHS AS MOUSEHOOKSTRUCT PTR
            LOCAL zClass   AS ASCIIZ * 50
            LOCAL hTry     AS DWORD
            MHS = lParam
            MPt = @MHS.Pt
            GetCursorPos( lpPoint )
            INCR dwcounter
    
            HTRY = WindowFromPoint(lpPoint.x, lpPoint.y)
            CONTROL SET TEXT hDlg, %IDC_TEXTBOX4,"windows handle"+STR$(htry)
            CONTROL REDRAW  hDlg, %IDC_TEXTBOX4
            IF wparam=517& THEN   'IF wparam=517& or wparam=516& THEN
                CONTROL SET TEXT hDlg, %IDC_TEXTBOX7,""
                IF iscursorintaskbar THEN
                     ' GetCursorPos( lpPoint )
                     ' HTRY = WindowFromPoint(lpPoint.x, lpPoint.y)
                      WHILE hTry
                        GetClassName(hTry, zClass, SIZEOF(zClass))
                        IF zClass = "MSTaskListWClass"   THEN   '"MSTaskListWClass"
                            CONTROL SET TEXT hDlg, %IDC_TEXTBOX7,"MSTaskListWClass"
    'place send messeage here to send an escape key to the htry window
                           'send an escape key to the htry window
                            EXIT LOOP
                        END IF
                        hTry = GetWindow(hTry, %GW_HWNDNEXT)
                    WEND
                    CONTROL SET TEXT hDlg, %IDC_TEXTBOX6,"in taskbar"
                ELSE
                    CONTROL SET TEXT hDlg, %IDC_TEXTBOX6,"out of taskbar"
                END IF
                CONTROL REDRAW  hDlg, %IDC_TEXTBOX6
                CONTROL REDRAW  hDlg, %IDC_TEXTBOX7
            END IF
          CONTROL SET TEXT hDlg, %IDC_TEXTBOX1,STR$(lpPoint.x)
          CONTROL SET TEXT hDlg, %IDC_TEXTBOX2,STR$(lpPoint.y)
          CONTROL SET TEXT hDlg, %IDC_TEXTBOX3,"mouse event count"+STR$(dwcounter)
          CONTROL REDRAW  hDlg, %IDC_TEXTBOX1
          CONTROL REDRAW  hDlg, %IDC_TEXTBOX2
          CONTROL REDRAW  hDlg, %IDC_TEXTBOX3
           FUNCTION = CallNextHookEx(BYVAL hMouseHook, BYVAL nCode, BYVAL wParam, BYVAL lParam)
        END FUNCTION
    
    
    '------------------------------------------------------------------------------
    '   ** Main Application Entry Point **
    '------------------------------------------------------------------------------
    FUNCTION PBMAIN()
        PBFormsInitComCtls (%ICC_WIN95_CLASSES OR %ICC_DATE_CLASSES OR _
            %ICC_INTERNET_CLASSES)
    
        ShowDIALOG1 %HWND_DESKTOP
    END FUNCTION
    '------------------------------------------------------------------------------
    
    '------------------------------------------------------------------------------
    '   ** CallBacks **
    '------------------------------------------------------------------------------
    CALLBACK FUNCTION ShowDIALOG1Proc()
     LOCAL pt        AS POINTAPI
          LOCAL hWnd      AS DWORD
          LOCAL szClass  AS ASCIIZ*%MAX_PATH
          LOCAL szBuf    AS ASCIIZ*%MAX_PATH
          LOCAL hParent  AS DWORD
          LOCAL DlgID    AS DWORD
    
    
        SELECT CASE AS LONG CB.MSG
            CASE %WM_INITDIALOG
                ' Initialization handler
    
                SetWindowPos CBHNDL, %HWND_TOPMOST, 0,0,0,0, %SWP_NOMOVE OR %SWP_NOSIZE
                SetProcessWorkingSetSize GetCurrentProcess, -1???, -1???
                  hMouseHook = SetWindowsHookEx (%WH_MOUSE_LL  , CODEPTR(MouseHookProc)  , hInst, BYVAL 0???)
    
            CASE %WM_DESTROY
                IF hMouseHook THEN
                    UnhookWindowsHookEx hMouseHook
                    hMouseHook = 0&
                END IF
    
            CASE %WM_NCACTIVATE
                STATIC hWndSaveFocus AS DWORD
                IF ISFALSE CB.WPARAM THEN
                    ' Save control focus
                    hWndSaveFocus = GetFocus()
                ELSEIF hWndSaveFocus THEN
                    ' Restore control focus
                    SetFocus(hWndSaveFocus)
                    hWndSaveFocus = 0
                END IF
                DIALOG REDRAW  CBHNDL
            CASE %WM_COMMAND
                ' Process control notifications
                SELECT CASE AS LONG CB.CTL
                    CASE %IDC_TEXTBOX1
                    CASE %IDC_TEXTBOX2
                    CASE %IDC_TEXTBOX3
                    CASE %IDC_TEXTBOX4
                    CASE %IDC_TEXTBOX5
                    CASE %IDC_TEXTBOX6
    
                END SELECT
        END SELECT
    END FUNCTION
    '------------------------------------------------------------------------------
    
    '------------------------------------------------------------------------------
    '   ** Dialogs **
    '------------------------------------------------------------------------------
    FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
        LOCAL lRslt  AS LONG
    
    #PBFORMS BEGIN DIALOG %IDD_DIALOG1->->
        LOCAL hFont1 AS DWORD
    
        DIALOG NEW hParent, "mousetest3", 70, 70, 350, 200, %WS_POPUP OR _
            %WS_BORDER OR %WS_DLGFRAME OR %WS_CAPTION OR %WS_SYSMENU OR _
            %WS_MINIMIZEBOX OR %WS_MAXIMIZEBOX OR %WS_CLIPSIBLINGS OR _
            %WS_VISIBLE OR %DS_MODALFRAME OR %DS_3DLOOK OR %DS_NOFAILCREATE OR _
            %DS_SETFONT, %WS_EX_CONTROLPARENT OR %WS_EX_LEFT OR _
            %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR, TO hDlg
        CONTROL ADD TEXTBOX, hDlg, %IDC_TEXTBOX1, "", 70, 10, 65, 20
        CONTROL ADD TEXTBOX, hDlg, %IDC_TEXTBOX2, "", 70, 36, 65, 20
        CONTROL ADD TEXTBOX, hDlg, %IDC_TEXTBOX3, "", 20, 58, 300, 20
        CONTROL ADD TEXTBOX, hDlg, %IDC_TEXTBOX4, "move the mouse", 20, 80, 300, 20
        CONTROL ADD TEXTBOX, hDlg, %IDC_TEXTBOX5, "right click some where", 20, 107, 300, 20
        CONTROL ADD TEXTBOX, hDlg, %IDC_TEXTBOX6, "", 20, 135, 300, 20
        CONTROL ADD TEXTBOX, hDlg, %IDC_TEXTBOX7, "", 20, 163, 300, 20
    
        FONT NEW "MS Sans Serif", 14, 0, %ANSI_CHARSET TO hFont1
    
        CONTROL SET FONT hDlg, %IDC_TEXTBOX1, hFont1
        CONTROL SET FONT hDlg, %IDC_TEXTBOX2, hFont1
        CONTROL SET FONT hDlg, %IDC_TEXTBOX3, hFont1
        CONTROL SET FONT hDlg, %IDC_TEXTBOX4, hFont1
        CONTROL SET FONT hDlg, %IDC_TEXTBOX5, hFont1
        CONTROL SET FONT hDlg, %IDC_TEXTBOX6, hFont1
        CONTROL SET FONT hDlg, %IDC_TEXTBOX7, hFont1
    #PBFORMS END DIALOG
        DIALOG SHOW MODAL hDlg, CALL ShowDIALOG1Proc TO lRslt
    
    #PBFORMS BEGIN CLEANUP %IDD_DIALOG1
        FONT END hFont1
    #PBFORMS END CLEANUP
    
        FUNCTION = lRslt
    END FUNCTION
    '------------------------------------------------------------------------------
    
    
    'other code text to myself to work with if needed i need it later
    
    'LOCAL rc AS RECT
    'LOCAL hMsgBox, hParent, hdc, ret, wi, ht, x, y AS LONG
    '
    ' IF hParent THEN
    '    GetWindowRect hParent, rc: x = rc.nLeft: y = rc.nTop
    '    w = rc.nRight - rc.nLeft: h = rc.nBottom - rc.nTop
    ' ELSE
    '    DESKTOP GET CLIENT TO w, h
    p purvis

  • #2
    exe on the above, to test, i want you to right click on all the items on the taskbar if it is on the bottom of the desktop.
    it will now work if you do not have the taskbar on the bottom in an unhidden mode.
    Attached Files
    p purvis

    Comment


    • #3
      I believe the code will work just fine searching for the class "MSTaskListWClass" in the window handle, without even doing any cursor location coding.
      That should help bring the cpu usage down and i will test on slow cpu's with single processors and single cores later.
      p purvis

      Comment


      • #4
        sorry, i left out something important to say
        the location of code i feel i need inserted is where this text is located
        'place send messeage here to send an escape key to the htry window 'send and escape key to the htry window
        p purvis

        Comment


        • #5
          I have not tested this code on windows 8 or windows 10, maybe some will try it.
          The best i can tell on windows 7, the only thing this program effects is when trying to get at the task manager from the taskbar and as far as windows 10 goes, i personally do not want at work users fiddling with setting as windows 10 allows you to do. So if this would stop that too. It would be a bonus. There are other ways to get to the same functions and most people do not need to be making a lot of those changes on production work anyways and that is my 2 cents on that subject.
          If i go forward with this method and i likely will for not finding a better solution. I am sure there can be many adjustments to exceptions to allow a context menu on right clicking the mouse.

          And for testing, you do not want to send a message to htry to close the windows. I did and it close down explorer itself, which all the taskbar disappeared.
          Using CTRL-ALT-DEL helped to bring back explorer and place the items back on the taskbar with the same programs still running with their windows. I do not believe i actually lost any windows on the desktop either, but i am not going to try that again.
          p purvis

          Comment


          • #6
            (never mind you've seen this already!)
            ,
            Dale

            Comment


            • #7
              Paul,

              You can control which options are available to your user by simply hiding the Window / Console Taskbar Icon.
              Code posted here by Pierre.

              An alternate more draconian step could be to hide the whole taskbar! Code here by Mark Hunter for that.
              Rgds, Dave

              Comment


              • #8
                Dave Thank you, I will try that out the program by Pierre. Been busy with many issues.
                Hiding the taskbar is not an option, specially when I see some kinds of relieve are possibly in the happening.
                p purvis

                Comment

                Working...
                X