Solved

Controlbox question

Posted on 2000-04-12
10
306 Views
Last Modified: 2010-05-02
When I run my application I do not want the users to minimize, maximize, or close out the program by using the "controls" in the upper right hand corner.  So I set minButton, MaxButton, and Controlbox to false.  However I have an icon on that form, and it does not show when I set controlbox to false.

I would like the icon of my app to show in the taskbar when it is running, without having the controlbox.  Is this possible?

thanks
0
Comment
Question by:sopheak
10 Comments
 
LVL 2

Expert Comment

by:burntout
Comment Utility
I don't think is is possible, the icon is the controlbox.
0
 
LVL 28

Expert Comment

by:AzraSound
Comment Utility
0
 
LVL 27

Expert Comment

by:Ark
Comment Utility
Hi
Don't set ControlBox to False. If you want Max and Min buttons be invisible, set them to False (even if they will be visible, they won't work). Add command button cmdClose to close your form.
Add following code at your form:
Option Explicit
Private Declare Function DeleteMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long
Private Const MF_BYPOSITION = &H400&

Private Sub RemoveMenus(frm As Form, remove_restore As Boolean, remove_move As Boolean, remove_size As Boolean, remove_minimize As Boolean, remove_maximize As Boolean, remove_seperator As Boolean, remove_close As Boolean)
   Dim hMenu As Long
  ' Get the form's system menu handle.
   hMenu = GetSystemMenu(hwnd, False)
   If remove_close Then DeleteMenu hMenu, 6, MF_BYPOSITION
   If remove_seperator Then DeleteMenu hMenu, 5, MF_BYPOSITION
   If remove_maximize Then DeleteMenu hMenu, 4, MF_BYPOSITION
   If remove_minimize Then DeleteMenu hMenu, 3, MF_BYPOSITION
   If remove_size Then DeleteMenu hMenu, 2, MF_BYPOSITION
   If remove_move Then DeleteMenu hMenu, 1, MF_BYPOSITION
   If remove_restore Then DeleteMenu hMenu, 0, MF_BYPOSITION
End Sub

Private Sub cmdClose_Click()
    Unload Me
End Sub

Private Sub Form_Load()
    ' Remove all system menu item and the
    ' menu separator.
    RemoveMenus Me, True, True, True, True, True, True, True
End Sub


Cheers
0
 
LVL 32

Accepted Solution

by:
Erick37 earned 50 total points
Comment Utility
"Killing Any Form's Close Menu and 'X' Button - SDI, MDIParent or MDIChild"

http://www.mvps.org/vbnet/code/system/killclosemdi.htm

"HOWTO: Disable the Close Option on Control Menu of a VB Form"

http://support.microsoft.com/support/kb/articles/Q184/6/86.ASP
0
 
LVL 1

Expert Comment

by:adam8
Comment Utility
Nup, it isn't
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 1

Expert Comment

by:adam8
Comment Utility
put the icon in the system tray.
thought about that?
0
 
LVL 1

Expert Comment

by:adam8
Comment Utility
Public Type NOTIFYICONDATA
    cbSize As Long
    hwnd As Long
    uId As Long
    uFlags As Long
    uCallBackMessage As Long
    hIcon As Long
    szTip As String * 64
    End Type
    'constants required by Shell_NotifyIcon
    '     API call:
    Public Const NIM_ADD = &H0
    Public Const NIM_MODIFY = &H1
    Public Const NIM_DELETE = &H2
    Public Const NIF_MESSAGE = &H1
    Public Const NIF_ICON = &H2
    Public Const NIF_TIP = &H4
    Public Const WM_MOUSEMOVE = &H200
    Public Const WM_LBUTTONDOWN = &H201 'Button down
    Public Const WM_LBUTTONUP = &H202'Button up
    Public Const WM_LBUTTONDBLCLK = &H203'Double-click
    Public Const WM_RBUTTONDOWN = &H204 'Button down
    Public Const WM_RBUTTONUP = &H205'Button up
    Public Const WM_RBUTTONDBLCLK = &H206'Double-click
Public Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
    Public nid As NOTIFYICONDATA

Me.Show
    Me.Refresh
   


    With nid
        .cbSize = Len(nid)
        .hwnd = Me.hwnd
        .uId = vbNull
        .uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
        .uCallBackMessage = WM_MOUSEMOVE
        .hIcon = Me.Icon
        .szTip = " Click Right Mouse Button " & vbNullChar
    End With


    Shell_NotifyIcon NIM_ADD, nid
End Sub




Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)


    'This procedure receives the callbacks f

    '     rom the System Tray icon.

    Dim Result As Long
    Dim msg As Long
    'The value of X will vary depending upon

    '     the scalemode setting



    If Me.ScaleMode = vbPixels Then
        msg = X
    Else
        msg = X / Screen.TwipsPerPixelX
    End If




    Select Case msg
        Case WM_LBUTTONUP'514 restore form window
        Me.WindowState = vbNormal
        Result = SetForegroundWindow(Me.hwnd)
        Me.Show
        Case WM_LBUTTONDBLCLK'515 restore form window
        Me.WindowState = vbNormal
        Result = SetForegroundWindow(Me.hwnd)
        Me.Show
        Case WM_RBUTTONUP'517 display popup menu
        Result = SetForegroundWindow(Me.hwnd)

        Me.PopupMenu Me.mnu_1
    End Select


End Sub




Private Sub Form_Resize()


    'this is necessary to assure that the mi

    '     nimized window is hidden

    If Me.WindowState = vbMinimized Then Me.Hide
End Sub




Private Sub Form_Unload(Cancel As Integer)


    'this removes the icon from the system t

    '     ray

    Shell_NotifyIcon NIM_DELETE, nid
End Sub




Private Sub mPopExit_Click()


    'called when user clicks the popup menu

    '     Exit command

    Unload Me
End Sub




Private Sub mPopRestore_Click()


    'called when the user clicks the popup m

    '     enu Restore command

    Me.WindowState = vbNormal
    Result = SetForegroundWindow(Me.hwnd)
    Me.Show
End Sub

0
 
LVL 27

Expert Comment

by:Ark
Comment Utility
IMHO, System Tray and TaskBar is different things.
0
 

Expert Comment

by:fuggles
Comment Utility
Why not use the QueryUnload event and set Cancel=False in the code so if the user clicks on the close button the program will not close...

Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)

   Beep
   cancel=true

End Sub

0
 

Author Comment

by:sopheak
Comment Utility
Thanks to all, but this is the one I ended up using
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now