|
发表于 2014-8-14 13:31:14
|
显示全部楼层
#include "stdafx.h"
#include "resource.h"
HINSTANCE g_hInst;
void OnPaint(HWND hWnd)
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd,&ps);
//HBITMAP hBitmap = (HBITMAP)LoadImage(NULL,"./Picture.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
HBITMAP hBitmap = LoadBitmap(g_hInst,(LPCTSTR)IDB_BITMAP1);
BITMAP bm;
//获取图片信息
GetObject(hBitmap,sizeof(bm),&bm);
HDC dc = CreateCompatibleDC(hdc);
SelectObject(dc,hBitmap);
MoveWindow(hWnd,0,0,bm.bmWidth,bm.bmHeight,FALSE);
BitBlt(hdc,0,0,bm.bmWidth,bm.bmHeight,dc,0,0,SRCCOPY);
//
RECT rect;
GetClientRect(hWnd,&rect);
Rectangle(hdc,100,100,300,500);
LineTo(hdc,100,100);
MoveToEx(hdc,300,500,NULL);
EndPaint(hWnd,&ps);
}
void OnInitDialog(HWND hwnd)
{
//HICON hIcon = (HICON)LoadImage(NULL,"./1.ico",IMAGE_ICON,0,0,LR_LOADFROMFILE);
HICON hIcon = LoadIcon(g_hInst,(LPCTSTR)IDI_ICON1);
::SendMessage(hwnd, WM_SETICON, FALSE, (LPARAM)hIcon);
SetWindowText(hwnd,"绘图测试");
}
void OnMouseMove(HWND hwnd)
{
HCURSOR hCursor = LoadCursor(g_hInst,(LPCTSTR)IDC_CURSOR1);
SetCursor(hCursor);
}
BOOL CALLBACK DialogProc(
HWND hwndDlg,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{
switch(uMsg) {
case WM_PAINT:
OnPaint(hwndDlg);
return TRUE;
case WM_INITDIALOG:
OnInitDialog(hwndDlg);
return TRUE;
case WM_MOUSEMOVE:
OnMouseMove(hwndDlg);
return TRUE;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDCANCEL:
EndDialog(hwndDlg,IDCANCEL);
return TRUE;
case IDOK:
return TRUE;
} |
|