?
Solved

Controlbox question

Posted on 2000-04-12
10
Medium Priority
?
314 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
[X]
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
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: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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 32

Accepted Solution

by:
Erick37 earned 200 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

Industry Leaders: 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!

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…
Suggested Courses

800 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