|
Use Control Class MousePosition Property and PointToScreen and PointToClient methods.
|
|
|
|
|
I hope someone can help me with this!
I am trying to set some environment variables from my VB.NET application.
I am using System.Environment.GetEnvironmentVariable to return the values and to set them I am using the following function....
Private Declare Function SetEnvironmentVariableA Lib "kernel32.dll" _
(ByVal lpName As String, _
ByVal lpValue As String) As Integer
When I set a variable and then check that it has been set from within the application it appears fine. However, if I open a command prompt window and use SET I cannot see the variable at all. This seems to indicate to me that each .NET applicaiton runs in its own "shell".
The problem I have is that I am kicking of a sub-process that runs in a JVM and this needs various environment variables to be set.
So how can I set variables from VB.NET into the master Windows environment so these can be picked up on by the sub-process?
|
|
|
|
|
You're right, every app that runs launches with its own copy of the environment variables. This happens even to apps that your app spawns, they get a copy of your app's environment.
The solution is a little surprising. See this[^] article on MSDN.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Well for some reason my sub-process is not inheriting the variables set ni my .NEt applicaiton.
I finally found the MSDN article Dave pointed to before I came back here and read his reply! I found MSDN very unhelpful in terms of explaining how to implement this in VB.NET particulrly because of the LPARAM argument to the SendMessageTimeout function
OK so this is how you propagate environment variables to the system with VB.NET
First of all you need the following Win32 API function declarations...
Private Declare Function SendMessageTimeoutA Lib "user32" _<br />
(ByVal hwnd As Integer, _<br />
ByVal MSG As Integer, _<br />
ByVal wParam As Integer, _<br />
ByVal lParam As Byte(), _<br />
ByVal fuFlags As Integer, _<br />
ByVal uTimeout As Integer, _<br />
ByRef lpdwResult As Integer) As Integer<br />
<br />
Private Declare Function SetEnvironmentVariableA Lib "kernel32.dll" _<br />
(ByVal lpName As String, _<br />
ByVal lpValue As String) As Integer
To set a variable I then defined my function as follows...
<br />
Sub SetEnvironmentVariable(ByVal strVariableName As String, ByVal strValue As String)<br />
<br />
Const WM_SETTINGCHANGE = &H1A<br />
Const HWND_BROADCAST = &HFFFF<br />
Const SMTO_NORMAL = 2<br />
Const SMTO_ABORTIFHUNG = &H2<br />
<br />
Dim regKey As RegistryKey<br />
Dim lpdwResult, result As Integer<br />
<br />
' declare the system environment variable for the current user by inserting it <br />
' into the registry<br />
regKey = Registry.CurrentUser.OpenSubKey("Environment", True)<br />
regKey.SetValue(strVariableName, strValue)<br />
<br />
' now propagate the system with the variable...<br />
result = SendMessageTimeoutA(HWND_BROADCAST, _<br />
WM_SETTINGCHANGE, _<br />
0, <br />
Encoding.GetEncoding(1252).GetBytes("Environment"), _<br />
SMTO_ABORTIFHUNG, _<br />
5000, _<br />
lpdwResult)<br />
<br />
' even though the variable is now available to the windows system<br />
' it is not seen in the current "shell" by the application<br />
' to ensure it is seen we need to set it agauin but his time using<br />
' Win32 API SetEnvironmentVariableA function of kernel32.dll<br />
result = SetEnvironmentVariableA(strVariableName, strValue)<br />
<br />
End Sub<br />
....to delete an environment variable, is then pretty simple. Use code as above but replace regKey.SetValue with...
regKey.DeleteValue(strVariableName, False)
and remove strValue from the subroutine declaration and relpace it in the code with an empty string ""
Note that the LPARAM argument is passed to SetMessageTimeout as an array of bytes that represent the string "Environment" and that in my example I am using code page 1252 (ANSI Latin I) - you may wish to change this code page to suit your system. I'm not sure whether this would work if your system uses a multi-byte or double-byte character set....
hope that helps other people!
cheers
mf
|
|
|
|
|
Welcome to the world of P/Invoking the Win32 API. You'll run into lots of it because Windows is not a .NET native environment. That being said, you'll find that you'll have to translate MANY examples of code, be it on MSDN or on the web in general, into VB.NET code on your own. Congratulations on your first attempt!
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
How do I inherit DataGridColumnStyle?
|
|
|
|
|
|
Thanks! Just what I needed. A concrete example.
|
|
|
|
|
I am binding a picture box. I have format the picture box to ensure it's not bind to an empty path or invalid path or invalid file. But problem raise, after formating the binding picture, the form doesn't load correctly. After &qt form1.Show() &qt executed, it doesn't call form1_load. But if i am not formating the binding picture, it will execute the f0rm1_load after it execute the &qt form1.Show() &qt. Is there any other code I need to put to the form1? Or what actually the problem?
Thanks. Please help me!!!
Learning .NET
|
|
|
|
|
Hello all. I'm working on a school project and it would be mad cool if I could get my VB forms to run in a browser and query a MySQL database thats on a web server. Do I embed the code as I would Perl or PHP into the HTML code or do I embed the executable file into the HTML coding? Any and all assistance would be appreciated.
Dare
|
|
|
|
|
Mad Cool???
You can't embed the form in an HTML page. You'd have to rewrite your app as an ASP.NET application. The only thing you could do with the .EXE you have now is to include a link in your web page. Clicking that link would download the .EXE just like any other file. You'll get the Save dialog box, ...
The user's machine would have to have the same version of the .NET Framework installed in order for that .EXE to download and work.
If you rewrite your app as an ASP.NET application, the user will only need a web browser to get to your new ASP.NET version.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
damn. thats not very mad cool (hey man, it was 2 in the morning!)
I will take your advice and try to code it in ASP. I only have a couple of days to do, but I think it'll be worth the shot. Thanks
|
|
|
|
|
You could create a UserControl and use that in a web page as you would an activeX control, however, the client would need the .Net run time.
|
|
|
|
|
I have a problem when displaying a report that have more than 1 page.
When I click on "next page" button in crystal report toolbar, the page cannot be shown.
Pleaaseee help meeeeee
|
|
|
|
|
Need more information. For example does the viewer show a + sign next to the page number to indicate multiple pages. Maybe there are no pages because this is the end of the displayed data and you are filtering off the last remaining expected records.
|
|
|
|
|
HELP! Could anyone please help me, I am trying to us the PsSetLoadImageNotifyRoutine process structure routine in Visual Basic 6 and I would like to be able to intercept process images and stop them from opening. Does anyone have a clue how to do this? and is it possible in Visual Basic?
|
|
|
|
|
I seriously doubt anyone has used that in VB6, or any VB for that matter. Why would you want to stop executable code from loading? You do realize that when your callback is called, the image is already loaded but has not started execution yet. You can't use the callback to stop an image from being loaded or executed. It's just used to notify your code that an executable image was loaded and is about to start.
What, exactly, are you looking at stopping?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Is there any way to intercept an image and be able to stop it. I am writing a security application and I am using the registry to stop applications running. By adding a gate in the HKCR\exefile\shell\run\command key I have successfully been able to block applications but the main problem is when an application is not loaded using the ShellExecute API i.e. it is loaded using the Shell("") command in VB instead. Do you have any ideas? Or are you going to tell me it can't be done based from your own knowledge?
TTFN!
|
|
|
|
|
I am trying to respond to Outlook's "BeforeItemPaste" event. However, I am being notified by visual studio that the calling signature is wrong.
I think this is because the event's signature includes the param "clipboardcontent as Variant". Obviously VB.NET no longer supports a Variant data type. I have tried Object and VariantType, to no avail. How do I work around this? Thanks for the help.
.................
Dim WithEvents olExplorer As Outlook.Explorer
Private Sub olExplorer_BeforeItemPaste(ByVal ClipboardContent As VariantType, ByVal Target As Outlook.MAPIFolder, ByVal Cancel As Boolean) Handles olExplorer.BeforeItemPaste
MsgBox("got it! ")
Cancel = True
End Sub
JRich
|
|
|
|
|
Hello EveryBody
I implemented one ActiveX Control in Visual Basic 6.0. And I want to add instances of this control (Dynamically) in new control or new form. But VB is not allowing me to Set object to ActiveX control. (it allow to declare object but problem is in set operation). ...every suggtion and help is regreated..
|
|
|
|
|
You might want to post the code your using so we can see what's going on. Adding the control is as easy as Dim myControl As New myActiveXControl and then adding it to the Form's controls collection.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Here try this it should allow you to create infinate instances of and object using a dynamic array... (First of all set the index property of your ActiveX object to 0)
{
Private Sub CreateNewActiveXObjectInstance()<br />
<br />
Load ActiveXObject(ActiveXObject.UBound + 1)<br />
'Object Upper-Boundary increases by 1 now<br />
<br />
ActiveXObject(ActiveXObject.UBound) = ActiveXObject(ActiveXObject.UBound - 1)<br />
'If the previous line gives you an ERROOOOOORRRRRGH! then try setting<br />
'the properties of the new object, bearing in mind you have just created<br />
'a new instance in memory, all of its property values will be empty.<br />
<br />
'e.g.<br />
ActiveXObject (ActiveXObject.UBound).[Property] = [Value]<br />
<br />
End Sub
Call this routine everytime you want to create a new instance of the object
};
|
|
|
|
|
Dear VB Gurus,
I want to get the row of the MSHFlexGrid's row on mouse move. How do i go about it?
Plz Help,
Ravi.
|
|
|
|
|
I want to make a dll in vb 6 and use it in another project by vb6 too but i don't know how plzz help me
|
|
|
|
|
For using dll in the another project you have two ways:
One way is to add ur dll project in the client vb project and make references Project -> References. In the references window it will show you the dll project's name select that name and say ok. Now you can use your dll in your client project.
--Or--
Make the dll of your dll project. By making the dll vb6 automatically registers it on your system. If you want to use or deploy it on another computer you need to explicitly register it using regsvr32.exe. Then open your client project Goto Project -> References in the references window look for your dll name and select it and click on ok. Now you can use your dll in the client project.
The former is best way to debug your dll project from the client project.
|
|
|
|