-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheditdlg.c
139 lines (116 loc) · 4.53 KB
/
editdlg.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*====================================================================
* 編集ダイアログ editdlg.c
*===================================================================*/
#include <windows.h>
#include <commctrl.h>
#include "resource.h"
#include "editdlg.h"
#include "logo.h"
#include "optdlg.h"
#include "logodef.h"
extern char filter_name[]; // フィルタ名[filter.c]
static HWND owner; // 親ウインドウ
static int list_n;
//----------------------------
// 関数プロトタイプ
//----------------------------
void on_wm_initdialog(HWND hdlg);
BOOL on_IDOK(HWND hdlg);
/*====================================================================
* EditDlgProc() コールバックプロシージャ
*===================================================================*/
BOOL CALLBACK EditDlgProc(HWND hdlg,UINT msg,WPARAM wParam,LPARAM lParam)
{
switch(msg){
case WM_INITDIALOG:
owner = GetWindow(hdlg,GW_OWNER);
list_n = (int)lParam;
on_wm_initdialog(hdlg);
break;
case WM_COMMAND:
switch(LOWORD(wParam)){
case IDOK:
if(on_IDOK(hdlg))
EndDialog(hdlg,LOWORD(wParam));
break;
case IDCANCEL:
EndDialog(hdlg,LOWORD(wParam));
break;
}
}
return FALSE;
}
/*--------------------------------------------------------------------
* on_wm_initdialog() 初期化
*-------------------------------------------------------------------*/
void on_wm_initdialog(HWND hdlg)
{
char title[LOGO_MAX_NAME+10];
LOGO_HEADER* lp;
// ロゴデータ取得
lp = (LOGO_HEADER *)SendDlgItemMessage(owner,IDC_LIST,LB_GETITEMDATA,list_n,0);
// エディットボックス
SendDlgItemMessage(hdlg,ID_EDIT_NAME,EM_SETLIMITTEXT,LOGO_MAX_NAME-1,0);
SendDlgItemMessage(hdlg,ID_EDIT_START, EM_SETLIMITTEXT, 4,0);
SendDlgItemMessage(hdlg,ID_EDIT_END, EM_SETLIMITTEXT, 4,0);
SendDlgItemMessage(hdlg,ID_EDIT_FIN, EM_SETLIMITTEXT, 3,0);
SendDlgItemMessage(hdlg,ID_EDIT_FOUT, EM_SETLIMITTEXT, 3,0);
SendDlgItemMessage(hdlg,ID_EDIT_SPINST, UDM_SETRANGE, 0, LOGO_STED_MAX);
SendDlgItemMessage(hdlg,ID_EDIT_SPINED, UDM_SETRANGE, 0, LOGO_STED_MAX);
SendDlgItemMessage(hdlg,ID_EDIT_SPINFI, UDM_SETRANGE, 0, LOGO_FADE_MAX);
SendDlgItemMessage(hdlg,ID_EDIT_SPINFO, UDM_SETRANGE, 0, LOGO_FADE_MAX);
SendDlgItemMessage(hdlg,ID_EDIT_X, EM_SETLIMITTEXT, 5,0);
SendDlgItemMessage(hdlg,ID_EDIT_Y, EM_SETLIMITTEXT, 5,0);
SendDlgItemMessage(hdlg,ID_EDIT_SPINX, UDM_SETRANGE, 0, 0x7fff); // signed 16bitの上限
SendDlgItemMessage(hdlg,ID_EDIT_SPINY, UDM_SETRANGE, 0, 0x7fff);
SetDlgItemText(hdlg,ID_EDIT_NAME,lp->name);
SetDlgItemInt(hdlg,ID_EDIT_START,lp->st,FALSE);
SetDlgItemInt(hdlg,ID_EDIT_END ,lp->ed,FALSE);
SetDlgItemInt(hdlg,ID_EDIT_FIN ,lp->fi,FALSE);
SetDlgItemInt(hdlg,ID_EDIT_FOUT ,lp->fo,FALSE);
SetDlgItemInt(hdlg,ID_EDIT_X,lp->x,FALSE);
SetDlgItemInt(hdlg,ID_EDIT_Y,lp->y,FALSE);
// キャプション
wsprintf(title,"%s - 編集",lp->name);
SetWindowText(hdlg,title);
}
/*--------------------------------------------------------------------
* on_IDOK() OKボタン動作
* ロゴデータの変更
*-------------------------------------------------------------------*/
BOOL on_IDOK(HWND hdlg)
{
LOGO_HEADER *newdata;
LOGO_HEADER *olddata;
char newname[LOGO_MAX_NAME];
int num;
// 新ロゴ名前
GetDlgItemText(hdlg,ID_EDIT_NAME,newname,LOGO_MAX_NAME);
// リストボックスを検索
num = SendDlgItemMessage(owner,IDC_LIST,LB_FINDSTRING,-1,(WPARAM)newname);
if(num!=CB_ERR && num!=list_n){ // 編集中のもの以外に同名が見つかった
MessageBox(hdlg,"同名のロゴがあります\n別の名称を設定してください",filter_name,MB_OK|MB_ICONERROR);
return FALSE;
}
olddata = (LOGO_HEADER *)SendDlgItemMessage(owner,IDC_LIST,LB_GETITEMDATA,list_n,0);
// メモリ確保
newdata = (LOGO_HEADER *)malloc(LOGO_DATASIZE(olddata));
if(newdata==NULL){
MessageBox(hdlg,"メモリを確保できませんでした",filter_name,MB_OK|MB_ICONERROR);
return TRUE;
}
// ロゴデータコピー
memcpy(newdata,olddata,LOGO_DATASIZE(olddata));
// ロゴデータ設定
lstrcpy(newdata->name,newname);
newdata->st = min(GetDlgItemInt(hdlg,ID_EDIT_START,NULL,FALSE),LOGO_STED_MAX);
newdata->ed = min(GetDlgItemInt(hdlg,ID_EDIT_END, NULL,FALSE),LOGO_STED_MAX);
newdata->fi = min(GetDlgItemInt(hdlg,ID_EDIT_FIN, NULL,FALSE),LOGO_FADE_MAX);
newdata->fo = min(GetDlgItemInt(hdlg,ID_EDIT_FOUT, NULL,FALSE),LOGO_FADE_MAX);
newdata->x = GetDlgItemInt(hdlg,ID_EDIT_X,NULL,FALSE);
newdata->y = GetDlgItemInt(hdlg,ID_EDIT_Y,NULL,FALSE);
// リストボックスを更新
DeleteItem(owner,list_n);
InsertItem(owner,list_n,newdata);
return TRUE;
}