[RESOLVED] Capture a window - Page 2
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 19 of 19

Thread: [RESOLVED] Capture a window

  1. #16
    Join Date
    Jun 2011
    Posts
    25

    Re: Capture a window

    Thanks for the update Eri. That's a neat way and not obvious from what documentation I've read.
    Quote Originally Posted by Eri523 View Post
    I think it's worth noting that this leaks memory: The dynamically allocated rect is never released. Actually, there's no need to dynamically allocate it anyway. The reason why I dynamically allocated lpNativeText in Win32::GetWindowText_() ....
    Ok but I didn't use dynamic allocation to mimic your example but because the help I read for GetWindowRect specified LPRECT (and I didn't see any use of "RECT and &rect")
    I did have the following in my original Win32::GetWindowRect
    Code:
      System::Drawing::Rectangle^ nrect = gcnew System::Drawing::Rectangle(rect->left,rect->top,rect->right-rect->left,rect->bottom-rect->top);
      delete rect;
      return nrect;
    For some reason I didn't use it but can't now remember why... Am I right in thinking this would be ok from the GC POV?

  2. #17
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,583

    Re: Capture a window

    Quote Originally Posted by RogerD View Post
    Thanks for the update Eri. That's a neat way and not obvious from what documentation I've read.Ok but I didn't use dynamic allocation to mimic your example but because the help I read for GetWindowRect specified LPRECT (and I didn't see any use of "RECT and &rect")
    Well, needlessly dynamically allocating an object just because some API demands a pointer to it instead of simply using the & operaror to take the address of an automatic (i.e. local) or class member object is a common beginner's mistake in native C++. That said, I think I have no idea how experienced you actually are...

    I did have the following in my original Win32::GetWindowRect
    Code:
      System::Drawing::Rectangle^ nrect = gcnew System::Drawing::Rectangle(rect->left,rect->top,rect->right-rect->left,rect->bottom-rect->top);
      delete rect;
      return nrect;
    For some reason I didn't use it but can't now remember why... Am I right in thinking this would be ok from the GC POV?
    It's ok insofar as it doesn't leak memory (and tolerating the unnecessary dynamic allocation). However, Rectangle is a value type, so there's no point in gcnewing it and storing a tracking handle to the boxed object. Instead you can directly work with the value object:

    Code:
      System::Drawing::Rectangle nrect = System::Drawing::Rectangle(rect->left,rect->top,rect->right-rect->left,rect->bottom-rect->top);
    Or, rather than the initialization syntax, use the shorter construction syntax:

    Code:
      System::Drawing::Rectangle nrect(rect->left,rect->top,rect->right-rect->left,rect->bottom-rect->top);
    Also, the return type of the function should be changed from Rectangle ^ to Rectangle for the same reason. (In fact I didn't notice the wrong return type until now, since it was the only place where originally you explicitly treated Rectangle like a reference type, and the syntactical difference was really small there.)
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  3. #18
    Join Date
    Jun 2011
    Posts
    25

    Re: Capture a window

    Quote Originally Posted by Eri523 View Post
    That said, I think I have no idea how experienced you actually are....)
    I'm a electronics engineer (retd) and have done a bit of assembler both on microcontroller and previously on DOS /Borland C++ for apps supporting my electronics designs and then on Borland Builder for windows apps. I now program mostly to support my other interests and share my efforts.
    BB is very similar syntactically to .net which makes me think .net is copied from the former Anyway it made the transition to VC++ less painful perhaps for me than someone raised on Win32. However I am now finding it harder when I need to use Win32 AFAIK there is no designer in VC++2010 and the help items are not especially helpful (at least the downloaded ones which I have to use as I have no permanent internet plus what I do have is very slow ~ 40Kbits... This site is invaluable for me as browsing the web mostly just isn't an option for me.
    Quote Originally Posted by Eri523 View Post
    It's ok insofar as it doesn't leak memory (and tolerating the unnecessary dynamic allocation).
    Yes, that was all I meant

  4. #19
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,583

    Re: Capture a window

    Quote Originally Posted by RogerD View Post
    I'm a electronics engineer (retd) and have done a bit of assembler both on microcontroller and previously on DOS /Borland C++ for apps supporting my electronics designs and then on Borland Builder for windows apps. [...]
    I really welcome it when delevelopers have this sort of low-level experience. It tends to sharpen their sense to understand things. Of course it's a long way to go from there to high-level concepts like .NET, but the key is being able to think in very simple building-blocks, and that's somewhat universal.

    BB is very similar syntactically to .net which makes me think .net is copied from the former [...]
    Except that syntax is a matter of language, while you seem to rather be referring to the runtime library design... When initially reading this, I thought that would just be a natural similarity due to the fact that they both encapsulate native Win32 GUI APIs (GDI+ in the case of .NET, specifically Windows Forms), but that was just some subjecive perception, so I did some additional reading up the topic. Actually, you appear to have been right on the spot:

    Quote Originally Posted by Wikipedia
    .NET is modeled after VCL, since one of the main architects of the first Delphi versions, Anders Hejlsberg, went to Microsoft and was one of the main architects of .NET there.
    (From http://en.wikipedia.org/wiki/Visual_Component_Library)

    [...] Anyway it made the transition to VC++ less painful perhaps for me than someone raised on Win32. However I am now finding it harder when I need to use Win32 AFAIK there is no designer in VC++2010 and the help items are not especially helpful [...]
    VC++ isn't a language, it's an IDE/compiler package, and the code we're discussing here for the most part isn't even "the real" (i.e. native) C++, it's C++/CLI, which in fact is a distinct lanquage, despite its similar name and syntax.

    Apparently you're using the VC++ Express edition. Visual Studio (which includes VC++) Professional edition and upward does feature a "designer" for native C++, though that's not directly Win32-based, it rather is based on MFC, which is another wrapper around Win32 APIs. The Pro version is not quite cheap, though...
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

Page 2 of 2 FirstFirst 12

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center