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

Thread: Drawing an icon

  1. #1
    Join Date
    Feb 2011
    Location
    UK
    Posts
    73

    Drawing an icon

    Hi, I know that:

    //here im creating a handle to an icon...

    HICON hIcon;

    //here im loading the icon into to the icon variable...

    hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));

    //here im creating a handle to a device context..

    HDC handleDeviceContext;

    From this point onwards could you explain to me what exactly is going on I know how to use these, and have a fair idea of whats happening, but i want to hear it from you people

    PAINTSTRUCT PaintSt;

    handleDeviceContext = BeginPaint(hWnd, &PaintSt);

    DrawIcon(handleDeviceContext, X, Y, hIcon);

    EndPaint(hWnd, &PaintSt);

  2. #2
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,244

    Re: Drawing an icon

    PAINTSTRUCT PaintSt;
    handleDeviceContext = BeginPaint(hWnd, &PaintSt);
    DrawIcon(handleDeviceContext, X, Y, hIcon);
    EndPaint(hWnd, &PaintSt);

    // Is something unclear in the above links?
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  3. #3
    Join Date
    Feb 2011
    Location
    UK
    Posts
    73

    Re: Drawing an icon

    Ok, so...

    //here we're making a structure which holds information about how we are gonna paint in the client area...

    PAINTSTRUCT PaintSt;

    //here we are calling the beginpaint function and passing its return value to the HDC variable. By calling this function im not too sure of what we're doing and why we pass its return value.

    handleDeviceContext = BeginPaint(hWnd, &PaintSt);

    //here we are drawing the icon on scren...

    DrawIcon(handleDeviceContext, X, Y, hIcon);

    //This function is called at the end of painting (not exactly sure why we have to tho)

    EndPaint(hWnd, &PaintSt);

  4. #4
    Join Date
    Feb 2011
    Location
    UK
    Posts
    73

    Re: Drawing an icon

    ?

  5. #5
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,244

    Re: Drawing an icon

    BeginPaint returns a...
    [MSDN Library]
    ...handle to a display device context for the specified window...
    ... which is necessary for GDI functions that perform painting or drawing.
    What other stuff does BeginPaint, as well as any other WinAPI function?
    You can find out by paying attention to its whole documentation including parameters, return value, remarks, examples, and see also sections.

    DrawIcon is a GDI function which requires a handle to a device context. In our case, this handle has been returned by BeginPaint.

    EndPaint is called because...
    [MSDN Library]
    ...this function is required for each call to the BeginPaint function after the painting is complete.
    What is a device context? Which are painting and drawing functions? How to draw in the client area?...
    See MDSN Library, MSDN Library, MSDN Library,...


    // Please document yourself, as much as possible, before posting quiz-like questions in discussion forums!
    // Windows programming is quite difficult to learn if you don't know its basics.
    // Beside MSDN Library, I would like to recommend books like:



    [ Moved thread ]
    Last edited by ovidiucucu; June 14th, 2011 at 02:25 AM. Reason: typos
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured