// bmp_1.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include "resource.h"
//窗口初始化工作
void InithInstance(HINSTANCE hInstance,int nCmdShow);
//实现窗口类的定义和注册
void MyRegisterClass(HINSTANCE hInstance,int nCmdShow);
LRESULT CALLBACK WinProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam);
TCHAR className[] = L"my windows";
TCHAR titleName[] = L"softeem_windows";
HBITMAP hbmp;
HDC hdcmem;
int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
hbmp = LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_BITMAP2));
InithInstance(hInstance,nCmdShow);
MSG msg;
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
//完成窗口初始化工作
void InithInstance(HINSTANCE hInstance,int nCmdShow)
{
MyRegisterClass(hInstance,nCmdShow);
HWND hWnd = CreateWindow(className,titleName,
WS_SYSMENU|WS_CAPTION|WS_MINIMIZEBOX|WS_MAXIMIZEBOX,
100,50,600,450,
0,0,hInstance,0);
ShowWindow(hWnd,nCmdShow);
UpdateWindow(hWnd);
}
void MyRegisterClass(HINSTANCE hInstance,int nCmdShow)
{
WNDCLASS wndClass;
wndClass.style = 0;
wndClass.lpfnWndProc =WinProc;
wndClass.cbClsExtra = 0;
wndClass.cbWndExtra = 0;
wndClass.hInstance = hInstance;
wndClass.hIcon = 0;
wndClass.hCursor = 0;
wndClass.hbrBackground = (struct HBRUSH__ *)GetStockObject(WHITE_BRUSH);
wndClass.lpszMenuName = 0;
wndClass.lpszClassName = className;
RegisterClass(&wndClass);
}
LRESULT CALLBACK WinProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
{
switch (message)
{
case WM_CREATE:
{
HDC hdc = GetDC(hWnd);
hdcmem = CreateCompatibleDC(hdc);
SelectObject(hdcmem,hbmp);
ReleaseDC(hWnd,hdc);
}
break;
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd,&ps);
HDC hdcmem1 = CreateCompatibleDC(hdc);
HBITMAP hbmp1 = CreateCompatibleBitmap(hdc,600,450);
SelectObject(hdcmem1,hbmp1);
BitBlt(hdcmem1,10,10,200,200,hdcmem,200,100,SRCCOPY);
BitBlt(hdc,10,10,200,200,hdcmem1,0,0,SRCCOPY);
DeleteObject(hbmp1);
DeleteDC(hdcmem1);
EndPaint(hWnd,&ps);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd,message,wParam,lParam);
}
}