S
ssubbarayan
Dear all,
I am in the process of implementing pageup/pagedown feature in our
consumer electronics project.The idea is to provide feature to the
customers to that similar to viewing a single sms message in a mobile
device.With in the given view area if the whole message does not
fit,we need to provide the ability for users to scroll through the
entire message using pageup/pagedown or key up and key down.In our
case we have the whole contents to be displayed stored in a buffer.I
am giving below one implementation I have tried:
Note:We are using only pure C code and dont have active x controls
like tabs or pageup/down buttons as in .NET or VC++.
#include <stdio.h>
#include "string.h"
void pageup();
void pagedown();
static int pagecounter=0;
/*bytes per page calculated by trial and error
considering the viewable area in my device*/
int bytesperpage=161;
int numpages=0;
int contentremaining=0;
char* customstringcopy=NULL;
char arr[161]={0};
int main(int argc, char *argv[])
{
int totlen=0;
int pagenum=0;
char* customstring=NULL;
char* data="Bloodshed Dev-C++ is a full-featured Integrated
Development Environment (IDE) for the C/C++ programming language. It
uses Mingw port of GCC (GNU Compiler Collec.";
char* stringdata="Bloodshed Dev-C++ is a full-featured Integrated
Development Environment (IDE) for the C/C++ programming language. It
uses Mingw port of GCC (GNU Compiler Collection) as it's compiler. Dev-
C++ can also be used in combination with Cygwin or any other GCC based
compiler.";
char* stringdata1="the #bloodshed channel has recently been
created on the Undernet IRC server. I will be please to talk with you
there so feel free to join If you want have an IRC client you can
get one for Windows at mirc.com and for Linux at xchat.org";
char* stringdata2="You can subscribe to the Dev-C++ mailing list
(for asking and answering questions on Dev-C++ and C/C++ programming)
by clicking here and filling out the subscribe form there.";
totlen=strlen(stringdata)+strlen(stringdata)+strlen(stringdata2);
printf("total length is %d\n",totlen);
printf("length of data is %d\n",strlen(data) );
customstring=(char*)(malloc)(totlen+4);
customstringcopy=customstring;
memset(customstring,0,totlen+4);
memcpy(customstring,stringdata,strlen(stringdata));
customstring=customstring+strlen(stringdata);
customstring[0]='\n';
customstring++;
/*printf("%s\n",stringdata);
printf("%s\n",customstringcopy);*/
/*customstring[0]='\n';
customstring++;*/
memcpy(customstring,stringdata1,strlen(stringdata1));
customstring=customstring+strlen(stringdata1);
customstring[0]='\n';
customstring++;
/*printf("%s\n",stringdata1);
printf("%s\n",customstringcopy);*/
memcpy(customstring,stringdata2,strlen(stringdata2));
customstring=customstring+strlen(stringdata2);
customstring[0]='\n';
customstring++;
/* printf("%s\n",stringdata2);*/
printf("%s\n",customstringcopy);
numpages=totlen/bytesperpage;
printf("total number of pages is %d\n",numpages);
contentremaining=(totlen)%(bytesperpage);
if(contentremaining > 0)
{
numpages=numpages+1;
}
printf("total number of pages is %d\n",numpages);
for(pagenum=0;pagenum<=numpages;pagenum++)
{
pageup();
}
for(pagenum=numpages;pagenum>0;pagenum--)
{
pagedown();
}
system("PAUSE");
return EXIT_SUCCESS;
}
void pageup()
{
if(pagecounter<numpages)
{
pagecounter++;
printf("pagecounter value is %d\n",pagecounter);
memcpy(arr,customstringcopy,161);
printf("%s\n\n",arr);
customstringcopy=customstringcopy
+bytesperpage;
}
}
void pagedown()
{
if(pagecounter==numpages)
{
pagecounter--;
printf("pagecounter value is %d
\n",pagecounter);
customstringcopy=customstringcopy-2*(bytesperpage);
memcpy(arr,customstringcopy,161);
printf("%s\n\n",arr);
}
else
{
if(pagecounter>1)
{
pagecounter--;
printf("pagecounter value is %d
\n",pagecounter);
customstringcopy=customstringcopy-(bytesperpage);
memcpy(arr,customstringcopy,161);
printf("%s\n\n",arr);
}
}
/* if(pagecounter>0)
{
customstringcopy=customstringcopy-
bytesperpage;
memcpy(arr,customstringcopy,161);
printf("%s\n\n",arr);
} */
}
Incase you find bugs in above code please let me know ways to fix it.
I believe there are much better ways then the one I have tried here.It
would be helpful if some one could provide me some sample code for
similar features you would have come across in your product or some
sample links which shows me sample code on how to implement such a
feature.
Note:I am looking for only C code and not C#,JAVA,.NET,VC++
Looking farward for all your replies and advanced thanks for the same,
Regards,
s.subbarayan
I am in the process of implementing pageup/pagedown feature in our
consumer electronics project.The idea is to provide feature to the
customers to that similar to viewing a single sms message in a mobile
device.With in the given view area if the whole message does not
fit,we need to provide the ability for users to scroll through the
entire message using pageup/pagedown or key up and key down.In our
case we have the whole contents to be displayed stored in a buffer.I
am giving below one implementation I have tried:
Note:We are using only pure C code and dont have active x controls
like tabs or pageup/down buttons as in .NET or VC++.
#include <stdio.h>
#include "string.h"
void pageup();
void pagedown();
static int pagecounter=0;
/*bytes per page calculated by trial and error
considering the viewable area in my device*/
int bytesperpage=161;
int numpages=0;
int contentremaining=0;
char* customstringcopy=NULL;
char arr[161]={0};
int main(int argc, char *argv[])
{
int totlen=0;
int pagenum=0;
char* customstring=NULL;
char* data="Bloodshed Dev-C++ is a full-featured Integrated
Development Environment (IDE) for the C/C++ programming language. It
uses Mingw port of GCC (GNU Compiler Collec.";
char* stringdata="Bloodshed Dev-C++ is a full-featured Integrated
Development Environment (IDE) for the C/C++ programming language. It
uses Mingw port of GCC (GNU Compiler Collection) as it's compiler. Dev-
C++ can also be used in combination with Cygwin or any other GCC based
compiler.";
char* stringdata1="the #bloodshed channel has recently been
created on the Undernet IRC server. I will be please to talk with you
there so feel free to join If you want have an IRC client you can
get one for Windows at mirc.com and for Linux at xchat.org";
char* stringdata2="You can subscribe to the Dev-C++ mailing list
(for asking and answering questions on Dev-C++ and C/C++ programming)
by clicking here and filling out the subscribe form there.";
totlen=strlen(stringdata)+strlen(stringdata)+strlen(stringdata2);
printf("total length is %d\n",totlen);
printf("length of data is %d\n",strlen(data) );
customstring=(char*)(malloc)(totlen+4);
customstringcopy=customstring;
memset(customstring,0,totlen+4);
memcpy(customstring,stringdata,strlen(stringdata));
customstring=customstring+strlen(stringdata);
customstring[0]='\n';
customstring++;
/*printf("%s\n",stringdata);
printf("%s\n",customstringcopy);*/
/*customstring[0]='\n';
customstring++;*/
memcpy(customstring,stringdata1,strlen(stringdata1));
customstring=customstring+strlen(stringdata1);
customstring[0]='\n';
customstring++;
/*printf("%s\n",stringdata1);
printf("%s\n",customstringcopy);*/
memcpy(customstring,stringdata2,strlen(stringdata2));
customstring=customstring+strlen(stringdata2);
customstring[0]='\n';
customstring++;
/* printf("%s\n",stringdata2);*/
printf("%s\n",customstringcopy);
numpages=totlen/bytesperpage;
printf("total number of pages is %d\n",numpages);
contentremaining=(totlen)%(bytesperpage);
if(contentremaining > 0)
{
numpages=numpages+1;
}
printf("total number of pages is %d\n",numpages);
for(pagenum=0;pagenum<=numpages;pagenum++)
{
pageup();
}
for(pagenum=numpages;pagenum>0;pagenum--)
{
pagedown();
}
system("PAUSE");
return EXIT_SUCCESS;
}
void pageup()
{
if(pagecounter<numpages)
{
pagecounter++;
printf("pagecounter value is %d\n",pagecounter);
memcpy(arr,customstringcopy,161);
printf("%s\n\n",arr);
customstringcopy=customstringcopy
+bytesperpage;
}
}
void pagedown()
{
if(pagecounter==numpages)
{
pagecounter--;
printf("pagecounter value is %d
\n",pagecounter);
customstringcopy=customstringcopy-2*(bytesperpage);
memcpy(arr,customstringcopy,161);
printf("%s\n\n",arr);
}
else
{
if(pagecounter>1)
{
pagecounter--;
printf("pagecounter value is %d
\n",pagecounter);
customstringcopy=customstringcopy-(bytesperpage);
memcpy(arr,customstringcopy,161);
printf("%s\n\n",arr);
}
}
/* if(pagecounter>0)
{
customstringcopy=customstringcopy-
bytesperpage;
memcpy(arr,customstringcopy,161);
printf("%s\n\n",arr);
} */
}
Incase you find bugs in above code please let me know ways to fix it.
I believe there are much better ways then the one I have tried here.It
would be helpful if some one could provide me some sample code for
similar features you would have come across in your product or some
sample links which shows me sample code on how to implement such a
feature.
Note:I am looking for only C code and not C#,JAVA,.NET,VC++
Looking farward for all your replies and advanced thanks for the same,
Regards,
s.subbarayan