Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Limitations on Win32 API functions

Sonx_hvn7Sonx_hvn7 Member Posts: 54
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 modules and frames 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. My confusion is, most articles i read always have the two functions WndProc()to handle messages and WinMain() to create the window and run the application. In my case, i do not need to create a new windows since am using QUEST frames... Q. Is it possible to use WinProc without WinMain()?

Comments

  • LundinLundin Member Posts: 3,711
    You can't use WindProc unless the particular window is asociated with it. In case of the main window, it is created from WinMain(), so using the WindProc might be tricky without the WinMain.

    It is possible to use the Windows API if the IDE allows it. I don't know about your particular tool, but RAD-tools such as Borland Builder and Visual Studio allows you to easily use the Win API manually if you wish. The tricky part is usually to get a handle to the window (HWND). If the tool supports that, it should be easy enough to use the API. If not, you can still fetch the HWND through API functions such as EnumWindows(), but that is a bit trickier and perhaps not a beginner task.
  • Sonx_hvn7Sonx_hvn7 Member Posts: 54
    : You can't use WindProc unless the particular window is asociated
    : with it. In case of the main window, it is created from WinMain(),
    : so using the WindProc might be tricky without the WinMain.
    :
    : It is possible to use the Windows API if the IDE allows it. I don't
    : know about your particular tool, but RAD-tools such as Borland
    : Builder and Visual Studio allows you to easily use the Win API
    : manually if you wish. The tricky part is usually to get a handle to
    : the window (HWND). If the tool supports that, it should be easy
    : enough to use the API. If not, you can still fetch the HWND through
    : API functions such as EnumWindows(), but that is a bit trickier and
    : perhaps not a beginner task.

    Hi Lundin, i found these two lines under QUEST help file

    HWND hFrameWindow;
    hFrameWindow = GetFrameWindow();

    The function returns a handle to the current Quest window. Now if i use the WinMain() function but eliminate all the code which creates a new windows, perhaps leave the following lines...

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

    ...COULD THIS WORK?

    Thanks for your help!
  • LundinLundin Member Posts: 3,711
    Why do you want to do that? Doesn't the tool create the window for you?
  • Sonx_hvn7Sonx_hvn7 Member Posts: 54
    : Why do you want to do that? Doesn't the tool create the window for
    : you?

    Yes it does, but that's where i have problems... In Quest, you create modules where you may insert/draw frame(s). You may then insert objects to the frame and write a C code (in a code section) to manipulate objects (such as buttons, pictures, text etc) in a frame. CTRL+D compiles and runs the application frame with no external use of show()/displayframe() functions... I need to extend these functionalities by allowing more user interactions such as drawing lines, moving objects, button clicks to invoke some actions, etc. This is where i need use of Win API functions...

    I'm not sure if API function ShowWindow()can be use to show QUEST frames so that i can have control over these frames, and continue using other API functions. But then the function GetFrameWindow() returns a handle to the current frame. Which seems possible... Not sure if am clear enough
  • LundinLundin Member Posts: 3,711
    Ok. What you want to do isn't to replace the WindProc of your tool, but rather to add extended functionality to it. There is a method in the Win API called "subclassing" that allows you to add additional, custom functionality to an already existing window. When you subclass, you basically replace the WindProc with a new procedure which is called instead of the old one. But the old one still exists in the system, and for cases where you don't want to change the functionality, you can call the old one instead.

    Look for the topic subclassing and the function SetWindowLong().
Sign In or Register to comment.