• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 317
  • Last Modified:

Controlbox question

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
sopheak
Asked:
sopheak
1 Solution
 
burntoutCommented:
I don't think is is possible, the icon is the controlbox.
0
 
ArkCommented:
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Erick37Commented:
"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
 
adam8Commented:
Nup, it isn't
0
 
adam8Commented:
put the icon in the system tray.
thought about that?
0
 
adam8Commented:
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
 
ArkCommented:
IMHO, System Tray and TaskBar is different things.
0
 
fugglesCommented:
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
 
sopheakAuthor Commented:
Thanks to all, but this is the one I ended up using
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now