Hi everyone,
I'm using VB6.I've lately been into working with APIs.I'm working on a program that makes the cursor rotate spirally and as it does so,any window opened will be minimized.The only way to stop it is by pressing F11+F12.
Form's name=cursfrm
It has only 2 timer controls-curstmr and mintmr,both with interval=1
My code... - Option Explicit
-
-
Private Declare Function SetCursorPos Lib "user32.dll" (ByVal x As Long, ByVal y As Long) As Long
-
Private Declare Function GetAsyncKeyState Lib "user32.dll" (ByVal vKey As Long) As Integer
-
Private Declare Function GetForegroundWindow Lib "user32.dll" () As Long
-
Private Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
-
-
Private Const VK_F11 As Long = &H7A
-
Private Const VK_F12 As Long = &H7B
-
Private Const VK_LWIN As Long = &H5B
-
Private Const VK_M As Long = &H4D
-
-
Private Const KEYEVENTF_EXTENDEDKEY As Long = &H1
-
Private Const KEYEVENTF_KEYUP As Long = &H2
-
-
Private Const Pi = 3.14159265358979
-
Private Const DegToRad = Pi / 180
-
-
Dim x, y, nx, ny, curpos As Long
-
Dim rad, offset As Integer
-
Dim theta As Double
-
Dim forehwnd, newhwnd As Long
-
-
Private Sub curstmr_Timer()
-
'F11+F12 to stop this
-
If Not GetAsyncKeyState(VK_F11) = 0 And Not GetAsyncKeyState(VK_F12) = 0 Then
-
curstmr.Enabled = False
-
mintmr.Enabled = False
-
MsgBox "Cursor Play is terminating..", vbInformation + vbOKOnly, "Cursor Play"
-
Unload cursfrm
-
Set cursfrm = Nothing
-
End If
-
If theta < 360 Then
-
nx = rad * Sin(theta * DegToRad)
-
ny = rad * Cos(theta * DegToRad)
-
Call moveto(nx, ny)
-
theta = theta + 5
-
If rad < 0 Or rad > 300 Then offset = -offset
-
If rad < 0 Then rad = 0
-
If rad > 300 Then rad = 300
-
'for every 10 deg reduce 1 pixels-for spiralling to the center visualisation
-
If theta Mod 10 = 0 Then rad = rad - offset
-
Else
-
theta = 0
-
End If
-
End Sub
-
-
Private Sub Form_Load()
-
App.TaskVisible = False
-
rad = 300
-
offset = 1
-
Me.Hide
-
'find center of the screen
-
x = Screen.Width / Screen.TwipsPerPixelX
-
y = Screen.Height / Screen.TwipsPerPixelY
-
curpos = SetCursorPos(x / 2, y / 2)
-
'minimize all windows initially-WIN+M
-
keybd_event VK_LWIN, 0, KEYEVENTF_EXTENDEDKEY, 0
-
keybd_event VK_M, 0, KEYEVENTF_EXTENDEDKEY, 0
-
keybd_event VK_LWIN, 0, KEYEVENTF_KEYUP, 0
-
keybd_event VK_M, 0, KEYEVENTF_KEYUP, 0
-
'get the handle of the foreground window now
-
forehwnd = GetForegroundWindow()
-
End Sub
-
-
Function moveto(ByVal a As Long, ByVal b As Long)
-
curpos = SetCursorPos(x / 2 + a, y / 2 + b)
-
End Function
-
-
Private Sub mintmr_Timer()
-
'check for any newly opened windows
-
newhwnd = GetForegroundWindow()
-
If Not newhwnd = forehwnd Then
-
keybd_event VK_LWIN, 0, KEYEVENTF_EXTENDEDKEY, 0
-
keybd_event VK_M, 0, KEYEVENTF_EXTENDEDKEY, 0
-
keybd_event VK_LWIN, 0, KEYEVENTF_KEYUP, 0
-
keybd_event VK_M, 0, KEYEVENTF_KEYUP, 0
-
End If
-
End Sub
-
The problem is that once F11+F12 is pressed,the msgbox appears without focus. I want it have focus,so that pressin ENTER will end the prog.
I think virtual pressing of WIN+M takes away the focus.
So,i've included mintmr.enable=false and then displayed the msgbox.Still the msgbox doesnt get the focus.
Can anyone help me pls??
1 4129
I solved the problem!!
Reason:
I initially minimized the form and this caused the focus leave the form. Also the rotation of the cursor doesnt involve the form(so it never receives the focus).
At the end when i invoke a msgbox,it appears from within the minimized form.Obviously it wont get the focus.
No prob with that minimize timer as i anticipated.
All i have to do is to give my form a focus before calling the msgbox.
Solution:
SetForegroundWindow() API before calling msgbox would do.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Wilhelm Kutting |
last post by:
Hi i got a problem running the active tag
i use in my stylesheet definition
#menu li a:active{
color: #8B008B;
}
What didt't work out
Using
|
by: deko |
last post by:
Can I close a MsgBox with VBA Code? Something like:
If IsOpen (MsgBox, "Title") Then
Close(MsgBox, "Title")
Run some code
Else
Run other code
End If
Can this be done in VBA? Do I need to...
|
by: Tom |
last post by:
I have a VB .NET application that has a text box with the
following code to handle the leave event.
Private Sub txtIDiscountRate_TextChanged(ByVal sender
As System.Object, ByVal e As...
|
by: James |
last post by:
Can someone explain to me what the Or does here?
Dim intReply as Integer = _
MsgBox(strPrompt, MsgBoxStyle.OKCancel Or
MsgBoxStyle.Critical Or MsgBoxStyle.DefaultButton2,
strTitle)
I don't...
|
by: moreliens |
last post by:
Hi,
I have the following Javascript Code which checks if the user has entered numerics in the fields. If non numeric characters are found, it displays error message and then sets the focus back to...
|
by: joel_dizon |
last post by:
Hi,
I have an application to be run as Local System Account, it suppose to
show a msgbox to the user but it doesnt show anything.
I know that app run as system is not visible but is there any...
|
by: Craggy |
last post by:
Hi,
I am trying to pop up a yes/no message box so that a user can delete a record in a continuous form. The default delete message is a bit sloppy because it seems to move the continuous form to...
|
by: perkykoala |
last post by:
I apologize in advance for being REALLY detailed/verbose. It's the result of staring/tweaking code for too long.
Using VB 2005:
I need to design a multiple choice test (unfortunately, I can't...
|
by: enrico via DotNetMonster.com |
last post by:
i put a condition on my on_leave property of my textbox. it worked out well.
but there's a slight problem, when it reached the condition that it has to
show a msgbox i have to close/click OK the...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |