Click here to Skip to main content
15,905,071 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: 256 colors icon getting modified without a reason Pin
Atif Mushtaq22-Oct-03 20:16
Atif Mushtaq22-Oct-03 20:16 
GeneralRe: 256 colors icon getting modified without a reason Pin
DaFrawg27-Oct-03 1:53
DaFrawg27-Oct-03 1:53 
GeneralRe: Cbutton Pin
DaFrawg21-Oct-03 20:58
DaFrawg21-Oct-03 20:58 
GeneralTool Bar Pin
Neelesh K J Jain21-Oct-03 20:29
Neelesh K J Jain21-Oct-03 20:29 
GeneralRe: Tool Bar Pin
twing21-Oct-03 22:56
twing21-Oct-03 22:56 
Generalpostfix to infix Pin
ranjjj21-Oct-03 18:54
ranjjj21-Oct-03 18:54 
GeneralRe: postfix to infix Pin
David Crow22-Oct-03 2:33
David Crow22-Oct-03 2:33 
GeneralHelp w/ IPicture please Pin
Anonymous21-Oct-03 18:34
Anonymous21-Oct-03 18:34 
I'm trying to load some JPEGS onto a window but with no success...I have done this in the past with the same code and it worked as long as I declared a LPPICTURE global...in this case I need multiple pics to be loaded and displayed so I created a class with a linked list to load them all into

Here are some the functions:
class cPictureList
{
	public:
		class cPictureListElement
		{
			public:
				IPicture *pPicture;

				long hmWidth;
				long hmHeight;

				cPictureListElement()
				{
					pPicture = NULL;

					hmWidth  = 0;
					hmHeight = 0;
				}

			private:
				cPictureListElement *pNextPicture;

			friend class cPictureList;
		};

	public:
		cPictureListElement *pFirstPicture;

		cPictureList()
		{
			pFirstPicture = NULL;
		}

		void Enter           (char*);
		void LoadCovers      (long);
		void LoadGalleryPic  (char*, LPPICTURE);
		void DisplayPictures (HWND, HDC, RECT);
};

void cPictureList::Enter(char *szFileName)
{
	// Function to add gallery pics to the linked list

	if ( pFirstPicture == NULL )
	{
		cPictureListElement *pNewPicture;
		
		pNewPicture = new cPictureListElement;
		
		LoadGalleryPic(szFileName, pNewPicture->pPicture);

		pFirstPicture = pNewPicture;
		pNewPicture->pNextPicture = NULL;

		return;
	}

	// Add to the tail of the list
	cPictureListElement *pBeforePicture, *pAfterPicture;

	pBeforePicture = pFirstPicture;
	pAfterPicture  = pFirstPicture;

	while ( pAfterPicture != NULL )
	{
		pBeforePicture = pAfterPicture;
		pAfterPicture  = pAfterPicture->pNextPicture;
	}

	cPictureListElement *pNewPicture;

	pNewPicture = new cPictureListElement;

	LoadGalleryPic(szFileName, pNewPicture->pPicture);

	pBeforePicture->pNextPicture = pNewPicture;
	pNewPicture->pNextPicture    = NULL;

}

void cPictureList::LoadGalleryPic(char *szFile, IPicture *gpPic)
{
	// This function loads a file into an IStream.

	// open file
	HANDLE hFile = CreateFile(szFile, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);

	// get file size
	DWORD dwFileSize = GetFileSize(hFile, NULL);

	LPVOID pvData = NULL;

	// alloc memory based on file size
	HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, dwFileSize);

	pvData = GlobalLock(hGlobal);

	DWORD dwBytesRead = 0;

	// read file and store in global memory
	BOOL bRead = ReadFile(hFile, pvData, dwFileSize, &dwBytesRead, NULL);

	GlobalUnlock(hGlobal);
	CloseHandle(hFile);

	if ( bRead == FALSE )
		return;

	LPSTREAM pstm = NULL;

	// create IStream* from global memory
	HRESULT hr = CreateStreamOnHGlobal(hGlobal, TRUE, &pstm);

	hr = ::OleLoadPicture(pstm, dwFileSize, FALSE, IID_IPicture, (LPVOID *) &gpPic);

	pstm->Release();
}

void cPictureList::DisplayPictures(HWND hwnd, HDC hdc, RECT rc)
{
	// Function to "paint" the pictures into the gallery

	cPictureListElement *pDisplay;

	pDisplay = pFirstPicture;

	while ( pDisplay != NULL )
	{
		long hmHeight;
		long hmWidth;

		if ( pDisplay->pPicture != NULL )
		{
			pDisplay->pPicture->get_Width(&hmWidth);
			pDisplay->pPicture->get_Height(&hmHeight);
		}
		else
			MessageBox(NULL, "Picture is NULL", NULL, MB_OK);

		pDisplay = pDisplay->pNextPicture;
	}
}


In the function LoadGalleryPic gpPic is not NULL (I have tested this) and OleLoadPicture returns S_OK. The problem is in DisplayPictures...My test always gives me the messagebox saying the picture is NULL. I can only get it to work if gpPic is declared global and is not passed as a parameter to LoadGalleryPic. Any insight?
Generalassembly help Pin
Sirrius21-Oct-03 18:28
Sirrius21-Oct-03 18:28 
GeneralRe: assembly help Pin
ZoogieZork22-Oct-03 1:53
ZoogieZork22-Oct-03 1:53 
Generalcharacter set conversion(UTF8 and UCS2) Pin
convert_sg21-Oct-03 17:03
convert_sg21-Oct-03 17:03 
GeneralRe: character set conversion(UTF8 and UCS2) Pin
Joe Woodbury21-Oct-03 17:58
professionalJoe Woodbury21-Oct-03 17:58 
GeneralRe: character set conversion(UTF8 and UCS2) Pin
convert_sg21-Oct-03 19:03
convert_sg21-Oct-03 19:03 
Questionhow can i reach the same result in vc++? Pin
Habbit21-Oct-03 16:31
Habbit21-Oct-03 16:31 
AnswerRe: how can i reach the same result in vc++? Pin
David Crow21-Oct-03 16:51
David Crow21-Oct-03 16:51 
Generalthanks Pin
Habbit21-Oct-03 16:55
Habbit21-Oct-03 16:55 
GeneralRe: how can i reach the same result in vc++? Pin
includeh1022-Oct-03 4:49
includeh1022-Oct-03 4:49 
GeneralRe: how can i reach the same result in vc++? Pin
David Crow22-Oct-03 5:10
David Crow22-Oct-03 5:10 
GeneralDisable Auto Bitmap Scroll in CScrollView Pin
Swinefeaster21-Oct-03 15:45
Swinefeaster21-Oct-03 15:45 
GeneralRe: Disable Auto Bitmap Scroll in CScrollView Pin
John R. Shaw22-Oct-03 3:53
John R. Shaw22-Oct-03 3:53 
GeneralRe: Disable Auto Bitmap Scroll in CScrollView Pin
Swinefeaster22-Oct-03 7:15
Swinefeaster22-Oct-03 7:15 
GeneralEXCEPTION_ACCESS_VIOLATION Pin
John R. Shaw21-Oct-03 15:05
John R. Shaw21-Oct-03 15:05 
GeneralOpenGL in SDI/MDI tutorial Pin
ferryc@cbn.net.id21-Oct-03 14:37
ferryc@cbn.net.id21-Oct-03 14:37 
GeneralRe: OpenGL in SDI/MDI tutorial Pin
Snyp21-Oct-03 14:48
Snyp21-Oct-03 14:48 
GeneralRe: OpenGL in SDI/MDI tutorial Pin
Snyp21-Oct-03 14:53
Snyp21-Oct-03 14:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.