C Board  

Go Back   C Board > Platform Specific Boards > Windows Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 04-08-2008, 01:36 AM   #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);
}
csonx_p is offline   Reply With Quote
Old 04-08-2008, 08:20 AM   #2
Malum in se
 
abachler's Avatar
 
Join Date: Apr 2007
Posts: 3,188
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.
__________________
Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.
abachler is offline   Reply With Quote
Old 04-09-2008, 01:09 AM   #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()....
csonx_p is offline   Reply With Quote
Old 04-09-2008, 03:57 AM   #4
Mysterious C++ User
 
Elysia's Avatar
 
Join Date: Oct 2007
Posts: 14,785
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?
__________________
Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System
I dedicated my life to helping others. This is only a small sample of what they said:
"Thanks Elysia. You're a programming master! How the hell do you know every thing?"
Quoted... at least once.
Quote:
Originally Posted by cpjust
If C++ is 2 steps forward from C, then I'd say Java is 1 step forward and 2 steps back.
Elysia is offline   Reply With Quote
Old 04-09-2008, 04:06 AM   #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
csonx_p is offline   Reply With Quote
Old 04-09-2008, 04:09 AM   #6
Mysterious C++ User
 
Elysia's Avatar
 
Join Date: Oct 2007
Posts: 14,785
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.
__________________
Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System
I dedicated my life to helping others. This is only a small sample of what they said:
"Thanks Elysia. You're a programming master! How the hell do you know every thing?"
Quoted... at least once.
Quote:
Originally Posted by cpjust
If C++ is 2 steps forward from C, then I'd say Java is 1 step forward and 2 steps back.
Elysia is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Domain for Win32 API maxorator General Discussions 0 10-28-2006 10:16 AM
Will win32 API programming knowledge in C still aplly to MS Vista? mr.v. Windows Programming 7 09-18-2005 08:11 PM
Win32 API or Win32 SDK? jverkoey General Discussions 2 07-20-2005 03:26 PM
Classes and Win32 API, and another Question philvaira Windows Programming 10 04-10-2004 07:21 PM
pthread api vs win32 thread api Unregistered Windows Programming 1 11-20-2001 08:55 AM


All times are GMT -6. The time now is 01:14 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

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