Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Controlbox question

Posted on 2000-04-12
10
311 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
ID: 2710074
I don't think is is possible, the icon is the controlbox.
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2710085
0
 
LVL 28

Expert Comment

by:Ark
ID: 2710167
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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 32

Accepted Solution

by:
Erick37 earned 50 total points
ID: 2710230
"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
ID: 2710602
Nup, it isn't
0
 
LVL 1

Expert Comment

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

Expert Comment

by:adam8
ID: 2710612
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 28

Expert Comment

by:Ark
ID: 2710643
IMHO, System Tray and TaskBar is different things.
0
 

Expert Comment

by:fuggles
ID: 2711447
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
ID: 2713747
Thanks to all, but this is the one I ended up using
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

856 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