Skip to content

Commit 50b6e42

Browse files
committed
http://www.tomozon.sakura.ne.jp/wince/WinCE/download/JZP16/102/JZP16-102-src.zip
1 parent 36ccc97 commit 50b6e42

File tree

7 files changed

+468
-126
lines changed

7 files changed

+468
-126
lines changed

bmp00001.bmp

0 Bytes
Binary file not shown.

file.cpp

Lines changed: 203 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
#include <Winbase.h>
1414
#include "jzpaint.h"
1515

16-
TCHAR edit_filename[MAX_PATH+1]=TEXT("\\MyDocument\\(untitled).2bp");
16+
TCHAR edit_path[MAX_PATH+1]=TEXT("");
17+
TCHAR edit_filename[MAX_PATH+1]=TEXT("(untitled).bmp");
18+
//TCHAR edit_filename[MAX_PATH+1]=TEXT("\\MyDocument\\(untitled).2bp");
1719
//TCHAR backup_filename[MAX_PATH+1]=TEXT("(backup).2bp");
1820

1921
BMI bmi ;
@@ -26,6 +28,7 @@ int modified_flag=0;
2628
void force_save(void);
2729
void save_core(TCHAR *);
2830
BOOL load_core(HWND,TCHAR *);
31+
void save_clipboard_core(TCHAR *,int,int,int,int);
2932

3033
BOOL page_clear(HWND hWnd)
3134
{
@@ -38,7 +41,7 @@ BOOL page_clear(HWND hWnd)
3841
for (j=0;j<winHeight;j++)
3942
for (i=0;i<winWidth;i++)
4043
set_pixel(baseBuf,i,j,3);
41-
wsprintf(edit_filename,TEXT("\\MyDocument\\(untitled).2bp"));
44+
wsprintf(edit_filename,TEXT("(untitled).bmp"));
4245
return TRUE;
4346
}
4447

@@ -65,7 +68,7 @@ BOOL load_bmp(HWND hWnd)
6568
ofn.nMaxFile = MAX_PATH + 1 ;
6669
ofn.lpstrFileTitle = NULL ;
6770
ofn.nMaxFileTitle = 0 ;
68-
ofn.lpstrInitialDir = NULL ;
71+
ofn.lpstrInitialDir = edit_path ;
6972
ofn.lpstrTitle = NULL ;
7073
ofn.Flags = 0 ;
7174
ofn.nFileOffset = 0 ;
@@ -74,7 +77,11 @@ BOOL load_bmp(HWND hWnd)
7477
ofn.lCustData = 0 ;
7578
ofn.lpfnHook = NULL ;
7679
ofn.lpTemplateName = NULL ;
80+
#ifdef SH4
7781
if ( !GetOpenFileName( &ofn ) ) {
82+
#else
83+
if ( !tGetOpenFileName( &ofn ) ) {
84+
#endif
7885
return FALSE;
7986
}
8087

@@ -105,7 +112,7 @@ BOOL load_custum_tone(HWND hWnd)
105112
ofn.nMaxFile = MAX_PATH + 1 ;
106113
ofn.lpstrFileTitle = NULL ;
107114
ofn.nMaxFileTitle = 0 ;
108-
ofn.lpstrInitialDir = NULL ;
115+
ofn.lpstrInitialDir = edit_path ;
109116
ofn.lpstrTitle = NULL ;
110117
ofn.Flags = 0 ;
111118
ofn.nFileOffset = 0 ;
@@ -114,7 +121,11 @@ BOOL load_custum_tone(HWND hWnd)
114121
ofn.lCustData = 0 ;
115122
ofn.lpfnHook = NULL ;
116123
ofn.lpTemplateName = NULL ;
124+
#ifdef SH4
117125
if ( !GetOpenFileName( &ofn ) ) {
126+
#else
127+
if ( !tGetOpenFileName( &ofn ) ) {
128+
#endif
118129
return FALSE;
119130
}
120131

@@ -246,7 +257,7 @@ BOOL load_custum_tone(HWND hWnd)
246257
return TRUE;
247258
}
248259

249-
BOOL load_core(HWND hWnd,TCHAR *filename)
260+
BOOL load_core(HWND hWnd,TCHAR *fn)
250261
{
251262
HANDLE hFile;
252263
DWORD readsize ;
@@ -255,7 +266,7 @@ BOOL load_core(HWND hWnd,TCHAR *filename)
255266
int i,j;
256267
int x_file_offset;
257268

258-
hFile = CreateFile( filename, GENERIC_READ, FILE_SHARE_READ,
269+
hFile = CreateFile( fn, GENERIC_READ, FILE_SHARE_READ,
259270
0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0 ) ;
260271
if ( hFile == INVALID_HANDLE_VALUE ) {
261272
TCHAR Message[ 256 ] ;
@@ -377,7 +388,14 @@ BOOL load_core(HWND hWnd,TCHAR *filename)
377388
}
378389
CloseHandle( hFile ) ;
379390
InvalidateRect(hWnd,NULL,FALSE);
380-
memcpy( edit_filename, filename, MAX_PATH+1 ) ;
391+
for (i=0;;i++)
392+
if (fn[i]=='\0') break;
393+
for (;;i--)
394+
if (fn[i]=='\\') break;
395+
fn[i]='\0';
396+
wsprintf(edit_path,TEXT("%s"),fn);
397+
wsprintf(edit_filename,TEXT("%s"),&fn[i+1]);
398+
// memcpy( edit_filename, filename, MAX_PATH+1 ) ;
381399
// memcpy(tmpBuf,baseBuf,winWidth*winHeight/4);
382400
modified_flag=0;
383401
return TRUE;
@@ -406,7 +424,7 @@ BOOL load_palette(HWND hWnd)
406424
ofn.nMaxFile = MAX_PATH + 1 ;
407425
ofn.lpstrFileTitle = NULL ;
408426
ofn.nMaxFileTitle = 0 ;
409-
ofn.lpstrInitialDir = NULL ;
427+
ofn.lpstrInitialDir = edit_path ;
410428
ofn.lpstrTitle = NULL ;
411429
ofn.Flags = 0 ;
412430
ofn.nFileOffset = 0 ;
@@ -415,7 +433,11 @@ BOOL load_palette(HWND hWnd)
415433
ofn.lCustData = 0 ;
416434
ofn.lpfnHook = NULL ;
417435
ofn.lpTemplateName = NULL ;
436+
#ifdef SH4
418437
if ( !GetOpenFileName( &ofn ) ) {
438+
#else
439+
if ( !tGetOpenFileName( &ofn ) ) {
440+
#endif
419441
return FALSE;
420442
}
421443
hFile = CreateFile( buf1, GENERIC_READ, FILE_SHARE_READ,
@@ -507,25 +529,29 @@ BOOL save_bmp(HWND hWnd)
507529
ofn.lStructSize = sizeof ofn ;
508530
ofn.hwndOwner = hWnd ;
509531
ofn.hInstance = ghInst ;
510-
ofn.lpstrFilter = TEXT("Bitmap Files (*.bmp)\0\0") ;
532+
ofn.lpstrFilter = TEXT("Bitmap Files (*.bmp)\0*.bmp\0\0") ;
511533
ofn.lpstrCustomFilter = NULL ;
512534
ofn.nMaxCustFilter = 0 ;
513535
ofn.nFilterIndex = 0 ;
514536
ofn.lpstrFile = buf1 ;
515537
ofn.nMaxFile = MAX_PATH + 1 ;
516538
ofn.lpstrFileTitle = NULL ;
517539
ofn.nMaxFileTitle = 0 ;
518-
ofn.lpstrInitialDir = NULL ;
540+
ofn.lpstrInitialDir = edit_path ;
519541
ofn.lpstrTitle = NULL ;
520542
ofn.Flags = 0 ;
521543
ofn.nFileOffset = 0 ;
522544
ofn.nFileExtension = 0 ;
523-
ofn.lpstrDefExt = TEXT("2BP") ;
545+
ofn.lpstrDefExt = TEXT("BMP") ;
524546
ofn.lCustData = 0 ;
525547
ofn.lpfnHook = NULL ;
526548
ofn.lpTemplateName = NULL ;
527-
549+
550+
#ifdef SH4
528551
if ( !GetSaveFileName( &ofn ) ) {
552+
#else
553+
if ( !tGetSaveFileName( &ofn ) ) {
554+
#endif
529555
MessageBeep( MB_ICONASTERISK ) ;
530556
return FALSE;
531557
}
@@ -546,7 +572,88 @@ BOOL save_bmp(HWND hWnd)
546572
return FALSE;
547573
*/
548574
save_core(BmpFn);
549-
memcpy( edit_filename, BmpFn, MAX_PATH+1 ) ;
575+
for (i=0;;i++)
576+
if (BmpFn[i]=='\0') break;
577+
for (;;i--)
578+
if (BmpFn[i]=='\\') break;
579+
BmpFn[i]='\0';
580+
wsprintf(edit_path,TEXT("%s"),BmpFn);
581+
wsprintf(edit_filename,TEXT("%s"),&BmpFn[i+1]);
582+
// memcpy( edit_filename, BmpFn, MAX_PATH+1 ) ;
583+
modified_flag=0;
584+
overwrite_flag=TRUE;
585+
return TRUE;
586+
}
587+
BOOL save_clipboard(HWND hWnd,int sx,int sy,int ex,int ey)
588+
{
589+
HANDLE hFile;
590+
TCHAR BmpFn[MAX_PATH + 1],buf1[MAX_PATH+1];
591+
OPENFILENAME ofn ;
592+
int i;
593+
594+
for (i=0;;i++)
595+
if (edit_filename[i]=='\0') break;
596+
edit_filename[i-4]='.';
597+
edit_filename[i-3]='b';
598+
edit_filename[i-2]='m';
599+
edit_filename[i-1]='p';
600+
601+
memset( &ofn, 0, sizeof ofn ) ;
602+
memcpy( buf1, edit_filename, MAX_PATH+1 ) ;
603+
ofn.lStructSize = sizeof ofn ;
604+
ofn.hwndOwner = hWnd ;
605+
ofn.hInstance = ghInst ;
606+
ofn.lpstrFilter = TEXT("Bitmap Files (*.bmp)\0*.bmp\0\0") ;
607+
ofn.lpstrCustomFilter = NULL ;
608+
ofn.nMaxCustFilter = 0 ;
609+
ofn.nFilterIndex = 0 ;
610+
ofn.lpstrFile = buf1 ;
611+
ofn.nMaxFile = MAX_PATH + 1 ;
612+
ofn.lpstrFileTitle = NULL ;
613+
ofn.nMaxFileTitle = 0 ;
614+
ofn.lpstrInitialDir = edit_path ;
615+
ofn.lpstrTitle = NULL ;
616+
ofn.Flags = 0 ;
617+
ofn.nFileOffset = 0 ;
618+
ofn.nFileExtension = 0 ;
619+
ofn.lpstrDefExt = TEXT("BMP") ;
620+
ofn.lCustData = 0 ;
621+
ofn.lpfnHook = NULL ;
622+
ofn.lpTemplateName = NULL ;
623+
624+
#ifdef SH4
625+
if ( !GetSaveFileName( &ofn ) ) {
626+
#else
627+
if ( !tGetSaveFileName( &ofn ) ) {
628+
#endif
629+
MessageBeep( MB_ICONASTERISK ) ;
630+
return FALSE;
631+
}
632+
_tcscpy(BmpFn,buf1);
633+
if (buf1[0]== L'\\' || buf1[0] == L'/')
634+
if (buf1[1]== L'\\' || buf1[0] == L'/')
635+
_tcscpy(BmpFn,&buf1[1]);
636+
637+
hFile = CreateFile( BmpFn, GENERIC_READ, FILE_SHARE_READ,
638+
0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0 ) ;
639+
if ( hFile != INVALID_HANDLE_VALUE )
640+
if (DialogBox(ghInst, MAKEINTRESOURCE(IDD_OVERWRITE_DIALOG), hWnd, SaveProc)==IDCANCEL)
641+
return FALSE;
642+
CloseHandle( hFile ) ;
643+
/*
644+
if ( modified_flag==1 )
645+
if (DialogBox(ghInst, MAKEINTRESOURCE(IDD_MODIFIED_DIALOG), hWnd, SaveProc)==IDCANCEL)
646+
return FALSE;
647+
*/
648+
save_clipboard_core(BmpFn,sx,sy,ex,ey);
649+
for (i=0;;i++)
650+
if (BmpFn[i]=='\0') break;
651+
for (;;i--)
652+
if (BmpFn[i]=='\\') break;
653+
BmpFn[i]='\0';
654+
wsprintf(edit_path,TEXT("%s"),BmpFn);
655+
wsprintf(edit_filename,TEXT("%s"),&BmpFn[i+1]);
656+
// memcpy( edit_filename, BmpFn, MAX_PATH+1 ) ;
550657
modified_flag=0;
551658
overwrite_flag=TRUE;
552659
return TRUE;
@@ -567,7 +674,7 @@ void save_core(TCHAR *fn)
567674
{
568675
HANDLE hFile;
569676
DWORD writesize ;
570-
int i,j;
677+
int i,j,k;
571678

572679
hFile = CreateFile( fn, GENERIC_WRITE, 0, 0,
573680
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0 ) ;
@@ -603,11 +710,92 @@ void save_core(TCHAR *fn)
603710
WriteFile( hFile, &BmpFH, sizeof BmpFH, &writesize, NULL ) ;
604711
WriteFile( hFile, &bmi, sizeof(BITMAPINFOHEADER)+sizeof(RGBQUAD)*16, &writesize, NULL ) ;
605712

606-
for (j=winHeight-1;j>=0;j--)
713+
k=0;
714+
for (j=winHeight-1;j>=0;j--) {
607715
for (i=0;i<winWidth;i+=2) {
608716
BYTE c=get_pixel(baseBuf,i,j)*16+get_pixel(baseBuf,i+1,j);
609717
WriteFile( hFile, &c, 1, &writesize, NULL ) ;
610718
}
719+
k+=winWidth/2;
720+
if (k>12*1024) {
721+
FlushFileBuffers (hFile);
722+
k-=12*1024;
723+
}
724+
}
725+
CloseHandle( hFile ) ;
726+
}
727+
void save_clipboard_core(TCHAR *fn,int sx,int sy,int ex,int ey)
728+
{
729+
HANDLE hFile;
730+
DWORD writesize ;
731+
int i,j,k;
732+
int pw,ph;
733+
734+
hFile = CreateFile( fn, GENERIC_WRITE, 0, 0,
735+
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0 ) ;
736+
if ( hFile == INVALID_HANDLE_VALUE ) {
737+
TCHAR Message[ 256 ] ;
738+
wsprintf( Message, TEXT("File Save error") ) ;
739+
MessageBox( NULL, Message, TEXT("Error"), MB_OK ) ;
740+
return;
741+
}
742+
743+
pw=ex-sx+1;
744+
ph=ey-sy+1;
745+
746+
bmi.bmih.biWidth = pw ;
747+
bmi.bmih.biHeight = ph ;
748+
bmi.bmih.biSize = sizeof(bmi.bmih) ;
749+
bmi.bmih.biPlanes = 1 ;
750+
bmi.bmih.biBitCount = 4 ;
751+
bmi.bmih.biCompression = BI_RGB ;
752+
bmi.bmih.biSizeImage = ((pw+8)&0xffffff8)*ph/2;
753+
bmi.bmih.biXPelsPerMeter = 0 ;
754+
bmi.bmih.biYPelsPerMeter = 0 ;
755+
bmi.bmih.biClrUsed = 0 ;
756+
bmi.bmih.biClrImportant = 0 ;
757+
for (i=0;i<16;i++) {
758+
bmi.rgq[i].rgbBlue = init_color[i][0];
759+
bmi.rgq[i].rgbGreen = init_color[i][1];
760+
bmi.rgq[i].rgbRed = init_color[i][2];
761+
}
762+
763+
BmpFH.bfType = 0x4D42 ;
764+
BmpFH.bfSize = 0x76 + ((pw+8)&0xffffff8)*ph/2 ;
765+
BmpFH.bfReserved1 = BmpFH.bfReserved2 = 0 ;
766+
BmpFH.bfOffBits = sizeof(BmpFH)+sizeof(BITMAPINFOHEADER)+sizeof(RGBQUAD)*16 ;
767+
768+
WriteFile( hFile, &BmpFH, sizeof BmpFH, &writesize, NULL ) ;
769+
WriteFile( hFile, &bmi, sizeof(BITMAPINFOHEADER)+sizeof(RGBQUAD)*16, &writesize, NULL ) ;
770+
771+
k=0;
772+
for (j=ey;j>=sy;j--) {
773+
for (i=sx;i<=ex;i+=8) {
774+
BYTE c1,c2,c3,c4,c5,c6,c7,c8,c;
775+
c2=c3=c4=c5=c6=c7=0;
776+
c1=get_pixel(copyBuf,i,j);
777+
if (i<=ex) c2=get_pixel(copyBuf,i+1,j);
778+
if (i<=ex) c3=get_pixel(copyBuf,i+2,j);
779+
if (i<=ex) c4=get_pixel(copyBuf,i+3,j);
780+
if (i<=ex) c5=get_pixel(copyBuf,i+4,j);
781+
if (i<=ex) c6=get_pixel(copyBuf,i+5,j);
782+
if (i<=ex) c7=get_pixel(copyBuf,i+6,j);
783+
if (i<=ex) c8=get_pixel(copyBuf,i+7,j);
784+
c=c1*16+c2;
785+
WriteFile( hFile, &c, 1, &writesize, NULL ) ;
786+
c=c3*16+c4;
787+
WriteFile( hFile, &c, 1, &writesize, NULL ) ;
788+
c=c5*16+c6;
789+
WriteFile( hFile, &c, 1, &writesize, NULL ) ;
790+
c=c7*16+c8;
791+
WriteFile( hFile, &c, 1, &writesize, NULL ) ;
792+
}
793+
k+=winWidth/2;
794+
if (k>12*1024) {
795+
FlushFileBuffers (hFile);
796+
k-=12*1024;
797+
}
798+
}
611799
CloseHandle( hFile ) ;
612800
}
613801

jzpaint.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@ extern BITMAPFILEHEADER BmpFH ;
4343
extern BITMAPINFOHEADER BmpIH ;
4444

4545
extern int winWidth,winHeight;
46-
46+
extern int picWidth,picHeight;
4747

4848
extern BOOL save_bmp(HWND);
49+
extern BOOL save_clipboard(HWND,int,int,int,int);
4950
extern BOOL load_bmp(HWND);
5051
extern BOOL load_custum_tone(HWND);
5152
extern BOOL load_palette(HWND);
@@ -56,7 +57,7 @@ extern void color_fit(int n);
5657
extern BOOL page_clear(HWND);
5758
extern void jzv_link(HWND);
5859

59-
extern BYTE *baseBuf,*tmpBuf,*base24Buf,*tmp24Buf,*dialogBuf;
60+
extern BYTE *baseBuf,*tmpBuf,*base24Buf,*tmp24Buf,*dialogBuf,*copyBuf;
6061
extern HDC dialogDC,tmpDC;
6162
extern int modified_flag;
6263

@@ -108,3 +109,13 @@ extern void init_color_conv_dialog(int,int);
108109
extern void init_color_mode_dialog();
109110
extern void init_color_bg_dialog(int);
110111
extern void init_color_area_dialog(void);
112+
113+
/* function prototypes */
114+
#ifdef __cplusplus
115+
extern "C" { /* Assume C declarations for C++ */
116+
#endif /* __cplusplus */
117+
BOOL tGetOpenFileName(OPENFILENAME *);
118+
BOOL tGetSaveFileName(OPENFILENAME *);
119+
#ifdef __cplusplus
120+
}
121+
#endif /* __cplusplus */

0 commit comments

Comments
 (0)