How can I make a form have no Titlebar, be resizeable, and have a caption in the taskbar?
Printable View
How can I make a form have no Titlebar, be resizeable, and have a caption in the taskbar?
Can I ask one thing, You do not know that.
Thats the 1st thing I ever did learn lol. An it was easy as pie.
Here. Use google...
Search, Make a boarderless window that can resize
An the title bar tect is done from the title caption on the properties. It will do the same on the taskbar...
But I also want to be able to resize the window from the sides as well.
And I was just wondering if theres a simple way to do this without having to use all of those custom controls.
Here is some code I've had laying around a while. I think it is what you are after. For the form style property select 2-Sizeable.
VB Code:
Option Explicit 'API Calls Used To Remove The Title Bar From Window (Make A Sizeable Borderless Form) 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 GetWindowLong Lib "user32" Alias "GetWindowLongA" _ (ByVal hwnd As Long, ByVal nIndex As Long) As Long Private Const GWL_STYLE = (-16) Private Const WS_DLGFRAME = &H400000 'API Calls Used To Move A Form With The Mouse Private Declare Function ReleaseCapture Lib "user32" () As Long Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _ (ByVal hwnd As Long, ByVal wMsg As Long, _ ByVal wParam As Long, lParam As Any) As Long Private Const HTCAPTION = 2 Private Const WM_NCLBUTTONDOWN = &HA1 Private Sub Form_Load() 'ERASE the Title Bar SetWindowLong Me.hwnd, GWL_STYLE, GetWindowLong(Me.hwnd, GWL_STYLE) + WS_DLGFRAME End Sub Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) 'Move the form with the Left Mouse Button If Button = vbLeftButton Then Me.MousePointer = vbSizeAll Call ReleaseCapture Call SendMessage(hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&) Me.MousePointer = vbArrow End If End Sub
Whoa! Thanks! That was exactly what I was looking for. I think I posted a topic similar to this before but I can't find it.
is there a way of "deactivating" or returning the form back to normal? i put the code in a "fullscreen" menu button thing.
Yeah, and also the titlebar reappears after I change the form's caption. How do I avoid that?
anyone............???
I guess not :(
dang... wheres MarkT?? WHY HAS HE FORESAKEN US?!!! *runs to a corner and cries*
Probably when you change the caption it removes the style and shows the title bar again. So I would assume that your could just make another call of the line that removes it.
VB Code:
SetWindowLong Me.hwnd, GWL_STYLE, GetWindowLong(Me.hwnd, GWL_STYLE) + WS_DLGFRAME
You need to change the style back to its original state before making you changes and then remove the title bar again.
VB Code:
Private Sub Command1_Click() 'Set the style back to where you started SetWindowLong Me.hwnd, GWL_STYLE, GetWindowLong(Me.hwnd, GWL_STYLE) - WS_DLGFRAME 'Change your caption Me.Caption = "New Caption" 'Remove the title bar SetWindowLong Me.hwnd, GWL_STYLE, GetWindowLong(Me.hwnd, GWL_STYLE) + WS_DLGFRAME End Sub
Menu options or command buttonsQuote:
Originally Posted by battery
Thanks!
i stuck in in a menu option and im trying to adapt it into my project
arg it fails - heres my code... please make it work :P
VB Code:
Private Sub mnuflashfs_Click() Dim t As Integer, l As Integer, w As Integer, h As Integer fs = False If fs = False Then If mnuflashfs.Caption = "Fullscreen" Then t = Top l = Left w = Width h = Height Top = 0 Left = 0 frmflash.Height = Screen.Height + 450 frmflash.Width = Screen.Width flashplayer.Height = Screen.Height flashplayer.Width = Screen.Width mnuflashfs.Caption = "Normal" SetWindowLong Me.hwnd, GWL_STYLE, GetWindowLong(Me.hwnd, GWL_STYLE) + WS_DLGFRAME fs = True End If End If If fs = False Then If mnuflashfs.Caption = "Normal" Then SetWindowLong Me.hwnd, GWL_STYLE, GetWindowLong(Me.hwnd, GWL_STYLE) - WS_DLGFRAME SetWindowLong Me.hwnd, GWL_STYLE, GetWindowLong(Me.hwnd, GWL_STYLE) + WS_DLGFRAME Top = t Left = l Width = w Height = h flashplayer.Height = Height flashplayer.Width = Width mnuflashfs.Caption = "Fullscreen" fs = True End If End If fs = False End Sub
i dont know why it doesnt wanna work
i made a buncha variables (t,l,w,h) as the settings prior to the fullscreening, so when they de-fullscreen it , the form goes back to the prior size.. plz help
its been 5 days.. does no one have an answer to my inquiry?????
If you want the title bar back then just update the formcaption :D
doesnt work :(
i did all that stuff and it doesnt wanna work
i added in the caption thing and still nothing
it says a form cant be maximized/minimized bla bla bla - if i take out the t,l,w,h it doesnt do anything but change the caption of the menu
If all you are trying to do is change between fulls creen and normal form size then just change the windowstate property.
VB Code:
Option Explicit 'API Calls Used To Remove The Title Bar From Window (Make A Sizeable Borderless Form) 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 GetWindowLong Lib "user32" Alias "GetWindowLongA" _ (ByVal hwnd As Long, ByVal nIndex As Long) As Long Private Const GWL_STYLE = (-16) Private Const WS_DLGFRAME = &H400000 'API Calls Used To Move A Form With The Mouse Private Declare Function ReleaseCapture Lib "user32" () As Long Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _ (ByVal hwnd As Long, ByVal wMsg As Long, _ ByVal wParam As Long, lParam As Any) As Long Private Const HTCAPTION = 2 Private Const WM_NCLBUTTONDOWN = &HA1 Dim t As Integer, l As Integer, w As Integer, h As Integer Dim fs As Boolean Private Sub Form_Load() 'ERASE the Title Bar SetWindowLong Me.hwnd, GWL_STYLE, GetWindowLong(Me.hwnd, GWL_STYLE) + WS_DLGFRAME mnuflashfs.Caption = "Fullscreen" End Sub Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) 'Move the form with the Left Mouse Button If Button = vbLeftButton Then Me.MousePointer = vbSizeAll Call ReleaseCapture Call SendMessage(hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&) Me.MousePointer = vbArrow End If End Sub Private Sub mnuflashfs_Click() If mnuflashfs.Caption = "Fullscreen" Then Me.WindowState = vbMaximized mnuflashfs.Caption = "Normal" Else Me.WindowState = vbNormal mnuflashfs.Caption = "Fullscreen" End If End Sub
it sorta works, cept that when the form loads it starts without the title bar (borderstyle 0 or whatever) - i'd like for it to start with the border, then when the user clicks the fs menu thing then it ditches the border - when the click it again, to make the form normal, it add back the border thing
heres what i've adapted:
VB Code:
Private Sub mnuflashfs_Click() ' all of this is pretty obvious but i'll explain anyway... If mnuflashfs.Caption = "Fullscreen" Then 'store the top,left,width, and heigh prior to fullscreening t = Top l = Left w = Width h = Height 'set the top and left to the top left corner of the screen - didnt do that before Me.Top = 0 Me.Left = 0 flashplayer.Height = Screen.Height flashplayer.Width = Screen.Width 'and heres your stuff Me.WindowState = vbMaximized SetWindowLong Me.hwnd, GWL_STYLE, GetWindowLong(Me.hwnd, GWL_STYLE) + WS_DLGFRAME mnuflashfs.Caption = "Normal" Else 'reapply prior settings Width = w Height = h Top = t Left = l 'your stuff once more Me.WindowState = vbNormal mnuflashfs.Caption = "Fullscreen" End If End Sub
my code doesnt work - when it's fullscreened when you click it just makes a beep sound when you click (like when you have a popup and when you click off it - that sound)
I got notepad's current hWnd (with Spy++) and got rid of its menu bar :D :D :D
I've run into a slight problem with the code. When I maximize the window, the window fills up the entire screen, including the taskbar (I have the taskbar set to stay on top of other windows and the test window isn't set to stay on top of other windows). Is there a way for the window to stop at the taskbar? Thanks