+ Post New Thread
Page 1 of 2 12 LastLast
Results 1 to 15 of 19
Coding Thread, Looking to learn more about coding.. Got MS Visual Studio 2012. Where to start? in Coding and Web Development; Scripting/coding has always been something I've been intrigued by and after working on several small batch files to automate repetitive ...
  1. #1


    Join Date
    Jan 2012
    Posts
    2,571
    Thank Post
    922
    Thanked 342 Times in 263 Posts
    Rep Power
    206

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

    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?
    Last edited by Garacesh; 28th June 2013 at 10:44 AM.

  2. #2

    Join Date
    Apr 2013
    Posts
    27
    Thank Post
    1
    Thanked 7 Times in 7 Posts
    Rep Power
    4
    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 <language>' 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.

  3. #3


    Join Date
    Jan 2012
    Posts
    2,571
    Thank Post
    922
    Thanked 342 Times in 263 Posts
    Rep Power
    206
    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
    Last edited by Garacesh; 28th June 2013 at 11:40 AM.

  4. #4

    Join Date
    Dec 2012
    Location
    Skipton, North Yorkshire
    Posts
    23
    Thank Post
    10
    Thanked 3 Times in 3 Posts
    Rep Power
    15
    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.

  5. #5


    Join Date
    Jan 2012
    Posts
    2,571
    Thank Post
    922
    Thanked 342 Times in 263 Posts
    Rep Power
    206
    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!

  6. #6

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,689
    Thank Post
    334
    Thanked 515 Times in 483 Posts
    Rep Power
    179
    Quote Originally Posted by Garacesh View Post
    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

  7. #7


    Join Date
    Jan 2012
    Posts
    2,571
    Thank Post
    922
    Thanked 342 Times in 263 Posts
    Rep Power
    206
    Code:
                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)

  8. #8

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,689
    Thank Post
    334
    Thanked 515 Times in 483 Posts
    Rep Power
    179
    Quote Originally Posted by Garacesh View Post
    Code:
                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

  9. #9


    Join Date
    Jan 2012
    Posts
    2,571
    Thank Post
    922
    Thanked 342 Times in 263 Posts
    Rep Power
    206
    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..
    Last edited by Garacesh; 1st July 2013 at 09:51 AM.

  10. #10

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,689
    Thank Post
    334
    Thanked 515 Times in 483 Posts
    Rep Power
    179
    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

  11. #11


    Join Date
    Jan 2012
    Posts
    2,571
    Thank Post
    922
    Thanked 342 Times in 263 Posts
    Rep Power
    206
    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.

  12. #12

    Join Date
    Dec 2012
    Location
    Skipton, North Yorkshire
    Posts
    23
    Thank Post
    10
    Thanked 3 Times in 3 Posts
    Rep Power
    15
    What's wrong with your suggestion of narrowing down by content or window type? Sounds perfectly reasonable to me.

  13. #13


    Join Date
    Jan 2012
    Posts
    2,571
    Thank Post
    922
    Thanked 342 Times in 263 Posts
    Rep Power
    206
    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..
    Code:
    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.
    Last edited by Garacesh; 1st July 2013 at 10:51 AM.

  14. #14

    LosOjos's Avatar
    Join Date
    Dec 2009
    Location
    West Midlands
    Posts
    5,447
    Thank Post
    1,438
    Thanked 1,168 Times in 797 Posts
    Rep Power
    707
    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.

  15. #15


    Join Date
    Jan 2012
    Posts
    2,571
    Thank Post
    922
    Thanked 342 Times in 263 Posts
    Rep Power
    206
    comet.PNG
    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.

SHARE:
+ Post New Thread
Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •