Questions about WINAPI

This is a discussion on Questions about WINAPI within the Windows Programming forums, part of the Platform Specific Boards category; Hi! About a week ago I started to study WINAPI functions and I'm a little confused about a lot of ...

  1. #1
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669

    Question Questions about WINAPI

    Hi!

    About a week ago I started to study WINAPI functions and I'm a little confused about a lot of things.

    The first one is that I do not know what HWND, WPARAM and LPARAM returns and what is their purpose?

    And the second one is what this function "LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)" returns?
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  2. #2
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,230
    >>The first one is that I do not know what HWND, WPARAM and LPARAM returns and what is their purpose? <<

    They don't "return" anything. They're just variable types like int, char, double, etc.

    HWND = handle to your window
    WPARAM & LPARAM = when a message is sent there are generally 4 pieces to it: the high-order bytes of the WPARAM, the low-order bytes of the WPARAM, the high-order of the LPARAM and the low-order of the LPARAM. They're just parts of a windows message.

    >>LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)" <<

    It returns different things based on what happens. It's the part of your program that takes action when messages occur.

  3. #3
    Registered User Invincible's Avatar
    Join Date
    Feb 2002
    Posts
    210
    I'm right here with you GaPe. The API is confusing to say the least. It's like trying to learn how to program all over again. There are some good tutorials out there, but they're all pretty confusing at the same time. Ken, I'm not sure you haven't told us anything we don't already know. Well, maybe. But the biggest questions in my mind are, how do I use these new variable types, what the hell is a CALLBACK, and how does windows process messages? I've spent days trying to figure out how to get my app to accept tabbing between edit controls and all it does is beep at me! This is probably because I don't really understand what's going on during the message process.
    "The mind, like a parachute, only functions when open."

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    First up you create a window or dialog with CreateWindow() Ex() ect.

    Messages are sent from the OS (Windows) to your app. You recieve them with a loop like
    Code:
    while(GetMessage(&msg, NULL , 0, 0))	//get all messages associated with the current thread
    {
        TranslateMessage(&msg) ;
        DispatchMessage(&msg) ;
    }
    Send them to a callback (one for a dialog in most cases)
    A callback has a complicated (nested) switch statement.
    Code:
    switch	(message)
    {
    case WM_CREATE:
    //do stuff when window created
    break;
    case WM_DESTROY:
    //do stuff when window closed
    break:
    case WM_COMMAND:
    //a control has been pressed, get its ID number and switch that
    idControl=GET_WM_COMMAND_ID(wParam,lParam) ;
         switch(idControl)
         {
         case IDM_FILE:
         //user has presses menu item 'File'
         //do stuff for 'file'
         break;
    //ect
         }//end of command switch
    default:
    //any message you do not want to process, let windows do default stuff with it
    DefWindowProc(hWnd, message, wParam, lParam); 
    break;
    
    }//end of message switch
    All contols / dialogs have an ID number (an int index for the control) and a HWND (handle to the window). These data types are info on how to comunicate with the control. All controls are considered children of the dialog they are on. All dialogs are considered children of the main window.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  5. #5
    Registered User
    Join Date
    Feb 2002
    Posts
    4
    HWND is nothing more than a long integer identifiying a window that you created. Windows will supply this for you.

    WPARAM and LPARAM are parameters part of the MSG structure

    Code:
    struct typedef tagMSG {
    HWND hwnd; // Here is a handle to the window getting messages
    UINT message; // The type of message
    WPARAM wparam; // More information about message
    LPARAM lparam;  // More information about message
    DWORD time;
    POINT pt;
    } MSG;
    WPARAM and LPARAM are just more information about the message if you need it.

    Understanding Windows programming requires a good knowledge of how windows deals with applications. You need to understand how messages are passed to your application(program), and how you can pass messages back to windows.

    http://msdn.microsoft.com - Microsoft Developer Network
    This site has everything about windows, including understanding windows programming. Use this site often as it will help you along.

  6. #6
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    From WINDEF.h:

    #define CALLBACK __stdcall

    ie 'CALLBACK' is a placeholder for stdcall calling convention.

    I have no idea where the others are declared but LRESULT is probably #defined as LONG (at a guess), likewise LPARAM and WPARAM. All 3 are currently 32bit; the reason for the strange defines is for 16bit (backward compatible) and 64bit (when it comes) - apparently it makes it more flexible: you write your code one way and it should theoretically compile under different circumstances. That's why you could write eg.

    LRESULT __stdcall WndProc(blah...)

    and probably get away with it, but would be screwed if ms decided to change it.

    Anyway, check the header files, there's a lot of interesting (and boring) info to be found in them.

    Good luck.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  7. #7
    Registered User Invincible's Avatar
    Join Date
    Feb 2002
    Posts
    210

    Thumbs down

    http://msdn.microsoft.com - Microsoft Developer Network
    MSDN may as well be written in greek. It assumes you already know the structure of the API. Either that, or it tells you to buy a damn book. It's funny, several function descriptions talk about pointers to the message struct. But they all fail to mention that it's a predefined stucture. Rarely have I ever learned anything useful from reading this library. Also, sometimes it seems HWND is a struct too, when is this true? I'm confused. Learning Win32 is painfully frustrating.

    {beats self in head with stick}
    Last edited by Invincible; 02-26-2002 at 12:26 AM.
    "The mind, like a parachute, only functions when open."

  8. #8
    Unregistered
    Guest
    As far as I know HWND is a memory address.

    Its harder to get into as it is more event driven than structured.

    Most begining programs allow just one path thru the code. In WIN32, as in client-server apps, you must let the OS and the user generate events and then handle them.

    Once you understand a callback and a message loop you will just copy them from project to project (in most cases) and modify the callback to suit.

    Look at the thread
    http://www.cprogramming.com/cboard/s...threadid=10866
    down load the 'graphfix.zip' and have a look inside an almost working WIN32 app. Pretty simple once you get past the M$ techno-babble.

  9. #9
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    That was me


    Note to self: Stop trying to kill all cookies, some have a purpose. Some taste good and not all are tracking where I go / what I do.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 10
    Last Post: 11-22-2007, 11:13 PM
  2. A very long list of questions... maybe to long...
    By Ravens'sWrath in forum C Programming
    Replies: 16
    Last Post: 05-16-2007, 05:36 AM
  3. Several Questions, main one is about protected memory
    By Tron 9000 in forum C Programming
    Replies: 3
    Last Post: 06-02-2005, 07:42 AM
  4. Trivial questions - what to do?
    By Aerie in forum A Brief History of Cprogramming.com
    Replies: 23
    Last Post: 12-26-2004, 08:44 AM
  5. 2 questions: WINAPI? lpcmdline?
    By Cheeze-It in forum Windows Programming
    Replies: 2
    Last Post: 12-05-2002, 04:44 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21