Loading image dialog

Posted By: MMike

Loading image dialog - 05/22/10 22:24

I have this, but now how i pass the return image to a BMAP pointer, and to save in the working folder..

the code:

Code:
IPicture* pPic;

int abd()
{
	OPENFILENAME of;
	char buf[256];
					FillMemory(&of,sizeof(of),0);
					FillMemory(buf,256,0);
					
					of.Flags=OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST;
					of.lStructSize=sizeof(of);
					of.hwndOwner=hWnd;	
					of.lpstrFilter	="Supported Files Types (*.bmp;*.gif;*.jpg;*.ico;*.emf;*.wmf)\0*.bmp;*.gif;*.jpg;*.ico;*.emf;*.wmf\0Bitmaps (*.bmp)\0*.bmp\0GIF Files (*.gif)\0*.gif\0JPEG Files (*.jpg)\0*.jpg\0Icons (*.ico)\0*.ico\0Enhanced Metafiles (*.emf)\0*.emf\0Windows Metafiles (*.wmf)\0*.wmf\0\0";
					
					of.lpstrFile=buf;
					of.nMaxFile=255;	
					of.lpstrTitle="Open";	
					if (GetOpenFileName(&of)){
						if (pPic) pPic->Release();
						pPic=LoadPic(buf);
						
					}
}


Posted By: Quad

Re: Loading image dialog - 05/22/10 22:49

use returning filename with bmap_create and return the resulting bmap.
Posted By: MMike

Re: Loading image dialog - 05/23/10 00:04

i dont work Api / C a long time, can you just write those lines for me please?

ai tred add_buffer but it did not worked as i excepted...
you mean return the filename, like
BMAP* x= bmap_create("string");
where i get that string value?
Posted By: 825707653

Re: Loading image dialog - 05/23/10 02:32

I can't understand these code.
Posted By: Espér

Re: Loading image dialog - 05/23/10 10:58

try this:

Code:
OPENFILENAME ofd;
	char buf[256];
	FillMemory(&ofd,sizeof(ofd),0);
	FillMemory(buf,256,0);
	
	ofd.Flags=OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST|OFN_NOCHANGEDIR;
	ofd.lStructSize=sizeof(ofd);
	ofd.hwndOwner=hWnd;
	ofd.lpstrFilter	="Supported Files Types (*.bmp;*.gif;*.jpg;*.ico;*.emf;*.wmf)\0*.bmp;*.gif;*.jpg;*.ico;*.emf;*.wmf\0Bitmaps (*.bmp)\0*.bmp\0GIF Files (*.gif)\0*.gif\0JPEG Files (*.jpg)\0*.jpg\0Icons (*.ico)\0*.ico\0Enhanced Metafiles (*.emf)\0*.emf\0Windows Metafiles (*.wmf)\0*.wmf\0\0";
	ofd.lpstrInitialDir = _chr(""); //work_dir
	ofd.lpstrFile=buf;
	ofd.nMaxFile=255;	
	ofd.lpstrTitle="Load an Image File";
	if (GetOpenFileName(&ofd))
	{
		BItmap_Pointer = bmap_create(ofd.lpstrFile);
	}


Posted By: MMike

Re: Loading image dialog - 05/24/10 01:18

Originally Posted By: 825707653
I can't understand these code.


LOL..Im sure im thankful
Posted By: MMike

Re: Loading image dialog - 05/24/10 17:46

strange its not working
Posted By: Espér

Re: Loading image dialog - 05/24/10 17:53

perhaps you can say, WHAT is not working...
Opening the dialog..?
Calling a picture..?

What?
Posted By: MMike

Re: Loading image dialog - 05/24/10 19:17

buf holds the path:
so it should be open_bmap=bmap_create(buf);
Posted By: EvilSOB

Re: Loading image dialog - 05/24/10 20:05

Same thing. "ofd.lpstrFile" is pointing to "buf" anyway...

Both ways works for me. I just tested it.

Maybe there is a bug in your "LoadPic" function?

Here is the COMPLETE script I was testing with...
Code:
#include <litec.h>
#include <default.c>
#include <windows.h>

PANEL*	output_pan = {	bmap="#64x64x24";		pos_x=50;  pos_y=50;	flags=SHOW;		}

function main()
{	wait(5);	level_load(NULL);		vec_fill(sky_color, 50);		wait(-3);

	OPENFILENAME ofd;		FillMemory(&ofd, sizeof(ofd), 0);
	char buf[256];			FillMemory(buf,  256, 0);
	ofd.Flags=OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST|OFN_NOCHANGEDIR;
	ofd.lStructSize		= sizeof(ofd);
	ofd.hwndOwner		= hWnd;
	ofd.lpstrFilter		= "Supported Files Types (*.bmp;*.gif;*.jpg;*.ico;*.emf;*.wmf)\0*.bmp;*.gif;*.jpg;*.ico;*.emf;*.wmf\0Bitmaps (*.bmp)\0*.bmp\0GIF Files (*.gif)\0*.gif\0JPEG Files (*.jpg)\0*.jpg\0Icons (*.ico)\0*.ico\0Enhanced Metafiles (*.emf)\0*.emf\0Windows Metafiles (*.wmf)\0*.wmf\0\0";
	ofd.lpstrInitialDir = _chr("");		//work_dir
	ofd.lpstrFile		= buf;
	ofd.nMaxFile		= 255;	
	ofd.lpstrTitle		= "Load an Image File";
	if (GetOpenFileName(&ofd))		{	output_pan.bmap = bmap_create(buf);	}
	else							{	output_pan.bmap = NULL;				}

}


Posted By: MMike

Re: Loading image dialog - 05/27/10 09:47

well you right, dont kknow wht happened :s

Now the bad side is that i want to copy the source file to the working folder, and im using bmap save_ ofcourse this is needs power of 2, and it adds extra black o the picture..
is there a way to save with the source dimensions.?
Posted By: EvilSOB

Re: Loading image dialog - 05/27/10 10:32

Save_bmap sucks... Avoid it for this sort of work.

Why not just 'actually' copy the file across?
Code:
...
	char buf[256];  //get file-path source name into 'buf'
			//(using one of the above methods will do)
	//////////////////////////////////////////////////////////////
	STRING* shortname  = str_create(buf);
		while(str_stri(shortname, "\\"))
		{	str_clip(shortname, str_stri(shortname, "\\"));		}
	STRING* targetname = str_create(work_dir);
		str_cat(targetname, shortname);
	file_cpy (targetname, _str(buf));
	//////////////////////////////////////////////////////////////
	str_remove(shortname);		str_remove(targetname);		//optional clean up


Be wary, there is NO crash-prevention checking in this code...
© 2024 lite-C Forums