Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Displaying the System Menu ANYWHERE.

1 view
Skip to first unread message

V. Garimella

unread,
Aug 10, 1997, 3:00:00 AM8/10/97
to

Hi everyone.
I am using Visual Basic 4.0 32 bit. I was wondering if there was a way
that I could display the system menu up anywhere I want to. Sort of like a
popup menu. The reason for this is that my program provides a task list of
all running applications. When they click on each task, I want to display
that application's system menu. Thanks in advance.


Sai Kayal

unread,
Aug 10, 1997, 3:00:00 AM8/10/97
to

One way to solve your might be using a few API calls. The following code
snippet is an attempt towards that:

'Start of Form1
Option Explicit
Private Const TPM_LEFTALIGN = &H0&
Private Const TPM_LEFTBUTTON = &H0&
Private Const TPM_NONOTIFY = &H80
Private Const TPM_RETURNCMD = &H100
Private Const WM_SYSCOMMAND = &H112

Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long,
ByVal bRevert As Long) As Long
Private Declare Function TrackPopupMenu Lib "user32" (ByVal hMenu As Long,
ByVal wFlags As Long, ByVal X As Long, ByVal Y As Long, ByVal nReserved As
Long, ByVal hwnd As Long, ByVal lprc As Long) 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 Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Long,
lpPoint As POINTAPI) As Long

Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type POINTAPI
X As Long
Y As Long
End Type


Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single,
Y As Single)

If (Button = vbRightButton) Then
Dim pt As POINTAPI
Dim hMenu As Long
Dim lRet As Long

pt.X = ScaleX(X, ScaleMode, vbPixels)
pt.Y = ScaleY(Y, ScaleMode, vbPixels)
Call ClientToScreen(hwnd, pt)
hMenu = GetSystemMenu(hwnd, 0)
lRet = TrackPopupMenu(hMenu, TPM_LEFTALIGN Or TPM_LEFTBUTTON Or _
TPM_NONOTIFY Or TPM_RETURNCMD, _
pt.X, pt.Y, 0, hwnd, 0)
If (lRet > 0) Then
Call SendMessage(hwnd, WM_SYSCOMMAND, lRet, 0)
End If
End If
End Sub
'End of Form1


Best of Luck,
-Sai

Note: My e-mail address is modified to discourage spammers.

V. Garimella <ki...@glci.net> wrote in article
<01bca535$4e787c60$5df5c3d0@chalam>...

0 new messages