Thread: WINAPI: Meaning of HDC ?

  1. #1
    Registered User
    Join Date
    Dec 2001

    WINAPI: Meaning of HDC ?

    I'm at the very beginning of programming for Windows.

    int a=1; // global integer
    long WINAPI WndProc(msg){
    HDC hdc; /* What is the exact meaning of this
    line? */
    case WM_PAINT:
    RECT rect;
    DrawText("Hello World");
    default: ...}}

    Q: Why do I always have to write RECT, BeginPaint, EndPaint, HDC ? What are the exact meanings of these Instructions? All my books say HDC has something to do with a device context, and that it is necessary. How is a line like HDC hdc; translated into Machine Instructions (such simple lines like LW r1,1000(r0) will not be enough, am I right?) What about the portability of programs using HDC hdc?
    I've also trouble with the SetFocus function, it almost ever leads to a window that can't be closed (this problem occurs in other contexts too. Sometimes I think GetMessage doesn't receive WM_CLOSE Messages though it had to.)
    If you could answer any of these questions I'd be grateful because it would improve my understanding of WINAPI programming (Those thousands of classes and functions found in the Windows-libraries are very confusing, I doubt there is anyone on earth who can say: "I'm a perfect WINAPI-programmer.")
    ******************** *************************

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    In dos you could directly access the screen memory to plot pixels etc. In windows you cannot do that. In windows we have device contexts. You can imagine a device context as a block of memory that will hold the image of your client area. You draw to that device context and that doesn't affect anything already on the screen. When your "canvas" is finished you pass the dc to windows for painting on the screen. Look for more information at msdn or better still buy Programming windows by charles petzold. This book is a must have for win32 api.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :-

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. My progress.. thnx to Cprogramming forumites
    By csonx_p in forum Windows Programming
    Replies: 6
    Last Post: 05-21-2008, 01:17 AM
  2. Avoiding Global variables
    By csonx_p in forum Windows Programming
    Replies: 32
    Last Post: 05-19-2008, 12:17 AM
  3. My first "real" windows app
    By JoshR in forum Windows Programming
    Replies: 2
    Last Post: 07-28-2005, 07:40 AM
  4. destroywindow() problem
    By algi in forum Windows Programming
    Replies: 6
    Last Post: 03-27-2005, 11:40 PM
  5. opengl program as win API menu item
    By SAMSAM in forum Game Programming
    Replies: 1
    Last Post: 03-03-2003, 07:48 PM