API |
MFC |
C++ |
C |
Programming Windows API
Copying the Screen with Bitmaps Example
//Copying a bitmap using the StretchBlt function
#include <windows.h>
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
PWSTR lpCmdLine, int nCmdShow)
{
MSG msg ;
WNDCLASS wc = {0};
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpszClassName = TEXT("Screen copy");
wc.hInstance = hInstance;
wc.hbrBackground = GetSysColorBrush(COLOR_BTNFACE);
wc.lpfnWndProc = WndProc;
wc.hCursor = LoadCursor(0, IDC_ARROW);
RegisterClass(&wc);
CreateWindow(wc.lpszClassName, TEXT("screen copy"),WS_OVERLAPPEDWINDOW | WS_VISIBLE,100, 100, 390, 350, NULL, NULL, hInstance, NULL);
while( GetMessage(&msg, NULL, 0, 0)) {
DispatchMessage(&msg);
}
return (int) msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg,
WPARAM wParam, LPARAM lParam)
{
static int maxX;
static int maxY;
HBITMAP hbit;
switch(msg)
{
case WM_LBUTTONDOWN:
maxX=GetSystemMetrics(SM_CXSCREEN);
maxY=GetSystemMetrics(SM_CYSCREEN);
int width;
int height;
HDC mhdc;
HDC hdc;
RECT rect;
;
if(GetWindowRect(hwnd, &rect))
{
width = rect.right - rect.left;
height = rect.bottom - rect.top;
}
mhdc = GetWindowDC(NULL);//creates a main windows device context
hdc=GetDC(hwnd);//creates application window device context
hbit=CreateCompatibleBitmap(mhdc,maxX,maxY);//create screen device context compatible bitmap
StretchBlt(hdc, 0, 0, width, height,mhdc,0,0,maxX,maxY,MERGECOPY);//copies main window bitmap to application screen
ReleaseDC(hwnd,mhdc);
ReleaseDC(hwnd,hdc);
break;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, msg, wParam, lParam);
}
Creating a Simple Window |
Common Elements |
Data Types and Character Sets |
The Device Context |
Graphics Device Interface |
Displaying Text |
Displaying Graphics |
Mapping Modes |
Keyboard Input |
Working with the Mouse |
Menus |
Child Windows |
ScrollBar Control |
The Dialog Box |
Windows Message Box |
Common Dialog Box |
Bitmaps |
Common Controls |
Creating a Toolbar |
Multiple Document Interface |
Timers |
DLL’s |
Creating Custom Controls |
Owner Drawn Controls |
API Hooking and DLL Injection |
File Management Functions |
String Manipulation |
System Information Functions |