|
You've been told by basically every reply that using exceptions to catch access-violations is almost certainly a bad design. This is why standard compliant compilers don't allow it. If you insist on ignoring the advice, I guess there's isn't a lot more we can do. In the link you gave you said you can't check for NULLs yourself. Why not?
Steve
|
|
|
|
|
Hi all,
i am trying to display a image in dialog box. i have used this code to do it so far.
CString szFilename ("C:\\abc.bmp");
HBITMAP hBmp = (HBITMAP)::LoadImage(
NULL,
szFilename,
IMAGE_BITMAP,
0,
0,
LR_LOADFROMFILE|LR_CREATEDIBSECTION
);
m_st_pic.SetBitmap(hBmp);
My problem is i want to resize my image that is i want to display it according to a particular size...
but i am not getting how to do it...
Can anybody help in this...
|
|
|
|
|
I'm probably not completely aware of all the bitmap-sizing capabilities of the static control (i assume your m_st_pic is a static) but you could try drawing the bitmap in your dialog's OnPaint and use StretchBlt[^] to size it to whatever size you want to.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Computers are evil, EVIL i tell you!! <
|
|
|
|
|
You should display the image (properly resized) in the WM_PAINT message handler (see, for instance, "Scaling an Image").
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
|
I have a C program, which has to be compiled in VS.NET 2005 environment. I don't have any issues with the compilation part and the EXE is generated. When I run the EXE the program is looping. Pls find below the source code:
/* ------------------------------------------------------------------------ */
/* Program Name : GLDBACK2.C */
/* Last Modified : 03/11/08 - RMC - Creation date */
/* N.B. GLD0DETL has 190 fields and is 1287 bytes */
/* */
/* ------------------------------------------------------------------------ */
/************************************************************************** */
/* Reads dBase file and outputs as text file. */
/* Based on Valour Software freeware. */
/************************************************************************** */
#include <fcntl.h>
#include <sys\types.h>
#include <sys\stat.h>
#include <io.h>
#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct dbase_head {
unsigned char version; /*03 for dbIII and 83 for dbIII w/memo file*/
unsigned char l_update[3]; /*yymmdd for last update*/
unsigned long count; /*number of records in file*/
unsigned int header; /*length of the header
*includes the \r at end
*/
unsigned int lrecl; /*length of a record
*includes the delete
*byte
*/
unsigned char reserv[20];
} DBASE_HEAD;
typedef struct dbase_fld {
char name[11]; /*field name*/
char type; /*field type*/
#define DB_FLD_CHAR 'C'
#define DB_FLD_NUM 'N'
#define DB_FLD_LOGIC 'L'
#define DB_FLD_MEMO 'M'
#define DB_FLD_DATE 'D'
/* A-T uses large data model but drop it for now */
//char far *data_ptr; /*pointer into buffer*/
unsigned char length; /*field length*/
unsigned char dec_point; /*field decimal point*/
unsigned char fill[14];
} DBASE_FIELD;
typedef struct fld_list {
struct fld_list *next;
DBASE_FIELD *fld;
char *data;
} FLD_LIST;
DBASE_HEAD dbhead={0};
FLD_LIST *db_fld_root=0;
char *Buffer;
char buf_work[255];
int dbfile;
int ck, fldtotal;
unsigned long reccount;
int fldcount=0;
FILE *outtxt, *infotxt;
char OUTNAME[50]= "";
char INFONAME[50]= "";
char *outf, *infof;
char *envSys;
char *envBrNo;
/*------------------------------------------------------------code-------*/
main(argc,argv)
int argc;
char *argv[];
{
printf("\nGLDBACK2\n");
if(argc!=2)
emessage("Usage is db_dump","filename.dbf", -1);
envSys = getenv("SYS");
envBrNo = getenv("BRN");
outf = OUTNAME;
infof = INFONAME;
sprintf(outf, "H:\\%s\\DATA\\BRANCH%s\\DATALOC\\glddbf.txt",envSys,envBrNo);
sprintf(infof, "H:\\%s\\DATA\\BRANCH%s\\DATALOC\\gldinfo.txt",envSys,envBrNo);
outtxt = fopen(OUTNAME,"w");
if (outtxt == 0)
{
emessage("Opening","glddbf", outtxt);
exit(2);
}
infotxt = fopen(INFONAME,"w");
if (infotxt == 0)
{
emessage("Opening","gldinfo", infotxt);
exit(2);
}
dbfile=open(argv[1],O_RDONLY);
if(dbfile==-1)
{emessage("Unable to open file",argv[1], -1);}
/* read data dictionary */
printf("Reading data dictionary\n");
db3_read_dic();
/* write out records */
printf("Writing records...\n");
db3_print_recs();
printf("\n\nProcessing complete\n");
close(dbfile);
exit(0);
/* Close output text file */
ck=fclose(outtxt);
if (ck != 0)
{
emessage("Closing","glddbf",ck);
exit(2);
}
}
/******************************************************
db3_read_dic()
This function is called with a file name to
read to create a record type to support the
dbase file
******************************************************/
db3_read_dic()
{
int fields;
DBASE_FIELD *fld;
if(dbfile==-1) {
printf("open failed");
exit(200);
}
read(dbfile,&dbhead,sizeof(DBASE_HEAD));
if( !(dbhead.version==3 || dbhead.version==0x83) )
{
printf("\n\aVersion %d not supported",dbhead.version);
emessage("Version not","supported", -1);
}
fprintf(infotxt, "update year %3d",dbhead.l_update[0]);
fprintf(infotxt, "update mon %3d",dbhead.l_update[1]);
fprintf(infotxt, "update day %3d",dbhead.l_update[2]);
fprintf(infotxt, "number of recs %6u",dbhead.count);
reccount = dbhead.count;
fprintf(infotxt, "header length %3d",dbhead.header);
fprintf(infotxt, "record length %3d\n",dbhead.lrecl);
Buffer=malloc(dbhead.lrecl);
printf("\nHeader reccount = %6u\n", reccount);
fldtotal = 0;
fields=(dbhead.header-1)/32-1;
fprintf(infotxt, "Field Name\tType\tLength\tDecimal Pos\n");
while(fields--) {
fld=(DBASE_FIELD *)malloc(sizeof(DBASE_FIELD));
if(!fld)
emessage("Not enough memory","DBASE_FIELD", -1);
read(dbfile,fld,sizeof(DBASE_FIELD));
fprintf(infotxt, "%-10s\t %c\t %3d\t %3d\n",fld->name,fld->type,
fld->length,fld->dec_point);
++fldtotal;
stack_field(fld);
}
read(dbfile,Buffer,1); /*read the silly little \r character*/
printf("Number of fields = %6d\n", fldtotal);
/* Close info text file */
ck=fclose(infotxt);
if (ck != 0)
{
emessage("Closing","gldinfo",ck);
exit(2);
}
return;
}
/******************************************************
db3_print_recs()
Read records and print the data
******************************************************/
db3_print_recs()
{
int bytes;
unsigned long readcnt=0;
int maxflag=0; /* max count = 65536 */
double maxcnt=0;
while(Buffer[0]!='*')
{
bytes=read(dbfile,Buffer,dbhead.lrecl);
if(bytes!=dbhead.lrecl)
break;
if(Buffer[0]!='*') {
db3_print();
++readcnt;
if(readcnt==65536)
{
printf("\ncount boundary reached\n");
maxflag=1;
}
printf("Writing record number %6u\r", readcnt);
}
}
if(maxflag==1)
{
maxcnt = readcnt;
printf("\nFinal number written is %0.6f\n", maxcnt);
}
return;
}
/******************************************************
db3_print()
Print a single record
******************************************************/
db3_print()
{
FLD_LIST *list, *temp;
temp=db_fld_root;
while(temp) {
memcpy(buf_work,temp->data,temp->fld->length);
++fldcount;
buf_work[temp->fld->length]='\0';
if (fldcount==fldtotal)
{fldcount=0;
fprintf(outtxt,"%s\n",buf_work);}
else
{fprintf(outtxt,"%s",buf_work);}
temp=temp->next;
}
return;
}
/******************************************************
stack_field()
Add a field to the linked list of fields
******************************************************/
stack_field(fld)
DBASE_FIELD *fld;
{
FLD_LIST *list, *temp;
list=(FLD_LIST *)calloc(1,sizeof(FLD_LIST));
if(!list)
emessage("Not enough memory","FLD_LIST", -1);
list->fld=fld;
if(!db_fld_root) {
list->data=Buffer+1; /*skip delete byte*/
db_fld_root=list;
return;
}
temp=db_fld_root;
while(temp->next)
temp=temp->next;
temp->next=list;
list->data=temp->data + temp->fld->length;
return;
}
/***********************/
/* emessage routine */
/***********************/
emessage(edesc,efile,ecode)
char edesc[7];
char efile[8];
int ecode;
{
printf ("\n\n***************************************************************\n");
printf ("** **\n");
printf ("** Error %s %s file. Status = %2d **\n",edesc,efile,ecode);
printf ("** **\n");
printf ("** Print This Screen and **\n");
printf ("** **\n");
printf ("** PLEASE CALL LONDON SUPPORT **\n");
printf ("** **\n");
printf ("***************************************************************\n");
printf("\nPress any key to continue ");
getchar();
return (9);
}
/* End of program */
The function db3_read_dic() is reading a .DBF file and writing the header details to a .TXT file. In that process, the record length is 0. The same EXE generated from MC6 environment works fine. But when the program is being compiled in VS.NET, it loops. Any idea?
|
|
|
|
|
Some suggestions:
- Please use the pre tag to format your code properly. As it is now, it is barely readable.
- What do you mean by "it loops" exactly ? Is it hanging ?
- Did you try to use your debugger to track down the problem ?
|
|
|
|
|
Did it compile on the platform you've been porting it from? If it didn't it might be worth debugging it there rather than using a tool you're unfamiliar with.
Cheers,
Ash
|
|
|
|
|
I am familiar only with VS.NET environment. I was able to debug and found that dbhead.lrecl property is showing "0". Also I don't have MC6 environment.
But I am not able to guess why record length property (dbread.lrecl) is giving "0". If this has some value, then my EXE will work. Any ideas?
|
|
|
|
|
I'd look in db3_read_dic myself, that seems to be where the header's read. Start there and work out.
Cheers,
Ash
|
|
|
|
|
It is a VC++, Win32 project created in VS.NET 2005 environment.
I knew where the header is being read. But the property dbhead.lrecl itself is giving a value of 0. It is just a straight forward property...
|
|
|
|
|
Okay, so you know something's going wrong with the read. Next step is to find out what! I can't answer this as I don't have (or want) access to your data file. So have you checked...
- that the data's kosher - what you really think's in the file is in the file
- that the compiler's not making some assumptions about the size of data objects? That code looks so old it might be a 16 bit relic or the compiler may have made different assumptions about structure packing
and so on...
Cheers,
Ash
|
|
|
|
|
Hi,
I want to custome CEdit control in this way that when I select text inside edit control, selection will be an image or my own selected color combination.
Is this possible?
I dont want to color backgournd or foregroung, I just want to replace the selection color with image or any selected color......
|
|
|
|
|
Can anybody answer this question....
|
|
|
|
|
I am trying to create an application which contains non-ascii text.
I pasted an unicode string into the ide like datatype data = "வணக்கம்"; but it shows as ??????.
How to save static unicode texts?
Today's Beautiful Moments are
Tomorrow's Beautiful Memories
|
|
|
|
|
Is the source file Unicode (UTF16 or UTF8)?
Steve
|
|
|
|
|
I opened it in notepad and saved as UTF-8.
Then i opened in msdev ide.
it looks like this. MessageBox(NULL, L"வணகà¯à®•à®®à¯", L"Note", MB_OK);
Today's Beautiful Moments are
Tomorrow's Beautiful Memories
|
|
|
|
|
#include <windows.h><br />
#include <io.h><br />
#include <fcntl.h><br />
<br />
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, <br />
LPSTR lpCmdLine, int nCmdShow)<br />
{<br />
<br />
int f;<br />
f = open("c:\\uni.txt",O_RDONLY);<br />
char str[100];<br />
read(f,str,100);<br />
<br />
MessageBox(NULL, L"வணகà¯à®•à®®à¯", L"Note", MB_OK);<br />
<br />
<br />
<br />
return 0;<br />
}
i was trying to do the above but i wasnt much sure of all the type castings...
uni.txt contains the UFT chars... so i thought i can open it from a file.
Today's Beautiful Moments are
Tomorrow's Beautiful Memories
|
|
|
|
|
You can try to use string resources instead of putting the text directly in your source files. CString has a constructor that accepts an ID of a string resource.
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
My program is a non MFC program. Just API's.
What should we say a non MFC program of vc++ ? any specific terminology ?
I use the word c style.
and i dont know about MFC but i use some string function using namespace STD.
Today's Beautiful Moments are
Tomorrow's Beautiful Memories
|
|
|
|
|
I am coding now.
i created a resource script and defined string entries...
i tried to past unicode text it just appeared as ???
so i opened in notepad and pasted the text and saved.
i again opened in msdev but it says file not found and some more few warning boxes.
i enabled the multiple language option in regional settings in control panel. yet
Today's Beautiful Moments are
Tomorrow's Beautiful Memories
|
|
|
|
|
Hi,
How would I take my vector of doubles and divide each element in the vector by a scalar (without using a for loop and explicitly referring to each element using the loop index)?
I tried vec/scalar but that doesn't work.
|
|
|
|
|
You can use a while loop and use an iterator to achieve this.
|
|
|
|
|
|
|