Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with activex and hwnd 1

Status
Not open for further replies.

PoLaK

Programmer
Oct 1, 2001
15
0
0
AU
Hi
I am creating an activex control in vb and i am trying to find the hwnd of the form that the control is....i have been trying to integrate other coding that i have used for other applications but it just isn't working...

please any help with this would be appreciated

the previous code was
Me.hwnd
but that was when the coding was in the written in the form but this coding needs to be in the control and me.hwnd i know is incorrect for this

thanks
 
Hi Polak, you need this:

UserControl.Parent.hWnd
 
ok thanks

i tried this and i am kinda guessing it is working in the right way but it came up with an error saying 'client site no available'

any help would be really appreciated

thanks
 
are you using "UserControl.Parent.hWnd" in UserControl_Initialize Event?

 
You can´t use that in this event. try to use in a Public Function of a Control or in the UserControl_Resize event...
 
um ok...one thing is that the control is not visible...would it work if say i had a timer than ran once and then disabled itself? that would waste some resources though....


also thought i'd mention i've used UserControl.Parent.Icon.Handle
as well but i am not sure if this will cause an error either because it hasn't passes the previous hwnd error yet
 
PoLak, I don´t undersand you (my english...)
but i think you can call it in Show event and then set the visible property to False
 
oh ok then....
i am trying to make an activex control that is customizable but it lets you place an icon in the system tray that is linked to the main window....

this is all the coding i have at the moment
see if you can understand what is wrong.... thanks for this by the way

Option Explicit

Const MAX_TOOLTIP As Integer = 64
Const NIF_ICON = &H2
Const NIF_MESSAGE = &H1
Const NIF_TIP = &H4
Const NIM_ADD = &H0
Const NIM_DELETE = &H2
Const WM_MOUSEMOVE = &H200
Const WM_LBUTTONDOWN = &H201
Const WM_LBUTTONUP = &H202
Const WM_LBUTTONDBLCLK = &H203
Const WM_RBUTTONDOWN = &H204
Const WM_RBUTTONUP = &H205
Const WM_RBUTTONDBLCLK = &H206

Private Type NOTIFYICONDATA
cbSize As Long
hwnd As Long
uID As Long
uFlags As Long
uCallbackMessage As Long
hIcon As Long
szTip As String * MAX_TOOLTIP
End Type
Private nfIconData As NOTIFYICONDATA

Private Declare Function Shell_NotifyIcon Lib "shell32.dll" _
Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData _
As NOTIFYICONDATA) As Long

Private Sub UserControl_Initialize()
'----------------------------------------------------------------------
' Add this application's icon to the system tray.
'
' Parm 1 = Handle of the window to receive notification messages
' associated with an icon in the taskbar status area.
' Parm 2 = Icon to display.
' Parm 3 = Handle of icon to display.
' Parm 4 = Tooltip displayed when cursor moves over system tray icon.
'
With nfIconData
.hwnd = UserControl.Parent.hwnd
.uID = UserControl.Parent.hwnd
.uFlags = NIF_ICON Or NIF_MESSAGE Or NIF_TIP
.uCallbackMessage = WM_MOUSEMOVE
.hIcon = UserControl.Parent.Icon.Handle
.szTip = "System Tray Example" & vbNullChar
.cbSize = Len(nfIconData)
End With
Call Shell_NotifyIcon(NIM_ADD, nfIconData)
'----------------------------------------------------------------------
End Sub

Private Sub UserControl_Terminate()
Call Shell_NotifyIcon(NIM_DELETE, nfIconData) 'remove icon when done
End Sub



'Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
'Dim lMsg As Single
''
'' Determine the event that happened to the System Tray icon.
'' Left clicking the icon displays a message box.
'' Right clicking the icon creates an instance of an object from an
'' ActiveX Code component then invokes a method to display a message.
''
'lMsg = X / Screen.TwipsPerPixelX
'Select Case lMsg
' Case WM_LBUTTONUP 'Left button up
' Case WM_RBUTTONUP 'Right button up
' Case WM_MOUSEMOVE 'Mouse moved over icon
' Case WM_LBUTTONDOWN 'Left button down
' Case WM_LBUTTONDBLCLK 'Left button double click
' frmMain.WindowState = 0
' Case WM_RBUTTONDOWN 'Right button down
' Case WM_RBUTTONDBLCLK 'Right button double click
' Case Else
'End Select
'End Sub
 
i just tried moving all the coding in the usercontrol_initialize to a timer that had an interval of 1 and then disabled the timer after it ran and the coding works. but there must be a way of doing this without a timer to cut down the resource's being used
 
The form that uses this control could call a Sub of the control (Control.Init) in form_load
in this sub you can call Call Shell_NotifyIcon(NIM_ADD...
 
but if this is a control to be added on to a form. then each time i add the component i would have to write in that code wouldn't I?
 
yeah...this is a bad solution.
are you tried with something like this:?

Private Sub UserControl_Resize()
MsgBox UserControl.Parent.Icon.Handle
End Sub
this event occurs after the usercontrol initialize_event
 
Private Sub UserControl_Initialize()
UserControl.Width = 10
End Sub
Private Sub UserControl_Resize()
On Error Resume Next
MsgBox UserControl.Parent.Icon.Handle
End Sub
 
ok i've tried that and tried to put it into the program but it creates two icons...one is an invisible icon, like a spacing and the other is the actual icon....
 
although i found that this is not a problem once the project is compiled and running
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top