[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

VB6 Form caption in taskbar

Posted on 2007-07-23
30
Medium Priority
?
1,349 Views
Last Modified: 2011-10-03
In my VB6 application I am using a form in which controlbox is set to false and the Border Style is set to Fixed Dialog (as per requirements). I cannot set a caption at design time because that will add a blue title bar to the form. The problem is that when the application is minimized in the taskbar only an icon is displayed without the caption. Although i tried Me.Caption = "Applicationname" just before form is minimized it does not work. I need the caption when the form is minimized.
0
Comment
Question by:hiteshgoldeneye
  • 10
  • 8
  • 7
  • +3
30 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 19553559
you might try to set the caption when the form is minimized, and remove it when it get's restored?
0
 
LVL 13

Author Comment

by:hiteshgoldeneye
ID: 19553600
>you might try to set the caption when the form is minimized, and remove it when it get's restored?

Actually i have already tried that doesnt work. :(
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 19553870
is the "showintaskbar" property set to true or to false?

now, you might be interested reading the following article (and using that code):
http://www.vbaccelerator.com/codelib/winstyle/taskshow.htm
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 38

Expert Comment

by:PaulHews
ID: 19554008
Just tested, this works okay.

Fixed dialog, No controlbox and ShowInTaskbar = true

Option Explicit

Private Sub Command1_Click()
    Me.WindowState = vbMinimized
End Sub


Private Sub Form_Resize()
    If Me.WindowState = vbMinimized Then
        Me.Caption = "This is the caption"
    Else
        Me.Caption = ""
    End If
End Sub
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 19554024
One little problem... I have to set the height back to what it was before manually, or it shrinks every time it loses the title bar...

Option Explicit

Private Sub Command1_Click()
    Me.WindowState = vbMinimized
End Sub


Private Sub Form_Resize()
    If Me.WindowState = vbMinimized Then
        Me.Caption = "This is the caption"
    Else
        Me.Caption = ""
        Me.Height = 3180
    End If
End Sub
0
 
LVL 13

Author Comment

by:hiteshgoldeneye
ID: 19554236
Hi PaulHews I tried your code but still the form is shrinking or rather it is shifting downwards everytime i mininmize and maximize, any suggestions?
0
 
LVL 7

Expert Comment

by:tward
ID: 19555088
What am I missing, this seems to work just fine:

BorderStyle = 3 - Fixed Dialog
ControlBox = False
ShowInTaskbar = True

Private Sub Form_Resize()

  If Me.WindowState = vbMinimized Then

    Me.Caption = "this is a test"

  Else
     
     Me.Caption = ""

  End If

End Sub
0
 
LVL 13

Author Comment

by:hiteshgoldeneye
ID: 19555324
Please check after minimizing and maximizing many times, each time the form shiftws down in the screen
0
 
LVL 15

Expert Comment

by:Ralf Klatt
ID: 19555348
Hi,

This issue can be solved using:

Private Sub Form_Resize()
    If Me.WindowState = vbMinimized Then
        Me.Caption = "this is a test"
    Else
        Me.Caption = ""
        Me.Top = 0 'Define the top position of your choice here
        Me.Left = 0 'Define the left position of your choice here
    End If
End Sub


Best regards,
Raisor
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 19555699
This will save the top, left and height on load and reset them each time you restore.


Option Explicit
Private mTop, mLeft, mHeight As Long

Private Sub Command1_Click()
    Me.WindowState = vbMinimized
End Sub


Private Sub Form_Load()
    mTop = Me.Top
    mLeft = Me.Left
    mHeight = Me.Height
End Sub

Private Sub Form_Resize()
    If Me.WindowState = vbMinimized Then
        Me.Caption = "This is the caption"
    Else
        Me.Caption = ""
        Me.Height = mHeight
        Me.Move mLeft, mTop
    End If
End Sub
0
 
LVL 13

Author Comment

by:hiteshgoldeneye
ID: 19556010
I am stumped, it still doesn't work, you can try it,   the following lines do not work
        Me.Height = mHeight
        Me.Move mLeft, mTop
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 19556118
I have tried it.  It's working here.  Do you have any code that positions the form other than what we've posted here?
0
 
LVL 15

Expert Comment

by:Ralf Klatt
ID: 19556216
Hi,

I'm stumped too! ... :)

The key to solve this was to set ShowInTaskbar = True at design time (you can't set it at runtime!) ... only the location of the windows remained to be solved ...

Haven't you tried this?

Private Sub Form_Resize()
    If Me.WindowState = vbMinimized Then
        Me.Caption = "This is the caption"
    Else
        Me.Caption = ""
        Me.Top = 0 'Define the top position of your choice here
        Me.Left = 0 'Define the left position of your choice here
    End If
End Sub

-> just to tell ... Me.Height is absolutely irrelevant in this code as the window is set to be a fixed dialog box -> you'll set the size already at design time!


Best regards,
Raisor
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 19556355
>> just to tell ... Me.Height is absolutely irrelevant in this code as the window is set to be a fixed dialog box -> you'll set the size already at design time!

Nope... the form gets a little smaller each time, slowly rolling up like a window blind on each min-restore cycle.  That's what the height setting is for.

If the StartUpPosition property is set to CenterScreen or the like, that positioning will be lost.  You would have to center manually:

Set startupposition to manual, and use:

Private Sub Form_Load()
    Me.Move Screen.Width / 2 - Me.Width / 2, Screen.Height / 2 - Me.Height / 2
    mTop = Me.Top
    mLeft = Me.Left
    mHeight = Me.Height
   
   
End Sub
0
 
LVL 15

Expert Comment

by:Ralf Klatt
ID: 19556860
Hi,

Given, that the window has to be centered on the screen ... I've tested this:


'=================================================
VERSION 5.00
Begin VB.Form frmMain
   BorderStyle     =   3  'Fixed Dialog
   ClientHeight    =   2910
   ClientLeft      =   45
   ClientTop       =   45
   ClientWidth     =   5910
   ControlBox      =   0   'False
   HasDC           =   0   'False
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   2519.48
   ScaleMode       =   0  'User
   ScaleWidth      =   5480.68
   StartUpPosition =   2  'CenterScreen
   Begin VB.CommandButton Command2
      Caption         =   "Exit"
      Height          =   375
      Left            =   5040
      TabIndex        =   1
      Top             =   120
      Width           =   735
   End
   Begin VB.CommandButton Command1
      Caption         =   "Minimize"
      Height          =   495
      Left            =   1800
      TabIndex        =   0
      Top             =   600
      Width           =   2295
   End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private Sub Command1_Click()
    Me.WindowState = vbMinimized
End Sub

Private Sub Command2_Click()
    End
End Sub

Private Sub Form_Resize()
    With Me
        If .WindowState = vbMinimized Then
            .Caption = App.EXEName
        Else
            .Caption = ""
            .Top = Screen.Height / 2 - .Height / 2
            .Left = Screen.Width / 2 - .Width / 2
            .Width = 6000
            .Height = 3000
        End If
    End With
End Sub
'=================================================

... and it worked ...


Best regards,
Raisor
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 1400 total points
ID: 19556918
Try this out...

*** Set your desired Caption at DESIGN-TIME ***

Then, the code below removes the caption bar at run-time.  It doesn't appear to have the same "crawling" behaviour described in the other approaches:

Option Explicit

Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
    (ByVal hWnd As Long, ByVal nIndex As Long) As Long

Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
    (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
     
Private Const GWL_STYLE = (-16)
Private Const WS_CAPTION = &HC00000

Private Sub Form_Load()
    Dim lStyle As Long
   
    lStyle = GetWindowLong(Me.hWnd, GWL_STYLE)
    lStyle = lStyle And Not WS_CAPTION
    Call SetWindowLong(Me.hWnd, GWL_STYLE, lStyle)
End Sub

Private Sub Command1_Click()
    Me.WindowState = vbMinimized
End Sub
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 19557901
>It doesn't appear to have the same "crawling" behaviour described in the other

You get a little extra space at the bottom of the form, presumably making up for the removal of the title bar, but yes, it works well.  

The extra space could be fixed by setting height = client height before removing the caption:

Me.Height = Me.ScaleHeight + 6 * Screen.TwipsPerPixelY  'The extra 6 pixels seem to account for borders, top and bottom.

It also works with http://support.microsoft.com/kb/173773 which is nice if you need to move your form around.  And also, the caption stays in the task bar when restored (which is a problem for the other method.)

I'd say Idle_Mind's is the best solution so far.
0
 
LVL 15

Expert Comment

by:Ralf Klatt
ID: 19557935
Hi,

When I first read the alert I was thinking about something similar (API) to what Idle_Mind suggested ... but could only find C++ code on this ... when PaulHews brought up the ShowInTaskbar = True suggestion I was sure that it would do the trick that hiteshgoldeneye was looking for ... but I've tested Idle_Mind's suggestion and have to say that it's absolutely perfect ... you'll still see the caption in the task bar when the form is not minimized -> without having the caption on the form!

I enjoyed to see you at work Idle_Mind!


Best regards,
Raisor
0
 
LVL 13

Author Comment

by:hiteshgoldeneye
ID: 19562827
Guys i dont know what i am doing wrong,
ShowTaskBar is True,ControlBox = False and
BorderStyle = 3 - Fixed Dialog

But none of the above solutions work for me correctly, the form keeps shifting downwards everytime i minimize and maximize, the caption does appear properly.
0
 
LVL 15

Expert Comment

by:Ralf Klatt
ID: 19563124
Hi,

Please try the following:

1.) Create a text file in your projects folder
2.) Place this code in the text file:

'***************************************************
VERSION 5.00
Begin VB.Form frmMain
   BorderStyle     =   3  'Fixed Dialog
   Caption         =   "Minimizer"
   ClientHeight    =   2910
   ClientLeft      =   45
   ClientTop       =   345
   ClientWidth     =   5910
   ControlBox      =   0   'False
   HasDC           =   0   'False
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   2519.48
   ScaleMode       =   0  'User
   ScaleWidth      =   5480.681
   StartUpPosition =   2  'CenterScreen
   Begin VB.CommandButton Command2
      Caption         =   "Exit"
      Height          =   375
      Left            =   5040
      TabIndex        =   1
      Top             =   120
      Width           =   735
   End
   Begin VB.CommandButton Command1
      Caption         =   "Minimize"
      Height          =   495
      Left            =   1800
      TabIndex        =   0
      Top             =   600
      Width           =   2295
   End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
    (ByVal hWnd As Long, ByVal nIndex As Long) As Long

Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
    (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
     
Private Const GWL_STYLE = (-16)
Private Const WS_CAPTION = &HC00000

Private Sub Form_Load()
    Dim lStyle As Long
    lStyle = GetWindowLong(Me.hWnd, GWL_STYLE)
    lStyle = lStyle And Not WS_CAPTION
    Call SetWindowLong(Me.hWnd, GWL_STYLE, lStyle)
End Sub

Private Sub Command1_Click()
    Me.WindowState = vbMinimized
End Sub

Private Sub Command2_Click()
    End
End Sub
'***************************************************

3.) Save the text file
4.) Rename the text file to "testform.frm"
5.) Click on "Project" -> "Add File" and add "testform.frm" to your project
6.) Click on "Project" -> "<yourApp> Properties" and select "testform.frm" as Startup Object
7.) Run the project and see Idle_Mind's solution in action


Best regards,
Raisor
0
 
LVL 13

Author Comment

by:hiteshgoldeneye
ID: 19563578
Hi raisor i tried your form and it works fine,
but why is it not working in my form, the properties of my form are

Begin VB.Form QuickTab
   BorderStyle     =   3  'Fixed Dialog
   ClientHeight    =   11520
   ClientLeft      =   0
   ClientTop       =   -615
   ClientWidth     =   15360
   ClipControls    =   0   'False
   ControlBox      =   0   'False
   BeginProperty Font
      Name            =   "Arial"
      Size            =   9
      Charset         =   0
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   Icon            =   "FrmQuickTable.frx":0000
   KeyPreview      =   -1  'True
   LinkTopic       =   "Form1"
   LockControls    =   -1  'True
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   11520
   ScaleWidth      =   15360
   WindowState     =   2  'Maximized
0
 
LVL 15

Expert Comment

by:Ralf Klatt
ID: 19563676
Hi,

I've just used your parameters and it is still working!

Please paste the complete source code of your "QuickTab" form (text of "quicktab.frm") so I can test it here.


Best regards,
Raisor
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 19565862
You can also upload the project here so we can find the problem easier:
http://www.ee-stuff.com
0
 
LVL 13

Author Comment

by:hiteshgoldeneye
ID: 19567319
sorry friends but the project and the form contains confidential code, can you let me know what all steps i have to take finally?
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 19567553
hiteshgoldeneye,

First from your post above, I don't see that "ShowInTaskbar" is set to true for your form.  From what I've tried here, using Idle_Mind's code, if you minimize the window, it will just disappear without having ShowInTaskbar set to true.

Secondly with the form in maximized state (you posted above: WindowState     =   2  'Maximized) you shouldn't have any problems with the window moving or resizing...  It's just maximized all the time.  If you are using the code as posted, you should have no problems.  I've tested it here.

Thirdly, since you can't post the code, unless you can give us more information, we've pretty much come to the end of where we can help you.  A solution was posted at http:#a19556918  , and it works.  
0
 
LVL 13

Author Comment

by:hiteshgoldeneye
ID: 19567673
Paul with regard to the points -
1- I have ShowInTaskBar = True in my form, god knows why it isnt appearing in the code
First from your post above, I don't see that "ShowInTaskbar" is set to true for your form.  From what I've tried here, using Idle_Mind's code, if you minimize the window, it will just disappear without having ShowInTaskbar set to true.

2 -Even though my form is maximized, with the above solution my form keeps shifting downwards (does not cover the screen)

Secondly with the form in maximized state (you posted above: WindowState     =   2  'Maximized) you shouldn't have any problems with the window moving or resizing...  It's just maximized all the time.  If you are using the code as posted, you should have no problems.  I've tested it here.

3 - I can post some part of the code which is very necessary for the solution lets say form_ resize(), form_load() and so on.
Thirdly, since you can't post the code, unless you can give us more information, we've pretty much come to the end of where we can help you.  A solution was posted at http:#a19556918  , and it works.  
0
 
LVL 15

Expert Comment

by:Ralf Klatt
ID: 19572478
Hi,

You may want to leave the vbMavimized state folly out of your project and set it at design time to "0 - Normal "

In addition to the used 2 API calls you'd add to mor API calls and to mor constants ... and the you replace add the following additional code to your form:

'========================================================
Option Explicit

Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
    (ByVal hwnd As Long, ByVal nIndex As Long) As Long

Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
    (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Private Declare Function SetWindowPos Lib "user32" _
    (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, _
    ByVal x As Long, ByVal y As Long, ByVal cx As Long, _
    ByVal cy As Long, ByVal wFlags As Long) As Long

Private Declare Function GetSystemMetrics Lib "user32" _
    (ByVal nIndex As Long) As Long

Private Const GWL_STYLE = (-16)
Private Const WS_CAPTION = &HC00000
Private Const SM_CXSCREEN = 0
Private Const SM_CYSCREEN = 1

Private myScreenWidth As Long
Private myScreenHeight As Long

Private Sub Form_Load()
    myScreenWidth = GetSystemMetrics(SM_CXSCREEN)
    myScreenHeight = GetSystemMetrics(SM_CYSCREEN)
    Dim lStyle As Long
    lStyle = GetWindowLong(Me.hwnd, GWL_STYLE)
    lStyle = lStyle And Not WS_CAPTION
    Call SetWindowLong(Me.hwnd, GWL_STYLE, lStyle)
End Sub

Private Sub Command1_Click()
    Me.WindowState = vbMinimized
End Sub

Private Sub Command2_Click()
    End
End Sub

Private Sub Form_Resize()
    If Me.WindowState <> vbMinimized Then
        SetWindowPos Me.hwnd, 0, 0, 0, myScreenWidth, myScreenHeight, 0
    End If
End Sub
'========================================================

If that doesn't work for you ... well, then I definitely don't know what's going on -> without seeing the code then, it'll be like PaulHews stated!


Best regards,
Raisor
0
 
LVL 13

Author Comment

by:hiteshgoldeneye
ID: 19572708
Raisor with the above code that you just posted, I am having the blue title bat on the form with the caption, but the form is not crawling.
0
 
LVL 15

Assisted Solution

by:Ralf Klatt
Ralf Klatt earned 600 total points
ID: 19572794
Hi,

... if you want to tell me that (due to the enhancement I've provided) a blue title bar with the caption appeared then I must tell you that this is definitely impossible -> I'm not giving you some copy written code, I'm giving you tested code from my system and nothing ... absolutely nothing! ... from the given code makes a title bar appear!

If you'd be a beginner in VB I'd say that it's due to that fact ... but looking at your profile, I see that you made close to 30K pts. only this month -> in all kind of programming zones including VB ... so you're very well on track to soon becoming a master at EE ... everything further will be without words from my part!


Good luck!
Best regards,
Raisor
0
 
LVL 13

Author Comment

by:hiteshgoldeneye
ID: 19572932
Well Raisor and Idle_Mind I want to thank both of you for putting in so much effort for me. I have decided to split my points as raisor to deserves some of them apart from Idle_Mind.

Once again thank you friends. :)
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!

Question has a verified solution.

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

In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
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…
Introduction to Processes

873 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