I've set property ShowInTaskBar to true, but my application is not visible in taskbar.
Form has minimize, maximize and close buttons. When I click minimize, form minimizes to a small form in the bottom left corner on the screen, but doesn't show up in the taskbar.
Is your form modal?
MyForm.Show vbModal
If so then you'll have to do something like this to make it show in the taskbar.
This question is old but I still work with VB6 on a daily basis. I found this work around to make a form shown by MyForm.Show vbModal appear on the taskbar.
Private Declare Function ShowWindow Lib "user32" (ByVal hWnd As Long, ByVal nCmdShow As Long) As Long
Private Sub Form_Activate()
Call ShowWindow(Me.hWnd, vbHide)
Me.Caption = Me.Caption
Call ShowWindow(Me.hWnd, vbNormalFocus)
End Sub
Related
I'm having an issue with a process that involves the LostFocus event.
When the cursor loses focus from a particular textbox, I'm simply putting the focus back into that box.
My issue is removing focus long enough for the user to click a log out button. Is there a way to intercept the LostFocus event long enough to allow the user to click the log out button?
Obviously I don't know the big picture here. But keeping only with what you said, the following does the trick. Effectively the event is delayed briefly, allowing the button to be clicked:
Option Explicit
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Sub Text1_LostFocus()
Sleep 100
DoEvents
Text1.SetFocus
End Sub
With a combination of a Timer and another control that is outside of the borders of your form, you can achieve this.
Private Sub Text1_LostFocus()
Combo1.SetFocus
ReturnFocusTimer.Enabled = True
End Sub
Private Sub ReturnFocusTimer_Timer()
ReturnFocusTimer.Enabled = False
Text1.SetFocus
End Sub
In this example Combo1 is positioned beyond the bottom of the form. You can control the ReturnFocusTimer interval to however long you need.
I have a project for fun in VB6, I'm using quite long labels and would like them to stretch the entire length of my monitor however they seem to be capped at 256 chars per line. It let's me set their caption to as long as I like but after the 256th character, the rest does not appear on the screen.
If I change it to multiline however, it will display the full text but again will automatically take a new line at the 256th character meaning it doesn't utilise the full width of my monitor.
I was wondering if anyone knows why this is, a way around it or what my options are?
Edit: After testing, using a text box and making it look like a label is an alright work around, as text boxes don't seem to have this same restriction.
Edit 2: Text boxes lack an autosize function which is crucial to my project so any further advice is appreciated.
According to the MSDN documentation:
A Label control’s caption size is unlimited. For forms and all other
controls that have captions, the limit is 255 characters.
However, as you have seen this statement may not be correct. It appears to apply to Label controls as well, and the limit is actually 256 characters in my experimentation.
I think your idea of a TextBox control should work for what you need. Since there is no AutoSize property, simply change the width of the control in the Form Resize event.
Private Sub Form_Resize()
Text1.Width = Me.ScaleWidth
End Sub
Adding onto Brian's answer, yes, you will need to use a TextBox if you want your "label" to be more than 255 characters. You can make a TextBox look and act like a label if you set a few things.
First, set the BorderStyle property to vbBSNone (or 0, if you prefer). Then, you don't want users entering text into and otherwise changing your "label." If you're not fussy, you can set the Locked property to true. This isn't perfect, because setting the Locked property still allows users to click on the text and move around in it.
If you're really not fussy, you can set Enabled to false. This can confuse users, because everything gets greyed out and users are conditioned to understand that to mean that something is disabled. However, a disabled control can't be landed on or tabbed to, which is the behavior you want for a label.
If you want to get disabled behavior without altering the appearance, you need to use the API:
Private Const WS_DISABLED = &H8000000
Private Const GWL_STYLE = -16
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 Sub Form_Load()
Dim theStyle As Long
theStyle = GetWindowLong(myTextBox.hwnd, GWL_STYLE) Or WS_DISABLED
Call SetWindowLong(myTextBox.hwnd, GWL_STYLE, theStyle)
End Sub
Pretty straightforward. GWL_STYLE is the index for the window's style properties. It's a hex value that amounts to a series of flags. If you Or the WS_DISABLED hex value with it, the result is to set the disabled flag. Which gets set when you set the window with the new value for GWL_STYLE.
Here are the different settings handled by GW_STYLE.
I've got a VB6 program. I'm using the Mainfest to apply "XP Themes" and give it the modern (as of 8 years ago!) look.
However, for graphical style Command buttons, I have to use some special code to redraw the button. Therein lies the problem.
When I click on one of this Graphical buttons it gets the proper "highlighting" of the background, but when another button gets the focus or mouseover, etc. that former button keeps the background highlighting.
If I move another window in front of it, the form redraws itself and this "residual" background color disappears.
I'm trying to figure out how to force that to happen.
What I've tried:
button.refresh
form.refresh
Doevents
Here is a video demo of the problem
I don't have anything like your setup to try this in, but you can try using the API call InvalidateRect. I've shown the declarations and created a Sub that uses it. It should be a simple copy and paste to try.
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function InvalidateRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT, ByVal bErase As Long) As Long
Private Declare Function GetClientRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Sub RefreshMe()
Dim udtRect As RECT
Call GetClientRect(Me.hwnd, udtRect)
InvalidateRect Me.hwnd, udtRect, 1
DoEvents 'give windows a chance to handle the event
End Sub
I have utlized the User32 library from MS Access in VBA to Hide the MDI window:
Global Const SW_HIDE = 0
Global Const SW_SHOWNORMAL = 1
Global Const SW_SHOWMINIMIZED = 2
Global Const SW_SHOWMAXIMIZED = 3
' Windows User32 Library reference to modify the window by one of the above commands
Private Declare Function apiShowWindow Lib "User32" Alias "ShowWindow" _
(ByVal hWnd As Long, ByVal nCmdShow As Long) As Long
At the appropriate point in my application I have triggered a call to this function effectively hiding the application while specific forms are set with Modal = True and Popup = True to have them show through the hidden parent MDI window.
This works great! However, I would like to still have a reference on the windows Taskbar for the open instance of MS Access:
This functionality went away once I hid the parent MDI window. Previously the user could click on this reference order to bring focus back to the respective open form.
Does anyone know how I can accomplish this? Is there a User32 Library reference or parameter which could be passed into the apiShowWindow method to have this occur?
why not just make the call with SW_SHOWMINIMIZED? that seems to be the desired functionality. (e.g. window not showing but still on taksbar vs. window totally hidden)
In the "Control Panel > Ease of Access Centre > Make the keyboard easier to use" is an option to "Underline keyboard shortcuts and access keys."
Is there a way of programmatically switching this on and off?
I'm using Visual Basic Scripts, but can use .NET.
Run Registry Editor and go to HKEY_CURRENT_USER\Control Panel\Accessibility\Keyboard Preference
Now create or modify a String Value (REG_SZ) called On and set its value to 1
Information is comming from:
http://www.windowsvalley.com/get-underlined-keyboard-shortcuts-and-access-keys-permanently/
AFAIK, there's no way to toggle this option programmatically except for automating the approproate GUI actions (opening the Control Panel, switching the option on/off and applying the changes). In this case, I'd recommend using AutoIt to automate the option switching.
It turns out you CAN programatically change the “underline keyboard shortcuts” option in your own application. You need to send the WM_UPDATEUISTATE message to your main form according to the documentation found at: https://learn.microsoft.com/en-us/windows/win32/menurc/wm-updateuistate
Since you mentioned Visual Basic, here's how to do it:
Private Const WM_UPDATEUISTATE = &H128
Private Const UIS_CLEAR = &H2
Private Const UISF_HIDEACCEL = &H2
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hWnd As
Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Then in the "Form_Load" event send the message and it will activate keyboard shortcuts underlining for all controls and menus present on that form:
Private Sub Form_Load()
PostMessage Me.hWnd, WM_UPDATEUISTATE, UIS_CLEAR + UISF_HIDEACCEL * 65536, 0
End Sub