Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
Milotic
Mar 4, 2009

9CL apologist
Slippery Tilde

Prefect Six posted:

I don't know what a method is yet :ohdear:

e: outside that "Main" is a method that starts every program.

A method is a labelled unit of work that can typically be called repeatedly* or combined with other methods to produce a more complex program

*One method you can't call repeatedly is Environment.Exit() since that forces the currently running program to exit.

Adbot
ADBOT LOVES YOU

raminasi
Jan 25, 2005

a last drink with no ice

SirViver posted:

Really? Where in the specs does it say that? :colbert:

Yeah, I should have :colbert:ed Ithaqua, but I was worried that Prefect Six would miss it.

Mongolian Queef
May 6, 2004

I have a really strange error. My Visual Studio 2010 just exits entirely on its own.
If I debug my application in Visual Studio and just leave it there, all of a sudden Visual Studio asks if I want to stop debugging. If I click "No", it will still exit on its own.
It behaves just like an unhandled exception in that the process just dies, but there's no crash handler like you would expect. What the christ?

Edit: Now running an instance of Visual Studio in another Visual Studio and debugging it.

Edit edit: Results are in! This is what the non crashing Visual Studio reports.

A first chance exception of type 'System.InvalidOperationException' occurred in JetBrains.Platform.dotTrace.Util.dll
A first chance exception of type 'System.InvalidOperationException' occurred in JetBrains.Platform.dotTrace.Util.dll

The above exceptions happen sporadically long before any crashes, so they may not be related.

'devenv.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.VisualStudio.Shell.StartPage\v4.0_10.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Shell.StartPage.dll'
The thread 'ExecutionMode - Thread 1' (0x1034) has exited with code 0 (0x0).
The thread '<No Name>' (0xf0c) has exited with code 0 (0x0).
'devenv.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.Windows.Design.Host\v4.0_4.0.0.0__b03f5f7f11d50a3a\Microsoft.Windows.Design.Host.dll'
A first chance exception of type 'System.ObjectDisposedException' occurred in Microsoft.VisualStudio.Shell.10.0.dll
A first chance exception of type 'System.Runtime.InteropServices.InvalidComObjectException' occurred in VSLangProj.dll

Above exception repeated 36 times

A first chance exception of type 'System.Runtime.InteropServices.InvalidComObjectException' occurred in EnvDTE.dll
A first chance exception of type 'System.Runtime.InteropServices.InvalidComObjectException' occurred in EnvDTE.dll
The program '[4832] devenv.exe: Managed (v4.0.30319)' has exited with code 0 (0x0).

Mongolian Queef fucked around with this message at 14:10 on Aug 27, 2012

PDP-1
Oct 12, 2004

It's a beautiful day in the neighborhood.
I had something like that happen when my application was talking to another process via remoting. If my application's actions caused a problem in the remote process an exception would get generated 'outside' my program and VS would terminate my program without providing any useful info.

Try using the AppDomain.CurrentDomain.UnhandledException event to log the exception message and stack trace somewhere. That should pinpoint the code that's initiating the crash.

Mongolian Queef
May 6, 2004

I'm sorry, I completely forgot to mention that the above crash just happened even when my application wasn't running. The solution is loaded but all editor windows were closed. I wasn't using VS at the time, it just died.

Edit: Tried the old "delete solution.sdf and solution.suo", but it still crashed while I was coding.
Started VS with /Log now, will see if it finds anything funny.

Mongolian Queef fucked around with this message at 15:56 on Aug 27, 2012

Prefect Six
Mar 27, 2009

Ithaqua posted:

I said a method! But that's okay.

So I hit a brick wall with methods using this tutorial. I'm trying to make two different methods to get a string input and then use stringbuilder to reverse the order of the strings.

Here is my awful code:

code:
namespace FunWithMethods
{
    class StringReverse
    {
        public static void Main(string[] args)
        {
            StringReverse sr = new StringReverse();

            string word = sr.getWord();

            string reverseWord = sr.reverseWord;

            Console.WriteLine();
            Console.ReadLine();
        }

        string getWord()
        {
            string word;

            Console.WriteLine("Enter your word: ");
            word = Console.ReadLine();

            return word;
        }

        string reverseWord()
        {
            StringReverse sr = new StringReverse();
            string word = sr.getWord();
            string reverseWord = new StringBuilder();

            for (int wordLength = word.Length; wordLength > 0; wordLength--)
            {
                int wordIndex = wordLength - 1;
                char indexCharacter = word[wordIndex];
                reverseWord.Append(indexCharacter);
            }

            return reverseWord;
        }
    }
}
I'm kind of just throwing poo poo at a wall and seeing what sticks, so I'm probably completely off-base. Pretty sure I don't really understand why or how to call methods and return values.

Orzo
Sep 3, 2004

IT! IT is confusing! Say your goddamn pronouns!
Well, you have most of it right, you're just missing a couple things. You know how to call a method, because you are calling it correctly for getWord(). For some reason you aren't doing that for reverseWord -- make sure you add parentheses to invoke (call) a method.

Finally, the Console.WriteLine method accepts a string as an argument, you should be passing the result of your function--reverseWord--into it. Console.WriteLine(reverseWord).

Edit: Oops, I didn't read the entire thing. You have a couple more problems.

You should modify your reverseWord function to accept a string as an argument.
code:
string reverseWord(string wordToReverse)
..then you should call your reverseWord function with the result of your "getWord" function, that is, 'word'. Then have your loop operate on 'wordToReverse'.

Orzo fucked around with this message at 20:49 on Aug 27, 2012

raminasi
Jan 25, 2005

a last drink with no ice

tunah posted:

I'm sorry, I completely forgot to mention that the above crash just happened even when my application wasn't running. The solution is loaded but all editor windows were closed. I wasn't using VS at the time, it just died.

Edit: Tried the old "delete solution.sdf and solution.suo", but it still crashed while I was coding.
Started VS with /Log now, will see if it finds anything funny.

You did try sending a crash report to Microsoft, right?

Prefect Six
Mar 27, 2009

Orzo posted:

Well, you have most of it right, you're just missing a couple things. You know how to call a method, because you are calling it correctly for getWord(). For some reason you aren't doing that for reverseWord -- make sure you add parentheses to invoke (call) a method.

Finally, the Console.WriteLine method accepts a string as an argument, you should be passing the result of your function--reverseWord--into it. Console.WriteLine(reverseWord).

Edit: Oops, I didn't read the entire thing. You have a couple more problems.

You should modify your reverseWord function to accept a string as an argument.
code:
string reverseWord(string wordToReverse)
..then you should call your reverseWord function with the result of your "getWord" function, that is, 'word'. Then have your loop operate on 'wordToReverse'.

Ugh, good catch. I guess my only problem then is that StringBuilder has to be var type? And you can't return a var?

Dietrich
Sep 11, 2001

Prefect Six posted:

Ugh, good catch. I guess my only problem then is that StringBuilder has to be var type? And you can't return a var?

Var is not a type.

Var is a command to the compiler to infer the type. It doesn't work on method return signatures. It probably could, but it doesn't.

So
code:
public string HiThere()
{
  var s = "hi"; //s is a string!
  var d = "dude"; //d is a string!
  var returnThis = s + " " + d; //a string + a string + a string, so a string!
  return returnThis;
}
but this is not legal.
code:
public var HiThere()
{
  return "hi dude";
}
most likely because it would be troublesome to track down what's going on with something like this:

code:
public var HiThere()
{
  if (something) 
  {
    return "hi dude"; // so hi there returns a string?
  }
  else 
  {
    return 3; // wait now it returns an int? do we cast it to a string or refuse to compile? 
  }
}

Dietrich fucked around with this message at 21:10 on Aug 27, 2012

glompix
Jan 19, 2004

propane grill-pilled

Prefect Six posted:

Ugh, good catch. I guess my only problem then is that StringBuilder has to be var type? And you can't return a var?

Var isn't a type. It's just an implicit way to declare the type of the variable. These two lines of code are identical when compiled:

code:
StringBuilder builder = new StringBuilder();

var builder = new StringBuilder();
In the second snippet, var is effectively replaced with StringBuilder by the compiler, since the return type of "new StringBuilder()" is a StringBuilder.

You might be asking why you can't just use var everywhere, but you'll get different answers to that question. I don't mind it because I know my development environment well enough to guess what methods will return, and in a pinch I can always just hover over a method name or property to figure out what the type is. I also hate typing long type names like IDictionary<string, IEnumerable<string>>. Opponents of var say it's harder to read code littered with vars, and don't like being able to change a return type of a method without compilation breaking at every point the method was used. Either way, you pretty easily rig something up to replace all of those vars if it becomes a problem, so do whatever you prefer.

Mongolian Queef
May 6, 2004

GrumpyDoctor posted:

You did try sending a crash report to Microsoft, right?

I would if it would have shown up. Like I said, the process just disappears.

Orzo
Sep 3, 2004

IT! IT is confusing! Say your goddamn pronouns!
Prefect six: another thing, you need to call the ToString() function on your StringBuilder when you're done with it. That 'extracts' the contents of the StringBuilder into a string. Then you can return that string.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Prefect Six posted:

So I hit a brick wall with methods using this tutorial. I'm trying to make two different methods to get a string input and then use stringbuilder to reverse the order of the strings.

Here is my awful code:

code:
namespace FunWithMethods
{
    class StringReverse
    {
        public static void Main(string[] args)
        {
            StringReverse sr = new StringReverse(); 

            string word = sr.getWord(); // Good!

            string reverseWord = sr.reverseWord; // You need to do reverseWord(word);

            Console.WriteLine();
            Console.ReadLine();
        }

        string getWord() // Method names should start with uppercase letters!
        {
            string word;

            Console.WriteLine("Enter your word: ");
            word = Console.ReadLine();

            return word;
        }

        string reverseWord() // should be "string reverseWord(string wordToReverse)"
        {
            StringReverse sr = new StringReverse(); // Unnecessary
            string word = sr.getWord(); // Unnecessary 
            string reverseWord = new StringBuilder(); // Should be StringBuilder reverseWord = new StringBuilder();

            for (int wordLength = word.Length; wordLength > 0; wordLength--) // This is going to cause a runtime exception, but I'll leave the reason why to you to figure out
            {
                int wordIndex = wordLength - 1;
                char indexCharacter = word[wordIndex];
                reverseWord.Append(indexCharacter);
            }

            return reverseWord;
        }
    }
}
I'm kind of just throwing poo poo at a wall and seeing what sticks, so I'm probably completely off-base. Pretty sure I don't really understand why or how to call methods and return values.

I went through and put some comments in your code above.

Prefect Six
Mar 27, 2009

I'm still getting an error that tells me I can't implicitly convert type StringBuilder to string on the return and method call.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Prefect Six posted:

I'm still getting an error that tells me I can't implicitly convert type StringBuilder to string on the return and method call.

Call a .ToString() on it!

Funking Giblet
Jun 28, 2004

Jiglightful!
You need to return reverseWord.ToString()

raminasi
Jan 25, 2005

a last drink with no ice

tunah posted:

I would if it would have shown up. Like I said, the process just disappears.

Oh, right. Do you get a crash report if you attach a debugger and then detach it?

Prefect Six
Mar 27, 2009

Funking Giblet posted:

You need to return reverseWord.ToString()

That did it, thanks guys!

Sab669
Sep 24, 2009

This is kind of a dumb question, but I've never made a class that inherits from another control before. Using some code I found online, I've made a property grid subclass that enables tab-key navigation. What I'm curious about is how does Visual Studios know to display this custom control in the Toolbox automatically?

Mongolian Queef
May 6, 2004

GrumpyDoctor posted:

Oh, right. Do you get a crash report if you attach a debugger and then detach it?

I'll check next time I'm working from home. Luckily this doesn't happen in the office.

dotalchemy
Jul 16, 2012

Before they breed, male Mallards have bright green/blue heads. After breeding season, they molt and become brown all over, to make it easier to hide in the brush while nesting.

~SMcD

Sab669 posted:

This is kind of a dumb question, but I've never made a class that inherits from another control before. Using some code I found online, I've made a property grid subclass that enables tab-key navigation. What I'm curious about is how does Visual Studios know to display this custom control in the Toolbox automatically?

Because you're inheriting from a control, so it knows your class is a control and adds it as a user control. Visual Studio is just smart like that.

If you want to disable it, there's an option in VS to do so.

edmund745
Jun 5, 2010
I'm trying to get a vb.net program to be able to type into another program using Sendkeys. So far I can't even get a VB program to grab any foreground window other than itself, however. What is the secret here? So far I cannot find one easy-to-understand, working example of this (written in vb.net) online.

The example below works, but not really, because it only works when the VB program itself has focus--which is no help. When the vb program isn't in the foreground, the timer event doesn't seem to trigger at all, and yet everything I've read says that it should. What is wrong with it?

code:
Public Class KeySender01 '--the form

    Public loopCatcher As Boolean
    Public sendkeysTargetForm As Form


    Private Sub KeySender01_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        sendkeysTargetForm = Nothing
    End Sub


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        TextBox1.Text = ""
        Timer1.Enabled = True '--timer1 interval set to 5000
    End Sub


    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Timer1.Enabled = False
        TextBox1.Text = Convert.ToString(sendkeysTargetForm)
    End Sub


    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles wtf.Click, Timer1.Tick
        grabWindow()
    End Sub


    Private Sub grabWindow()
        sendkeysTargetForm = Form.ActiveForm
        'TextBox1.Text = ""
        'TextBox1.Text = Convert.ToString(sendkeysTargetForm)
    End Sub


End Class

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

edmund745 posted:

I'm trying to get a vb.net program to be able to type into another program using Sendkeys. So far I can't even get a VB program to grab any foreground window other than itself, however. What is the secret here? So far I cannot find one easy-to-understand, working example of this (written in vb.net) online.

The example below works, but not really, because it only works when the VB program itself has focus--which is no help. When the vb program isn't in the foreground, the timer event doesn't seem to trigger at all, and yet everything I've read says that it should. What is wrong with it?


There has to be more code than that. The code you pasted shows literally nothing.

edmund745
Jun 5, 2010

Ithaqua posted:

There has to be more code than that. The code you pasted shows literally nothing.

Well,,, the timer event is set to Button6_Click. I forgot to comment that on there.

That should be all it takes.... And it does work, when the vb program is in the foreground. The timer just doesn't work when its in the background. So maybe this is more of a timer question?

I have also tried putting timer1.start and timer1.stop in the buttons with the timer enable/disable, and it still does(n't) do the same thing. :\

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
Where is the sending keys bit supposed to be happening?

edmund745
Jun 5, 2010

Jabor posted:

Where is the sending keys bit supposed to be happening?
The Sendkeys part isn't even in there yet. I would need to be able to grab the target window somehow before I could use Sendkeys. All that the code I posted is supposed to do is grab the foreground window every 5 seconds (even if its not in the foreground) and show the info in the textbox.

Here is another example I tried:
http://www.vbforums.com/showthread.php?281243-Get-Active-Control-Resolved&highlight=active (the example code given in post #10)

It works fine when the VB program has foreground, but when its in the background it raises an error about an "unbalanced stack". A number of the others I tried said the same thing.

edmund745
Jun 5, 2010
well nuts.
I been trying to find ONE working example of this for about three days now.
I finally come on here and ask, and about two minutes later find one that actually works:

http://www.vbforums.com/showthread.php?494477-Get-foreground-window-text

The code given in post #10 there does actually work. And doesn't crash the program or anything.

------

This has been a pain I think because a lot of examples aren't concerned with finding ANY foreground window,,, they just have a bunch of child windows, and are trying to find out which one the user is in.

adaz
Mar 7, 2009

Well I've had to do this before so you get lucky! There is probably a better way of doing this, but maybe not sending keys between different programs is pretty much always a kludge.

code:

' Win32Forms class - grabbed this off internet somewhere!
Public Class Win32Forms
    <Runtime.InteropServices.DllImport("user32.dll")>
    Public Shared Function ShowWindow(<Runtime.InteropServices.In()> ByVal hWnd As IntPtr, <Runtime.InteropServices.In()> ByVal nCmdShow As Int32) As System.Boolean
    End Function

    <Runtime.InteropServices.DllImport("user32.dll")>
    Public Shared Function SetForegroundWindow(<Runtime.InteropServices.In()> ByVal hWnd As IntPtr) As System.Boolean
    End Function

End Class


' example method, sends "Y" to the foreground window
  Dim _possibleProcs = Process.GetProcessesByName("csrss")
        For Each _proc In _possibleProcs
            Dim _winhandle = _proc.MainWindowHandle()
            '3.) If _winhandle > 0 that means it has a UI
            If _winhandle.ToInt32() > 0 Then
                Win32Forms.ShowWindow(_winhandle, 10)
                Win32Forms.SetForegroundWindow(_winhandle)
                Windows.Forms.SendKeys.SendWait("Y")
            End If
        Next

adaz fucked around with this message at 15:49 on Aug 28, 2012

Crazy Mike
Sep 16, 2005

Now with 25% more kimchee.
PROBLEM:
Someone's birthday is in a datagridview cell in yyyy/mm/dd format. I want to get a copy of it in mm/dd/yyyy format in a masked text box in case it's wrong and needs to be edited. After all, I'm pretty sure his birthday isn't 19/81/1028.
SOLUTION:
code:
string convertedDOB = (string)datagridview[7, e.RowIndex].Value;
string convertedYear = convertedDOB.Remove(4);
string convertedMonthDay = convertedDOB.Remove(0, 5);
convertedDOB = (convertedMonthDay + convertedYear);
mtxtDOB.Text = convertedDOB;
This looks like it works. The masked text box inserts the slashes automatically so i don't have to put .Replace("/", string.Empty) at the end of convertedDOB. Is there a more elegant way to solve this problem? Is this a case where I should be using StringBuilder instead?

SirViver
Oct 22, 2008
Personally I'd do proper date parsing instead of just shuffling strings around, but both gets the job done. Using a StringBuilder wouldn't make this more elegant nor perform better, btw.
C# code:
using System.Globalization;
...
private string ParseAndFormatDate(string input)
{
	DateTime parsedDate;
	if (DateTime.TryParseExact(input, "yyyyMMdd", CultureInfo.CurrentUICulture, DateTimeStyles.None, out parsedDate))
	{
		return parsedDate.ToString("MMddyyyy");
	}
	else
	{
		// Do whatever should happen if parsing fails.
	}
}
...
mtxtDOB.Text = ParseAndFormatDate((string)datagridview[7, e.RowIndex].Value);
PS: gently caress MM/DD/YYYY.

E: Though the whole thing smells like a badly designed application. Stuff like date formats should be handled by the controls black-box style, i.e. displaying and reading them according to the current user's culture settings. All you should ever see is DateTime instances, not having to mess around with string manipulation.

SirViver fucked around with this message at 20:26 on Aug 28, 2012

edmund745
Jun 5, 2010

adaz posted:

Well I've had to do this before so you get lucky! There is probably a better way of doing this, but maybe not sending keys between different programs is pretty much always a kludge.
So do you call the method with a timer? I tried that and it doesn't work.

The vb program loses focus when the timer tics, but nothing appears in the target window (in this case, notepad--the only other window open).

PhonyMcRingRing
Jun 6, 2002

edmund745 posted:

code:
    Private Sub grabWindow()
        sendkeysTargetForm = Form.ActiveForm
    End Sub

This doesn't do what you think it does. Form.ActiveForm gives you the currently active form in your application. It knows nothing about any outside application.

edmund745
Jun 5, 2010

PhonyMcRingRing posted:

This doesn't do what you think it does. Form.ActiveForm gives you the currently active form in your application. It knows nothing about any outside application.
Yea I noticed that. It could be that there isn't any way left to do it in vb now.

Most of what I find is using C#, and using code that doesn't have an equivalent in vb.net. Of the 3 or 4 examples of on-screen keyboards that were written in vb, they were all for earlier versions of VB and none of them will work now.

Eggnogium
Jun 1, 2010

Never give an inch! Hnnnghhhhhh!
Anybody an expert in System.Configuration?

I have an API which has tons of configurable values. First obstacle was getting ConfigurationManager to open the library's app.config rather than the executing assembly's. Workaround was easy enough, use ConfigurationManager.OpenExeConfiguration(Assembly.GetExecutingAssembly().Location).

Furthermore, I have a custom configuration section:

code:
<section name="common" type="Foo.Bar.CommonConfiguration, Foo.Common"/>
Foo.Bar.CommonConfiguration is the class which inherits from ConfigurationSection and Foo.Common.dll is the name of the binary.

This has previously worked fine in every context. Now, however, I have a consumer that wants to use Powershell to work with the API. For some reason, in the context of Powershell, System.Configuration totally shits itself and can't find the binary with CommonConfiguration:

code:
New-Object : Exception calling ".ctor" with "0" argument(s): "An error occurred creating the configuration section handler for common: Could not load file or assembly Foo.Common' or one of 
its dependencies. The system cannot find the file specified. (D:\temp\Foo.Common.dll.config line 4)"
At line:29 char:20
+ $Baz= New-Object Foo.Bar.Baz
+                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [New-Object], MethodInvocationException
    + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand
This is extra retarded because the binary is already loaded by powershell.exe, in fact it contains the code that is loading the configuration in the first place.

Here's someone else who had the same problem but there's no answer.

Anyone encountered this before or have a suggestion? Is there some way to explore exactly where .NET is looking to load the assembly from? I'm having trouble even getting a breakpoint to trigger when I attach to powershell.exe. To clarify, the correct config file is being located just fine, it's locating the assembly which contains my custom configuration class while parsing the config file that is failing.

Edit: Problem solved. The issue is that even though the assembly is already loaded, the configuration library still tries to load the assembly a second time in order to bind the configuration. Since the assemblies were manually loaded they're not in the GAC or anywhere else the AppDomain knows where to look, so they don't get found.

Since AppDomain.AppendPrivatePath is deprecated, the solution is to add an event handler which returns the executing assembly before your configuration is accessed.

Eggnogium fucked around with this message at 00:26 on Aug 29, 2012

ljw1004
Jan 18, 2005

rum

edmund745 posted:

Most of what I find is using C#, and using code that doesn't have an equivalent in vb.net. Of the 3 or 4 examples of on-screen keyboards that were written in vb, they were all for earlier versions of VB and none of them will work now.

Almost everything in C# has an equivalent in VB. (the only things which don't are "unsafe" and imports-alias). Post the C# code you're struggling to translate and I'll write out the VB equivalent.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

ljw1004 posted:

Almost everything in C# has an equivalent in VB. (the only things which don't are "unsafe" and imports-alias). Post the C# code you're struggling to translate and I'll write out the VB equivalent.

Or he could just use this tool:
http://www.developerfusion.com/tools/convert/csharp-to-vb/

It's not perfect but I've had pretty good luck with it.

Zhentar
Sep 28, 2003

Brilliant Master Genius
Or tell us what you're actually trying to accomplish, and you may get more help.

adaz
Mar 7, 2009

edmund745 posted:

So do you call the method with a timer? I tried that and it doesn't work.

The vb program loses focus when the timer tics, but nothing appears in the target window (in this case, notepad--the only other window open).

In that particular case I invoked the method by creating a new Task from the TPL and put like a second delay in there before it fired. For the record, it's an application that is just OK'ing the box the certificate import wizard gives warning about importing root certificates. SO yeah, it is an different application which is why you have to use the 'ol windows api stuff

code:
Dim _clearOKTask = Task.Factory.StartNew(Sub() GetRidSecurityWarning())

adaz fucked around with this message at 06:01 on Aug 29, 2012

Adbot
ADBOT LOVES YOU

edmund745
Jun 5, 2010

Zhentar posted:

Or tell us what you're actually trying to accomplish, and you may get more help.
I wanted a vb form sub or function to be able to get the previous foreground window, in a way that can be used with Sendkeys.
The sendkeys target will be ANOTHER totally-separate application, that I don't know any info on in advance. So it has to find it the way that an on-screen keyboard does--by identifying the previously-active window, of a separate application.
,,,,,,,
There is reasons it may not be workable with the target app anyway. I didn't expect it to be so difficult though.

When I said there may be "no way to do it", I meant no officially-supported way. While trying to figure out other versions of on-screen keyboards written in c# or C++, frequently there is calls they make that appear to have no VB equivalent (at least none given on the MSDN site).

I think I tried three different on-screen keyboards that were written in earlier versions of VB, and none of them will compile/run on vb.net at all. -And of the ones posted online, nobody seems to have written newer ones or updated older ones in a long time.

Also I noticed that a lot of the C# and C++ ones go into details about how to prevent the on-screen keyboard from stealing focus, by intercepting mouse messages. None of the (old) VB ones seem to bother with this, so that is another reason I think this isn't supported in VB anymore. Something seems to have changed between then and now... ?
One example (discussing focus-stealing and how to prevent it):
http://www.yortondotnet.com/2006/11/on-screen-keyboards.html

edmund745 fucked around with this message at 13:28 on Aug 29, 2012

  • Locked thread