Jump to content

Looking to learn more about coding.. Got MS Visual Studio 2012. Where to start?


Recommended Posts

Posted (edited)

Scripting/coding has always been something I've been intrigued by and after working on several small batch files to automate repetitive tasks I want to delve into it deeper.

 

So I've grabbed myself a copy of Microsoft Visual Studio 2012, which gives me the options of Visual Basic, C#, C++ and some others. I'm having trouble coming across any clear tutorials online that actually explain themselves (There's no shortage of YouTube and DailyMotion vids, but I find text tutorials much easier to work from than video ones)

 

Realistically (though I don't know how realistic this may be) I'm looking to learn commands/syntax/etc and what they do so I can combine them together and achieve my goal, rather than 'Do-what-we-tell-you-and-don't-experiment' tutorials, much in the same way as I learnt to write batch files. I find a 'here's a tonne of code and a brief explanation' doesn't really sink in very well, for me.

 

The two 'projects' I have so far are:

Create an .exe that pulls data from a web page and prints it to a specific printer (used for printing a staff list when the fire alarm goes off)

A loop to check every now-and-again if a specific dialogue box has appeared, and if it has, to wait around 30s and then click 'OK' (the program is question is too stupid to retry its own connection and just stops if there's a blip)

 

Would anybody have any tutorials bookmarked that I might not have come across?

Edited by Garacesh
Posted

When ever I've taught myself a lower level language like C I've always preferred books. I haven't got any personal recommendations for the languages you've chosen but some of the books for 'Visual ' might concentrate more on interface design and include the coding as more of an after thought. Personally I prefer the books that teach you the code and then introduce the interface design once you've got a grasp of the basics.

 

From the projects you describe you might want to look at Powershell, as that's going to be more useful from a System Admin perspective. I've not learnt it myself yet but I'm fairly familiar with vbscript which is what Powershell seems to be replacing. If you hadn't already invested in the Microsoft visual studio I would recommend python as a language to learn the basics from with plenty of real world uses and free learning resources.

Posted (edited)

Very much so. Books/written tutorials over videos any day! And yes, that's the kind of tutorial I'm looking for. Start off with 'Here's the coding structure and a some commands. Learn those, then we'll start actually doing something with them.'

 

Well I'm trying to look into C# right now (Only just learnt it was 'C-Sharp' not 'C-Hash', whoops!) and I've gotten a Hello, world! working.

Compiling that into an actual exe, not so much. Grumble.

 

I've heard about PowerShell but I thought I'd take baby steps first with a more simple language

Edited by Garacesh
Posted

I'm a big fan of the Ruby scripting language so I'd recommend that to anyone, especially beginners, but as @DanielRF said Python is another great alternative.

 

If you were looking to learn a language for a career, I'd definitely recommend C# of the list that you gave, but Visual Basic or PowerShell are probably most appropriate for the sort of stuff you're looking to do and they're great languages for that kind of thing (and not too difficult).

 

Once again, I'd echo that a decent beginners book is the way to go. Use it to learn the syntax, techniques and conventions, then once you're up and running you should only need the web as a resource to figure out the rest. That's my preferred learning technique.

Posted

Well so far I've managed to discover and adapt a C# jobbie that detects if a window is open by its title and closes it.

Problem is I then find out the title of the popup is the title of all the other windows the program generates, too D: So if the popup wasn't there, it would close the program. Darnit!

 

Back to the drawing board!

Posted
Well so far I've managed to discover and adapt a C# jobbie that detects if a window is open by its title and closes it.

Problem is I then find out the title of the popup is the title of all the other windows the program generates, too D: So if the popup wasn't there, it would close the program. Darnit!

 

Back to the drawing board!

 

You can check the parent of the window using HWND and if it is itself ignore it?

 

Steve

Posted

            try
           {
               IntPtr hWndError = Process.GetProcessesByName("Wordpad")[0].MainWindowHandle;
               if (hWndError != null)
               {
                   PostMessage(hWndError, WM_COMMAND, WM_CLOSE, 0);   // Close window
               }
           }
           catch (Exception)
           {
               ; ;
           }

(Forgive that it says Wordpad - that was just for testing purposes)

 

Unfortunately all child windows of the program contain the same title, therefore I need to either narrow it down by content (Interface not responding) or by type (pop-up dialogue box)

Posted
            try
           {
               IntPtr hWndError = Process.GetProcessesByName("Wordpad")[0].MainWindowHandle;
               if (hWndError != null)
               {
                   PostMessage(hWndError, WM_COMMAND, WM_CLOSE, 0);   // Close window
               }
           }
           catch (Exception)
           {
               ; ;
           }

(Forgive that it says Wordpad - that was just for testing purposes)

 

Unfortunately all child windows of the program contain the same title, therefore I need to either narrow it down by content (Interface not responding) or by type (pop-up dialogue box)

 

If it's always a popup I'm assuming it'll be top window? If so you could use the Z level orders? (aka topmost window that contains the title?) Or can it be behind other windows?

 

Steve

Posted (edited)

It's usually the top window, but the problem is this appears when the programs connection blips, but it's too stupid to wait 30s and retry so it instead throws up an error.

It then does literally nothing until 'OK' is clicked. So what I'm looking to do is run a scheduled task that checks if it's there and presses O or Enter (SendKeys.Send("{ENTER}");)

 

However, in its current state, it would detect the window exists (unfortunately it's not $Program - Error! or anything, they're all just $Program) and close it as per instructed, closing the actual program if it hadn't error'd. Or, possibly even worse, closing the scheduled (and rather critical) tests it performs ('cause wouldn't you know it? Titled $Program again rather than $Program - Running Test)

There's no event created for it, either, else I'd just tie the program into an event. That'd be simple. System.Threading.Thread.Sleep(30000); / SendKeys.Send("{ENTER}"); - problem solved. But nooo..

Edited by Garacesh
Posted

Well it depends how the rest of the program works, but if it's a standalone on a server kinda one, can't you just having a recurring check of amount of windows/programs under "program name etc" and when it increases send it? Or is it actually used by an end user thus always changing?

 

Steve

Posted

Unlikely. Though I haven't checked, I'd assume that the number would also increase when it started testing, because that's a separate window too.

... the program in question isn't an especially smart one.

Posted (edited)

Just managed to reproduce.. The popup is not produced as the foremost window. So now I also need to find a way of detecting it and bringing it to the front. Joyous. Still, baptism by fire and all..

@mikecampbell - There's nothing wrong with narrowing it down by type or content, I'm just having trouble finding out how to do this xD

 

Annoyingly..

IntPtr hWndError = Process.GetProcessesByName("WordPad", !="Document - WordPad")[0].MainWindowHandle;

doesn't work. I was hoping for a 'Close if contains x but not y', since it turns out there are actually differences, but so it shall not be.

So it looks like what I have to do is detect and differentiate 'error popup' from 'actual program', and either terminate it with PostMessage(hWndError, WM_COMMAND, WM_CLOSE, 0); or preferably bring the popup to the front and OK it with SendKeys.Send("{ENTER}");

 

.. Oh, and it may be worth mentioning this program was written for Windows 3.1.

Edited by Garacesh
Posted

I've not done this myself, but I'd be looking at using something like AU3Info (AutoIt Window Info Tool) to find some sort of field I can accurately identify the error window by, then tailoring my code to target it.

 

I don't know how much work you've done with Windows API, but it's worth noting that every single component (buttons, icons, even text fields) is classed as a window and so will have it's own set of window properties. It might be worth pursuing a way of identifying a window which contains the error icon (assuming it does!) as the icon itself should be identifiable via API calls.

Posted

[ATTACH=CONFIG]19108[/ATTACH]

As well as being created in the background, the error also doesn't always show up in the same place either. So relying on moving the mouse and clicking wouldn't work, either.

Posted
[ATTACH=CONFIG]19108[/ATTACH]

As well as being created in the background, the error also doesn't always show up in the same place either. So relying on moving the mouse and clicking wouldn't work, either.

 

From the picture there the other option would be checking what windows have the icon. Assuming it isn't on any other pages you need?

 

Steve

  • 1 month later...
Posted
.. Oh, and it may be worth mentioning this program was written for Windows 3.1.

 

This could be an issue as Win 3.x apps run in under a seperate "emulation" layer called WinOldApp I think ? Win 3.x was 16-bit, Windows 95 onwards was 32-bit so this layer was used to translate ("thunk") the calls between the two different systems.

Posted

Out of curiosity, what does this relic of an application actually do?!

 

As for closing the popup window, I'd go for @Steve21's solution of looking for the specific window icon is a good one as long as it's unique. Alternatively, you could check the dialog text for the specific string it displays.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...