Bitmaps
Bitmap is a file format to store image pixels in terms of bits in a file. It is a 2D array of bits (4bit, 8 bit, 16bit, 24bit) to store a 2D image. A graphical application can use a bitmap in tool-bars, buttons, menus and many other places. Image editor applications can create, manipulate (scale, scroll, rotate, and paint), and store images as files on a disk. Win32 or Linux graphical subsystem reads these bits one by one and creates pixels in the screen. Thus the entire picture is formed in the screen.
LoadBitmap
The LoadBitmap function loads the input bitmap resource from a module's executable file and returns the handle. This function has been superseded by the generic LoadImage function.
HBITMAP LoadBitmap( HINSTANCE hInstance, /* handle to application instance */ LPCTSTR lpBitmapName /* address of bitmap resource name */ );
Parameters
- hInstance - A valid handle to the instance of the module executable file that contains the bitmap to be loaded.
- lpBitmapName - Pointer to a null-terminated input string that contains the name of the bitmap resource to be loaded. Alternate way to give this parameter is to provide the resource identifier in the low-order word and zero in the high-order word. MAKEINTRESOURCE macro can be used to create this id value.
Return Values
If the function succeeds, the return value is the handle to the specified bitmap. This handle to bitmap can be used further in various drawing/GDI functions. If the function fails, the return value is NULL.
Loading steps:
- Call LoadBitmap with the resource file string name
- Create a new device context which is compatible to current Window DC
- Select this bitmap to this newly created memory device context
- Copy bits from source of new device context to window device context
- Free bitmap resource using DeleteObject
- Free this new DC by calling DeleteDC
Source Code
Output
About our authors: Team EQA
Further readings
Where is WinMain() function in MFC application ?
MFC hides WinMain in its framework and includes source file on WinMain(). This explains how framework calls global CWinApp::Initinstance() from entry WinMain.
What is the utility of CWinApp class?
This is constructed during global C++ objects are constructed and is already available when Windows calls the WinMain function, which is supplied by the ...
Basic steps in Win32 GUI Application with source code.
Define a custom Window class structure, Register the class name, CreateWindow, Show windows and write message get and dispatch loop statements. Define the Window CallBack procedure and write the handlers.
What is a Window CallBack procedure and what is its utility?
DispatchMessage() is a API which indirectly triggers the Window CallBack procedure. Message structure members from this function are passed to the CallBack procedure. CallBack procedure should implement event handlers depending on the need of the application.
What are LPARAM and WPARAM in window proc function?
LPARAM and WPARAM are the two parameters in Window CallBack procedure. They signifies parameters of various events. They are used in handing individual events.
What are the basic steps of a typical MFC based application?
We need to write WinMain and need to follow all these in a Win32 application. However we need not to write much if we are writing an application with MFC ...
Questions index C Questions C++ Questions Win32 MFC COM/DCOM DLL Questions
Compilers & Editors
Download Visual Studio Download XCode Download Visual Studio Code Android studio install sdk Eclipse installer Best C compilers IDEs
Development system setup
Windows media creation tool MSDN subscription Ubuntu virtualbox
New updated posts
Why learn C? Draw on printer Memory leaks