CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Threaded View

  1. #1
    Join Date
    Jun 2010

    [RESOLVED] How to add a cursor resource to my app (VC++ 2010 Express)

    Well, maybe this would be easy if I had the Pro Edition with the integrated resource editor, but unfortunately I only have the Express Edition and tried to add a cursor resource from a .cur file to my app.

    What I couldn't get to work:
    • Add the .cur file as a file resource to Form1.resX (right click on Form1.resX in the project explorer etc.) and try to construct the Cursor object using the Cursor(Type ^, String ^) constructor as described on MSDN. The resource option as described on the MSDN page for VB .NET and C# doesn't exist for cl. Maybe it could actually be done that way, but then I couldn't figure out how to obtain the correct Type ^ argument for the constructor.
    • Add a reference to the .cur file in the .rc file (by editing it manually), invoking the native LoadCursor() and trying the Cursor(IntPtr) constructor.

    If I don't mess up my memory now, both of these attempts resulted in the Cursor constructor failing and thus gcnew returning nullptr.

    I actually could construct the Cursor object from the .cur file on disk, but as the app consists only of a sole .exe file up to now, I didn't want to add the extra ballast of the .cur file.

    I finally resorted to convert the .cur file to a bunch of hex literals (hidden inside the macro in the code below) and construct the Cursor from a MemoryStream constructed from the array<unsigned char>:

    System::Void Form1::btnScreenPicker_MouseDown(System::Object^  sender, System::Windows::Forms::MouseEventArgs^  e)
      array<unsigned char> ^RawData = {PICKER_CURSOR_RAW_DATA};
      static_cast<Button ^>(sender)->Cursor =
        gcnew System::Windows::Forms::Cursor(gcnew IO::MemoryStream(RawData, false));
    It works, but I'm not happy with this solution. Is there really no way to do it that's more elegant/straightforward?

    TIA for any help.
    Last edited by Eri523; October 22nd, 2010 at 07:22 PM.
    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.

Tags for this Thread

Posting Permissions

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

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)