23-05-2012, 02:55 PM
WINDOWS PROGRAMMING
WINDOWS PROGRAMMING.doc (Size: 54.5 KB / Downloads: 35)
1) Using the concept of handles, show difference between HINSTANCE, HWND and HANDLE, with example.
Ans: - Difference between HINSTANCE, HWND, HANDLE are:-
• hInstance: - This is the “instance handle” for running application. Windows create this unique id number when the application starts. If you start more than one instance of a program, each will have a unique instance handle. Physically, hInstance is the memory handle to the application’s default data segment. This low-level meaning is not important to you as a window programmer; we can consider hInstance to be an arbitrary number that identifies the running application’s data.
For Example: - int PASCAL WinMain (HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpszCmdLine, int nCmdshow)
• HWND: -The variable hWnd is declared to be a HWND, a handle to a window. The function CreateWindow () creates the program’s window. CreateWindow () returns a unique ID value for the window created, which is actually an unsigned integer. We will call it a HWND to make the meaning clear. The variable hWnd starts with a letter”h” to tag the variable type as a handle.
For Example: - HWND hWnd;
hWnd = CreateWindow (“BUTTON”, “Hello World”, BS_PUSHBUTTON,
10, 10, 100, 100, NULL, NULL, hInstance, NULL);
• HANDLE: -The one unusual data type in the list of variables name prefixes is HANDLE. Handles are unsigned integers that Windows uses internally to keep track of objects in memory. We will use handles frequently while programming in windows to keep track of various objects in memory.
For example: - Every window on the screen has a unique window handle. Handles are also used to keep track of running applications, of allocated memory blocks, and a host of other-objects.