November 28, 2014
Hot Topics:

Windows API Tutorial - Part Two

  • November 19, 2002
  • By Karl Moore
  • Send Email »
  • More Articles »

Fancy a cunning quickie? Hey, who doesn't...

  • Create a new VB project
  • Lookup and declare the following in the form:
Private Declare Function PaintDesktop _        Lib "user32" _        (ByVal hdc As Long) As Long

I decided to put this behind a form just to show you it can be done. However when you do declare API calls like this, they have to start with the 'private' keyword and can only be called by that one form.

  • On your Form, add a Command Button
  • Place the following code behind the button:
PaintDesktop Form1.hdc

Here, our API call is asking for hdc. First off, just remember that any argument that starts with h is a handle, a pointer of some kind.

We've already encountered hWnd, which is the handle of a window even though a 'window' can be anything from a form to a control.

Now the dc bit of hdc stands for 'device context' and is, in effect, a pointer to the 'graphical side of stuff'. So whereas hWnd could be a pointer to a form (or rather, a window), hdc is a pointer to the potentially graphical part of the form. Controls such as the PictureBox also have a hdc property.

And as we're talking to user32.dll in this call that's the user interface part of the Win32 API, remember? you could guess we're doing something slightly visual.

So in this code, we're simple passing the PaintDesktop function your form's graphical pointer, hdc. And this function uses it to... to do what?

I'm not telling, you're going to have to find out yourself but it's very cool and usually only used by desktop replacement programs.

Note: A download of the PaintDesktop project is available here.





Page 5 of 9



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Sitemap | Contact Us

Rocket Fuel