Thread: Limitations on Win32 API functions

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    610

    Limitations on Win32 API functions

    Hi friends, completely new on the Win32 API programming. I've learned two functions and their use in C [WndProc() & WinMain()]. I believe that one develop in this environment if they need to write programs which will have windows, dialog boxes, buttons, i/o (mouse, keyboard, etc). My question is, can i use some of the API functions in my own development tools/environment? I'm busy learning learning to write programs using QUEST (a Computer Based Training tool) which has it's own frame windows where one can insert/draw objects (pictures/boxes/etc). My first task is to draw a line using a mouse, or a shape. So there only solution i have in my mind is to use MoveToEx(), and LineTo() functions to draw markers and use the WinAPI functions to handle mouse or window messages.

    ... Usually, one has to first define WndProc() function to handle messages and then use WinMain() to create a window. In my case, there's no need to create a new window in the WinMain() function, QUEST has a function GetFrameWindow() which return a handle (HWND). Can i use the WinMain() function but eliminate all the code which creates a new windows, perhaps leave the following lines...

    Code:
    ShowWindow(hWnd,iCmdShow);
    UpdateWindow(hWnd);
    while (GetMessage(&msg,NULL,0,0))
    {
         TranslateMessage(&msg);
         DispatchMessage(&msg);
    }

  2. #2
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    CreateWindow() is what actually creates the window. ShowWindow() displays it. that while loop is the message loop that actually handles displatching the messages to the window procedure (WindProc) for the window you specify. In yoru case you are specifying NULL which means the window for the callign thread. If you want ot manipulate the window that is already created by the application, you need to retrieve a handle to that window, and use that handle in the API calls.

  3. #3
    Registered User
    Join Date
    Apr 2008
    Posts
    610
    Quote Originally Posted by abachler View Post
    CreateWindow() is what actually creates the window. ShowWindow() displays it. that while loop is the message loop that actually handles displatching the messages to the window procedure (WindProc) for the window you specify. In yoru case you are specifying NULL which means the window for the callign thread. If you want ot manipulate the window that is already created by the application, you need to retrieve a handle to that window, and use that handle in the API calls.
    That's exactly what i though Abachler. There's is a function GetFrameHandle() which returns HWND, meaning i can then use it in WinMain()... But then my concern is the function ShowWindow(). When i run QUEST (the tool am developing in) it automatically runs the windows/frames anyway... Someone said i need to override or replace the WndProc() function with the one QUEST uses (apparently tools which have their on windows/frames should have their own Windows Procedure function to run frames..?). Topic under "Subclassing using SetWindowLong()....

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Yes, it's possible to specify a new WindowProc using SetWindowLong. It's called subclassing.
    But what is need of such a thing? Is there some behavior you need to override?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Registered User
    Join Date
    Apr 2008
    Posts
    610
    Quote Originally Posted by Elysia View Post
    Yes, it's possible to specify a new WindowProc using SetWindowLong. It's called subclassing.
    But what is need of such a thing? Is there some behavior you need to override?
    I need to have control over my frames (draw objects, animate them, listen to messages, etc). But this has to be done on existing frame windows (no need to CreateWindow() in WinMain() )... QUEST tool i'm using uses its own frames

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I see. In that case, you can specify your own WindowProc using SetWindowLong. It will returns the previous WindowProc function, so you can also use a function pointer and call the old windowproc for any messages your own function doesn't handle.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Domain for Win32 API
    By maxorator in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 10-28-2006, 10:16 AM
  2. Replies: 7
    Last Post: 09-18-2005, 08:11 PM
  3. Win32 API or Win32 SDK?
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 07-20-2005, 03:26 PM
  4. Classes and Win32 API, and another Question
    By philvaira in forum Windows Programming
    Replies: 10
    Last Post: 04-10-2004, 07:21 PM
  5. pthread api vs win32 thread api
    By Unregistered in forum Windows Programming
    Replies: 1
    Last Post: 11-20-2001, 08:55 AM