winapi 문제 질문입니다.

zxasd9874의 이미지

공부하면서 거쳐가는 단계로 winapi를 한창 공부 중입니다.
WM_PAINT 파트를 진행 중인데요, 도저히 알 수 없는 문제가 생겨서 질문 올립니다.

코드를 짜는 목표는 카드 뒤집기 게임-흔히 아시는 2장의 카드를 뒤집어서 같은 그림이면 짝이 맞춰져서 뒤집어진 상태 그대로 있고 아니면 다시 뒷면이 보이는 그것-를 만드는 것이고 될 수 있으면 클래스를 나누어 작업하는 것입니다.
현재 코드 진척 상황은 LoadImage를 통하여 지정 경로에 있는 이미지를 가져오는 것까진 성공했고,
카드 정보를 담고 있는 구조체를 총 10개 만들어 정보를 초기화 한 다음 구조체 벡터에 담는 것 또한 성공했습니다.

그런데 구조체가 가지고 있는 정보인 카드의 넘버링과 좌표를 보내서 출력하도록 하려는데 그게 제대로 이루어지지 않고 있네요.
우선 정보가 필요한 코드 파트를 가져오자면 다음과 같습니다.

메인 함수

struct CardInformation
{
	bool IsRevealed;	//false이면 카드가 뒤집어져 있는 상태
	int CardNumbering;	//카드 그림 넘버링
	int XLocation;
	int YLocation;
};
 
...
 
LRESULT CALLBACK WndProc(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam)
{
	static HDC hdc, MemDC;
	static PAINTSTRUCT ps;
	static BitMapManager NewBitMapManager(hdc, g_hInst);
	static std::vector <CardInformation> CardVector = std::vector <CardInformation> ();	//카드 정보 구조체를 담을 벡터
	static int NumberOfRevealed = 0;	//맞춰진 짝의 개수
 
switch (iMessage)
	{
	...
 
	case WM_PAINT:
		hdc = BeginPaint(hWnd, &ps);
		NewBitMapManager.PrintBitMap(hdc, 0, CARD_LOCATION_FIRST_X, CARD_LOCATION_FIRST_Y);
		NewBitMapManager.PrintBitMap(hdc, 2, 50, 450);
		NewBitMapManager.PrintBitMap(hdc, 3, 350, 450);
 
 
		NewBitMapManager.PrintBitMap(hdc, CardVector[1].CardNumbering, CardVector[1].XLocation, CardVector[1].YLocation);
		NewBitMapManager.PrintBitMap(hdc, CardVector[2].CardNumbering, CardVector[2].XLocation, CardVector[2].YLocation);
 
		EndPaint(hWnd, &ps);
		return 0;
	...
}

BitMap 클래스의 헤더입니다.

class BitMap
{
private:
	HBITMAP m_BitMap;
public:
	BitMap(std::string FileName);
	bool DataNullCheck();	//이미지가 제대로 로드 된 것인가 확인
 
	HBITMAP ReturnBitMap() { return m_BitMap; }
};

비트맵 가져오기와 출력 등등을 제어하는 BitMapManager에서 출력에 관여하는 함수 부분입니다.

void BitMapManager::PrintBitMap(HDC hdc, int BitMapNumber, int xLocation, int yLocation)
{
	HBITMAP OldBitMap;
	HBITMAP BitMapTmp;
	HDC MemDC = CreateCompatibleDC(hdc);
 
	BitMapTmp = m_BitMapVector[BitMapNumber]->ReturnBitMap();
	OldBitMap = (HBITMAP)SelectObject(MemDC, BitMapTmp);
 
	DWORD LastError;
	if (OldBitMap == NULL)
	{
		LastError = GetLastError();
	}
 
	BitBlt(hdc, xLocation, yLocation, IMAGESIZE_X, IMAGESIZE_Y, MemDC, 0, 0, SRCCOPY);
 
	SelectObject(MemDC, OldBitMap);
 
	DeleteObject(BitMapTmp);
	DeleteDC(MemDC);
}

아마 필요한 부분은 이정도면 되지 않을까... 싶습니다.

지금 컴파일러 상에서 에러가 뜨지 않고 실제로 프로그램 실행을 하였을 경우 어떠한 오류도 뱉지 않지만 당초 상정했던 결과와는 완전 딴판으로 굴러가는데요
PrintBitMap 함수에서 OldBitMap이 SelectObject로 MemDC와 BitMapTmp의 정보를 넘겨받을 때 문제가 발생하고 있습니다.
디버깅 모드로 살펴보니

NewBitMapManager.PrintBitMap(hdc, 2, 50, 450);

이런식으로 매개변수를 건네주면 이미지 출력이 제대로 되고 있습니다만

NewBitMapManager.PrintBitMap(hdc, CardVector[1].CardNumbering, CardVector[1].XLocation, CardVector[1].YLocation);

이런식으로 매개변수를 건네주면 분명히 OldBitMap이 정보를 넘겨 받았는데도 NULL이라서 출력이 되지 않고 있습니다.

그래서 GetLastError()로 오류 코드를 받아봤습니다만, 0이 반환되어서 도대체 뭐가 문젠지 모르겠네요.
구글에 뒤져봐도 저와 흡사한 원인을 겪는 것 같은 사람도 없는 것 같고... 지식이 짧아 답을 못 찾겠어서 고민하다가 질문글을 올려봅니다.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.