473,406 Members | 2,312 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Msgbox doesnt get focus

vdraceil
236 100+
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...

Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2.  
  3. Private Declare Function SetCursorPos Lib "user32.dll" (ByVal x As Long, ByVal y As Long) As Long
  4. Private Declare Function GetAsyncKeyState Lib "user32.dll" (ByVal vKey As Long) As Integer
  5. Private Declare Function GetForegroundWindow Lib "user32.dll" () As Long
  6. Private Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
  7.  
  8. Private Const VK_F11 As Long = &H7A
  9. Private Const VK_F12 As Long = &H7B
  10. Private Const VK_LWIN As Long = &H5B
  11. Private Const VK_M As Long = &H4D
  12.  
  13. Private Const KEYEVENTF_EXTENDEDKEY As Long = &H1
  14. Private Const KEYEVENTF_KEYUP As Long = &H2
  15.  
  16. Private Const Pi = 3.14159265358979
  17. Private Const DegToRad = Pi / 180
  18.  
  19. Dim x, y, nx, ny, curpos As Long
  20. Dim rad, offset As Integer
  21. Dim theta As Double
  22. Dim forehwnd, newhwnd As Long
  23.  
  24. Private Sub curstmr_Timer()
  25. 'F11+F12 to stop this
  26. If Not GetAsyncKeyState(VK_F11) = 0 And Not GetAsyncKeyState(VK_F12) = 0 Then
  27.  curstmr.Enabled = False
  28.  mintmr.Enabled = False
  29.  MsgBox "Cursor Play is terminating..", vbInformation + vbOKOnly, "Cursor Play"
  30.  Unload cursfrm
  31.  Set cursfrm = Nothing
  32. End If
  33. If theta < 360 Then
  34.  nx = rad * Sin(theta * DegToRad)
  35.  ny = rad * Cos(theta * DegToRad)
  36.  Call moveto(nx, ny)
  37.  theta = theta + 5
  38.  If rad < 0 Or rad > 300 Then offset = -offset
  39.  If rad < 0 Then rad = 0
  40.  If rad > 300 Then rad = 300
  41.  'for every 10 deg reduce 1 pixels-for spiralling to the center visualisation
  42.  If theta Mod 10 = 0 Then rad = rad - offset
  43. Else
  44.  theta = 0
  45. End If
  46. End Sub
  47.  
  48. Private Sub Form_Load()
  49. App.TaskVisible = False
  50. rad = 300
  51. offset = 1
  52. Me.Hide
  53. 'find center of the screen
  54. x = Screen.Width / Screen.TwipsPerPixelX
  55. y = Screen.Height / Screen.TwipsPerPixelY
  56. curpos = SetCursorPos(x / 2, y / 2)
  57. 'minimize all windows initially-WIN+M
  58. keybd_event VK_LWIN, 0, KEYEVENTF_EXTENDEDKEY, 0
  59. keybd_event VK_M, 0, KEYEVENTF_EXTENDEDKEY, 0
  60. keybd_event VK_LWIN, 0, KEYEVENTF_KEYUP, 0
  61. keybd_event VK_M, 0, KEYEVENTF_KEYUP, 0
  62. 'get the handle of the foreground window now
  63. forehwnd = GetForegroundWindow()
  64. End Sub
  65.  
  66. Function moveto(ByVal a As Long, ByVal b As Long)
  67. curpos = SetCursorPos(x / 2 + a, y / 2 + b)
  68. End Function
  69.  
  70. Private Sub mintmr_Timer()
  71. 'check for any newly opened windows
  72. newhwnd = GetForegroundWindow()
  73. If Not newhwnd = forehwnd Then
  74.  keybd_event VK_LWIN, 0, KEYEVENTF_EXTENDEDKEY, 0
  75.  keybd_event VK_M, 0, KEYEVENTF_EXTENDEDKEY, 0
  76.  keybd_event VK_LWIN, 0, KEYEVENTF_KEYUP, 0
  77.  keybd_event VK_M, 0, KEYEVENTF_KEYUP, 0
  78. End If
  79. End Sub
  80.  
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??
Jan 23 '09 #1
1 4129
vdraceil
236 100+
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.
Feb 2 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

11
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
8
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...
3
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...
6
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...
6
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...
5
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...
4
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...
2
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...
1
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
marktang
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,...
0
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...
0
Oralloy
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,...
0
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...
0
agi2029
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.