Hi everyone! Im new to vb.net. I'm currently recoding my vb6.0 codes to vb.net(for upgrading purposes), unfortunately some of the codes dont work/execute the way it executes in vb6.0, though I never get any error. That is, the program runs without error but the function being called dont execute. Can anybody help me figure out this matter??
***HERES WHAT SHOULD THE PROGRAM DO....
message box should always display at the center of the owner form and not at the center of the screen(monitor) upon invoking it.
I used the SetWindowsHookE x API in vb6.0 and it executes perfectly. but when i recoded it in vb.net it doesnt execute the it did in vb6...
[HERES MY CODE IN VB.NET]
by simply calling the code inside button1 click event: - Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
-
-
Call Sys_WindowAdjustment(Me)
-
MsgBox("THIS IS A TEST")
-
-
End Sub
-
**** "THIS IS A TEST" message box should always appear at the center of the owner form. even if i move the owner form anywhere in the screen, the msgbox shuld always at the center of it..
HERE'S THE ENTIRE CODE RELATED TO Sys_WindowAdjus tment - Public lngHookProcHandle As Long
-
-
'API CONSTANTS
-
Public Const GWL_HINSTANCE = (-6)
-
Public Const WH_CBT = 5
-
Public Const HCBT_ACTIVATE = 5
-
Public Const SWP_NOZORDER = &H4
-
Public Const SWP_NOSIZE = &H1
-
Public Const SWP_NOACTIVATE = &H10
-
-
-
Public Declare Function UnhookWindowsHookEx Lib "user32.dll" _
-
(ByVal hhk As Long) As Long
-
Public Declare Function SetWindowPos Lib "user32" _
-
(ByVal HWND As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
-
Public Declare Function GetWindowPlacement Lib "user32.dll" _
-
(ByVal HWND As Long, ByVal lpwndpl As WINDOWPLACEMENT) As Long
-
Public Declare Function GetWindowLong Lib "user32.dll" Alias "GetWindowLongA" _
-
(ByVal HWND As Long, ByVal nIndex As Long) As Long
-
-
Public Declare Function GetCurrentThreadId Lib "kernel32.dll" () As Long
-
Public Declare Function SetWindowsHookEx Lib "user32.dll" Alias "SetWindowsHookExA" _
-
(ByVal idHook As Long, ByVal lpfn As Sys_WindowHookProcDelegate, ByVal hMod As Long, ByVal dwThreadId As Long) As Long
-
-
Public Delegate Function Sys_WindowHookProcDelegate(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
-
-
Public Structure WINDOWRECT
-
Dim LEFT As Long
-
Dim TOP As Long
-
Dim RIGHT As Long
-
Dim BOTTOM As Long
-
End Structure
-
-
Public Structure POINTCOORDINATES
-
Dim X_POINT As Long
-
Dim Y_POINT As Long
-
End Structure
-
-
-
Public Structure WINDOWPLACEMENT
-
Dim length As Long
-
Dim Flags As Long
-
Dim showCmd As Long
-
Dim ptMinPosition As POINTCOORDINATES
-
Dim ptMaxPosition As POINTCOORDINATES
-
Dim rcNormalPosition As WINDOWRECT
-
End Structure
-
-
Public sysWindowPlacement As WINDOWPLACEMENT
-
-
Public Structure WINDOWCONTAINER
-
Dim W_TOP As Double
-
Dim W_LEFT As Double
-
Dim W_WIDTH As Double
-
Dim W_HEIGHT As Double
-
End Structure
-
-
Public sysWindowContainer As WINDOWCONTAINER
-
-
-
-
Public Function Sys_WindowAdjustment(ByVal objOwnerForm As Form) As Long
-
-
Dim dlgWinHookDel As Sys_WindowHookProcDelegate
-
Dim strErrMsg As String
-
Dim strErrNum As String
-
Dim strErrorDesc As String
-
Dim strErrLocNum As String
-
Dim lngInstanceHandle As Long
-
Dim lngThreadId As Long
-
-
On Error GoTo Sys_WindowAdjustment_Err
-
-
strErrMsg = "CommonTools -- Sys_WindowAdjustment"
-
-
'Initialize window adjustment to 0
-
Sys_WindowAdjustment = 0
-
'Get ownerform's top,left,height, width values
-
With sysWindowContainer
-
.W_TOP = objOwnerForm.Top
-
.W_LEFT = objOwnerForm.Left
-
.W_HEIGHT = objOwnerForm.Height
-
.W_WIDTH = objOwnerForm.Width
-
End With
-
-
'Get ownerform's instance handle
-
lngInstanceHandle = GetWindowLong(objOwnerForm.Handle, GWL_HINSTANCE)
-
-
'Get current thread ID
-
lngThreadId = GetCurrentThreadId
-
'Instantiate new window hook delegate
-
dlgWinHookDel = New Sys_WindowHookProcDelegate(AddressOf Sys_WindowHookProc)
-
'Set windows hook (set position of window to be loaded)
-
lngHookProcHandle = SetWindowsHookEx(WH_CBT, _
-
dlgWinHookDel, _
-
lngInstanceHandle, _
-
lngThreadId)
-
-
Sys_WindowAdjustment = lngHookProcHandle
-
End Function
-
-
Public Function Sys_WindowHookProc(ByVal nCode As Long, _
-
ByVal wParam As Long, _
-
ByVal lParam As Long) As Long
-
-
Dim lngXPos As Long 'Window's Left position
-
Dim lngYPos As Long 'Window's Top Position
-
Dim dblXPos As Double
-
Dim dblYPos As Double
-
Dim lngPlacement As Long 'Window Placement
-
-
On Error Resume Next
-
-
'If window is to be activated
-
If nCode = HCBT_ACTIVATE Then
-
-
sysWindowPlacement.length = Len(sysWindowPlacement)
-
'Get window placement
-
lngPlacement = GetWindowPlacement(wParam, sysWindowPlacement)
-
'Set Top and Left position of window to be activated
-
With sysWindowPlacement.rcNormalPosition
-
dblYPos = sysWindowContainer.W_TOP + (sysWindowContainer.W_HEIGHT / 2 - (.BOTTOM - .TOP) * 15 / 2)
-
dblXPos = sysWindowContainer.W_LEFT + (sysWindowContainer.W_WIDTH / 2 - (.RIGHT - .LEFT) * 15 / 2)
-
End With
-
-
'Convert to pixels
-
lngXPos = CLng(dblXPos / 15)
-
lngYPos = CLng(dblYPos / 15)
-
-
'Set window position
-
SetWindowPos(wParam, _
-
0, _
-
lngXPos, _
-
lngYPos, _
-
0, _
-
0, _
-
SWP_NOSIZE Or _
-
SWP_NOZORDER Or _
-
SWP_NOACTIVATE)
-
'After setting window position, remove window's hook
-
UnhookWindowsHookEx(lngHookProcHandle)
-
End If
-
-
'Set Sys_WindowHookProc to false to continue normal execution
-
Sys_WindowHookProc = False
-
-
End Function
-
****EVERY TIME THE PROGRAM EXECUTES THE Sys_WindowHookP roc FUNCTION IS NEVER EXECUTED OR BEING BY-PASSED...WHAT SHOULD BE THE PROBLEM OF THIS CODE?....I BELIEVE I PRETTY CODED IT WELL(MORE READABLE AND UNDERSTANDABLE I THINK)...BTW I JUST WROTE THIS IN CAPITALS SO THAT VB CODES CAN BE RECOGNIZE OR EMPHASIZE..TNX A LOT.
5 4561 Plater 7,872
Recognized Expert Expert
MsgBox is not .NET code. Try using MessageBox.Show () and going through the overloads to specify who the "owner form" is?
Please enclose your posted code in [CODE] [/CODE] tags (See How to Ask a Question).
This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.
Please use [CODE] [/CODE] tags in future.
MODERATOR
oh my apology....
hi Plater...I used MessageBox.Show () and it did not make any difference....t he message box appeared but its not at the center of the owner form(as what im expecting)....a s what ive said..Im new to vb.net. Just started using this like 2 days ago..;-)
Plater 7,872
Recognized Expert Expert
Hmm I guess it's not available.
The only other thing I can think of is to make your own custom popup form.
You can either set its start position to "manual" and compute where it goes...
Or you can set TopMost =false (manually in code when you create an instance of it), give its Parent property that of the form you want it centered on, then attempt to set the StartPosition to "CenterPare nt"
tnx for that bright idea Plater...maybe i should try it then...(",)
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: x muzuo |
last post by:
Hi guys,
I have got a prob of javascript form validation which just doesnt work
with my ASP code. Can any one help me out please.
Here is the code:
{////<<head>
<title>IIBO Submit Page</title>
</head>
<style type="text/css">
|
by: Jason |
last post by:
Hi,
I was wondering if any could point me to an example or give me ideas on how
to dynamically create a form based on a database table? So, I would have a
table designed to tell my application to create certain textboxes, labels,
and combo boxes? Any ideas would be appreciated.
Thanks
|
by: bugs bunny via .NET 247 |
last post by:
Does anyone have actually used SetWindowsHookEx() to hook upShellExecute() so as to find what application was started bywindows or which folder is currently browsed by explorer. I knowone thing and that is ... Windows uses ShellExecute() to doalmost every task.
I need some implementation help. I want to trigger an userdefined function when suppose Notepad is opened or in simplecase a messagebox that says Notepad has started.
If anyone has a...
|
by: bruno |
last post by:
I need some help on how write SetWindowsHookEx in vb.net 2005 to hook kb input.
this is the statement:
hHOOKKb = SetWindowsHookEx( _
WH_KEYBOARD, _
lpfn, _
hMod, _
dwThreadId)
And this is from MSDN Library:
lpfn Pointer to the hook procedure.
|
by: David Van D |
last post by:
Hi there,
A few weeks until I begin my journey towards a degree in Computer
Science at Canterbury University in New Zealand,
Anyway the course tutors are going to be teaching us JAVA wth bluej and
I was wondering if anyone here would be able to give me some tips for
young players such as myself, for learning the language.
Is this the best Newsgroup for support with JAVA?
| |
by: Mike Carlisle |
last post by:
Hi,
Can't seem to find any sensible C# examples of this, struggling to work out
the correct way to trap key combinations using SetWindowsHookEx with
WH_KEYBOARD_LL, such as ALT-ESC.
private int InterpretKey(int nCode, IntPtr wParam, IntPtr lParam)
{
.....
|
by: abcd |
last post by:
I am having trouble with pyHook on python 2.4.1. Basically I have a
python app that uses pyHook to capture keyboard events and write them
straight to a file. The application is running as a service on a
windows machine. If I am at that windows machine the application
works just fine, logging my keystrokes. However, if I use Remote
Desktop to connect to the machine and open up say Notepad it doesn't
capture the keystrokes. Is this a...
|
by: KWhat4 |
last post by:
I seem to have an issue that I cant resolve. I have a jni dll that
calls SetWindowsHookEx with a callback to HookKeyboardProc (basically
a real simple global keyboard hook). Now the dll almost works all the
jni hooks are fine and the program appears to run but the callback
(HookKeyboardProc) does not seem to get executed or possibly never
returns from execution. The code is as follows. None of the
variables being set in the code...
|
by: niksoftware |
last post by:
I'm making a kiosk style desktop replacement.
Im using setwindowshookex to run a callback system to trap the keys just trapping "windows" key atm.
if I step through just as the program goes the the keyboardcallback function declaration line it pauses for seconds before moving to the next line.
This directly precedes the new variable declaration of the callback variable
While running this leads to only 1 press of the "windows" keys...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |