win API 프로그램에서 DrawImage를 쓸 수 있는 방법이 궁금합니다.
글쓴이: mydream / 작성시간: 토, 2016/12/03 - 7:37오후
#include <windows.h> #include <tchar.h> #include <Gdiplus.h> #pragma comment(lib, "gdiplus.lib") using namespace Gdiplus; LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { WNDCLASS wndCls; wndCls.cbClsExtra=wndCls.cbWndExtra=0; wndCls.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH); wndCls.hInstance=hInstance; wndCls.hCursor=LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW)); wndCls.hIcon=NULL; wndCls.lpszClassName=_T("test180 class"); wndCls.lpszMenuName=NULL; wndCls.lpfnWndProc=WndProc; wndCls.style=CS_HREDRAW | CS_VREDRAW; RegisterClass(&wndCls); HWND hwnd=CreateWindow(wndCls.lpszClassName, _T("test180 window"), WS_OVERLAPPEDWINDOW, 100, 100, 500, 500, NULL, NULL, hInstance, NULL); ShowWindow(hwnd, nShowCmd); //PostMessage(hwnd, WM_USER, 0, 0); MSG msg; while( GetMessage(&msg, NULL, 0, 0) ) { TranslateMessage(&msg); DispatchMessage(&msg); } return 0; } LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) { switch(message) { case WM_PAINT: { //HDC mainHdc=GetDC(hwnd); PAINTSTRUCT pst; HDC mainHdc=BeginPaint(hwnd, &pst); Graphics graphic(mainHdc); Image image1(L"grim.jpg"); graphic.DrawImage(&image1, 0, 0);//여기서 이미지가 제대로 화면에 출력되지 않는군요. 방법이 없을까요? TextOut(mainHdc, 0, 0, _T("download"), _tcslen(_T("download"))); EndPaint(hwnd, &pst); } return 0; case WM_DESTROY: PostQuitMessage(0); return 0; } return DefWindowProc(hwnd, message, wparam, lparam); }
Forums:
grim.jpg 경로를 확인해보세요.
돌려보진 않았지만 문제는 없는 코드로 보입니다.
grim.jpg의 경로를 확인해보세요.
확실하게 할려면 절대경로로 한번 시도해보세요.
처럼 말이죠..
/* How to Love Others */
while(GetDepth(Love) < Enough) DoLove();
댓글 달기