source: dev/trunk/abdev/ProjectEditor/IconEditor.cpp@ 237

Last change on this file since 237 was 24, checked in by dai_9181, 18 years ago

保存されていないドキュメントのタブに(*)をつける機能に対応。
MDITEXTEDITINFOをCMdiTextEditに変更。今後、オブジェクト指向化を進める。

File size: 17.0 KB
Line 
1#include "Common.h"
2
3RGBQUAD DefaultColorTable16[16]={
4 0,0,0,0,
5 0,0,128,0,
6 0,128,0,0,
7 0,128,128,0,
8 128,0,0,0,
9 128,0,128,0,
10 128,128,0,0,
11 128,128,128,0,
12 192,192,192,0,
13 0,0,255,0,
14 0,255,0,0,
15 0,255,255,0,
16 255,0,0,0,
17 255,0,255,0,
18 255,255,0,0,
19 255,255,255,0,
20};
21RGBQUAD DefaultColorTable256[256]; //ファイルから読み込む(SetupProjectEditor関数を参照)
22
23void ResizeIconWindow(HWND hMain,HWND hToolDlg,HWND hColorDlg,int width,int height){
24 MoveWindow(hMain,0,0,width-170,height-50,1);
25 MoveWindow(hToolDlg,width-170,0,170,height,1);
26 MoveWindow(hColorDlg,0,height-50,width-170,50,1);
27}
28void ResetIconType(int WndNum){
29 extern MDIINFO MdiInfo[MAX_WNDNUM];
30 int i;
31 HWND hCombo;
32 char temporary[MAX_PATH];
33 BITMAPINFOHEADER *pBmpInfoHdr;
34
35 hCombo=GetDlgItem(MdiInfo[WndNum].MdiIconEditInfo->hToolDlg,IDC_ICONTYPECOMBO);
36
37 for(i=0;i<MdiInfo[WndNum].MdiIconEditInfo->num;i++){
38 pBmpInfoHdr=(BITMAPINFOHEADER *)MdiInfo[WndNum].MdiIconEditInfo->pIconImage[i];
39
40 //例: "32*32 (xxxx色)"
41 sprintf(temporary,"%d*%d (%d%s)",
42 pBmpInfoHdr->biWidth,
43 pBmpInfoHdr->biHeight/2,
44 (int)pow((double)2,(double)pBmpInfoHdr->biBitCount),
45 STRING_UNIT_COLORS);
46 SendMessage(hCombo,CB_ADDSTRING,0,(long)temporary);
47 }
48 SendMessage(hCombo,CB_SETCURSEL,0,0);
49}
50BYTE *CreateIconType(int IconType,DWORD *dwBytes){
51 extern HANDLE hHeap;
52 int i,width,BitCount,dwBytesInRes;
53 BITMAPINFOHEADER *pBmpHdr;
54 BYTE *pImageBuffer;
55
56 switch(IconType){
57 case ICONTYPE_16_16:
58 width=16;
59 BitCount=4;
60 break;
61 case ICONTYPE_16_256:
62 width=16;
63 BitCount=8;
64 break;
65 case ICONTYPE_32_16:
66 width=32;
67 BitCount=4;
68 break;
69 case ICONTYPE_32_256:
70 width=32;
71 BitCount=8;
72 break;
73 }
74
75 //イメージサイズを計算
76 dwBytesInRes=sizeof(BITMAPINFOHEADER)+
77 sizeof(RGBQUAD)*(int)pow((double)2,(double)BitCount)+
78 BitCount*width*width/8;
79 if(width==16) dwBytesInRes+=width*width*2/8;
80 else dwBytesInRes+=width*width/8;
81 *dwBytes=dwBytesInRes;
82
83 //メモリ領域を確保
84 pImageBuffer=(BYTE *)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,dwBytesInRes);
85
86 //ヘッダ情報をセット
87 pBmpHdr=(BITMAPINFOHEADER *)pImageBuffer;
88 pBmpHdr->biSize=sizeof(BITMAPINFOHEADER);
89 pBmpHdr->biWidth=width;
90 pBmpHdr->biHeight=width*2;
91 pBmpHdr->biPlanes=1;
92 pBmpHdr->biBitCount=BitCount;
93
94 //カラーテーブルをセット
95 RGBQUAD *pRgbq;
96 pRgbq=(RGBQUAD *)(pImageBuffer+sizeof(BITMAPINFOHEADER));
97 if(BitCount==4){
98 //16色
99 memcpy(pRgbq,DefaultColorTable16,sizeof(RGBQUAD)*16);
100 }
101 else if(BitCount==8){
102 //256色
103 memcpy(pRgbq,DefaultColorTable256,sizeof(RGBQUAD)*256);
104 }
105
106 //マスクビットをセット
107 BYTE *pMaskBuf;
108 pMaskBuf=pImageBuffer+
109 sizeof(BITMAPINFOHEADER)+
110 sizeof(RGBQUAD)*(int)pow((double)2,(double)BitCount)+
111 BitCount*width*width/8;
112 if(width==16){
113 //一行の4バイト境界を考慮
114 for(i=0;i<16;i++){
115 pMaskBuf[i*4]=0xFF;
116 pMaskBuf[i*4+1]=0xFF;
117 pMaskBuf[i*4+2]=0;
118 pMaskBuf[i*4+3]=0;
119 }
120 }
121 else memset(pMaskBuf,0xFF,width*width/8);
122
123 return pImageBuffer;
124}
125void AddIconType(int WndNum,int IconType){
126 extern HANDLE hHeap;
127 extern MDIINFO MdiInfo[MAX_WNDNUM];
128 int i,width,BitCount;
129
130 switch(IconType){
131 case ICONTYPE_16_16:
132 width=16;
133 BitCount=4;
134 break;
135 case ICONTYPE_16_256:
136 width=16;
137 BitCount=8;
138 break;
139 case ICONTYPE_32_16:
140 width=32;
141 BitCount=4;
142 break;
143 case ICONTYPE_32_256:
144 width=32;
145 BitCount=8;
146 break;
147 }
148
149 MdiInfo[WndNum].MdiIconEditInfo->pIconImage[MdiInfo[WndNum].MdiIconEditInfo->num]=
150 CreateIconType(IconType,
151 &MdiInfo[WndNum].MdiIconEditInfo->dwBytesInRes[MdiInfo[WndNum].MdiIconEditInfo->num]);
152
153 //イメージ選択用のメモリを解放
154 if(MdiInfo[WndNum].MdiIconEditInfo->SelectLevel==2)
155 DeleteObject(MdiInfo[WndNum].MdiIconEditInfo->hSelectingBmp);
156 MdiInfo[WndNum].MdiIconEditInfo->SelectLevel=0;
157
158 //アイコンタイプを追加
159 MdiInfo[WndNum].MdiIconEditInfo->SelectIconNum=MdiInfo[WndNum].MdiIconEditInfo->num;
160 MdiInfo[WndNum].MdiIconEditInfo->num++;
161
162 //変更情報を初期化
163 i=MdiInfo[WndNum].MdiIconEditInfo->SelectIconNum;
164 MdiInfo[WndNum].MdiIconEditInfo->undo[i].NowPos=0;
165 memset(MdiInfo[WndNum].MdiIconEditInfo->undo[i].lpData,0,sizeof(BYTE *)*MAX_ICONEDIT_UNDONUM);
166
167 //アイコンタイプコンボボックスに追加
168 char temporary[32];
169 HWND hCombo;
170 hCombo=GetDlgItem(MdiInfo[WndNum].MdiIconEditInfo->hToolDlg,IDC_ICONTYPECOMBO);
171
172 //例: "32*32 (xxxx色)"
173 sprintf(temporary,"%d*%d (%d%s)",
174 width,
175 width,
176 (int)pow((double)2,(double)BitCount),
177 STRING_UNIT_COLORS);
178 i=SendMessage(hCombo,CB_ADDSTRING,0,(long)temporary);
179
180 SendMessage(hCombo,CB_SETCURSEL,i,0);
181
182 //再描画
183 HBRUSH hOldBrush;
184 hOldBrush=(HBRUSH)SelectObject(MdiInfo[WndNum].MdiIconEditInfo->memdc,GetStockObject(WHITE_BRUSH));
185 PatBlt(MdiInfo[WndNum].MdiIconEditInfo->memdc,0,0,400,400,PATCOPY);
186 SelectObject(MdiInfo[WndNum].MdiIconEditInfo->memdc,hOldBrush);
187 DrawIconToMemBmp(WndNum,0);
188 InvalidateRect(MdiInfo[WndNum].MdiIconEditInfo->hMain,NULL,1);
189 InvalidateRect(MdiInfo[WndNum].MdiIconEditInfo->hColorDlg,NULL,0);
190}
191void DeleteIconType(int WndNum){
192 extern MDIINFO MdiInfo[MAX_WNDNUM];
193 int i;
194
195 //変更情報を解放
196 for(i=0;i<MAX_ICONEDIT_UNDONUM;i++){
197 if(MdiInfo[WndNum].MdiIconEditInfo->undo[MdiInfo[WndNum].MdiIconEditInfo->SelectIconNum].lpData[i])
198 HeapDefaultFree(MdiInfo[WndNum].MdiIconEditInfo->undo[MdiInfo[WndNum].MdiIconEditInfo->SelectIconNum].lpData[i]);
199 }
200
201 //メモリを解放
202 HeapDefaultFree(MdiInfo[WndNum].MdiIconEditInfo->pIconImage[MdiInfo[WndNum].MdiIconEditInfo->SelectIconNum]);
203
204 //イメージ選択用のメモリを解放
205 if(MdiInfo[WndNum].MdiIconEditInfo->SelectLevel==2)
206 DeleteObject(MdiInfo[WndNum].MdiIconEditInfo->hSelectingBmp);
207 MdiInfo[WndNum].MdiIconEditInfo->SelectLevel=0;
208
209 ////////////////////////
210 // アイコンタイプを削除
211 for(i=MdiInfo[WndNum].MdiIconEditInfo->SelectIconNum;i<MdiInfo[WndNum].MdiIconEditInfo->num-1;i++){
212 MdiInfo[WndNum].MdiIconEditInfo->pIconImage[i]=MdiInfo[WndNum].MdiIconEditInfo->pIconImage[i+1];
213 MdiInfo[WndNum].MdiIconEditInfo->dwBytesInRes[i]=MdiInfo[WndNum].MdiIconEditInfo->dwBytesInRes[i+1];
214 MdiInfo[WndNum].MdiIconEditInfo->undo[i]=MdiInfo[WndNum].MdiIconEditInfo->undo[i+1];
215 }
216 MdiInfo[WndNum].MdiIconEditInfo->num--;
217 if(MdiInfo[WndNum].MdiIconEditInfo->num==MdiInfo[WndNum].MdiIconEditInfo->SelectIconNum)
218 MdiInfo[WndNum].MdiIconEditInfo->SelectIconNum=MdiInfo[WndNum].MdiIconEditInfo->num-1;
219
220 //コンボボックスからアイコンタイプを削除
221 HWND hCombo;
222 hCombo=GetDlgItem(MdiInfo[WndNum].MdiIconEditInfo->hToolDlg,IDC_ICONTYPECOMBO);
223 i=SendMessage(hCombo,CB_DELETESTRING,
224 SendMessage(hCombo,CB_GETCURSEL,0,0),
225 0);
226 SendMessage(hCombo,CB_SETCURSEL,MdiInfo[WndNum].MdiIconEditInfo->SelectIconNum,0);
227
228 //再描画
229 HBRUSH hOldBrush;
230 hOldBrush=(HBRUSH)SelectObject(MdiInfo[WndNum].MdiIconEditInfo->memdc,GetStockObject(WHITE_BRUSH));
231 PatBlt(MdiInfo[WndNum].MdiIconEditInfo->memdc,0,0,400,400,PATCOPY);
232 SelectObject(MdiInfo[WndNum].MdiIconEditInfo->memdc,hOldBrush);
233 DrawIconToMemBmp(WndNum,0);
234 InvalidateRect(MdiInfo[WndNum].MdiIconEditInfo->hMain,NULL,1);
235 InvalidateRect(MdiInfo[WndNum].MdiIconEditInfo->hColorDlg,NULL,0);
236}
237void NewIconEditWindow(char *filepath){
238 extern HINSTANCE hInst,hResInst;
239 extern HANDLE hHeap;
240 extern HWND hDocCombo;
241 extern MDIINFO MdiInfo[MAX_WNDNUM];
242 int i,i2,IconNum;
243 char str[MAX_PATH],str2[32],*buffer;
244 BYTE *pImageBuffer[8];
245 DWORD dwBytesInRes[8];
246 HWND hChild;
247 HDC hdc;
248 MDICREATESTRUCT mdic;
249
250 if(filepath){
251
252 //すでに指定されたファイルが開かれている場合
253 hChild=GetWindow(hClient,GW_CHILD);
254 while(hChild){
255 i=GetWndNum(hChild);
256 if(MdiInfo[i].DocType==WNDTYPE_ICONEDIT){
257 if(lstrcmpi(MdiInfo[i].path,filepath)==0) break;
258 }
259 hChild=GetNextWindow(hChild,GW_HWNDNEXT);
260 }
261 if(hChild){
262 BringWindowToTop(hChild);
263 return;
264 }
265
266 //ファイル読み込み(正常に読み込めるかの確認も含む)
267 HANDLE hFile;
268 DWORD dw;
269 hFile=CreateFile(filepath,GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
270 if(hFile==INVALID_HANDLE_VALUE){
271 //"\"%s\" ファイルの読み込みに失敗しました。"
272 sprintf(str,STRING_ERROR_CANT_FILEOPEN,filepath);
273 MessageBox(hOwner,str,STRING_ERROR,MB_OK|MB_ICONEXCLAMATION);
274 return;
275 }
276 i=GetFileSize(hFile,NULL);
277 buffer=(char *)HeapAlloc(hHeap,0,i+1);
278 ReadFile(hFile,buffer,i,&dw,NULL);
279 CloseHandle(hFile);
280
281 ICONDIR *pIconDir;
282 ICONDIRENTRY *pIconDirEntry;
283 pIconDir=(ICONDIR *)buffer;
284 IconNum=pIconDir->idCount;
285 bool FileOk = true;
286 for(i=0;i<IconNum;i++){
287 pIconDirEntry=(ICONDIRENTRY *)(buffer+sizeof(ICONDIR)+sizeof(ICONDIRENTRY)*i);
288
289 pImageBuffer[i]=(BYTE *)HeapAlloc(hHeap,0,pIconDirEntry->dwBytesInRes);
290 memcpy(pImageBuffer[i],buffer+pIconDirEntry->dwImageOffset,pIconDirEntry->dwBytesInRes);
291
292 dwBytesInRes[i]=pIconDirEntry->dwBytesInRes;
293
294 //対応チェック
295 BITMAPINFOHEADER *pBmpInfoHdr=(BITMAPINFOHEADER *)pImageBuffer[i];
296 if( !(pBmpInfoHdr->biBitCount == 4 || pBmpInfoHdr->biBitCount == 8 ) ){
297 //16色、256色以外の場合
298 //未対応
299 FileOk = false;
300 }
301 }
302
303 _splitpath(filepath,NULL,NULL,str,str2);
304 lstrcat(str,str2);
305 mdic.szTitle=str;
306
307 HeapDefaultFree(buffer);
308
309 if( !FileOk ){
310 for(i=0;i<IconNum;i++){
311 HeapDefaultFree( pImageBuffer[i] );
312 }
313
314 char msg[1024];
315 sprintf( msg, "\"%s\"\n\n16色または256色以外の形式のファイルには対応していません。", filepath );
316 MessageBox( hOwner, msg, "ActiveBasic", MB_OK | MB_ICONEXCLAMATION );
317 return;
318 }
319 }
320 else{
321 extern int DocumentCounter;
322 buffer=0;
323 DocumentCounter++;
324 sprintf(str,"Icon[%d]",DocumentCounter);
325 mdic.szTitle=str;
326
327 IconNum=1;
328 pImageBuffer[0]=CreateIconType(ICONTYPE_32_16,&dwBytesInRes[0]);
329 }
330 mdic.szClass="MDIClientWindow_IconEdit";
331 mdic.hOwner=hInst;
332 mdic.x=CW_USEDEFAULT;
333 mdic.y=CW_USEDEFAULT;
334 mdic.cx=CW_USEDEFAULT;
335 mdic.cy=CW_USEDEFAULT;
336
337 hChild=GetWindow(hClient,GW_CHILD);
338 if(IsWindow(hChild)){
339 if(IsZoomed(hChild)) mdic.style=WS_MAXIMIZE;
340 else mdic.style=0;
341 }
342 else{
343 if(pobj_nv->bMDIZoomed) mdic.style=WS_MAXIMIZE;
344 else mdic.style=0;
345 }
346
347 mdic.lParam=0;
348 hChild=(HWND)SendMessage(hClient,WM_MDICREATE,0,(long)&mdic); //ウィンドウ作成
349
350 ////////////////////
351 //子ウィンドウ作成
352
353 //エディタ中央部分を作成
354 HWND hMain;
355 hMain=CreateWindowEx(WS_EX_CLIENTEDGE,"IconEditWindowProc",NULL,
356 WS_CHILD|WS_VISIBLE,
357 0,0,0,0,
358 hChild,NULL,hInst,NULL);
359
360 //ツールダイアログ部分を作成
361 HWND hToolDlg;
362 hToolDlg=CreateDialog(hResInst,MAKEINTRESOURCE(IDD_ICONEDIT_TOOL),hChild,(DLGPROC)DlgIconToolProc);
363
364 //ツールダイアログのボタン部分を作成
365 HWND hButtonsDlg;
366 hButtonsDlg=CreateDialog(hResInst,MAKEINTRESOURCE(IDD_ICONEDIT_BUTTONS),hToolDlg,(DLGPROC)DlgIconButtons);
367
368 //カラーテーブルダイアログ部分を作成
369 HWND hColorDlg;
370 hColorDlg=CreateDialog(hResInst,MAKEINTRESOURCE(IDD_ICONEDIT_COLOR),hChild,(DLGPROC)DlgIconColorProc);
371
372 //ウィンドウのID登録
373 for(i=0;i<MAX_WNDNUM;i++){
374 if(MdiInfo[i].hwnd==0){
375 MdiInfo[i].hwnd=hChild;
376 MdiInfo[i].DocType=WNDTYPE_ICONEDIT;
377 MdiInfo[i].title=(char *)GlobalAlloc(GMEM_FIXED,lstrlen(str)+1);
378 lstrcpy(MdiInfo[i].title,str);
379 if(filepath){
380 MdiInfo[i].path=(char *)GlobalAlloc(GMEM_FIXED,lstrlen(filepath)+1);
381 lstrcpy(MdiInfo[i].path,filepath);
382 }
383 else MdiInfo[i].path=(char *)GlobalAlloc(GPTR,1);
384
385 MdiInfo[i].MdiIconEditInfo=(MDIICONEDITINFO *)HeapAlloc(hHeap,0,sizeof(MDIICONEDITINFO));
386 MdiInfo[i].MdiIconEditInfo->hMain=hMain;
387 MdiInfo[i].MdiIconEditInfo->hToolDlg=hToolDlg;
388 MdiInfo[i].MdiIconEditInfo->hButtonsDlg=hButtonsDlg;
389 MdiInfo[i].MdiIconEditInfo->hColorDlg=hColorDlg;
390 hdc=GetDC(hMain);
391 MdiInfo[i].MdiIconEditInfo->memdc=CreateCompatibleDC(hdc);
392 MdiInfo[i].MdiIconEditInfo->hMemBmp=CreateCompatibleBitmap(hdc,600,400);
393 SelectObject(MdiInfo[i].MdiIconEditInfo->memdc,MdiInfo[i].MdiIconEditInfo->hMemBmp);
394 ReleaseDC(hMain,hdc);
395
396 MdiInfo[i].MdiIconEditInfo->SelectLevel=0;
397
398 MdiInfo[i].MdiIconEditInfo->num=IconNum;
399 MdiInfo[i].MdiIconEditInfo->SelectIconNum=0;
400 memcpy(MdiInfo[i].MdiIconEditInfo->pIconImage,pImageBuffer,sizeof(DWORD)*IconNum);
401
402 memcpy(MdiInfo[i].MdiIconEditInfo->dwBytesInRes,dwBytesInRes,sizeof(DWORD)*IconNum);
403
404 MdiInfo[i].MdiIconEditInfo->NowTool=IDC_TOOL_PEN;
405 MdiInfo[i].MdiIconEditInfo->MainColor=RGB(0,0,0);
406 extern COLORREF TransparentClrRef;
407 MdiInfo[i].MdiIconEditInfo->SubColor=TransparentClrRef;
408
409 for(i2=0;i2<MdiInfo[i].MdiIconEditInfo->num;i2++){
410 MdiInfo[i].MdiIconEditInfo->undo[i2].NowPos=0;
411 memset(MdiInfo[i].MdiIconEditInfo->undo[i2].lpData,0,sizeof(BYTE *)*MAX_ICONEDIT_UNDONUM);
412 }
413 MdiInfo[i].MdiIconEditInfo->bModify=0;
414 break;
415 }
416 }
417
418 //メモリへ初期描画を行う
419 HBRUSH hOldBrush;
420 hOldBrush=(HBRUSH)SelectObject(MdiInfo[i].MdiIconEditInfo->memdc,GetStockObject(WHITE_BRUSH));
421 PatBlt(MdiInfo[i].MdiIconEditInfo->memdc,0,0,600,400,PATCOPY);
422 SelectObject(MdiInfo[i].MdiIconEditInfo->memdc,hOldBrush);
423 DrawIconToMemBmp(i,0);
424
425 //ウィンドウ位置を初期化
426 RECT rc;
427 GetClientRect(hChild,&rc);
428 ResizeIconWindow(hMain,hToolDlg,hColorDlg,rc.right,rc.bottom);
429
430 //アイコンタイプコンボボックスをセット
431 ResetIconType(i);
432
433 if(MdiInfo[i].MdiIconEditInfo->num<=1)
434 EnableWindow(GetDlgItem(hToolDlg,IDC_DELETE_ICONTYPE),0);
435
436 //Docコンボボックスに追加
437 i=SendMessage(hDocCombo,CB_ADDSTRING,0,(long)str);
438 SendMessage(hDocCombo,CB_SETCURSEL,i,0);
439
440 //タブに追加
441 pobj_MainTab->InsertItem( str, true );
442
443 SetStatusText(NULL);
444
445 //メニュー状態を設定
446 ResetState_DocMenu();
447}
448void SaveIconFile(char *filepath,HWND hwnd){
449 extern MDIINFO MdiInfo[MAX_WNDNUM];
450 int i,i2,WndNum;
451 char buffer[8192],temporary[MAX_PATH];
452 int ImgBufSize[8];
453
454 WndNum=GetWndNum(hwnd);
455
456 i2=0;
457
458 ///////////
459 // ICONDIR
460 *((WORD *)(buffer+i2))=0; //idReserved
461 i2+=sizeof(WORD);
462 *((WORD *)(buffer+i2))=1; //idType
463 i2+=sizeof(WORD);
464 *((WORD *)(buffer+i2))=MdiInfo[WndNum].MdiIconEditInfo->num; //idCount
465 i2+=sizeof(WORD);
466
467 ////////////////
468 // ICONDIRENTRY
469 ICONDIRENTRY IconDirEntry;
470 memset(&IconDirEntry,0,sizeof(ICONDIRENTRY));
471
472 //イメージバッファの初期位置
473 IconDirEntry.dwImageOffset=sizeof(ICONDIR)+
474 sizeof(ICONDIRENTRY)*MdiInfo[WndNum].MdiIconEditInfo->num;
475
476 for(i=0;i<MdiInfo[WndNum].MdiIconEditInfo->num;i++){
477 BITMAPINFOHEADER *pBmpInfoHdr;
478 pBmpInfoHdr=(BITMAPINFOHEADER *)MdiInfo[WndNum].MdiIconEditInfo->pIconImage[i];
479
480 IconDirEntry.bWidth=(BYTE)pBmpInfoHdr->biWidth;
481 IconDirEntry.bHeight=(BYTE)pBmpInfoHdr->biHeight/2;
482 if(pBmpInfoHdr->biBitCount<=8)
483 IconDirEntry.bColorCount=(BYTE)pow((double)2,(double)pBmpInfoHdr->biBitCount);
484 else IconDirEntry.bColorCount=0;
485
486 IconDirEntry.dwBytesInRes=sizeof(BITMAPINFOHEADER);
487 if(pBmpInfoHdr->biBitCount<=8) //256色以下の場合はカラーパレットのサイズを考慮
488 IconDirEntry.dwBytesInRes+=(DWORD)pow((double)2,(double)pBmpInfoHdr->biBitCount)*sizeof(long);
489 IconDirEntry.dwBytesInRes+=pBmpInfoHdr->biBitCount*pBmpInfoHdr->biWidth*(pBmpInfoHdr->biHeight/2)/8;
490 if(pBmpInfoHdr->biWidth==16){
491 //16*16のアイコン
492 IconDirEntry.dwBytesInRes+=pBmpInfoHdr->biWidth*(pBmpInfoHdr->biHeight/2)/8*2;
493 }
494 else{
495 //32*32のアイコン
496 IconDirEntry.dwBytesInRes+=pBmpInfoHdr->biWidth*(pBmpInfoHdr->biHeight/2)/8;
497 }
498
499 ImgBufSize[i]=IconDirEntry.dwBytesInRes;
500
501 memcpy(buffer+i2,&IconDirEntry,sizeof(ICONDIRENTRY));
502 i2+=sizeof(ICONDIRENTRY);
503
504 IconDirEntry.dwImageOffset+=IconDirEntry.dwBytesInRes;
505 }
506
507 ////////////////////
508 // イメージバッファ
509 for(i=0;i<MdiInfo[WndNum].MdiIconEditInfo->num;i++){
510 memcpy(buffer+i2,
511 MdiInfo[WndNum].MdiIconEditInfo->pIconImage[i],
512 ImgBufSize[i]);
513
514 i2+=ImgBufSize[i];
515 }
516
517
518 //ファイルへ書き込み
519 HANDLE hFile;
520 DWORD dummy;
521 hFile=CreateFile(filepath,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
522 if(hFile==INVALID_HANDLE_VALUE){
523 //"\"%s\" ファイルへの書き込みに失敗しました。"
524 sprintf(temporary,STRING_ERROR_CANT_FILESAVE,filepath);
525 MessageBox(hOwner,temporary,STRING_ERROR,MB_OK|MB_ICONSTOP);
526 return;
527 }
528 WriteFile(hFile,buffer,i2,&dummy,NULL);
529 CloseHandle(hFile);
530}
531
532LRESULT CALLBACK MDIClientWindow_IconEdit(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam){
533 extern HWND hDocCombo;
534 extern MDIINFO MdiInfo[MAX_WNDNUM];
535 extern PROJECTINFO ProjectInfo;
536 int i,WndNum;
537
538 switch(message){
539 case WM_MDIACTIVATE:
540 if(!lParam) return 0;
541 i=GetWndNum((HWND)lParam);
542 if(i==-1) return 0; //ウィンドウが初期状態の場合
543
544 i=SendMessage(hDocCombo,CB_FINDSTRINGEXACT,0,(long)MdiInfo[i].title);
545 SendMessage(hDocCombo,CB_SETCURSEL,i,0);
546 SetStatusText(NULL);
547 ResetState_EditMenu();
548 return 0;
549 case WM_SIZE:
550 WndNum=GetWndNum(hwnd);
551 if(WndNum==-1) break;
552 ResizeIconWindow(MdiInfo[WndNum].MdiIconEditInfo->hMain,
553 MdiInfo[WndNum].MdiIconEditInfo->hToolDlg,
554 MdiInfo[WndNum].MdiIconEditInfo->hColorDlg,
555 LOWORD(lParam),HIWORD(lParam));
556 break;
557 case WM_CLOSE:
558 CloseDocWindow(GetWndNum(hwnd));
559 pobj_nv->bMDIZoomed=IsZoomed(hwnd);
560 i=DefMDIChildProc(hwnd,message,wParam,lParam);
561
562 //メニュー状態を設定
563 ResetState_DocMenu();
564
565 return i;
566 }
567 return DefMDIChildProc(hwnd,message,wParam,lParam);
568}
Note: See TracBrowser for help on using the repository browser.