?? thebitmap.cpp
字號:
#include <Windows.h>
#include "TheBitMap.h"
const struct MessageDo myMSG[]={
WM_CREATE,DoCreate,
WM_PAINT,DoPaint,
WM_DESTROY,DoDestroy,
};
const TCHAR winName[]=TEXT("bitmap");
BYTE bitData[48*48*3];
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPWSTR lpCmdLine,int nShowCmd)
{
MSG msg;
HWND hWnd = InitApp(hInstance,lpCmdLine,nShowCmd);
if(!IsWindow(hWnd)) return 0;
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return TermApp(hInstance,msg.wParam);
}
HWND InitApp(HINSTANCE hInstance,LPWSTR lpCmdLine,int nShowCmd)
{
WNDCLASS wc;
HWND hWnd;
#if defined(WIN32_PLATFORM_PSPC)
hWnd=FindWindow(winName,NULL);
if(hWnd)
{
SetForegroundWindow((HWND)(((DWORD)hWnd)|0x10));
return 0;
}
#endif
wc.style=0;
wc.cbClsExtra=0;
wc.cbWndExtra=0;
wc.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wc.hCursor=LoadCursor(NULL,IDC_ARROW);
wc.hIcon=NULL;
wc.hInstance=hInstance;
wc.lpfnWndProc=MainWndProc;
wc.lpszClassName=winName;
wc.lpszMenuName=NULL;
if(RegisterClass(&wc)==0) return 0;
hWnd=CreateWindow(winName,
TEXT("位圖處理示例"),
WS_BORDER|WS_CAPTION|WS_SYSMENU,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
if(!IsWindow(hWnd)) return 0;
ShowWindow(hWnd,nShowCmd);
UpdateWindow(hWnd);
return hWnd;
}
int TermApp(HINSTANCE hInstance,int nDefRec)
{
return nDefRec;
}
LRESULT CALLBACK MainWndProc(HWND hWnd,UINT wMsg,WPARAM wParam,LPARAM lParam)
{
for(int i=0;i<dim(myMSG);i++)
{
if(wMsg==myMSG[i].code)
{
return (*myMSG[i].Fxn)(hWnd,wMsg,wParam,lParam);
}
}
return DefWindowProc(hWnd,wMsg,wParam,lParam);
}
LRESULT DoCreate(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
memset(bitData,0x7f,sizeof(bitData));
return 0;
}
LRESULT DoPaint(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
HBITMAP htp;
PAINTSTRUCT ps;
RECT rect;
HDC hdc,hdcMemo;
GetClientRect(hWnd,&rect);
//獲取當前圖形顯示設備對象
hdc = BeginPaint(hWnd,&ps);
//創建一個虛擬設備顯示對像
hdcMemo=CreateCompatibleDC(hdc);
//建立設備相關位圖對像
//兩者都是創建設備相關位圖,返回hbitmap位圖對象
//不通之處在于,createbitmap返回根據位圖格式設定的位圖對象
//createcompatiblebitmap返回的是當前設備色置相關的位圖對象
//htp=CreateBitmap(48,48,1,24,bitData);
htp=CreateCompatibleBitmap(hdc,40,40);
DrawText(hdc,TEXT("位圖示例"),-1,&rect,DT_CENTER);
//將設備相關位圖對象設進虛擬設備顯示對象
SelectObject(hdcMemo,htp);
//轉換虛擬設備顯示對象到當前設備顯示
BitBlt(hdc,20,20,48,48,hdcMemo,0,0,SRCCOPY);
//清理
DeleteDC(hdcMemo);
EndPaint(hWnd,&ps);
return 0;
}
LRESULT DoDestroy(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
PostQuitMessage(0);
return 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -