source: dev/trunk/ab5.0/abdev/abdev/WindowControl.cpp @ 624

Last change on this file since 624 was 624, checked in by dai_9181, 15 years ago

WindowInfoクラスをリファクタリング

File size: 80.7 KB
Line 
1#include "stdafx.h"
2
3#include "Common.h"
4
5using namespace ActiveBasic::IDE;
6
7#if defined(JPN)
8//日本語
9#include "pj_msg_jpn.h"
10#else
11//英語
12#include "pj_msg_eng.h"
13#endif
14
15int GetWndInfoNum(char *name){
16    for( int i=0;i<static_cast<int>(projectInfo.windowInfos.size());i++){
17        if(lstrcmpi(name,projectInfo.windowInfos[i]->GetName().c_str())==0) return i;
18    }
19    return -1;
20}
21ActiveBasic::PM::WindowInfo *GetWndInfo( char *name )
22{
23    BOOST_FOREACH( ActiveBasic::PM::WindowInfo *pWindowInfo, projectInfo.windowInfos )
24    {
25        if(lstrcmpi(name,pWindowInfo->GetName().c_str())==0) return pWindowInfo;
26    }
27    return NULL;
28}
29void ChangeDivisionToOrSign(char *CopyBuffer,const char *ReadBuffer){
30    int i,i2;
31    for(i=0,i2=0;;i++,i2++){
32        if(ReadBuffer[i]=='|'){
33            CopyBuffer[i2]=0;
34            lstrcpy(CopyBuffer+i2," or ");
35            i2+=3;
36            continue;
37        }
38        CopyBuffer[i2]=ReadBuffer[i];
39        if(ReadBuffer[i]=='\0') break;
40    }
41}
42void ChangeOrSignToDivision(char *CopyBuffer,const char *ReadBuffer){
43    int i,i2,IsStr;
44    for(i=0,i2=0,IsStr=0;;i++,i2++){
45        if(ReadBuffer[i]=='\"') IsStr^=1;
46        if(ReadBuffer[i]=='\0'){
47            CopyBuffer[i2]=0;
48            break;
49        }
50        if(ReadBuffer[i+3]=='\0'){
51            memcpy(CopyBuffer+i2,ReadBuffer+i,3);
52            CopyBuffer[i2+3]=0;
53            break;
54        }
55        if((ReadBuffer[i]==' '||ReadBuffer[i]=='\t')&&
56            (ReadBuffer[i+1]=='O'||ReadBuffer[i+1]=='o')&&(ReadBuffer[i+2]=='R'||ReadBuffer[i+2]=='r')&&
57            (ReadBuffer[i+3]==' '||ReadBuffer[i+3]=='\t')&&IsStr==0){
58            CopyBuffer[i2]='|';
59            i+=3;
60            continue;
61        }
62        CopyBuffer[i2]=ReadBuffer[i];
63    }
64}
65
66HGLOBAL Rad_GetChildInfoClipboardData(int WndNum,int WndInfoNum){
67    //ChildWindowInfo構造体をクリップボード用データ(pByteが示すバッファ)に変換する
68    extern MDIINFO MdiInfo[MAX_WNDNUM];
69    HGLOBAL hGlobal;
70    BYTE *pByte;
71    int i2,i3,MemSize;
72
73    for(i3=0;;i3++){
74        if(MdiInfo[WndNum].MdiRadInfo->SelectingItem[i3]==-1) break;
75    }
76   
77
78    hGlobal=GlobalAlloc(GMEM_MOVEABLE,sizeof(int));
79    pByte=(BYTE *)GlobalLock(hGlobal);
80    *((int *)pByte)=i3;
81    GlobalUnlock(hGlobal);
82    i2=sizeof(int);
83
84    MemSize=i2;
85
86    for(i3--;i3>=0;i3--){
87        ActiveBasic::PM::ChildWindowInfo *pChildInfo = projectInfo.windowInfos[WndInfoNum]->childWindowInfos[MdiInfo[WndNum].MdiRadInfo->SelectingItem[i3]];
88
89        MemSize+=pChildInfo->GetName().size()+1+
90            sizeof(POINT)+
91            sizeof(SIZE)+
92            pChildInfo->GetCaption().size()+1+
93            sizeof(DWORD)+
94            sizeof(DWORD)+
95            sizeof(int)+
96            sizeof(int)+
97            pChildInfo->image.path.size()+1;
98
99        hGlobal=GlobalReAlloc(hGlobal,MemSize,0);
100        pByte=(BYTE *)GlobalLock(hGlobal);
101
102        lstrcpy((char *)pByte+i2,pChildInfo->GetName().c_str());
103        i2+=pChildInfo->GetName().size()+1;
104
105        memcpy(pByte+i2,&pChildInfo->pos,sizeof(POINT));
106        i2+=sizeof(POINT);
107
108        memcpy(pByte+i2,&pChildInfo->size,sizeof(SIZE));
109        i2+=sizeof(SIZE);
110
111        lstrcpy((char *)pByte+i2,pChildInfo->GetCaption().c_str());
112        i2+=pChildInfo->GetCaption().size()+1;
113
114        *(DWORD *)(pByte+i2) = pChildInfo->GetStyle();
115        i2+=sizeof(DWORD);
116
117        *(DWORD *)(pByte+i2) = pChildInfo->GetExStyle();
118        i2+=sizeof(DWORD);
119
120        memcpy(pByte+i2,&pChildInfo->Control,sizeof(int));
121        i2+=sizeof(int);
122
123        memcpy(pByte+i2,&pChildInfo->image.type,sizeof(int));
124        i2+=sizeof(int);
125
126        if( pChildInfo->image.path.empty() )
127        {
128            lstrcpy((char *)pByte+i2,"");
129            i2++;
130        }
131        else{
132            lstrcpy((char *)pByte+i2,pChildInfo->image.path.c_str());
133            i2+=pChildInfo->image.path.size()+1;
134        }
135
136        GlobalUnlock(hGlobal);
137    }
138
139    return hGlobal;
140}
141void Rad_PasteChildInfoClipboardData(int WndNum,HGLOBAL hGlobal){
142    //hGlobalに格納されているクリップボードデータをRAD画面に挿入する
143    extern MDIINFO MdiInfo[MAX_WNDNUM];
144    BYTE *pByte;
145    int i2,i3,WndInfoNum;
146    ActiveBasic::PM::ChildWindowInfo ChildInfo;
147
148    for(i2=1;i2<MAX_RAD_SELITEM;i2++) MdiInfo[WndNum].MdiRadInfo->SelectingItem[i2]=-1;
149
150    WndInfoNum=GetWndInfoNum(MdiInfo[WndNum].path);
151    pByte=(BYTE *)GlobalLock(hGlobal);
152    i3=*((int *)pByte);
153    i2=sizeof(int);
154
155    for(i3--;i3>=0;i3--){
156        //IdNameメンバは変更される可能性がある
157        ChildInfo.SetName( (char *)pByte+i2 );
158        i2 += ChildInfo.GetName().size()+1;
159
160        memcpy(&ChildInfo.pos,pByte+i2,sizeof(POINT));
161        i2+=sizeof(POINT);
162
163        memcpy(&ChildInfo.size,pByte+i2,sizeof(SIZE));
164        i2+=sizeof(SIZE);
165
166        ChildInfo.SetCaption( (char *)pByte+i2 );
167        i2+=ChildInfo.GetCaption().size()+1;
168
169        ChildInfo.SetStyle( *(DWORD *)(pByte+i2) );
170        i2+=sizeof(DWORD);
171
172        ChildInfo.SetExStyle( *(DWORD *)(pByte+i2) );
173        i2+=sizeof(DWORD);
174
175        memcpy(&ChildInfo.Control,pByte+i2,sizeof(int));
176        i2+=sizeof(int);
177
178        memcpy(&ChildInfo.image.type,pByte+i2,sizeof(int));
179        i2+=sizeof(int);
180
181        ChildInfo.image.path = (char *)pByte+i2;
182        i2+=ChildInfo.image.path.size()+1;
183
184        ChildInfo.pos.x+=17;
185        ChildInfo.pos.y+=10;
186
187        MdiInfo[WndNum].MdiRadInfo->SelectingItem[i3]=InsertDlgItem(WndNum,
188            WndInfoNum,
189            -1,
190            &ChildInfo.pos,
191            &ChildInfo.size,
192            ChildInfo.GetName().c_str(),
193            ChildInfo.GetCaption().c_str(),
194            ChildInfo.GetStyle(),
195            ChildInfo.GetExStyle(),
196            ChildInfo.Control,
197            ChildInfo.image.type,
198            ChildInfo.image.path.c_str(),
199            2);
200    }
201
202    GlobalUnlock(hGlobal);
203
204    ChangePropertyWindow(WndNum,WndInfoNum);
205}
206
207char *FormatCaption(const char *caption){
208    extern HANDLE hHeap;
209    int i2,i3,BufSize;
210    char *buffer;
211
212    BufSize=256*2;
213    buffer=(char *)HeapAlloc(hHeap,0,BufSize);
214    for(i2=0,i3=0;;i2++,i3++){
215        if(i2+256>=BufSize){
216            BufSize+=256;
217            buffer=(char *)HeapReAlloc(hHeap,0,buffer,BufSize);
218        }
219        if(caption[i3]=='\"'){
220            lstrcpy(buffer+i2,"\"+Chr$(34)+\"");
221            i2+=lstrlen(buffer+i2);
222            i2--;
223            continue;
224        }
225        buffer[i2]=caption[i3];
226        if(caption[i3]=='\0') break;
227    }
228
229    return buffer;
230}
231char *SetCaptionSequence(const char *caption){
232    extern HANDLE hHeap;
233    int i2,i3,BufSize;
234    char *buffer;
235
236    BufSize=256*2;
237    buffer=(char *)HeapAlloc(hHeap,0,BufSize);
238    for(i2=0,i3=0;;i2++,i3++){
239        if(i2+256>=BufSize){
240            BufSize+=256;
241            buffer=(char *)HeapReAlloc(hHeap,0,buffer,BufSize);
242        }
243        buffer[i2]=caption[i3];
244        if(caption[i3]=='\"'){
245            buffer[i2++]='\\';
246            buffer[i2]='1';
247        }
248        else if(caption[i3]=='\\'){
249            buffer[i2++]='\\';
250            buffer[i2]='\\';
251        }
252        else if(caption[i3]=='\0') break;
253    }
254
255    return buffer;
256}
257void RestoreCaptionSequence(char *caption){
258    int i2,i3;
259
260    for(i2=0,i3=0;;i2++,i3++){
261        caption[i2]=caption[i3];
262        if(caption[i3]=='\\'){
263            i3++;
264            if(caption[i3]=='1') caption[i2]='\"';
265            else caption[i2]=caption[i3];
266        }
267        else if(caption[i3]=='\0') break;
268    }
269}
270
271//テンプレートソースファイルに値をセットする
272char *PermutationWndPgmTemplate(char *pBuf,const char *pPjName, char *pWndName, char *pHandleName, char *pProcName){
273    extern HANDLE hHeap;
274    int i,i2;
275
276    for(i=0;;i++){
277        if(pBuf[i]=='\0') break;
278        if(memicmp(pBuf+i,"#name#",6)==0){
279            //プロジェクト名を置換
280            i2=lstrlen(pPjName);
281            if(i2>6) pBuf=(char *)HeapReAlloc(hHeap,HEAP_ZERO_MEMORY,pBuf,lstrlen(pBuf)+(i2-6)+1);
282            SlideString(pBuf+i+6,i2-6);
283            memcpy(pBuf+i,pPjName,i2);
284        }
285        if(memicmp(pBuf+i,"#window#",8)==0){
286            //ウィンドウ名を置換
287            i2=lstrlen(pWndName);
288            if(i2>6) pBuf=(char *)HeapReAlloc(hHeap,HEAP_ZERO_MEMORY,pBuf,lstrlen(pBuf)+(i2-8)+1);
289            SlideString(pBuf+i+8,i2-8);
290            memcpy(pBuf+i,pWndName,i2);
291        }
292        if(memicmp(pBuf+i,"#handle#",8)==0){
293            //ハンドル名を置換
294            i2=lstrlen(pHandleName);
295            if(i2>6) pBuf=(char *)HeapReAlloc(hHeap,HEAP_ZERO_MEMORY,pBuf,lstrlen(pBuf)+(i2-8)+1);
296            SlideString(pBuf+i+8,i2-8);
297            memcpy(pBuf+i,pHandleName,i2);
298        }
299        if(memicmp(pBuf+i,"#procedure#",11)==0){
300            //プロシージャ名を置換
301            i2=lstrlen(pProcName);
302            if(i2>6) pBuf=(char *)HeapReAlloc(hHeap,HEAP_ZERO_MEMORY,pBuf,lstrlen(pBuf)+(i2-11)+1);
303            SlideString(pBuf+i+11,i2-11);
304            memcpy(pBuf+i,pProcName,i2);
305        }
306    }
307
308    return pBuf;
309}
310
311BOOL GetItemNotifyMessageNameByEvent(char *buffer,int ClassID,const char *EventName){
312    if(lstrcmp(EventName,"Click")==0) lstrcpy(buffer,"NM_CLICK");
313    else if(lstrcmp(EventName,"CustomDraw")==0) lstrcpy(buffer,"NM_CUSTOMDRAW");
314    else if(lstrcmp(EventName,"DblClick")==0) lstrcpy(buffer,"NM_DBLCLK");
315    else if(lstrcmp(EventName,"KillFocus")==0) lstrcpy(buffer,"NM_KILLFOCUS");
316    else if(lstrcmp(EventName,"OutOfMemory")==0) lstrcpy(buffer,"NM_OUTOFMEMORY");
317    else if(lstrcmp(EventName,"RClick")==0) lstrcpy(buffer,"NM_RCLICK");
318    else if(lstrcmp(EventName,"RDblClick")==0) lstrcpy(buffer,"NM_RDBLCLK");
319    else if(lstrcmp(EventName,"ReleasedCapture")==0) lstrcpy(buffer,"NM_RELEASEDCAPTURE");
320    else if(lstrcmp(EventName,"Return")==0) lstrcpy(buffer,"NM_RETURN");
321    else if(lstrcmp(EventName,"SetFocus")==0) lstrcpy(buffer,"NM_SETFOCUS");
322    else{
323        if(ClassID==CT_LISTVIEW){
324            if(lstrcmp(EventName,"BeginDrag")==0) lstrcpy(buffer,"LVN_BEGINDRAG");
325            else if(lstrcmp(EventName,"BeginLabelEdit")==0) lstrcpy(buffer,"LVN_BEGINLABELEDIT");
326            else if(lstrcmp(EventName,"BeginRDrag")==0) lstrcpy(buffer,"LVN_BEGINRDRAG");
327            else if(lstrcmp(EventName,"ColumnClick")==0) lstrcpy(buffer,"LVN_COLUMNCLICK");
328            else if(lstrcmp(EventName,"DeleteAllItems")==0) lstrcpy(buffer,"LVN_DELETEALLITEMS");
329            else if(lstrcmp(EventName,"DeleteItem")==0) lstrcpy(buffer,"LVN_DELETEITEM");
330            else if(lstrcmp(EventName,"EndLabelEdit")==0) lstrcpy(buffer,"LVN_ENDLABELEDIT");
331            else if(lstrcmp(EventName,"GetDispInfo")==0) lstrcpy(buffer,"LVN_GETDISPINFO");
332            else if(lstrcmp(EventName,"InsertItem")==0) lstrcpy(buffer,"LVN_INSERTITEM");
333            else if(lstrcmp(EventName,"ItemChanged")==0) lstrcpy(buffer,"LVN_ITEMCHANGED");
334            else if(lstrcmp(EventName,"ItemChanging")==0) lstrcpy(buffer,"LVN_ITEMCHANGING");
335            else if(lstrcmp(EventName,"KeyDown")==0) lstrcpy(buffer,"LVN_KEYDOWN");
336            else if(lstrcmp(EventName,"SetDispInfo")==0) lstrcpy(buffer,"LVN_SETDISPINFO");
337            else return 0;
338        }
339        else if(ClassID==CT_UPDOWN){
340            if(lstrcmp(EventName,"Deltapos")==0) lstrcpy(buffer,"UDN_DELTAPOS");
341            else return 0;
342        }
343        else return 0;
344        //未完成
345    }
346    return 1;
347}
348BOOL GetNotifyCommandByItemMessage(ActiveBasic::PM::WindowInfo *pWindowInfo,ITEMEVENTINFO *pItemEventInfo,char *Command,char *spaces){
349    int i,i2,i3,sw;
350    char temporary[MAX_PATH];
351
352    i2=0;
353    sw=0;
354    for(i=0;;i++){
355        if(pItemEventInfo[i].IdName==0) break;
356        if(pItemEventInfo[i].ClassID==CT_LISTVIEW||
357            pItemEventInfo[i].ClassID==CT_TREEVIEW||
358            pItemEventInfo[i].ClassID==CT_UPDOWN||
359            pItemEventInfo[i].ClassID==CT_PROGRESSBAR||
360            pItemEventInfo[i].ClassID==CT_TRACKBAR){
361            //コモン コントロール(WM_NOTIFY)
362            sw=1;
363            sprintf(Command+i2,"%sCase %s\r\n",spaces,pItemEventInfo[i].IdName);
364            i2+=lstrlen(Command+i2);
365            sprintf(Command+i2,"%s\tSelect Case pnmHdr->code\r\n",spaces);
366            i2+=lstrlen(Command+i2);
367            for(i3=0;i3<pItemEventInfo[i].EventNum;i3++){
368                if(GetItemNotifyMessageNameByEvent(temporary,pItemEventInfo[i].ClassID,pItemEventInfo[i].pEventNames[i3])){
369                    sprintf(Command+i2,"%s\t\tCase %s\r\n",spaces,temporary);
370                    i2+=lstrlen(Command+i2);
371                    sprintf(Command+i2,"%s\t\t\t%s_%s_%s(ByVal (pnmHdr As VoidPtr))\r\n",
372                        spaces,
373                        pWindowInfo->GetName().c_str(),
374                        pItemEventInfo[i].IdName,pItemEventInfo[i].pEventNames[i3]
375                    );
376                    i2+=lstrlen(Command+i2);
377                }
378            }
379            sprintf(Command+i2,"%s\tEnd Select\r\n",spaces);
380            i2+=lstrlen(Command+i2);
381        }
382    }
383    return sw;
384}
385void GetItemMessageNameByEvent(char *buffer,int ClassID,const char *EventName){
386    if(ClassID==CT_BUTTON||
387        ClassID==CT_CHECKBOX||
388        ClassID==CT_RADIOBUTTON){
389        if(lstrcmp(EventName,"Click")==0) lstrcpy(buffer,"BN_CLICKED");
390        else if(lstrcmp(EventName,"DblClick")==0) lstrcpy(buffer,"BN_DBLCLK");
391    }
392    else if(ClassID==CT_COMBOBOX){
393        if(lstrcmp(EventName,"CloseUp")==0) lstrcpy(buffer,"CBN_CLOSEUP");
394        else if(lstrcmp(EventName,"DblClick")==0) lstrcpy(buffer,"CBN_DBLCLK");
395        else if(lstrcmp(EventName,"DropDown")==0) lstrcpy(buffer,"CBN_DROPDOWN");
396        else if(lstrcmp(EventName,"EditChange")==0) lstrcpy(buffer,"CBN_EDITCHANGE");
397        else if(lstrcmp(EventName,"EditUpdate")==0) lstrcpy(buffer,"CBN_EDITUPDATE");
398        else if(lstrcmp(EventName,"ErrSpace")==0) lstrcpy(buffer,"CBN_ERRSPACE");
399        else if(lstrcmp(EventName,"KillFocus")==0) lstrcpy(buffer,"CBN_KILLFOCUS");
400        else if(lstrcmp(EventName,"SelChange")==0) lstrcpy(buffer,"CBN_SELCHANGE");
401        else if(lstrcmp(EventName,"SelEndCancel")==0) lstrcpy(buffer,"CBN_SELENDCANCEL");
402        else if(lstrcmp(EventName,"SelEndOk")==0) lstrcpy(buffer,"CBN_SELENDOK");
403        else if(lstrcmp(EventName,"SetFocus")==0) lstrcpy(buffer,"CBN_SETFOCUS");
404    }
405    else if(ClassID==CT_EDIT){
406        if(lstrcmp(EventName,"Change")==0) lstrcpy(buffer,"EN_CHANGE");
407        else if(lstrcmp(EventName,"ErrSpace")==0) lstrcpy(buffer,"EN_ERRSPACE");
408        else if(lstrcmp(EventName,"HScroll")==0) lstrcpy(buffer,"EN_HSCROLL");
409        else if(lstrcmp(EventName,"KillFocus")==0) lstrcpy(buffer,"EN_KILLFOCUS");
410        else if(lstrcmp(EventName,"MaxText")==0) lstrcpy(buffer,"EN_MAXTEXT");
411        else if(lstrcmp(EventName,"SetFocus")==0) lstrcpy(buffer,"EN_SETFOCUS");
412        else if(lstrcmp(EventName,"Update")==0) lstrcpy(buffer,"EN_UPDATE");
413        else if(lstrcmp(EventName,"VScroll")==0) lstrcpy(buffer,"EN_VSCROLL");
414    }
415    else if(ClassID==CT_IMAGEBOX||
416        ClassID==CT_STATIC){
417        if(lstrcmp(EventName,"Click")==0) lstrcpy(buffer,"STN_CLICKED");
418        else if(lstrcmp(EventName,"DblClick")==0) lstrcpy(buffer,"STN_DBLCLK");
419    }
420    else if(ClassID==CT_LISTBOX){
421        if(lstrcmp(EventName,"SelChange")==0) lstrcpy(buffer,"LBN_SELCHANGE");
422        else if(lstrcmp(EventName,"DblClick")==0) lstrcpy(buffer,"LBN_DBLCLK");
423        else if(lstrcmp(EventName,"ErrSpace")==0) lstrcpy(buffer,"LBN_ERRSPACE");
424        else if(lstrcmp(EventName,"KillFocus")==0) lstrcpy(buffer,"LBN_KILLFOCUS");
425        else if(lstrcmp(EventName,"SelCancel")==0) lstrcpy(buffer,"LBN_SELCANCEL");
426        else if(lstrcmp(EventName,"SetFocus")==0) lstrcpy(buffer,"LBN_SETFOCUS");
427    }
428}
429void GetCommandByItemMessage(ActiveBasic::PM::WindowInfo *pWindowInfo,ITEMEVENTINFO *pItemEventInfo,char *Command,char *spaces){
430    extern HANDLE hHeap;
431    int i,i2,i3;
432    char temporary[MAX_PATH];
433
434    i2=0;
435    for(i=0;;i++){
436        if(pItemEventInfo[i].IdName==0) break;
437        if(pItemEventInfo[i].ClassID!=CT_LISTVIEW&&
438            pItemEventInfo[i].ClassID!=CT_PROGRESSBAR&&
439            pItemEventInfo[i].ClassID!=CT_TREEVIEW&&
440            pItemEventInfo[i].ClassID!=CT_TRACKBAR&&
441            pItemEventInfo[i].ClassID!=CT_UPDOWN
442            ){
443            //WM_COMMAND
444            sprintf(Command+i2,"%sCase %s\r\n",spaces,pItemEventInfo[i].IdName);
445            i2+=lstrlen(Command+i2);
446            if(pItemEventInfo[i].ClassID==CT_MENU){
447                sprintf(Command+i2,"%s\t%s_%s_MenuClick()\r\n",spaces,pWindowInfo->GetName().c_str(),pItemEventInfo[i].IdName);
448                i2+=lstrlen(Command+i2);
449                for(i3=0;i3<pItemEventInfo[i].EventNum;i3++)
450                    HeapDefaultFree(pItemEventInfo[i].pEventNames[i3]);
451            }
452            else{
453                sprintf(Command+i2,"%s\tSelect Case HIWORD(wParam)\r\n",spaces);
454                i2+=lstrlen(Command+i2);
455                for(i3=0;i3<pItemEventInfo[i].EventNum;i3++){
456                    GetItemMessageNameByEvent(temporary,pItemEventInfo[i].ClassID,pItemEventInfo[i].pEventNames[i3]);
457                    sprintf(Command+i2,"%s\t\tCase %s\r\n",spaces,temporary);
458                    i2+=lstrlen(Command+i2);
459                    sprintf(Command+i2,"%s\t\t\t%s_%s_%s()\r\n",spaces,pWindowInfo->GetName().c_str(),pItemEventInfo[i].IdName,pItemEventInfo[i].pEventNames[i3]);
460                    i2+=lstrlen(Command+i2);
461                    HeapDefaultFree(pItemEventInfo[i].pEventNames[i3]);
462                }
463                sprintf(Command+i2,"%s\tEnd Select\r\n",spaces);
464                i2+=lstrlen(Command+i2);
465            }
466            HeapDefaultFree(pItemEventInfo[i].IdName);
467            HeapDefaultFree(pItemEventInfo[i].pEventNames);
468        }
469        else{
470            //WM_NOTIFY情報のメモリ解放
471            for(i3=0;i3<pItemEventInfo[i].EventNum;i3++)
472                HeapDefaultFree(pItemEventInfo[i].pEventNames[i3]);
473            HeapDefaultFree(pItemEventInfo[i].IdName);
474            HeapDefaultFree(pItemEventInfo[i].pEventNames);
475        }
476    }
477}
478
479void GetItemClassName(char *buffer,int Control){
480    switch(Control){
481        case CT_BUTTON:
482        case CT_CHECKBOX:
483        case CT_GROUPBOX:
484        case CT_RADIOBUTTON:
485            lstrcpy(buffer,"BUTTON");
486            break;
487        case CT_COMBOBOX:
488            lstrcpy(buffer,"COMBOBOX");
489            break;
490        case CT_EDIT:
491            lstrcpy(buffer,"EDIT");
492            break;
493        case CT_HSCROLLBAR:
494        case CT_VSCROLLBAR:
495            lstrcpy(buffer,"SCROLLBAR");
496            break;
497        case CT_LISTBOX:
498            lstrcpy(buffer,"LISTBOX");
499            break;
500        case CT_LISTVIEW:
501            lstrcpy(buffer,"SysListView32");
502            break;
503        case CT_IMAGEBOX:
504        case CT_STATIC:
505            lstrcpy(buffer,"STATIC");
506            break;
507        case CT_PROGRESSBAR:
508            lstrcpy(buffer,"msctls_progress32");
509            break;
510        case CT_TRACKBAR:
511            lstrcpy(buffer,"msctls_trackbar32");
512            break;
513        case CT_TREEVIEW:
514            lstrcpy(buffer,"SysTreeView32");
515            break;
516        //CT_UPDOWNはCreateUpDownControl関数で独自に作成される
517    }
518}
519long GetCommandByMessage(int WndInfoNum,const char *MessageName,BOOL bProcedureCall,char *Command,char *spaces){
520    int i,i2,sw;
521    char temporary[MAX_PATH],*temp2;
522
523    ActiveBasic::PM::WindowInfo *pWindowInfo = projectInfo.windowInfos[WndInfoNum];
524
525    Command[0]=0;
526
527
528    /////////////////////
529    // Default コマンド
530
531    if(lstrcmp(MessageName,"Activate")==0){
532        sprintf(Command,"%sCase WM_ACTIVATE\r\n",spaces);
533        i=lstrlen(Command);
534        sprintf(Command+i,"%s\t%s_%s(LOWORD(wParam),HIWORD(wParam))\r\n",spaces,pWindowInfo->GetName().c_str(),MessageName);
535    }
536    else if(lstrcmp(MessageName,"Create")==0){
537        if(pWindowInfo->type==WNDTYPE_MODALDLG||pWindowInfo->type==WNDTYPE_MODELESSDLG)
538            sprintf(Command,"%sCase WM_INITDIALOG\r\n",spaces);
539        else sprintf(Command,"%sCase WM_CREATE\r\n",spaces);
540        i=lstrlen(Command);
541
542        sprintf(Command+i,"%s\t%s=hWnd\r\n",spaces,pWindowInfo->GetHandleName().c_str());
543        i+=lstrlen(Command+i);
544
545        if( pWindowInfo->HasMenu() )
546        {
547            //メニュー作成
548            for(i2=0;i2<projectInfo.NumberOfMenu;i2++){
549                if(lstrcmpi(projectInfo.pMenuInfo[i2].IdName,pWindowInfo->GetMenuIdName().c_str())==0) break;
550            }
551            if(i2!=projectInfo.NumberOfMenu){
552                sprintf(Command+i,"%s\tSetMenu(hWnd,hMenu_%s)\r\n",spaces,projectInfo.pMenuInfo[i2].IdName);
553                i+=lstrlen(Command+i);
554            }
555        }
556
557        //子ウィンドウ作成
558        sw = 0;
559        BOOST_FOREACH( const ActiveBasic::PM::ChildWindowInfo *pChildInfo, pWindowInfo->childWindowInfos )
560        {
561            if(pChildInfo->Control==CT_UPDOWN){
562                sprintf(Command+i,"%s\tCreateUpDownControl(%d,%d,%d,%d,%d,hWnd,%s,GetWindowLongPtr(hWnd,GWLP_HINSTANCE) As HINSTANCE,0,0,100,0)\r\n",
563                    spaces,
564                    pChildInfo->GetStyle(),
565                    pChildInfo->pos.x,pChildInfo->pos.y,
566                    pChildInfo->size.cx,pChildInfo->size.cy,
567                    pChildInfo->GetName().c_str());
568                i+=lstrlen(Command+i);
569            }
570            else{
571                GetItemClassName(temporary,pChildInfo->Control);
572                temp2=FormatCaption(pChildInfo->GetCaption().c_str());
573                sprintf(Command+i,"%s\tCreateWindowEx(&H%08x,\"%s\",\"%s\",&H%08x,%d,%d,%d,%d,hWnd,%s As HMENU,GetModuleHandle(0),0)\r\n",
574                    spaces,
575                    pChildInfo->GetExStyle(),
576                    temporary,
577                    temp2,
578                    pChildInfo->GetStyle(),
579                    pChildInfo->pos.x,
580                    pChildInfo->pos.y,
581                    pChildInfo->size.cx,
582                    pChildInfo->size.cy,
583                    pChildInfo->GetName().c_str());
584                i+=lstrlen(Command+i);
585                HeapDefaultFree(temp2);
586                sprintf(Command+i,"%s\tSendMessage(GetDlgItem(hWnd,%s),WM_SETFONT,hFont_%s As WPARAM,0)\r\n",
587                    spaces,
588                    pChildInfo->GetName().c_str(),
589                    pWindowInfo->GetName().c_str());
590                i+=lstrlen(Command+i);
591
592                if(pChildInfo->Control==CT_IMAGEBOX){
593                    //イメージ ボックスの場合
594                    if((pChildInfo->GetStyle()&0x000F)==SS_ICON){
595                        if(pChildInfo->image.IsFile()){
596                            if(strstr(pChildInfo->image.path.c_str(),":")||
597                                strstr(pChildInfo->image.path.c_str(),"\\\\")){
598                                sprintf(Command+i,"%s\thImage_%s_%s=LoadImage(GetWindowLongPtr(hWnd,GWLP_HINSTANCE) As HINSTANCE,\"%s\",IMAGE_ICON,0,0,LR_DEFAULTSIZE or LR_LOADFROMFILE)\r\n",
599                                    spaces,
600                                    pWindowInfo->GetName().c_str(),
601                                    pChildInfo->GetName().c_str(),
602                                    pChildInfo->image.path.c_str());
603                            }
604                            else{
605                                if(sw==0){
606                                    sw=1;
607                                    lstrcpy(Command+i,"\r\n");
608                                    i+=2;
609                                    sprintf(Command+i,"%s\tDim ImageFilePath[MAX_PATH] As Byte\r\n",spaces);
610                                    i+=lstrlen(Command+i);
611                                    sprintf(Command+i,"%s\tDim ModulePath[MAX_PATH] As Byte, i As Long\r\n",spaces);
612                                    i+=lstrlen(Command+i);
613                                    sprintf(Command+i,"%s\tGetModuleFileName(GetModuleHandle(0),ModulePath,MAX_PATH)\r\n",spaces);
614                                    i+=lstrlen(Command+i);
615                                    sprintf(Command+i,"%s\tFor i=lstrlen(ModulePath)-1 To 0 Step -1\r\n",spaces);
616                                    i+=lstrlen(Command+i);
617                                    sprintf(Command+i,"%s\t\tIf ModulePath[i]=&H5C Then Exit For\r\n",spaces);
618                                    i+=lstrlen(Command+i);
619                                    sprintf(Command+i,"%s\tNext\r\n",spaces);
620                                    i+=lstrlen(Command+i);
621                                    sprintf(Command+i,"%s\tModulePath[i+1]=0\r\n",spaces);
622                                    i+=lstrlen(Command+i);
623                                    lstrcpy(Command+i,"\r\n");
624                                    i+=2;
625                                }
626                                sprintf(Command+i,"%s\twsprintf(ImageFilePath,\"%%s%s\",ModulePath)\r\n",spaces,pChildInfo->image.path.c_str());
627                                i+=lstrlen(Command+i);
628                                sprintf(Command+i,"%s\thImage_%s_%s=LoadImage(GetWindowLongPtr(hWnd,GWLP_HINSTANCE) As HINSTANCE,ImageFilePath,IMAGE_ICON,0,0,LR_DEFAULTSIZE or LR_LOADFROMFILE)\r\n",
629                                    spaces,
630                                    pWindowInfo->GetName().c_str(),
631                                    pChildInfo->GetName().c_str());
632                            }
633                            i+=lstrlen(Command+i);
634                        }
635                        else if(pChildInfo->image.IsResource()){
636                            sprintf(Command+i,"%s\thImage_%s_%s=LoadImage(GetWindowLongPtr(hWnd,GWLP_HINSTANCE) As HINSTANCE,%s As *Byte,IMAGE_ICON,0,0,LR_DEFAULTSIZE)\r\n",
637                                spaces,
638                                pWindowInfo->GetName().c_str(),
639                                pChildInfo->GetName().c_str(),
640                                pChildInfo->image.path.c_str());
641                            i+=lstrlen(Command+i);
642                        }
643                        sprintf(Command+i,"%s\tSendMessage(GetDlgItem(hWnd,%s),STM_SETICON,hImage_%s_%s As WPARAM,0)\r\n",
644                            spaces,
645                            pChildInfo->GetName().c_str(),
646                            pWindowInfo->GetName().c_str(),
647                            pChildInfo->GetName().c_str());
648                        i+=lstrlen(Command+i);
649                    }
650                    else if((pChildInfo->GetStyle()&0x000F)==SS_BITMAP){
651                        if(pChildInfo->image.IsFile()){
652                            if(strstr(pChildInfo->image.path.c_str(),":")||
653                                strstr(pChildInfo->image.path.c_str(),"\\\\")){
654                                sprintf(Command+i,"%s\thImage_%s_%s=LoadImage(GetWindowLongPtr(hWnd,GWLP_HINSTANCE) As HINSTANCE,\"%s\",IMAGE_BITMAP,0,0,LR_DEFAULTSIZE or LR_LOADFROMFILE)\r\n",
655                                    spaces,
656                                    pWindowInfo->GetName().c_str(),
657                                    pChildInfo->GetName().c_str(),
658                                    pChildInfo->image.path.c_str());
659                            }
660                            else{
661                                if(sw==0){
662                                    sw=1;
663                                    lstrcpy(Command+i,"\r\n");
664                                    i+=2;
665                                    sprintf(Command+i,"%s\tDim ImageFilePath[MAX_PATH] As Byte\r\n",spaces);
666                                    i+=lstrlen(Command+i);
667                                    sprintf(Command+i,"%s\tDim ModulePath[MAX_PATH] As Byte, i As Long\r\n",spaces);
668                                    i+=lstrlen(Command+i);
669                                    sprintf(Command+i,"%s\tGetModuleFileName(GetModuleHandle(0),ModulePath,MAX_PATH)\r\n",spaces);
670                                    i+=lstrlen(Command+i);
671                                    sprintf(Command+i,"%s\tFor i=lstrlen(ModulePath)-1 To 0 Step -1\r\n",spaces);
672                                    i+=lstrlen(Command+i);
673                                    sprintf(Command+i,"%s\t\tIf ModulePath[i]=&H5C Then Exit For\r\n",spaces);
674                                    i+=lstrlen(Command+i);
675                                    sprintf(Command+i,"%s\tNext\r\n",spaces);
676                                    i+=lstrlen(Command+i);
677                                    sprintf(Command+i,"%s\tModulePath[i+1]=0\r\n",spaces);
678                                    i+=lstrlen(Command+i);
679                                    lstrcpy(Command+i,"\r\n");
680                                    i+=2;
681                                }
682                                sprintf(Command+i,"%s\twsprintf(ImageFilePath,\"%%s%s\",ModulePath)\r\n",spaces,pChildInfo->image.path.c_str());
683                                i+=lstrlen(Command+i);
684                                sprintf(Command+i,"%s\thImage_%s_%s=LoadImage(GetWindowLongPtr(hWnd,GWLP_HINSTANCE) As HINSTANCE,ImageFilePath,IMAGE_BITMAP,0,0,LR_LOADFROMFILE)\r\n",
685                                    spaces,
686                                    pWindowInfo->GetName().c_str(),
687                                    pChildInfo->GetName().c_str());
688                            }
689                            i+=lstrlen(Command+i);
690                        }
691                        else if(pChildInfo->image.IsResource()){
692                            sprintf(Command+i,"%s\thImage_%s_%s=LoadImage(GetWindowLongPtr(hWnd,GWLP_HINSTANCE) As HINSTANCE,%s As *Byte,IMAGE_BITMAP,0,0,LR_DEFAULTSIZE)\r\n",
693                                spaces,
694                                pWindowInfo->GetName().c_str(),
695                                pChildInfo->GetName().c_str(),
696                                pChildInfo->image.path.c_str());
697                            i+=lstrlen(Command+i);
698                        }
699                        sprintf(Command+i,"%s\tSendMessage(GetDlgItem(hWnd,%s),STM_SETIMAGE,IMAGE_BITMAP,hImage_%s_%s As LPARAM)\r\n",
700                            spaces,
701                            pChildInfo->GetName().c_str(),
702                            pWindowInfo->GetName().c_str(),
703                            pChildInfo->GetName().c_str());
704                        i+=lstrlen(Command+i);
705                    }
706                }
707            }
708        }
709
710        if(bProcedureCall)
711            sprintf(Command+i,"%s\t%s_%s(ByVal (lParam As VoidPtr))\r\n",spaces,pWindowInfo->GetName().c_str(),MessageName);
712        return WM_CREATE;
713    }
714    else if(lstrcmp(MessageName,"Destroy")==0){
715        sprintf(Command,"%sCase WM_DESTROY\r\n",spaces);
716        i=lstrlen(Command);
717        if(bProcedureCall){
718            sprintf(Command+i,"%s\t%s_%s()\r\n",spaces,pWindowInfo->GetName().c_str(),MessageName);
719            i+=lstrlen(Command+i);
720        }
721
722        if( pWindowInfo->HasMenu() )
723        {
724            //メニューを解放
725            for(i2=0;i2<projectInfo.NumberOfMenu;i2++){
726                if(lstrcmpi(projectInfo.pMenuInfo[i2].IdName,pWindowInfo->GetMenuIdName().c_str())==0) break;
727            }
728            if(i2!=projectInfo.NumberOfMenu){
729                sprintf(Command+i,"%s\tSetMenu(hWnd,NULL)\r\n",spaces);
730                i+=lstrlen(Command+i);
731            }
732        }
733
734        //イメージ ボックス用の変数を解放
735        BOOST_FOREACH( const ActiveBasic::PM::ChildWindowInfo *pChildInfo, pWindowInfo->childWindowInfos )
736        {
737            if(pChildInfo->Control==CT_IMAGEBOX){
738                if((pChildInfo->GetStyle()&0x000F)==SS_ICON)
739                    sprintf(Command+i,"%s\tDestroyIcon(hImage_%s_%s)\r\n",spaces,pWindowInfo->GetName().c_str(),pChildInfo->GetName().c_str());
740                else if((pChildInfo->GetStyle()&0x000F)==SS_BITMAP)
741                    sprintf(Command+i,"%s\tDeleteObject(hImage_%s_%s)\r\n",spaces,pWindowInfo->GetName().c_str(),pChildInfo->GetName().c_str());
742                i+=lstrlen(Command+i);
743            }
744        }
745        return WM_DESTROY;
746    }
747    else if(lstrcmp(MessageName,"DropFiles")==0){
748        sprintf(Command,"%sCase WM_DROPFILES\r\n",spaces);
749        i=lstrlen(Command);
750        sprintf(Command+i,"%s\t%s_%s(wParam As HDROP)\r\n",spaces,pWindowInfo->GetName().c_str(),MessageName);
751    }
752    else if(lstrcmp(MessageName,"HScroll")==0){
753        sprintf(Command,"%sCase WM_HSCROLL\r\n",spaces);
754        i=lstrlen(Command);
755        sprintf(Command+i,"%s\t%s_%s(LOWORD(wParam),HIWORD(wParam),lParam As HWND)\r\n",spaces,pWindowInfo->GetName().c_str(),MessageName);
756    }
757    else if(lstrcmp(MessageName,"KeyDown")==0){
758        sprintf(Command,"%sCase WM_KEYDOWN\r\n",spaces);
759        i=lstrlen(Command);
760        sprintf(Command+i,"%s\t%s_%s(wParam As Long,lParam As Long)\r\n",spaces,pWindowInfo->GetName().c_str(),MessageName);
761    }
762    else if(lstrcmp(MessageName,"KeyPress")==0){
763        sprintf(Command,"%sCase WM_CHAR\r\n",spaces);
764        i=lstrlen(Command);
765        sprintf(Command+i,"%s\t%s_%s(wParam As Long,lParam As Long)\r\n",spaces,pWindowInfo->GetName().c_str(),MessageName);
766    }
767    else if(lstrcmp(MessageName,"KeyUp")==0){
768        sprintf(Command,"%sCase WM_KEYUP\r\n",spaces);
769        i=lstrlen(Command);
770        sprintf(Command+i,"%s\t%s_%s(wParam As Long,lParam As Long)\r\n",spaces,pWindowInfo->GetName().c_str(),MessageName);
771    }
772    else if(lstrcmp(MessageName,"LButtonDown")==0){
773        sprintf(Command,"%sCase WM_LBUTTONDOWN\r\n",spaces);
774        i=lstrlen(Command);
775        sprintf(Command+i,"%s\t%s_%s(wParam As Long,LOWORD(lParam),HIWORD(lParam))\r\n",spaces,pWindowInfo->GetName().c_str(),MessageName);
776    }
777    else if(lstrcmp(MessageName,"LButtonDblClick")==0){
778        sprintf(Command,"%sCase WM_LBUTTONDBLCLK\r\n",spaces);
779        i=lstrlen(Command);
780        sprintf(Command+i,"%s\t%s_%s(wParam As Long,LOWORD(lParam),HIWORD(lParam))\r\n",spaces,pWindowInfo->GetName().c_str(),MessageName);
781    }
782    else if(lstrcmp(MessageName,"LButtonUp")==0){
783        sprintf(Command,"%sCase WM_LBUTTONUP\r\n",spaces);
784        i=lstrlen(Command);
785        sprintf(Command+i,"%s\t%s_%s(wParam As Long,LOWORD(lParam),HIWORD(lParam))\r\n",spaces,pWindowInfo->GetName().c_str(),MessageName);
786    }
787    else if(lstrcmp(MessageName,"MButtonDown")==0){
788        sprintf(Command,"%sCase WM_MBUTTONDOWN\r\n",spaces);
789        i=lstrlen(Command);
790        sprintf(Command+i,"%s\t%s_%s(wParam As Long,LOWORD(lParam),HIWORD(lParam))\r\n",spaces,pWindowInfo->GetName().c_str(),MessageName);
791    }
792    else if(lstrcmp(MessageName,"MButtonDblClick")==0){
793        sprintf(Command,"%sCase WM_MBUTTONDBLCLK\r\n",spaces);
794        i=lstrlen(Command);
795        sprintf(Command+i,"%s\t%s_%s(wParam As Long,LOWORD(lParam),HIWORD(lParam))\r\n",spaces,pWindowInfo->GetName().c_str(),MessageName);
796    }
797    else if(lstrcmp(MessageName,"MButtonUp")==0){
798        sprintf(Command,"%sCase WM_MBUTTONUP\r\n",spaces);
799        i=lstrlen(Command);
800        sprintf(Command+i,"%s\t%s_%s(wParam As Long,LOWORD(lParam),HIWORD(lParam))\r\n",spaces,pWindowInfo->GetName().c_str(),MessageName);
801    }
802    else if(lstrcmp(MessageName,"MouseMove")==0){
803        sprintf(Command,"%sCase WM_MOUSEMOVE\r\n",spaces);
804        i=lstrlen(Command);
805        sprintf(Command+i,"%s\t%s_%s(wParam As Long,LOWORD(lParam),HIWORD(lParam))\r\n",spaces,pWindowInfo->GetName().c_str(),MessageName);
806    }
807    else if(lstrcmp(MessageName,"Move")==0){
808        sprintf(Command,"%sCase WM_MOVE\r\n",spaces);
809        i=lstrlen(Command);
810        sprintf(Command+i,"%s\t%s_%s(LOWORD(lParam),HIWORD(lParam))\r\n",spaces,pWindowInfo->GetName().c_str(),MessageName);
811    }
812    else if(lstrcmp(MessageName,"Notify")==0){
813        //コモンコントロールメッセージと共に挿入
814        return WM_NOTIFY;
815    }
816    else if(lstrcmp(MessageName,"Paint")==0){
817        sprintf(Command,"%sCase WM_PAINT\r\n",spaces);
818        i=lstrlen(Command);
819        sprintf(Command+i,"%s\tDim ps As PAINTSTRUCT\r\n",spaces);
820        i+=lstrlen(Command+i);
821        sprintf(Command+i,"%s\tDim hDC As HDC\r\n",spaces);
822        i+=lstrlen(Command+i);
823        sprintf(Command+i,"%s\thDC=BeginPaint(hWnd,ps)\r\n",spaces);
824        i+=lstrlen(Command+i);
825        sprintf(Command+i,"%s\t%s_%s(hDC)\r\n",spaces,pWindowInfo->GetName().c_str(),MessageName);
826        i+=lstrlen(Command+i);
827        sprintf(Command+i,"%s\tEndPaint(hWnd,ps)\r\n",spaces);
828        return WM_PAINT;
829    }
830    else if(lstrcmp(MessageName,"QueryClose")==0){
831        sprintf(Command,"%sCase WM_CLOSE\r\n",spaces);
832        i=lstrlen(Command);
833        sprintf(Command+i,"%s\tDim cancel=0 As Integer\r\n",spaces);
834        i+=lstrlen(Command+i);
835        if(bProcedureCall){
836            sprintf(Command+i,"%s\t%s_%s(cancel)\r\n",spaces,pWindowInfo->GetName().c_str(),MessageName);
837            i+=lstrlen(Command+i);
838        }
839        if(pWindowInfo->type==WNDTYPE_MODALDLG)
840            sprintf(Command+i,"%s\tIf cancel=0 Then EndDialog(hWnd,0)\r\n",spaces);
841        else
842            sprintf(Command+i,"%s\tIf cancel=0 Then DestroyWindow(hWnd)\r\n",spaces);
843        return WM_CLOSE;
844    }
845    else if(lstrcmp(MessageName,"RButtonDblClick")==0){
846        sprintf(Command,"%sCase WM_RBUTTONDBLCLK\r\n",spaces);
847        i=lstrlen(Command);
848        sprintf(Command+i,"%s\t%s_%s(wParam As Long,LOWORD(lParam),HIWORD(lParam))\r\n",spaces,pWindowInfo->GetName().c_str(),MessageName);
849    }
850    else if(lstrcmp(MessageName,"RButtonDown")==0){
851        sprintf(Command,"%sCase WM_RBUTTONDOWN\r\n",spaces);
852        i=lstrlen(Command);
853        sprintf(Command+i,"%s\t%s_%s(wParam As Long,LOWORD(lParam),HIWORD(lParam))\r\n",spaces,pWindowInfo->GetName().c_str(),MessageName);
854    }
855    else if(lstrcmp(MessageName,"RButtonUp")==0){
856        sprintf(Command,"%sCase WM_RBUTTONUP\r\n",spaces);
857        i=lstrlen(Command);
858        sprintf(Command+i,"%s\t%s_%s(wParam As Long,LOWORD(lParam),HIWORD(lParam))\r\n",spaces,pWindowInfo->GetName().c_str(),MessageName);
859    }
860    else if(lstrcmp(MessageName,"Resize")==0){
861        sprintf(Command,"%sCase WM_SIZE\r\n",spaces);
862        i=lstrlen(Command);
863        sprintf(Command+i,"%s\t%s_%s(wParam As Long,LOWORD(lParam),HIWORD(lParam))\r\n",spaces,pWindowInfo->GetName().c_str(),MessageName);
864    }
865    else if(lstrcmp(MessageName,"SetFocus")==0){
866        sprintf(Command,"%sCase WM_SETFOCUS\r\n",spaces);
867        i=lstrlen(Command);
868        sprintf(Command+i,"%s\t%s_%s()\r\n",spaces,pWindowInfo->GetName().c_str(),MessageName);
869    }
870    else if(lstrcmp(MessageName,"Timer")==0){
871        sprintf(Command,"%sCase WM_TIMER\r\n",spaces);
872        i=lstrlen(Command);
873        sprintf(Command+i,"%s\t%s_%s(wParam As DWord)\r\n",spaces,pWindowInfo->GetName().c_str(),MessageName);
874    }
875    else if(lstrcmp(MessageName,"VScroll")==0){
876        sprintf(Command,"%sCase WM_VSCROLL\r\n",spaces);
877        i=lstrlen(Command);
878        sprintf(Command+i,"%s\t%s_%s(LOWORD(wParam),HIWORD(wParam),lParam As HWND)\r\n",spaces,pWindowInfo->GetName().c_str(),MessageName);
879    }
880
881
882    ///////////////////
883    // MMSYS コマンド
884
885    else if(lstrcmp(MessageName,"MciNotify")==0){
886        sprintf(Command,"%sCase MM_MCINOTIFY\r\n",spaces);
887        i=lstrlen(Command);
888        sprintf(Command+i,"%s\t%s_%s(wParam,lParam)\r\n",spaces,pWindowInfo->GetName().c_str(),MessageName);
889    }
890    return 0;
891}
892
893void GetMenuItemConstData(MENU_INFO *pMenuInfo,int NumberOfMenu,int *ConstNumber,Jenga::Common::Strings &namesForDuplicationCheck,char *buffer,int *base){
894    extern HANDLE hHeap;
895    int i;
896
897    for(i=0;i<NumberOfMenu;i++){
898        if(pMenuInfo[i].pMenuInfo){
899            //ポップアップ
900            GetMenuItemConstData(pMenuInfo[i].pMenuInfo,pMenuInfo[i].NumberOfMenu,ConstNumber,namesForDuplicationCheck,buffer,base);
901        }
902        else if(pMenuInfo[i].type==MFT_STRING){
903            //重複チェック
904            bool isMatch = false;
905            BOOST_FOREACH( const std::string &name, namesForDuplicationCheck )
906            {
907                if(lstrcmpi(name.c_str(),pMenuInfo[i].IdName)==0)
908                {
909                    isMatch = true;
910                    break;
911                }
912            }
913            if( !isMatch )
914            {
915                namesForDuplicationCheck.push_back( pMenuInfo[i].IdName );
916
917                sprintf(buffer+(*base),"Const %s=%d\r\n",pMenuInfo[i].IdName,*ConstNumber);
918                (*base)+=lstrlen(buffer+(*base));
919                (*ConstNumber)++;
920            }
921        }
922    }
923}
924int GetMakeMenuCommand(MENU_INFO *pMenuInfo,int NumberOfMenu,char *MenuHandle,char *Command,BOOL bMain){
925    int i,i2;
926    char temporary[MAX_PATH];
927
928    i=0;
929    sprintf(Command+i,"Dim %s As HMENU\r\n",MenuHandle);
930    i+=lstrlen(Command+i);
931    if(bMain) sprintf(Command+i,"%s=CreateMenu()\r\n",MenuHandle);
932    else sprintf(Command+i,"%s=CreatePopupMenu()\r\n",MenuHandle);
933    i+=lstrlen(Command+i);
934
935    for(i2=NumberOfMenu-1;i2>=0;i2--){
936        if(pMenuInfo[i2].pMenuInfo){
937            sprintf(temporary,"%s_%d",MenuHandle,i2);
938            i+=GetMakeMenuCommand(pMenuInfo[i2].pMenuInfo,pMenuInfo[i2].NumberOfMenu,temporary,Command+i,0);
939            sprintf(Command+i,"InsMenu %s,0,MF_BYPOSITION,Ex\"%s\",0,%s,%d\r\n",
940                MenuHandle,
941                pMenuInfo[i2].caption,
942                temporary,
943                pMenuInfo[i2].state);
944            i+=lstrlen(Command+i);
945        }
946        else{
947            if(pMenuInfo[i2].type==MFT_STRING){
948                sprintf(Command+i,"InsMenu %s,0,MF_BYPOSITION,Ex\"%s\",%s,0,%d\r\n",
949                    MenuHandle,
950                    pMenuInfo[i2].caption,
951                    pMenuInfo[i2].IdName,
952                    pMenuInfo[i2].state);
953                i+=lstrlen(Command+i);
954            }
955            else if(pMenuInfo[i2].type==MFT_SEPARATOR){
956                sprintf(Command+i,"InsMenu %s,0,MF_BYPOSITION,\"\"\r\n",
957                    MenuHandle);
958                i+=lstrlen(Command+i);
959            }
960        }
961    }
962    return i;
963}
964int GetDestroyMenuCommand(MENU_INFO *pMenuInfo,int NumberOfMenu,char *MenuHandle,char *Command){
965    int i,i2;
966    char temporary[MAX_PATH];
967
968    i=0;
969    sprintf(Command+i,"\tDestroyMenu(%s)\r\n",MenuHandle);
970    i+=lstrlen(Command+i);
971
972    for(i2=NumberOfMenu-1;i2>=0;i2--){
973        if(pMenuInfo[i2].pMenuInfo){
974            sprintf(temporary,"%s_%d",MenuHandle,i2);
975            i+=GetDestroyMenuCommand(pMenuInfo[i2].pMenuInfo,pMenuInfo[i2].NumberOfMenu,temporary,Command+i);
976        }
977    }
978    return i;
979}
980void SaveWindowProgram(){
981    extern HANDLE hHeap;
982    int i,i2,i3,i4,i5,sw1,sw2,sw3,sw4,size;
983    char *buffer,temporary[MAX_PATH];
984
985    size=2;
986    buffer=(char *)HeapAlloc(hHeap,0,65535*size);
987    lstrcpy(buffer,"'このファイルはウィンドウ定義ファイル(*.wnd)をもとに生成されています\r\n\r\n");
988    i2=lstrlen(buffer);
989
990    if(projectInfo.dwOption&PJ_OP_COMMCTRL){
991        //コマンコントロールを初期化
992        lstrcpy(buffer+i2,"Dim _RadSys_InitCtrls As INITCOMMONCONTROLSEX\r\n");
993        i2+=lstrlen(buffer+i2);
994        lstrcpy(buffer+i2,"_RadSys_InitCtrls.dwSize=Len(_RadSys_InitCtrls)\r\n");
995        i2+=lstrlen(buffer+i2);
996        lstrcpy(buffer+i2,"_RadSys_InitCtrls.dwICC=ICC_WIN95_CLASSES\r\n");
997        i2+=lstrlen(buffer+i2);
998        lstrcpy(buffer+i2,"InitCommonControlsEx(_RadSys_InitCtrls)\r\n\r\n");
999        i2+=lstrlen(buffer+i2);
1000    }
1001
1002
1003    ////////////
1004    //IDを定義
1005
1006    Jenga::Common::Strings namesForDuplicationCheck;
1007    i4=1000;
1008    i5=0;
1009    BOOST_FOREACH( ActiveBasic::PM::WindowInfo *pWindowInfo, projectInfo.windowInfos )
1010    {
1011        BOOST_FOREACH( const ActiveBasic::PM::ChildWindowInfo *pChildInfo, pWindowInfo->childWindowInfos )
1012        {
1013            //重複チェック
1014            bool isMatch = false;
1015            BOOST_FOREACH( const std::string &name, namesForDuplicationCheck )
1016            {
1017                if(lstrcmpi(name.c_str(),pChildInfo->GetName().c_str())==0){
1018                    isMatch = true;
1019                    break;
1020                }
1021            }
1022            if( isMatch ) continue;
1023
1024            namesForDuplicationCheck.push_back( pChildInfo->GetName() );
1025
1026            sprintf(buffer+i2,"Const %s=%d\r\n",pChildInfo->GetName().c_str(),i4);
1027            i2+=lstrlen(buffer+i2);
1028            i4++;
1029
1030            while(i2>65535*(size-1)){
1031                size++;
1032                buffer=(char *)HeapReAlloc(hHeap,0,buffer,65535*size);
1033            }
1034        }
1035    }
1036
1037    //メニューのIDを定義
1038    GetMenuItemConstData(projectInfo.pMenuInfo,projectInfo.NumberOfMenu,&i4,namesForDuplicationCheck,buffer,&i2);
1039
1040    lstrcpy(buffer+i2,"\r\n");
1041    i2+=lstrlen(buffer+i2);
1042
1043
1044    //ハンドル変数を定義
1045    BOOST_FOREACH( ActiveBasic::PM::WindowInfo *pWindowInfo, projectInfo.windowInfos )
1046    {
1047        sprintf(buffer+i2,"Dim %s As HWND\r\n",pWindowInfo->GetHandleName().c_str());
1048        i2+=lstrlen(buffer+i2);
1049        sprintf(buffer+i2,"Dim hFont_%s As HFONT\r\n",pWindowInfo->GetName().c_str());
1050        i2+=lstrlen(buffer+i2);
1051        sprintf(buffer+i2,"hFont_%s=CreateFont(%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,\"%s\")\r\n",
1052            pWindowInfo->GetName().c_str(),
1053            pWindowInfo->LogFont.lfHeight,
1054            pWindowInfo->LogFont.lfWidth,
1055            pWindowInfo->LogFont.lfEscapement,
1056            pWindowInfo->LogFont.lfOrientation,
1057            pWindowInfo->LogFont.lfWeight,
1058            pWindowInfo->LogFont.lfItalic,
1059            pWindowInfo->LogFont.lfUnderline,
1060            pWindowInfo->LogFont.lfStrikeOut,
1061            pWindowInfo->LogFont.lfCharSet,
1062            pWindowInfo->LogFont.lfOutPrecision,
1063            pWindowInfo->LogFont.lfClipPrecision,
1064            pWindowInfo->LogFont.lfQuality,
1065            pWindowInfo->LogFont.lfPitchAndFamily,
1066            pWindowInfo->LogFont.lfFaceName);
1067        i2+=lstrlen(buffer+i2);
1068
1069        while(i2>65535*(size-1)){
1070            size++;
1071            buffer=(char *)HeapReAlloc(hHeap,0,buffer,65535*size);
1072        }
1073    }
1074
1075    //背景に使用するブラシを定義
1076    lstrcpy(buffer+i2,"Dim h3DFaceBrush As HBRUSH\r\n");
1077    i2+=lstrlen(buffer+i2);
1078    lstrcpy(buffer+i2,"h3DFaceBrush=CreateSolidBrush(GetSysColor(COLOR_3DFACE))\r\n");
1079    i2+=lstrlen(buffer+i2);
1080    i=0;
1081    BOOST_FOREACH( ActiveBasic::PM::WindowInfo *pWindowInfo, projectInfo.windowInfos )
1082    {
1083        if(pWindowInfo->GetBackgroundColor()<=0&&
1084            pWindowInfo->GetBackgroundColor()!=-(int)RGB(255,255,255)&&
1085            pWindowInfo->GetBackgroundColor()!=-(int)RGB(0,0,0)){
1086                sprintf(buffer+i2,"Dim _RadSys_hBackBrush%d As HBRUSH\r\n",i);
1087                i2+=lstrlen(buffer+i2);
1088                sprintf(buffer+i2,"_RadSys_hBackBrush%d=CreateSolidBrush(%d)\r\n",i,-pWindowInfo->GetBackgroundColor());
1089                i2+=lstrlen(buffer+i2);
1090        }
1091        if(pWindowInfo->GetBackgroundColor()>=0x1000){
1092                sprintf(buffer+i2,"Dim _RadSys_hBackBrush%d As HBRUSH\r\n",i);
1093                i2+=lstrlen(buffer+i2);
1094                sprintf(buffer+i2,"_RadSys_hBackBrush%d=CreatePatternBrush(LoadImage(GetModuleHandle(0),%s,IMAGE_BITMAP,0,0,LR_DEFAULTSIZE or LR_SHARED))\r\n",
1095                    i,
1096                    projectInfo.resourceManager.bitmapResources[pWindowInfo->GetBackgroundColor()-0x1000].idName.c_str());
1097                i2+=lstrlen(buffer+i2);
1098        }
1099
1100        i++;
1101    }
1102
1103    lstrcpy(buffer+i2,"\r\n");
1104    i2+=lstrlen(buffer+i2);
1105
1106    //イメージ ボックス用の変数を定義
1107    BOOST_FOREACH( ActiveBasic::PM::WindowInfo *pWindowInfo, projectInfo.windowInfos )
1108    {
1109        BOOST_FOREACH( const ActiveBasic::PM::ChildWindowInfo *pChildInfo, pWindowInfo->childWindowInfos )
1110        {
1111            if(pChildInfo->Control==CT_IMAGEBOX){
1112                if((pChildInfo->GetStyle()&0x000F)==SS_ICON||
1113                    (pChildInfo->GetStyle()&0x000F)==SS_BITMAP){
1114                    sprintf(buffer+i2,"Dim hImage_%s_%s As HANDLE\r\n",pWindowInfo->GetName().c_str(),pChildInfo->GetName().c_str());
1115                    i2+=lstrlen(buffer+i2);
1116
1117                    while(i2>65535*(size-1)){
1118                        size++;
1119                        buffer=(char *)HeapReAlloc(hHeap,0,buffer,65535*size);
1120                    }
1121                }
1122            }
1123        }
1124    }
1125
1126    lstrcpy(buffer+i2,"\r\n");
1127    i2+=lstrlen(buffer+i2);
1128
1129    //メニュー作成
1130    for(i=0;i<projectInfo.NumberOfMenu;i++){
1131        sprintf(temporary,"hMenu_%s",projectInfo.pMenuInfo[i].IdName);
1132
1133        //InsertMenuItem郡
1134        i2+=GetMakeMenuCommand(projectInfo.pMenuInfo[i].pMenuInfo,projectInfo.pMenuInfo[i].NumberOfMenu,temporary,buffer+i2,1);
1135
1136        lstrcpy(buffer+i2,"\r\n");
1137        i2+=lstrlen(buffer+i2);
1138
1139        while(i2>65535*(size-1)){
1140            size++;
1141            buffer=(char *)HeapReAlloc(hHeap,0,buffer,65535*size);
1142        }
1143    }
1144
1145
1146    //////////////////////////
1147    //オブジェクトの解放処理
1148    sprintf(buffer+i2,"Sub %s_DestroyObjects()\r\n",projectInfo.GetName().c_str());
1149    i2+=lstrlen(buffer+i2);
1150
1151    //メニュー解放
1152    for(i=0;i<projectInfo.NumberOfMenu;i++){
1153        sprintf(temporary,"hMenu_%s",projectInfo.pMenuInfo[i].IdName);
1154        i2+=GetDestroyMenuCommand(projectInfo.pMenuInfo[i].pMenuInfo,projectInfo.pMenuInfo[i].NumberOfMenu,temporary,buffer+i2);
1155
1156        while(i2>65535*(size-1)){
1157            size++;
1158            buffer=(char *)HeapReAlloc(hHeap,0,buffer,65535*size);
1159        }
1160    }
1161
1162    BOOST_FOREACH( ActiveBasic::PM::WindowInfo *pWindowInfo, projectInfo.windowInfos )
1163    {
1164        //フォントハンドル解放
1165        sprintf(buffer+i2,"\tDeleteObject(hFont_%s)\r\n",pWindowInfo->GetName().c_str());
1166        i2+=lstrlen(buffer+i2);
1167
1168        while(i2>65535*(size-1)){
1169            size++;
1170            buffer=(char *)HeapReAlloc(hHeap,0,buffer,65535*size);
1171        }
1172    }
1173
1174    //背景ブラシを解放
1175    lstrcpy(buffer+i2,"\tDeleteObject(h3DFaceBrush)\r\n");
1176    i2+=lstrlen(buffer+i2);
1177    i=0;
1178    BOOST_FOREACH( ActiveBasic::PM::WindowInfo *pWindowInfo, projectInfo.windowInfos )
1179    {
1180        if(pWindowInfo->GetBackgroundColor()<=0&&
1181            pWindowInfo->GetBackgroundColor()!=-(int)RGB(255,255,255)&&
1182            pWindowInfo->GetBackgroundColor()!=-(int)RGB(0,0,0)){
1183                sprintf(buffer+i2,"\tDeleteObject(_RadSys_hBackBrush%d)\r\n",i);
1184                i2+=lstrlen(buffer+i2);
1185        }
1186        i++;
1187    }
1188
1189    sprintf(buffer+i2,"End Sub\r\n\r\n");
1190    i2+=lstrlen(buffer+i2);
1191
1192    //ユーザー定義のコールバック関数が存在するかどうか
1193    BOOL bAvailUserProc[MAX_WNDNUM];
1194
1195
1196    i=0;
1197    BOOST_FOREACH( ActiveBasic::PM::WindowInfo *pWindowInfo, projectInfo.windowInfos )
1198    {
1199        if(i!=0){
1200            lstrcpy(buffer+i2,"\r\n");
1201            i2+=lstrlen(buffer+i2);
1202        }
1203
1204        //////////////////////////
1205        //コールバック関数を生成
1206
1207        //処理メッセージを抽出
1208        ITEMEVENTINFO *pItemEventInfo;
1209        char **ppNames=GetProcedureNamesOfMessageCall(i,&pItemEventInfo,&i3,&bAvailUserProc[i]);
1210
1211        sprintf(buffer+i2,"Function EventCall_%s(hWnd As HWND, message As DWord, wParam As WPARAM, lParam As LPARAM) As LRESULT\r\n",pWindowInfo->GetName().c_str());
1212        i2+=lstrlen(buffer+i2);
1213
1214        lstrcpy(buffer+i2,"\tSelect Case message\r\n");
1215        i2+=lstrlen(buffer+i2);
1216
1217        //通常メッセージ郡
1218        for(i4=0,sw1=0,sw2=0,sw3=0,sw4=0;i4<i3;i4++){
1219            i5=GetCommandByMessage(i,ppNames[i4],1,buffer+i2,"\t\t");
1220            i2+=lstrlen(buffer+i2);
1221            if(i5==WM_CREATE) sw1=1;
1222            else if(i5==WM_DESTROY) sw2=1;
1223            else if(i5==WM_CLOSE) sw3=1;
1224            else if(i5==WM_NOTIFY) sw4=1;
1225            HeapDefaultFree(ppNames[i4]);
1226        }
1227        HeapDefaultFree(ppNames);
1228
1229        //WM_CREATE、WM_DESTROY、WM_PAINTが呼び出されていない場合
1230        if(!sw1){
1231            GetCommandByMessage(i,"Create",0,buffer+i2,"\t\t");
1232            i2+=lstrlen(buffer+i2);
1233        }
1234        if(!sw2){
1235            GetCommandByMessage(i,"Destroy",0,buffer+i2,"\t\t");
1236            i2+=lstrlen(buffer+i2);
1237        }
1238        if(!sw3){
1239            GetCommandByMessage(i,"QueryClose",0,buffer+i2,"\t\t");
1240            i2+=lstrlen(buffer+i2);
1241        }
1242
1243        //アイテムメッセージ郡(WM_NOTIFY)
1244        if(pItemEventInfo[0].IdName){
1245            i3=i2;
1246            lstrcpy(buffer+i2,"\t\tCase WM_NOTIFY\r\n");
1247            i2+=lstrlen(buffer+i2);
1248            if(sw4){
1249                sprintf(buffer+i2,"\t\t\t%s_Notify(ByVal (lParam As *NMHDR))\r\n",pWindowInfo->GetName().c_str());
1250                i2+=lstrlen(buffer+i2);
1251            }
1252            lstrcpy(buffer+i2,"\t\t\tDim pnmHdr As *NMHDR\r\n");
1253            i2+=lstrlen(buffer+i2);
1254            lstrcpy(buffer+i2,"\t\t\tpnmHdr=lParam As *NMHDR\r\n");
1255            i2+=lstrlen(buffer+i2);
1256            lstrcpy(buffer+i2,"\t\t\tSelect Case LOWORD(wParam)\r\n");
1257            i2+=lstrlen(buffer+i2);
1258
1259            if(GetNotifyCommandByItemMessage(pWindowInfo,pItemEventInfo,buffer+i2,"\t\t\t\t")){
1260                i2+=lstrlen(buffer+i2);
1261
1262                lstrcpy(buffer+i2,"\t\t\tEnd Select\r\n");
1263                i2+=lstrlen(buffer+i2);
1264            }
1265            else{
1266                //WM_NOTIFYを削除
1267                i2=i3;
1268                if(sw4) goto DefaultNotifyEvent;
1269            }
1270        }
1271        else if(sw4){
1272DefaultNotifyEvent:
1273            lstrcpy(buffer+i2,"\t\tCase WM_NOTIFY\r\n");
1274            i2+=lstrlen(buffer+i2);
1275            sprintf(buffer+i2,"\t\t\t%s_Notify(ByVal (lParam As *NMHDR))\r\n",pWindowInfo->GetName().c_str());
1276            i2+=lstrlen(buffer+i2);
1277        }
1278
1279        //アイテムメッセージ郡(WM_COMMAND)
1280        if(pItemEventInfo[0].IdName){
1281            lstrcpy(buffer+i2,"\t\tCase WM_COMMAND\r\n");
1282            i2+=lstrlen(buffer+i2);
1283            lstrcpy(buffer+i2,"\t\t\tSelect Case LOWORD(wParam)\r\n");
1284            i2+=lstrlen(buffer+i2);
1285
1286            //pItemEventInfoのIdName、EventNameメンバのメモリ解放はこの関数内で行う
1287            GetCommandByItemMessage(pWindowInfo,pItemEventInfo,buffer+i2,"\t\t\t\t");
1288            i2+=lstrlen(buffer+i2);
1289
1290            lstrcpy(buffer+i2,"\t\t\tEnd Select\r\n");
1291            i2+=lstrlen(buffer+i2);
1292        }
1293        HeapDefaultFree(pItemEventInfo);
1294
1295        // DefWindowProc関数
1296        lstrcpy(buffer+i2,"\t\tCase Else\r\n");
1297        i2+=lstrlen(buffer+i2);
1298        sprintf(buffer+i2,"\t\t\tEventCall_%s=DefWindowProc(hWnd,message,wParam,lParam)\r\n",pWindowInfo->GetName().c_str());
1299        i2+=lstrlen(buffer+i2);
1300        lstrcpy(buffer+i2,"\t\t\tExit Function\r\n");
1301        i2+=lstrlen(buffer+i2);
1302
1303        lstrcpy(buffer+i2,"\tEnd Select\r\n");
1304        i2+=lstrlen(buffer+i2);
1305
1306        sprintf(buffer+i2,"\tEventCall_%s=0\r\n",pWindowInfo->GetName().c_str());
1307        i2+=lstrlen(buffer+i2);
1308        lstrcpy(buffer+i2,"End Function\r\n");
1309        i2+=lstrlen(buffer+i2);
1310
1311        while(i2>65535*(size-1)){
1312            size++;
1313            buffer=(char *)HeapReAlloc(hHeap,0,buffer,65535*size);
1314        }
1315
1316        i++;
1317    }
1318
1319
1320    //////////////////////////
1321    //ダイアログボックス関連
1322
1323    //クラス登録
1324    lstrcpy(buffer+i2,"\r\nFunction DefaultCallProc(hWnd As HWND, message As DWord, wParam As WPARAM, lParam As LPARAM) As LRESULT\r\n");
1325    i2+=lstrlen(buffer+i2);
1326    lstrcpy(buffer+i2,"\tDefaultCallProc=DefWindowProc(hWnd,message,wParam,lParam)\r\n");
1327    i2+=lstrlen(buffer+i2);
1328    lstrcpy(buffer+i2,"End Function\r\n");
1329    i2+=lstrlen(buffer+i2);
1330    lstrcpy(buffer+i2,"\r\nDim _RadSys_dlgwcl As WNDCLASSEX\r\n");
1331    i2+=lstrlen(buffer+i2);
1332    lstrcpy(buffer+i2,"FillMemory(VarPtr(_RadSys_dlgwcl),Len(_RadSys_dlgwcl),0)\r\n");
1333    i2+=lstrlen(buffer+i2);
1334    lstrcpy(buffer+i2,"_RadSys_dlgwcl.cbSize=Len(_RadSys_dlgwcl)\r\n");
1335    i2+=lstrlen(buffer+i2);
1336    lstrcpy(buffer+i2,"_RadSys_dlgwcl.hInstance=GetModuleHandle(0)\r\n");
1337    i2+=lstrlen(buffer+i2);
1338    lstrcpy(buffer+i2,"_RadSys_dlgwcl.style=CS_HREDRAW or CS_VREDRAW or CS_DBLCLKS\r\n");
1339    i2+=lstrlen(buffer+i2);
1340    lstrcpy(buffer+i2,"_RadSys_dlgwcl.hIcon=LoadIcon(NULL,MAKEINTRESOURCE(IDI_APPLICATION))\r\n");
1341    i2+=lstrlen(buffer+i2);
1342    lstrcpy(buffer+i2,"_RadSys_dlgwcl.hIconSm=LoadIcon(NULL,MAKEINTRESOURCE(IDI_WINLOGO))\r\n");
1343    i2+=lstrlen(buffer+i2);
1344    lstrcpy(buffer+i2,"_RadSys_dlgwcl.hCursor=LoadCursor(NULL,MAKEINTRESOURCE(IDC_ARROW))\r\n");
1345    i2+=lstrlen(buffer+i2);
1346    lstrcpy(buffer+i2,"_RadSys_dlgwcl.lpszClassName=\"NORMALDLG\"\r\n");
1347    i2+=lstrlen(buffer+i2);
1348    lstrcpy(buffer+i2,"_RadSys_dlgwcl.hbrBackground=h3DFaceBrush\r\n");
1349    i2+=lstrlen(buffer+i2);
1350    lstrcpy(buffer+i2,"_RadSys_dlgwcl.lpfnWndProc=AddressOf(DefaultCallProc)\r\n");
1351    i2+=lstrlen(buffer+i2);
1352    lstrcpy(buffer+i2,"RegisterClassEx(_RadSys_dlgwcl)\r\n");
1353    i2+=lstrlen(buffer+i2);
1354
1355    //DialogBox関数
1356    lstrcpy(buffer+i2,"\r\nFunction DialogBox(hOwnerWnd As HWND, TemplateName As LPSTR) As LONG_PTR\r\n");
1357    i2+=lstrlen(buffer+i2);
1358    lstrcpy(buffer+i2,"\tDim hDlg As HWND\r\n");
1359    i2+=lstrlen(buffer+i2);
1360    sw1=0;
1361    i=0;
1362    BOOST_FOREACH( ActiveBasic::PM::WindowInfo *pWindowInfo, projectInfo.windowInfos )
1363    {
1364        if(pWindowInfo->type==WNDTYPE_MODALDLG){
1365            if(sw1==0){
1366                sprintf(buffer+i2,"\tIf lstrcmp(TemplateName,\"%s\")=0 Then\r\n",pWindowInfo->GetName().c_str());
1367                i2+=lstrlen(buffer+i2);
1368                sw1=1;
1369            }
1370            else{
1371                sprintf(buffer+i2,"\tElseIf lstrcmp(TemplateName,\"%s\")=0 Then\r\n",pWindowInfo->GetName().c_str());
1372                i2+=lstrlen(buffer+i2);
1373            }
1374            sprintf(buffer+i2,"\t\t%s=CreateWindowEx(&H%08x,\"NORMALDLG\",\"%s\",&H%08x,%d,%d,%d,%d,hOwnerWnd,NULL As HMENU,GetModuleHandle(0),0)\r\n",
1375                pWindowInfo->GetHandleName().c_str(),
1376                pWindowInfo->GetExStyle(),
1377                pWindowInfo->GetCaption().c_str(),
1378                pWindowInfo->GetStyle(),
1379                pWindowInfo->pos.x,
1380                pWindowInfo->pos.y,
1381                pWindowInfo->size.cx,
1382                pWindowInfo->size.cy);
1383            i2+=lstrlen(buffer+i2);
1384            sprintf(buffer+i2,"\t\thDlg=%s\r\n",
1385                pWindowInfo->GetHandleName().c_str());
1386            i2+=lstrlen(buffer+i2);
1387            if(bAvailUserProc[i]){
1388                sprintf(buffer+i2,"\t\tSetWindowLongPtr(%s,GWLP_WNDPROC,AddressOf(%s) As LONG_PTR)\r\n",
1389                    pWindowInfo->GetHandleName().c_str(),
1390                    pWindowInfo->CallBackName);
1391            }
1392            else{
1393                sprintf(buffer+i2,"\t\tSetWindowLongPtr(%s,GWLP_WNDPROC,AddressOf(EventCall_%s) As LONG_PTR)\r\n",
1394                    pWindowInfo->GetHandleName().c_str(),
1395                    pWindowInfo->GetName().c_str());
1396            }
1397            i2+=lstrlen(buffer+i2);
1398            sprintf(buffer+i2,"\t\tSendMessage(%s,WM_INITDIALOG,0,0)\r\n",pWindowInfo->GetHandleName().c_str());
1399            i2+=lstrlen(buffer+i2);
1400            if( pWindowInfo->HasIcon() )
1401            {
1402                sprintf(buffer+i2,"\t\tSendMessage(%s,WM_SETICON,ICON_SMALL,LoadIcon(GetModuleHandle(0),MAKEINTRESOURCE(%s)) As LPARAM)\r\n",pWindowInfo->GetHandleName().c_str(),pWindowInfo->GetIconResourceName().c_str());
1403                i2+=lstrlen(buffer+i2);
1404            }
1405            sprintf(buffer+i2,"\t\tShowWindow(%s,SW_SHOW)\r\n",pWindowInfo->GetHandleName().c_str());
1406            i2+=lstrlen(buffer+i2);
1407        }
1408        while(i2>65535*(size-1)){
1409            size++;
1410            buffer=(char *)HeapReAlloc(hHeap,0,buffer,65535*size);
1411        }
1412        i++;
1413    }
1414    if(sw1){
1415        lstrcpy(buffer+i2,"\tElse\r\n");
1416        i2+=lstrlen(buffer+i2);
1417        lstrcpy(buffer+i2,"\t\tExit Function\r\n");
1418        i2+=lstrlen(buffer+i2);
1419        lstrcpy(buffer+i2,"\tEnd If\r\n");
1420        i2+=lstrlen(buffer+i2);
1421        lstrcpy(buffer+i2,"\tEnableWindow(hOwnerWnd,0)\r\n\r\n");
1422        i2+=lstrlen(buffer+i2);
1423        lstrcpy(buffer+i2,"\tDim msg As MSG, iResult As Long\r\n");
1424        i2+=lstrlen(buffer+i2);
1425        lstrcpy(buffer+i2,"\tDo\r\n");
1426        i2+=lstrlen(buffer+i2);
1427        lstrcpy(buffer+i2,"\t\tiResult=GetMessage(msg,0,0,0)\r\n");
1428        i2+=lstrlen(buffer+i2);
1429        lstrcpy(buffer+i2,"\t\tIf iResult=0 or iResult=-1 Then Exit Do\r\n");
1430        i2+=lstrlen(buffer+i2);
1431        lstrcpy(buffer+i2,"\t\tIf IsDialogMessage(hDlg,msg) Then Continue\r\n");
1432        i2+=lstrlen(buffer+i2);
1433        lstrcpy(buffer+i2,"\t\tTranslateMessage(msg)\r\n");
1434        i2+=lstrlen(buffer+i2);
1435        lstrcpy(buffer+i2,"\t\tDispatchMessage(msg)\r\n");
1436        i2+=lstrlen(buffer+i2);
1437        lstrcpy(buffer+i2,"\tLoop\r\n");
1438        i2+=lstrlen(buffer+i2);
1439        lstrcpy(buffer+i2,"\tDialogBox=msg.wParam\r\n");
1440        i2+=lstrlen(buffer+i2);
1441    }
1442    lstrcpy(buffer+i2,"End Function\r\n");
1443    i2+=lstrlen(buffer+i2);
1444
1445    //EndDialog関数
1446    lstrcpy(buffer+i2,"Sub EndDialog(hWnd As HWND, lResult As Long)\r\n");
1447    i2+=lstrlen(buffer+i2);
1448    lstrcpy(buffer+i2,"\tEnableWindow(GetWindow(hWnd,GW_OWNER),1)\r\n");
1449    i2+=lstrlen(buffer+i2);
1450    lstrcpy(buffer+i2,"\tDestroyWindow(hWnd)\r\n");
1451    i2+=lstrlen(buffer+i2);
1452    lstrcpy(buffer+i2,"\tPostMessage(0,WM_QUIT,lResult,0)\r\n");
1453    i2+=lstrlen(buffer+i2);
1454    lstrcpy(buffer+i2,"End Sub\r\n");
1455    i2+=lstrlen(buffer+i2);
1456
1457    //CreateDialog関数
1458    lstrcpy(buffer+i2,"\r\nFunction CreateDialog(hOwnerWnd As HWND, TemplateName As LPSTR) As HWND\r\n");
1459    i2+=lstrlen(buffer+i2);
1460    i=0;
1461    BOOST_FOREACH( ActiveBasic::PM::WindowInfo *pWindowInfo, projectInfo.windowInfos )
1462    {
1463        if(pWindowInfo->type==WNDTYPE_MODELESSDLG){
1464            sprintf(buffer+i2,"\tIf lstrcmp(TemplateName,\"%s\")=0 Then\r\n",pWindowInfo->GetName().c_str());
1465            i2+=lstrlen(buffer+i2);
1466
1467            sprintf(buffer+i2,"\t\t%s=CreateWindowEx(&H%08x,\"NORMALDLG\",\"%s\",&H%08x,%d,%d,%d,%d,hOwnerWnd,NULL As HMENU,GetModuleHandle(0),0)\r\n",
1468                pWindowInfo->GetHandleName().c_str(),
1469                pWindowInfo->GetExStyle(),
1470                pWindowInfo->GetCaption().c_str(),
1471                pWindowInfo->GetStyle(),
1472                pWindowInfo->pos.x,
1473                pWindowInfo->pos.y,
1474                pWindowInfo->size.cx,
1475                pWindowInfo->size.cy);
1476            i2+=lstrlen(buffer+i2);
1477            sprintf(buffer+i2,"\t\tCreateDialog=%s\r\n",pWindowInfo->GetHandleName().c_str());
1478            i2+=lstrlen(buffer+i2);
1479            if(bAvailUserProc[i]){
1480                sprintf(buffer+i2,"\t\tSetWindowLongPtr(%s,GWLP_WNDPROC,AddressOf(%s) As LONG_PTR)\r\n",
1481                    pWindowInfo->GetHandleName().c_str(),
1482                    pWindowInfo->CallBackName);
1483            }
1484            else{
1485                sprintf(buffer+i2,"\t\tSetWindowLongPtr(%s,GWLP_WNDPROC,AddressOf(EventCall_%s) As LONG_PTR)\r\n",
1486                    pWindowInfo->GetHandleName().c_str(),
1487                    pWindowInfo->GetName().c_str());
1488            }
1489            i2+=lstrlen(buffer+i2);
1490            sprintf(buffer+i2,"\t\tSendMessage(%s,WM_INITDIALOG,0,0)\r\n",pWindowInfo->GetHandleName().c_str());
1491            i2+=lstrlen(buffer+i2);
1492            if( pWindowInfo->HasIcon() )
1493            {
1494                sprintf(buffer+i2,"\t\tSendMessage(%s,WM_SETICON,ICON_SMALL,LoadIcon(GetModuleHandle(0),MAKEINTRESOURCE(%s)) As LPARAM)\r\n",pWindowInfo->GetHandleName().c_str(),pWindowInfo->GetIconResourceName().c_str());
1495                i2+=lstrlen(buffer+i2);
1496            }
1497            sprintf(buffer+i2,"\tEnd If\r\n",pWindowInfo->GetName().c_str());
1498            i2+=lstrlen(buffer+i2);
1499        }
1500        while(i2>65535*(size-1)){
1501            size++;
1502            buffer=(char *)HeapReAlloc(hHeap,0,buffer,65535*size);
1503        }
1504        i++;
1505    }
1506    lstrcpy(buffer+i2,"End Function\r\n");
1507    i2+=lstrlen(buffer+i2);
1508
1509
1510    ///////////////////////
1511    // 保存(Callback.wbp)
1512    sprintf(temporary,"%sCallback.wbp",projectInfo.GetWorkDir().GetPath().c_str() );
1513    WriteBuffer(temporary,buffer,i2);
1514
1515
1516
1517    lstrcpy(buffer,"'このファイルはウィンドウ定義ファイル(*.wnd)をもとに生成されています\r\n\r\n");
1518    i2=lstrlen(buffer);
1519
1520    lstrcpy(buffer+i2,"Dim _RadSys_wcl As WNDCLASSEX\r\n");
1521    i2+=lstrlen(buffer+i2);
1522    lstrcpy(buffer+i2,"FillMemory(VarPtr(_RadSys_wcl),Len(_RadSys_wcl),0)\r\n");
1523    i2+=lstrlen(buffer+i2);
1524    lstrcpy(buffer+i2,"_RadSys_wcl.cbSize=Len(_RadSys_wcl)\r\n");
1525    i2+=lstrlen(buffer+i2);
1526    lstrcpy(buffer+i2,"_RadSys_wcl.hInstance=GetModuleHandle(0)\r\n");
1527    i2+=lstrlen(buffer+i2);
1528    lstrcpy(buffer+i2,"_RadSys_wcl.style=CS_HREDRAW or CS_VREDRAW or CS_DBLCLKS\r\n");
1529    i2+=lstrlen(buffer+i2);
1530    lstrcpy(buffer+i2,"_RadSys_wcl.hCursor=LoadCursor(NULL,MAKEINTRESOURCE(IDC_ARROW))\r\n");
1531    i2+=lstrlen(buffer+i2);
1532
1533    i=0;
1534    BOOST_FOREACH( ActiveBasic::PM::WindowInfo *pWindowInfo, projectInfo.windowInfos )
1535    {
1536        if(pWindowInfo->type==WNDTYPE_DEFAULT){
1537            //////////////////////
1538            //通常ウィンドウ作成
1539
1540            lstrcpy(buffer+i2,"\r\n");
1541            i2+=2;
1542
1543            if( pWindowInfo->HasIcon() )
1544            {
1545                sprintf(buffer+i2,"_RadSys_wcl.hIcon=LoadIcon(_RadSys_wcl.hInstance,MAKEINTRESOURCE(%s))\r\n",pWindowInfo->GetIconResourceName().c_str());
1546                i2+=lstrlen(buffer+i2);
1547                sprintf(buffer+i2,"_RadSys_wcl.hIconSm=LoadIcon(_RadSys_wcl.hInstance,MAKEINTRESOURCE(%s))\r\n",pWindowInfo->GetIconResourceName().c_str());
1548                i2+=lstrlen(buffer+i2);
1549            }
1550            else{
1551                lstrcpy(buffer+i2,"_RadSys_wcl.hIcon=LoadIcon(NULL,MAKEINTRESOURCE(IDI_APPLICATION))\r\n");
1552                i2+=lstrlen(buffer+i2);
1553                lstrcpy(buffer+i2,"_RadSys_wcl.hIconSm=LoadIcon(NULL,MAKEINTRESOURCE(IDI_WINLOGO))\r\n");
1554                i2+=lstrlen(buffer+i2);
1555            }
1556
1557            sprintf(buffer+i2,"_RadSys_wcl.lpszClassName=\"NORMAL%d\"\r\n",i);
1558            i2+=lstrlen(buffer+i2);
1559            if(bAvailUserProc[i])
1560                sprintf(buffer+i2,"_RadSys_wcl.lpfnWndProc=AddressOf(%s)\r\n",pWindowInfo->CallBackName);
1561            else sprintf(buffer+i2,"_RadSys_wcl.lpfnWndProc=AddressOf(EventCall_%s)\r\n",pWindowInfo->GetName().c_str());
1562            i2+=lstrlen(buffer+i2);
1563            if(pWindowInfo->GetBackgroundColor()==COLOR_3DFACE)
1564                lstrcpy(buffer+i2,"_RadSys_wcl.hbrBackground=h3DFaceBrush\r\n");
1565            else if(pWindowInfo->GetBackgroundColor()==-(int)RGB(255,255,255))
1566                lstrcpy(buffer+i2,"_RadSys_wcl.hbrBackground=GetStockObject(WHITE_BRUSH)\r\n");
1567            else if(pWindowInfo->GetBackgroundColor()==-(int)RGB(0,0,0))
1568                lstrcpy(buffer+i2,"_RadSys_wcl.hbrBackground=GetStockObject(BLACK_BRUSH)\r\n");
1569            else if(pWindowInfo->GetBackgroundColor()<=0||
1570                pWindowInfo->GetBackgroundColor()>=0x1000){
1571                //色指定またはビットマップ
1572                sprintf(buffer+i2,"_RadSys_wcl.hbrBackground=_RadSys_hBackBrush%d\r\n",i);
1573            }
1574            i2+=lstrlen(buffer+i2);
1575            lstrcpy(buffer+i2,"RegisterClassEx(_RadSys_wcl)\r\n");
1576            i2+=lstrlen(buffer+i2);
1577            sprintf(buffer+i2,"CreateWindowEx(&H%08x,\"%s%d\",\"%s\",&H%08x,%d,%d,%d,%d,0,0,GetModuleHandle(0),0)\r\n",
1578                pWindowInfo->GetExStyle(),
1579                pWindowInfo->GetClassName().c_str(), i,
1580                pWindowInfo->GetCaption().c_str(),
1581                pWindowInfo->GetStyle(),
1582                pWindowInfo->pos.x,
1583                pWindowInfo->pos.y,
1584                pWindowInfo->size.cx,
1585                pWindowInfo->size.cy);
1586            i2+=lstrlen(buffer+i2);
1587        }
1588
1589        while(i2>65535*(size-1)){
1590            size++;
1591            buffer=(char *)HeapReAlloc(hHeap,0,buffer,65535*size);
1592        }
1593
1594        i++;
1595    }
1596
1597
1598    /////////////////////////
1599    // 保存(MakeWindow.wbp)
1600    sprintf(temporary,"%sMakeWindow.wbp",projectInfo.GetWorkDir().GetPath().c_str());
1601    WriteBuffer(temporary,buffer,i2);
1602    HeapDefaultFree(buffer);
1603}
1604int GetSaveMenuData(char *buffer,int SpaceNum,MENU_INFO *pMenuInfo,int ItemNum){
1605    int i,i2;
1606    char spaces[MAX_PATH];
1607
1608    memset(spaces,' ',SpaceNum*4);
1609    spaces[SpaceNum*4]=0;
1610
1611    for(i=0,i2=0;i<ItemNum;i++){
1612        if(pMenuInfo[i].pMenuInfo){
1613            sprintf(buffer+i2,"%sPOPUP     = \"%s\",%d\r\n",spaces,pMenuInfo[i].caption,pMenuInfo[i].state);
1614            i2+=lstrlen(buffer+i2);
1615            i2+=GetSaveMenuData(buffer+i2,SpaceNum+1,pMenuInfo[i].pMenuInfo,pMenuInfo[i].NumberOfMenu);
1616            sprintf(buffer+i2,"%sEND\r\n",spaces);
1617            i2+=lstrlen(buffer+i2);
1618        }
1619        else if(pMenuInfo[i].type==MFT_STRING){
1620            sprintf(buffer+i2,"%sITEM      = %s,\"%s\",%d\r\n",spaces,pMenuInfo[i].IdName,pMenuInfo[i].caption,pMenuInfo[i].state);
1621            i2+=lstrlen(buffer+i2);
1622        }
1623        else if(pMenuInfo[i].type==MFT_SEPARATOR){
1624            sprintf(buffer+i2,"%sSEPARATOR\r\n",spaces);
1625            i2+=lstrlen(buffer+i2);
1626        }
1627    }
1628    return i2;
1629}
1630void SaveWindowFile( char *path, const ActiveBasic::PM::WindowInfos &windowInfos )
1631{
1632    extern HANDLE hHeap;
1633    extern MDIINFO MdiInfo[MAX_WNDNUM];
1634    int i,i2,size;
1635    char *buffer,*temporary;
1636
1637    size=2;
1638    buffer=(char *)HeapAlloc(hHeap,0,GENERAL_SIZE*size);
1639    i2=0;
1640    BOOST_FOREACH( ActiveBasic::PM::WindowInfo *pWindowInfo, projectInfo.windowInfos )
1641    {
1642        sprintf(buffer+i2,"WINDOW:%s\r\n",pWindowInfo->GetName().c_str());
1643        i2+=lstrlen(buffer+i2);
1644        sprintf(buffer+i2,"    HANDLE    = %s\r\n",pWindowInfo->GetHandleName().c_str());
1645        i2+=lstrlen(buffer+i2);
1646        sprintf(buffer+i2,"    POINT     = %d,%d\r\n",pWindowInfo->pos.x,pWindowInfo->pos.y);
1647        i2+=lstrlen(buffer+i2);
1648        sprintf(buffer+i2,"    SIZE      = %d,%d\r\n",pWindowInfo->size.cx,pWindowInfo->size.cy);
1649        i2+=lstrlen(buffer+i2);
1650        sprintf(buffer+i2,"    CAPTION   = \"%s\"\r\n",pWindowInfo->GetCaption().c_str());
1651        i2+=lstrlen(buffer+i2);
1652        sprintf(buffer+i2,"    STYLE     = &H%08x\r\n",pWindowInfo->GetStyle());
1653        i2+=lstrlen(buffer+i2);
1654        sprintf(buffer+i2,"    EXSTYLE   = &H%08x\r\n",pWindowInfo->GetExStyle());
1655        i2+=lstrlen(buffer+i2);
1656        if( pWindowInfo->HasMenu() )
1657        {
1658            sprintf(buffer+i2,"    MENUID    = %s\r\n",pWindowInfo->GetMenuIdName().c_str());
1659            i2+=lstrlen(buffer+i2);
1660        }
1661        sprintf(buffer+i2,"    BGCOLOR   = %d\r\n",pWindowInfo->GetBackgroundColor());
1662        i2+=lstrlen(buffer+i2);
1663        sprintf(buffer+i2,"    FONT      = %d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,\"%s\"\r\n",
1664            pWindowInfo->LogFont.lfHeight,
1665            pWindowInfo->LogFont.lfWidth,
1666            pWindowInfo->LogFont.lfEscapement,
1667            pWindowInfo->LogFont.lfOrientation,
1668            pWindowInfo->LogFont.lfWeight,
1669            pWindowInfo->LogFont.lfItalic,
1670            pWindowInfo->LogFont.lfUnderline,
1671            pWindowInfo->LogFont.lfStrikeOut,
1672            pWindowInfo->LogFont.lfCharSet,
1673            pWindowInfo->LogFont.lfOutPrecision,
1674            pWindowInfo->LogFont.lfClipPrecision,
1675            pWindowInfo->LogFont.lfQuality,
1676            pWindowInfo->LogFont.lfPitchAndFamily,
1677            pWindowInfo->LogFont.lfFaceName);
1678        i2+=lstrlen(buffer+i2);
1679        if( pWindowInfo->HasIcon() )
1680        {
1681            sprintf(buffer+i2,"    ICONID    = %s\r\n",pWindowInfo->GetIconResourceName().c_str());
1682            i2+=lstrlen(buffer+i2);
1683        }
1684        sprintf(buffer+i2,"    CLASS     = \"%s\"\r\n",pWindowInfo->GetClassName().c_str());
1685        i2+=lstrlen(buffer+i2);
1686        sprintf(buffer+i2,"    CALLBACK  = %s\r\n",pWindowInfo->CallBackName);
1687        i2+=lstrlen(buffer+i2);
1688        sprintf(buffer+i2,"    TYPE      = %d\r\n",pWindowInfo->type);
1689        i2+=lstrlen(buffer+i2);
1690        sprintf(buffer+i2,"    FILEPATH  = %s\r\n",pWindowInfo->filepath);
1691        i2+=lstrlen(buffer+i2);
1692        BOOST_FOREACH( const ActiveBasic::PM::ChildWindowInfo *pChildInfo, pWindowInfo->childWindowInfos )
1693        {
1694            temporary=SetCaptionSequence(pChildInfo->GetCaption().c_str());
1695            sprintf(buffer+i2,"    ITEM      = %s,%d,%d,%d,%d,\"%s\",&H%08x,&H%08x,%d",
1696                pChildInfo->GetName().c_str(),
1697                pChildInfo->pos.x,pChildInfo->pos.y,
1698                pChildInfo->size.cx,pChildInfo->size.cy,
1699                temporary,
1700                pChildInfo->GetStyle(),
1701                pChildInfo->GetExStyle(),
1702                pChildInfo->Control
1703            );
1704            i2+=lstrlen(buffer+i2);
1705            HeapDefaultFree(temporary);
1706            if(pChildInfo->Control==CT_IMAGEBOX){
1707                sprintf(buffer+i2,",%d,\"%s\"",pChildInfo->image.type,pChildInfo->image.path.c_str());
1708                i2+=lstrlen(buffer+i2);
1709            }
1710            lstrcpy(buffer+i2,"\r\n");
1711            i2+=lstrlen(buffer+i2);
1712            if(i2-GENERAL_SIZE<GENERAL_SIZE){
1713                size++;
1714                buffer=(char *)HeapReAlloc(hHeap,0,buffer,GENERAL_SIZE*size);
1715            }
1716        }
1717        sprintf(buffer+i2,"END\r\n",pWindowInfo->GetName().c_str());
1718        i2+=lstrlen(buffer+i2);
1719        if(i2-GENERAL_SIZE<GENERAL_SIZE){
1720            size++;
1721            buffer=(char *)HeapReAlloc(hHeap,0,buffer,GENERAL_SIZE*size);
1722        }
1723    }
1724    for(i=0;i<projectInfo.NumberOfMenu;i++){
1725        sprintf(buffer+i2,"MENU:%s\r\n",projectInfo.pMenuInfo[i].IdName);
1726        i2+=lstrlen(buffer+i2);
1727        i2+=GetSaveMenuData(buffer+i2,1,projectInfo.pMenuInfo[i].pMenuInfo,projectInfo.pMenuInfo[i].NumberOfMenu);
1728        sprintf(buffer+i2,"END\r\n",windowInfos[i]->GetName().c_str());
1729        i2+=lstrlen(buffer+i2);
1730        if(i2-GENERAL_SIZE<GENERAL_SIZE){
1731            size++;
1732            buffer=(char *)HeapReAlloc(hHeap,0,buffer,GENERAL_SIZE*size);
1733        }
1734    }
1735    WriteBuffer(path,buffer,i2);
1736    HeapDefaultFree(buffer);
1737
1738    projectInfo.ModifyOfMaterial=0;
1739}
1740
1741MENU_INFO *GetMenuData(char *buffer,int *pPos,int *pMenuNum){
1742    extern HANDLE hHeap;
1743    int i,i2,i3,i4;
1744    char temporary[MAX_PATH],*temp2,temp3[MAX_PATH];
1745    MENU_INFO *pMenuInfo;
1746
1747    temp2=(char *)HeapAlloc(hHeap,0,lstrlen(buffer)+1);
1748
1749    *pMenuNum=0;
1750    pMenuInfo=(MENU_INFO *)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,1);
1751
1752    for(i=*pPos;;i++){
1753        if(buffer[i]=='\0') return 0;
1754        if((buffer[i]=='\r'&&buffer[i+1]=='\n')||i==0){
1755            if(buffer[i]=='\r'&&buffer[i+1]=='\n')  i+=2;
1756            for(i2=0;;i++,i2++){
1757                if(!IsVariableChar(buffer[i])){
1758                    temporary[i2]=0;
1759                    break;
1760                }
1761                temporary[i2]=buffer[i];
1762            }
1763            if(i2==0){
1764                i--;
1765                continue;
1766            }
1767            if(buffer[i]=='='){
1768                for(i++,i2=0;;i++,i2++){
1769                    if((buffer[i]=='\r'&&buffer[i+1]=='\n')||buffer[i]=='\0'){
1770                        temp2[i2]=0;
1771                        break;
1772                    }
1773                    temp2[i2]=buffer[i];
1774                }
1775            }
1776            else{
1777                temp2[0]=0;
1778                i2=0;
1779            }
1780
1781
1782            if(lstrcmpi(temporary,"POPUP")==0){
1783                (*pMenuNum)++;
1784                pMenuInfo=(MENU_INFO *)HeapReAlloc(hHeap,HEAP_ZERO_MEMORY,pMenuInfo,(*pMenuNum)*sizeof(MENU_INFO));
1785                i3=*pMenuNum-1;
1786
1787                i4=GetOneParameter(temp2,0,temp3);
1788                RemoveStringQuotes(temp3);
1789                pMenuInfo[i3].caption=(char *)HeapAlloc(hHeap,0,lstrlen(temp3)+1);
1790                lstrcpy(pMenuInfo[i3].caption,temp3);
1791
1792                i4=GetOneParameter(temp2,i4,temp3);
1793                pMenuInfo[i3].state=GetValue(temp3);
1794
1795                pMenuInfo[i3].pMenuInfo=GetMenuData(buffer,&i,&pMenuInfo[i3].NumberOfMenu);
1796            }
1797            else if(lstrcmpi(temporary,"ITEM")==0){
1798                (*pMenuNum)++;
1799                pMenuInfo=(MENU_INFO *)HeapReAlloc(hHeap,HEAP_ZERO_MEMORY,pMenuInfo,(*pMenuNum)*sizeof(MENU_INFO));
1800                i3=*pMenuNum-1;
1801
1802                i4=GetOneParameter(temp2,0,temp3);
1803                pMenuInfo[i3].IdName=(char *)HeapAlloc(hHeap,0,lstrlen(temp3)+1);
1804                lstrcpy(pMenuInfo[i3].IdName,temp3);
1805
1806                i4=GetOneParameter(temp2,i4,temp3);
1807                RemoveStringQuotes(temp3);
1808                pMenuInfo[i3].caption=(char *)HeapAlloc(hHeap,0,lstrlen(temp3)+1);
1809                lstrcpy(pMenuInfo[i3].caption,temp3);
1810
1811                i4=GetOneParameter(temp2,i4,temp3);
1812                pMenuInfo[i3].state=GetValue(temp3);
1813
1814                pMenuInfo[i3].type=0;
1815            }
1816            else if(lstrcmpi(temporary,"SEPARATOR")==0){
1817                (*pMenuNum)++;
1818                pMenuInfo=(MENU_INFO *)HeapReAlloc(hHeap,HEAP_ZERO_MEMORY,pMenuInfo,(*pMenuNum)*sizeof(MENU_INFO));
1819                i3=*pMenuNum-1;
1820
1821                pMenuInfo[i3].type=MFT_SEPARATOR;
1822            }
1823            else if(lstrcmpi(temporary,"END")==0) break;
1824            i--;
1825        }
1826    }
1827    *pPos=i;
1828
1829    HeapDefaultFree(temp2);
1830
1831    return pMenuInfo;
1832}
1833_int8 OpenWindowFile(char *path){
1834    extern HANDLE hHeap;
1835    int i,i2,i3,i4,i5;
1836    char *buffer,temporary[MAX_PATH],*temp2,temp3[MAX_PATH];
1837
1838    buffer=ReadBuffer(path);
1839    if(!buffer) return 0;
1840    temp2=(char *)HeapAlloc(hHeap,0,lstrlen(buffer)+1);
1841    ChangeOrSignToDivision(temp2,buffer);
1842    KillSpaces(temp2,buffer);
1843    //temp2はこの後の処理の一時保存バッファにも利用するので解放しない
1844
1845    projectInfo.NumberOfMenu=0;
1846    projectInfo.pMenuInfo=(MENU_INFO *)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,1);
1847
1848    projectInfo.windowInfos.Clear();
1849
1850    for(i=0,i3=0;;i++){
1851        if(buffer[i]=='\0') break;
1852        if((buffer[i]=='\r'&&buffer[i+1]=='\n')||i==0){
1853            if(buffer[i]=='\r'&&buffer[i+1]=='\n')  i+=2;
1854            for(i2=0;;i++,i2++){
1855                if(!IsVariableChar(buffer[i])){
1856                    temporary[i2]=0;
1857                    break;
1858                }
1859                temporary[i2]=buffer[i];
1860            }
1861            if(i2==0){
1862                i--;
1863                continue;
1864            }
1865            if(buffer[i]==':'||buffer[i]=='='){
1866                for(i++,i2=0;;i++,i2++){
1867                    if((buffer[i]=='\r'&&buffer[i+1]=='\n')||buffer[i]=='\0'){
1868                        temp2[i2]=0;
1869                        break;
1870                    }
1871                    temp2[i2]=buffer[i];
1872                }
1873            }
1874            else{
1875                temp2[0]=0;
1876                i2=0;
1877            }
1878
1879
1880            //////////////
1881            //ウィンドウ
1882            if(lstrcmpi(temporary,"WINDOW")==0&&i3==0){
1883                projectInfo.windowInfos.push_back( new ActiveBasic::PM::WindowInfo() );
1884                i3=1;
1885
1886                projectInfo.windowInfos.back()->SetName( temp2 );
1887            }
1888            else if(lstrcmpi(temporary,"HANDLE")==0&&i3==1){
1889                projectInfo.windowInfos.back()->SetHandleName( temp2 );
1890            }
1891            else if(lstrcmpi(temporary,"POINT")==0&&i3==1){
1892                sscanf(temp2,"%d,%d",
1893                    &projectInfo.windowInfos.back()->pos.x,
1894                    &projectInfo.windowInfos.back()->pos.y);
1895                if(projectInfo.windowInfos.back()->pos.x==-1) projectInfo.windowInfos.back()->pos.x=CW_USEDEFAULT;
1896                if(projectInfo.windowInfos.back()->pos.y==-1) projectInfo.windowInfos.back()->pos.y=CW_USEDEFAULT;
1897            }
1898            else if(lstrcmpi(temporary,"SIZE")==0&&i3==1){
1899                sscanf(temp2,"%d,%d",
1900                    &projectInfo.windowInfos.back()->size.cx,
1901                    &projectInfo.windowInfos.back()->size.cy);
1902            }
1903            else if(lstrcmpi(temporary,"CAPTION")==0&&i3==1){
1904                if(temp2[0]=='\"'&&temp2[lstrlen(temp2)-1]=='\"'){
1905                    temp2[lstrlen(temp2)-1]=0;
1906                    projectInfo.windowInfos.back()->SetCaption( temp2+1 );
1907                }
1908            }
1909            else if(lstrcmpi(temporary,"STYLE")==0&&i3==1) projectInfo.windowInfos.back()->SetStyle( GetValue(temp2) );
1910            else if(lstrcmpi(temporary,"EXSTYLE")==0&&i3==1) projectInfo.windowInfos.back()->SetExStyle( GetValue(temp2) );
1911            else if(lstrcmpi(temporary,"MENUID")==0&&i3==1){
1912                projectInfo.windowInfos.back()->SetMenuIdName( temp2 );
1913            }
1914            else if(lstrcmpi(temporary,"ID")==0&&i3==1)
1915            {
1916                // 無視
1917            }
1918            else if(lstrcmpi(temporary,"BGCOLOR")==0&&i3==1){
1919                projectInfo.windowInfos.back()->SetBackgroundColor( GetValue(temp2) );
1920                if(projectInfo.dwVersion<=3){
1921                    //プロジェクトバージョンが3以前のときは新値に変換する
1922                    if(projectInfo.windowInfos.back()->GetBackgroundColor()==-1)
1923                        projectInfo.windowInfos.back()->SetBackgroundColor( -(int)RGB(255,255,255) );
1924                }
1925            }
1926            else if(lstrcmpi(temporary,"FONT")==0&&i3==1){
1927                i5=GetOneParameter(temp2,0,temp3);
1928                projectInfo.windowInfos.back()->LogFont.lfHeight=GetValue(temp3);
1929
1930                i5=GetOneParameter(temp2,i5,temp3);
1931                projectInfo.windowInfos.back()->LogFont.lfWidth=GetValue(temp3);
1932
1933                i5=GetOneParameter(temp2,i5,temp3);
1934                projectInfo.windowInfos.back()->LogFont.lfEscapement=GetValue(temp3);
1935
1936                i5=GetOneParameter(temp2,i5,temp3);
1937                projectInfo.windowInfos.back()->LogFont.lfOrientation=GetValue(temp3);
1938
1939                i5=GetOneParameter(temp2,i5,temp3);
1940                projectInfo.windowInfos.back()->LogFont.lfWeight=GetValue(temp3);
1941
1942                i5=GetOneParameter(temp2,i5,temp3);
1943                projectInfo.windowInfos.back()->LogFont.lfItalic=(BYTE)GetValue(temp3);
1944
1945                i5=GetOneParameter(temp2,i5,temp3);
1946                projectInfo.windowInfos.back()->LogFont.lfUnderline=(BYTE)GetValue(temp3);
1947
1948                i5=GetOneParameter(temp2,i5,temp3);
1949                projectInfo.windowInfos.back()->LogFont.lfStrikeOut=(BYTE)GetValue(temp3);
1950
1951                i5=GetOneParameter(temp2,i5,temp3);
1952                projectInfo.windowInfos.back()->LogFont.lfCharSet=(BYTE)GetValue(temp3);
1953
1954                i5=GetOneParameter(temp2,i5,temp3);
1955                projectInfo.windowInfos.back()->LogFont.lfOutPrecision=(BYTE)GetValue(temp3);
1956
1957                i5=GetOneParameter(temp2,i5,temp3);
1958                projectInfo.windowInfos.back()->LogFont.lfClipPrecision=(BYTE)GetValue(temp3);
1959
1960                i5=GetOneParameter(temp2,i5,temp3);
1961                projectInfo.windowInfos.back()->LogFont.lfQuality=(BYTE)GetValue(temp3);
1962
1963                i5=GetOneParameter(temp2,i5,temp3);
1964                projectInfo.windowInfos.back()->LogFont.lfPitchAndFamily=(BYTE)GetValue(temp3);
1965
1966                i5=GetOneParameter(temp2,i5,temp3);
1967                RemoveStringQuotes(temp3);
1968                lstrcpy(projectInfo.windowInfos.back()->LogFont.lfFaceName,temp3);
1969            }
1970            else if(lstrcmpi(temporary,"ICONID")==0&&i3==1){
1971                projectInfo.windowInfos.back()->SetIconResourceName( temp2 );
1972            }
1973            else if(lstrcmpi(temporary,"CLASS")==0&&i3==1){
1974                if(temp2[0]=='\"'&&temp2[lstrlen(temp2)-1]=='\"'){
1975                    temp2[lstrlen(temp2)-1]=0;
1976                    projectInfo.windowInfos.back()->SetClassName( temp2+1 );
1977                }
1978            }
1979            else if(lstrcmpi(temporary,"CALLBACK")==0&&i3==1){
1980                projectInfo.windowInfos.back()->CallBackName=(char *)HeapAlloc(hHeap,0,i2+1);
1981                lstrcpy(projectInfo.windowInfos.back()->CallBackName,temp2);
1982            }
1983
1984            //以前のバージョンとの互換用
1985            else if(lstrcmpi(temporary,"DLGTMP")==0&&i3==1) projectInfo.windowInfos.back()->type=GetValue(temp2);
1986
1987            else if(lstrcmpi(temporary,"TYPE")==0&&i3==1) projectInfo.windowInfos.back()->type=GetValue(temp2);
1988            else if(lstrcmpi(temporary,"FILEPATH")==0&&i3==1){
1989                projectInfo.windowInfos.back()->filepath=(char *)HeapAlloc(hHeap,0,i2+1);
1990                lstrcpy(projectInfo.windowInfos.back()->filepath,temp2);
1991            }
1992            else if(lstrcmpi(temporary,"ITEM")==0&&i3==1){
1993                ActiveBasic::PM::ChildWindowInfo *pChildInfo = new ActiveBasic::PM::ChildWindowInfo();
1994
1995                //ID
1996                i5=GetOneParameter(temp2,0,temp3);
1997                pChildInfo->SetName( temp3 );
1998
1999                //位置
2000                i5=GetOneParameter(temp2,i5,temp3);
2001                pChildInfo->pos.x=GetValue(temp3);
2002                i5=GetOneParameter(temp2,i5,temp3);
2003                pChildInfo->pos.y=GetValue(temp3);
2004                i5=GetOneParameter(temp2,i5,temp3);
2005                pChildInfo->size.cx=GetValue(temp3);
2006                i5=GetOneParameter(temp2,i5,temp3);
2007                pChildInfo->size.cy=GetValue(temp3);
2008
2009                //テキスト
2010                i5=GetOneParameter(temp2,i5,temp3);
2011                RemoveStringQuotes(temp3);
2012                RestoreCaptionSequence(temp3);
2013                pChildInfo->SetCaption( temp3 );
2014
2015                //スタイル
2016                i5=GetOneParameter(temp2,i5,temp3);
2017                pChildInfo->SetStyle( GetValue(temp3) );
2018
2019                //拡張スタイル
2020                i5=GetOneParameter(temp2,i5,temp3);
2021                pChildInfo->SetExStyle( GetValue(temp3) );
2022
2023                //クラス
2024                i5=GetOneParameter(temp2,i5,temp3);
2025                pChildInfo->Control=GetValue(temp3);
2026
2027                if(pChildInfo->Control==CT_IMAGEBOX){
2028                    //イメージ ボックスの場合
2029                    i5=GetOneParameter(temp2,i5,temp3);
2030                    pChildInfo->image.type = (ActiveBasic::PM::ImageReferenceType::EnumType)GetValue(temp3);
2031                    i5=GetOneParameter(temp2,i5,temp3);
2032                    RemoveStringQuotes(temp3);
2033                    pChildInfo->image.path = temp3;
2034                }
2035
2036                projectInfo.windowInfos.back()->childWindowInfos.push_back( pChildInfo );
2037            }
2038
2039
2040            ////////////
2041            //メニュー
2042            else if(lstrcmpi(temporary,"MENU")==0&&i3==0){
2043                projectInfo.NumberOfMenu++;
2044                projectInfo.pMenuInfo=(MENU_INFO *)HeapReAlloc(hHeap,HEAP_ZERO_MEMORY,projectInfo.pMenuInfo,projectInfo.NumberOfMenu*sizeof(MENU_INFO));
2045                i4=projectInfo.NumberOfMenu-1;
2046
2047                //ID名
2048                projectInfo.pMenuInfo[i4].IdName=(char *)HeapAlloc(hHeap,0,lstrlen(temp2)+1);
2049                lstrcpy(projectInfo.pMenuInfo[i4].IdName,temp2);
2050                projectInfo.pMenuInfo[i4].pMenuInfo=GetMenuData(buffer,&i,&projectInfo.pMenuInfo[i4].NumberOfMenu);
2051                if(!projectInfo.pMenuInfo[i4].pMenuInfo){
2052                    //"ウィンドウ定義ファイルが壊れています。\n\n%s"
2053                    sprintf(temporary,STRING_ERROR_BROKEN_WNDFILE,path);
2054                    MessageBox(hOwner,temporary,STRING_ERROR,MB_OK|MB_ICONEXCLAMATION);
2055
2056                    HeapDefaultFree(temp2);
2057                    HeapDefaultFree(buffer);
2058                    return 0;
2059                }
2060            }
2061
2062
2063            else if(lstrcmpi(temporary,"END")==0&&i3) i3=0;
2064            else{
2065                //"ウィンドウ定義ファイルが壊れています。\n\n%s"
2066                sprintf(temporary,STRING_ERROR_BROKEN_WNDFILE,path);
2067                MessageBox(hOwner,temporary,APPLICATION_NAME,MB_OK|MB_ICONEXCLAMATION);
2068
2069                HeapDefaultFree(temp2);
2070                HeapDefaultFree(buffer);
2071                return 0;
2072            }
2073            i--;
2074        }
2075    }
2076
2077    HeapDefaultFree(temp2);
2078    HeapDefaultFree(buffer);
2079    return 1;
2080}
2081
2082struct NEW_WINDOW{
2083    char name[MAX_PATH];
2084    char HandleName[MAX_PATH];
2085    char CallBackName[MAX_PATH];
2086    BOOL type;
2087};
2088NEW_WINDOW NewWindow;
2089BOOL CALLBACK DlgProject_NewWindow(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam){
2090    char temporary[MAX_PATH],temp2[MAX_PATH];
2091    switch(message){
2092        case WM_INITDIALOG:
2093            SetPosCenter(hwnd);
2094            SendDlgItemMessage(hwnd,IDC_AUTOSET,BM_SETCHECK,BST_CHECKED,0);
2095            SendMessage(hwnd,WM_COMMAND,IDC_AUTOSET,0);
2096            SendDlgItemMessage(hwnd,IDC_MODALDLG,BM_SETCHECK,BST_CHECKED,0);
2097            break;
2098        case WM_COMMAND:
2099            switch(LOWORD(wParam)){
2100                case IDOK:
2101                    GetDlgItemText(hwnd,IDC_WINDOWNAME,NewWindow.name,MAX_PATH);
2102                    GetDlgItemText(hwnd,IDC_WINDOWHANDLE,NewWindow.HandleName,MAX_PATH);
2103                    GetDlgItemText(hwnd,IDC_WINDOWPROC,NewWindow.CallBackName,MAX_PATH);
2104                    if(SendDlgItemMessage(hwnd,IDC_DEFWINDOW,BM_GETCHECK,0,0))
2105                        NewWindow.type=WNDTYPE_DEFAULT;
2106                    else if(SendDlgItemMessage(hwnd,IDC_MODALDLG,BM_GETCHECK,0,0))
2107                        NewWindow.type=WNDTYPE_MODALDLG;
2108                    else if(SendDlgItemMessage(hwnd,IDC_MODELESSDLG,BM_GETCHECK,0,0))
2109                        NewWindow.type=WNDTYPE_MODELESSDLG;
2110                    EndDialog(hwnd,1);
2111                    return 1;
2112                case IDCANCEL:
2113                    EndDialog(hwnd,0);
2114                    return 1;
2115                case IDC_WINDOWNAME:
2116                    if(HIWORD(wParam)==EN_CHANGE) SendMessage(hwnd,WM_COMMAND,IDC_AUTOSET,0);
2117                    return 1;
2118                case IDC_AUTOSET:
2119                    if(SendDlgItemMessage(hwnd,IDC_AUTOSET,BM_GETCHECK,0,0)){
2120                        SendDlgItemMessage(hwnd,IDC_WINDOWHANDLE,EM_SETREADONLY,1,0);
2121                        SendDlgItemMessage(hwnd,IDC_WINDOWPROC,EM_SETREADONLY,1,0);
2122                        GetDlgItemText(hwnd,IDC_WINDOWNAME,temporary,MAX_PATH);
2123                        if(temporary[0]){
2124                            sprintf(temp2,"h%s",temporary);
2125                            SetDlgItemText(hwnd,IDC_WINDOWHANDLE,temp2);
2126                            sprintf(temp2,"%sProc",temporary);
2127                            SetDlgItemText(hwnd,IDC_WINDOWPROC,temp2);
2128                        }
2129                        else{
2130                            SetDlgItemText(hwnd,IDC_WINDOWHANDLE,"");
2131                            SetDlgItemText(hwnd,IDC_WINDOWPROC,"");
2132                        }
2133                    }
2134                    else{
2135                        SendDlgItemMessage(hwnd,IDC_WINDOWHANDLE,EM_SETREADONLY,0,0);
2136                        SendDlgItemMessage(hwnd,IDC_WINDOWPROC,EM_SETREADONLY,0,0);
2137                    }
2138                    return 1;
2139            }
2140            break;
2141    }
2142    return 0;
2143}
2144void GetDefaultWindowFont(LOGFONT *LogFont){
2145    LogFont->lfHeight=-12;
2146    LogFont->lfWidth=0;
2147    LogFont->lfEscapement=0;
2148    LogFont->lfOrientation=0;
2149    LogFont->lfWeight=FW_REGULAR;
2150    LogFont->lfItalic=0;
2151    LogFont->lfUnderline=0;
2152    LogFont->lfStrikeOut=0;
2153    LogFont->lfCharSet=SHIFTJIS_CHARSET;
2154    LogFont->lfOutPrecision=OUT_STROKE_PRECIS;
2155    LogFont->lfClipPrecision=CLIP_STROKE_PRECIS;
2156    LogFont->lfQuality=DRAFT_QUALITY;
2157    LogFont->lfPitchAndFamily=FF_SWISS;
2158    lstrcpy(LogFont->lfFaceName,"MS Pゴシック");
2159}
2160void Project_Window_Insert(void){
2161    extern HANDLE hHeap;
2162    char temporary[MAX_PATH],temp2[1024],*pTemp;
2163
2164    if(!DialogBox(hResInst,MAKEINTRESOURCE(IDD_PROJECT_NEWWINDOW),hOwner,(DLGPROC)DlgProject_NewWindow)) return;
2165
2166    //重複チェック
2167    sprintf(temporary,"%s.sbp",NewWindow.name);
2168    if(projectInfo.pobj_DBFileInfo->dupli_check(temporary)){
2169        sprintf(temp2,"\"%s\" ファイルは既にプロジェクト内に存在します。",temporary);
2170        MessageBox(hOwner,temp2,APPLICATION_NAME,MB_OK|MB_ICONEXCLAMATION);
2171        return;
2172    }
2173    BOOST_FOREACH( ActiveBasic::PM::WindowInfo *pWindowInfo, projectInfo.windowInfos )
2174    {
2175        if(lstrcmpi(NewWindow.name,pWindowInfo->GetName().c_str())==0){
2176            //"\"%s\" ウィンドウは既にプロジェクト内に存在します。"
2177            sprintf(temporary,STRING_DUPLICATIONERROR_WINDOW_IN_PROJECT,pWindowInfo->GetName().c_str());
2178            MessageBox(hOwner,temporary,STRING_ERROR,MB_OK|MB_ICONEXCLAMATION);
2179            return;
2180        }
2181        if(lstrcmpi(NewWindow.HandleName,pWindowInfo->GetHandleName().c_str())==0){
2182            //"\"%s\" ハンドルは既にプロジェクト内に存在します。"
2183            sprintf(temporary,STRING_DUPLICATIONERROR_HANDLE_IN_PROJECT,pWindowInfo->GetHandleName().c_str());
2184            MessageBox(hOwner,temporary,STRING_ERROR,MB_OK|MB_ICONEXCLAMATION);
2185            return;
2186        }
2187        if(lstrcmpi(NewWindow.CallBackName,pWindowInfo->CallBackName)==0){
2188            //"\"%s\" プロシージャは既にプロジェクト内に存在します。"
2189            sprintf(temporary,STRING_DUPLICATIONERROR_PROC_IN_PROJECT,pWindowInfo->CallBackName);
2190            MessageBox(hOwner,temporary,STRING_ERROR,MB_OK|MB_ICONEXCLAMATION);
2191            return;
2192        }
2193    }
2194
2195    //projectInfo.windowInfos構造体コレクションに追加
2196    projectInfo.windowInfos.push_back( new ActiveBasic::PM::WindowInfo() );
2197
2198
2199    ///////////////////////////////////////
2200    //projectInfo.windowInfos構造体を設定
2201
2202    //ウィンドウ名
2203    projectInfo.windowInfos.back()->SetName( NewWindow.name );
2204
2205    //ハンドル名
2206    projectInfo.windowInfos.back()->SetHandleName( NewWindow.HandleName );
2207
2208    //位置情報
2209    projectInfo.windowInfos.back()->pos.x=-1;
2210    projectInfo.windowInfos.back()->pos.y=-1;
2211    projectInfo.windowInfos.back()->size.cx=480;
2212    projectInfo.windowInfos.back()->size.cy=360;
2213
2214    //ウィンドウテキスト
2215    projectInfo.windowInfos.back()->SetCaption( NewWindow.name );
2216
2217    //スタイル
2218    switch(NewWindow.type){
2219        case WNDTYPE_DEFAULT:
2220            //通常ウィンドウ
2221            projectInfo.windowInfos.back()->SetStyle( WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_THICKFRAME|WS_MINIMIZEBOX|WS_MAXIMIZEBOX );
2222            break;
2223        case WNDTYPE_MODALDLG:
2224        case WNDTYPE_MODELESSDLG:
2225            //ダイアログ テンプレート(最大化、最小化ボタンをなくして、細枠にする)
2226            projectInfo.windowInfos.back()->SetStyle( WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU );
2227            break;
2228    }
2229
2230    //拡張スタイル
2231    projectInfo.windowInfos.back()->SetExStyle( 0 );
2232
2233    //メニュー
2234    projectInfo.windowInfos.back()->SetMenuIdName( "" );
2235
2236    //背景色
2237    projectInfo.windowInfos.back()->SetBackgroundColor( COLOR_3DFACE );
2238
2239    //フォント
2240    GetDefaultWindowFont(&projectInfo.windowInfos.back()->LogFont);
2241
2242    //アイコン
2243    projectInfo.windowInfos.back()->SetIconResourceName( "" );
2244
2245    //クラス名
2246    lstrcpy(temporary,"NORMAL");
2247    projectInfo.windowInfos.back()->SetClassName( temporary );
2248
2249    //コールバック関数名
2250    projectInfo.windowInfos.back()->CallBackName=(char *)HeapAlloc(hHeap,0,lstrlen(NewWindow.CallBackName)+1);
2251    lstrcpy(projectInfo.windowInfos.back()->CallBackName,NewWindow.CallBackName);
2252
2253    //タイプ識別
2254    projectInfo.windowInfos.back()->type=NewWindow.type;
2255
2256
2257    //メッセージ処理ファイル名
2258    sprintf(temporary,"%s.ab",projectInfo.windowInfos.back()->GetName().c_str());
2259    projectInfo.windowInfos.back()->filepath=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+1);
2260    lstrcpy(projectInfo.windowInfos.back()->filepath,temporary);
2261
2262
2263    //////////////////////////
2264    // メッセージ処理ファイル
2265    //////////////////////////
2266
2267    //テンプレートを読み込む
2268    const std::string newWindowTemplateSbpPath = ActiveBasic::Common::Environment::GetAbdevSystemDirPath() + "\\new_window_template.sbp";
2269    pTemp = ReadBuffer( newWindowTemplateSbpPath );
2270
2271    //#name#をプロジェクト名に置換
2272    pTemp=PermutationWndPgmTemplate(pTemp,
2273        projectInfo.GetName().c_str(),
2274        NewWindow.name,
2275        NewWindow.HandleName,
2276        NewWindow.CallBackName);
2277
2278    sprintf(temporary,"%s%s.ab",projectInfo.GetWorkDir().GetPath().c_str(),projectInfo.windowInfos.back()->GetName().c_str());
2279
2280    //書き込み
2281    WriteBuffer(temporary,pTemp,lstrlen(pTemp));
2282    Project_File_Insert(temporary);
2283
2284    HeapDefaultFree(pTemp);
2285
2286
2287    //////////////////////
2288    //ツリービューに追加
2289
2290    extern HWND hMaterialTreeView;
2291    TV_INSERTSTRUCT tv;
2292    tv.hInsertAfter=TVI_SORT;
2293    tv.item.mask=TVIF_TEXT|TVIF_IMAGE|TVIF_SELECTEDIMAGE;
2294    tv.item.iImage=2;
2295    tv.item.iSelectedImage=2;
2296    tv.hParent=projectInfo.hWindowTreeItem;
2297    lstrcpy( temp2, projectInfo.windowInfos.back()->GetName().c_str() );
2298    tv.item.pszText = temp2;
2299
2300    projectInfo.windowInfos.back()->hTreeItem=TreeView_InsertItem(hMaterialTreeView,&tv);
2301
2302    TreeView_SelectItem(hMaterialTreeView,projectInfo.windowInfos.back()->hTreeItem);
2303
2304
2305    projectInfo.ModifyOfMaterial=1;
2306
2307    NewRadWindow( *projectInfo.windowInfos.back() );
2308}
2309void Project_Window_Delete(int WndInfoNum){
2310    extern HANDLE hHeap;
2311    extern MDIINFO MdiInfo[MAX_WNDNUM];
2312    int i;
2313
2314    ActiveBasic::PM::WindowInfo *pWindowInfo = projectInfo.windowInfos[WndInfoNum];
2315
2316    //ウィンドウが開かれている場合は閉じる
2317    for(i=0;i<MAX_WNDNUM;i++){
2318        if(MdiInfo[i].hwnd&&lstrcmpi(pWindowInfo->GetName().c_str(),MdiInfo[i].path)==0){
2319            SendMessage(MdiInfo[i].hwnd,WM_CLOSE,0,0);
2320            break;
2321        }
2322    }
2323
2324    //ウィンドウ情報のメモリを解放
2325    HeapDefaultFree(pWindowInfo->filepath);
2326    HeapDefaultFree(pWindowInfo->CallBackName);
2327
2328    //子ウィンドウのメモリを解放
2329    BOOST_FOREACH( ActiveBasic::PM::ChildWindowInfo *pChildWindowInfo, pWindowInfo->childWindowInfos )
2330    {
2331        delete pChildWindowInfo;
2332    }
2333    pWindowInfo->childWindowInfos.clear();
2334
2335    //ツリービューから削除
2336    extern HWND hMaterialTreeView;
2337    TreeView_DeleteItem(hMaterialTreeView,pWindowInfo->hTreeItem);
2338
2339    //projectInfo.windowInfos構造体から削除
2340    projectInfo.windowInfos.Erase( WndInfoNum );
2341
2342    projectInfo.ModifyOfMaterial=1;
2343}
Note: See TracBrowser for help on using the repository browser.