ダイアログボックスを表示しようとしていたところ
何故か関数から―1が毎度返ってきて表示することができません
原因と疑っているのはinitialize(HWND hwnd)のhwndの内容がおかしくなってるんでは?
と思ってるんですが
親ウィンドウのハンドルをグローバル変数化しても結果は同じでした……
(というわけでいまはグローバル変数にはしていません)
流れ的には
WndProc(...) ↓ initialize(HWND hwnd)呼び出し ↓ initialize()内部でDialogBox(...)を実行 ↓ -1が返って来る……?結局原因分からずじまいなのでどなたかわかる方いらっしゃったらお願いいたします
環境:WinXP VS2005 Express C++
コードです
global.hヘッダー部(あまり関係ないかも)
#include "struct.h"
#define MAX_LOADSTRING 100
#define vt(_n) #_n
#define NUM_DRAWNUM 256
/*Define DrawSwitch of Drawprocess*/
#define _DS _int16 //Type of "Draw Switch"
#define _DSFA_XYONLY 0x01
#define _DSFA_RECTMODE 0x02
#define _DSFA_AUTODIVISION 0x03
#define _DSFB_LPCWSTRTYPE 0x10
#define _DSFB_LPTSTRTYPE 0x20
#define ID_EDIT 100
#define ID_BUTTON 200
#define INI_FILENAME "./seais.ini" //This file is encrypted
#define INI_SYSMSG "#_sys_msg## " //system message(this don't load into variable)
#define INI_APP_STIME "#_app_tim## " //application runned time
#define INI_USERNAMFAM "#_app_unm## " //Registered user family name
#define INI_USERNAMFIS "#_app_uns## " //Registered user first name
#define INI_USERMAIL "#_app_mal## " //Registered user use mail
#define INI_USEDICNAME "#_ais_dic## " //Using Dictionary Paths
#define INI_ENDMARK "*ini_end[EOF]" //file end marker
#define _IS _int16 //Type of "INI Switch"
#define INI_SYSMSG_I 0x01
#define INI_APP_STIME_I 0x02
#define INI_USERNAMFAM_I 0x03
#define INI_USERNAMFIS_I 0x04
#define INI_USERMAIL_I 0x05
#define INI_USEDICNAME_I 0x06
#define APP_MSGTITLE_TEMPL "e-CAIS;see :"
#define M_FATAL_CODE 0x00010000L
#define M_NOTICE_CODE 0x00020000L
#define M_INFO_CODE 0x00030000L
#define M_MSGDEF_MAX 0x00040000L
#define M_NOT_FOUND 0x000000A0L
#define M_SYSTEM_INFO 0x000000B0L
#define M_FROM_DATABASE 0x000000C0L
#define M_FROM_FUNCTION 0x000000D0L
#define M_REMEDY_APPEXIT 0x00000001L
#define M_REMEDY_ADDDATA 0x00000002L
#define M_REMEDY_REMOVE 0x00000003L
#define M_REMEDY_SETUP 0x00000004L
#define M_REMEDY_RESETUP 0x00000005L
#ifdef global_instance
#define global
#else
#define global extern
#endif
#include "defunc.h"
#define APP_VERSION "0.86a"
#define APP_BUILDVERSION APP_BUILDVERSION_F()
global ini_t ini_data;
global dp_ts_t dp_ts;
global dp_ts_t *draw_process_text;
/*コンパイルビルドバージョンformat-YmdHMS:最初に一度きり内容を書き込む*/
global long long APP_BUILDVER;
global int now_state;
global int statics_text_p[NUM_DRAWNUM];
/*セットアップダイアログINI01*/
global wchar_t email[256];
global wchar_t domain[64];
global wchar_t usernamefam[64];
global wchar_t usernamefir[64];
global int sendok;
global int sendsim;
global int nosend;
// グローバル変数:
global HINSTANCE hInst; // 現在のインターフェイス
global TCHAR szTitle[MAX_LOADSTRING]; // タイトル バーのテキスト
global TCHAR szWindowClass[MAX_LOADSTRING]; // メイン ウィンドウ クラス名
global HWND hEdit;
global HWND hButton;
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
RECT rc;
dp_ts_t *p = draw_process_text;
switch (message)
{
case WM_CREATE:
GetClientRect(hWnd, &rc);
rc.right -= 8*2;
rc.left += 8;
rc.top = ((rc.bottom - rc.top)/8)*6;
rc.bottom = (rc.bottom) - (8+rc.top);
hEdit = CreateWindow( L"EDIT", NULL,
WS_CHILD | WS_VISIBLE | ES_WANTRETURN |
ES_MULTILINE | ES_AUTOVSCROLL | WS_VSCROLL |
ES_AUTOHSCROLL | WS_HSCROLL,
rc.left, rc.top, rc.right, rc.bottom, hWnd,
(HMENU)ID_EDIT, hInst, NULL);
SendMessage(hEdit, EM_SETLIMITTEXT, (WPARAM)1024*64, 0);
rc.left += rc.right - 40;
rc.right = rc.right - 40;
rc.top -= 24 + 4;
rc.bottom = 24;
hButton = CreateWindow( L"BUTTON", L"発言",
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
rc.left, rc.top, rc.right, rc.bottom, hWnd ,
(HMENU)ID_BUTTON, hInst, NULL);
initialize(hWnd);
initialize_interface(hWnd);
interfaceA.cpp呼び出し先
#include "stdafx.h"
#include "struct.h"
#include "global.h"
#include "SAIS -Iris-.h"
void initialize(HWND hwnd)
{
int ret;
int ret2;
char temp[512];
/*現在のビルドバージョンを初期化*/
strcpy(temp,APP_BUILDVERSION);
APP_BUILDVER = _atoi64(temp);
now_state = 0x00;
/*Memory initialize*/
ZeroMemory(ini_data.pre_stime,256);
ZeroMemory(ini_data.username_family,256);
ZeroMemory(ini_data.username_first,256);
ZeroMemory(ini_data.usermail,320);
ZeroMemory(ini_data.usedicname,256);
RECT rc;
GetClientRect(hwnd,&rc);
//hello text initialize
statics_text_p[0] = _DEF_PLUSCONTENTS(
hwnd,
L"SAIS -Iris- starts with a test mode.\nAll functions are limited now",
L"MS UI Gothic",
12,8,8,rc.right-8,64,RGB(0,0,0),_DSFA_AUTODIVISION,_DSFB_LPCWSTRTYPE);
initialize_vivo();
if(strcmp(ini_data.username_family,"") == 0)
{
error_msg(
hwnd ,
"初期設定を行います。" ,
M_INFO_CODE | M_SYSTEM_INFO | M_REMEDY_SETUP);
RESETUPINI:
ret = DialogBox(hInst ,L"IDD_DIALOG1" ,hWndstatic ,(DLGPROC)IniSetupDlgProc);
if(ret == IDCANCEL)
{
ret2 = error_msg(
hwnd ,
"キャンセルされました\ne-CAIS;seeを終了します\nもう一度情報を入力する場合は[キャンセル]を押してください" ,
M_FATAL_CODE | M_SYSTEM_INFO | M_REMEDY_APPEXIT , MB_OKCANCEL);
if(ret2 == IDCANCEL)goto RESETUPINI;
if(ret2 == IDOK)exit(EXIT_FAILURE);
}
if(ret == IDOK)
{
wcstombs(ini_data.usermail,email,sizeof(ini_data.usermail));
strcat_s(ini_data.usermail,320,"@");
char temp6[64];
wcstombs(temp6,domain,sizeof(temp6));
strcat_s(ini_data.usermail,320,temp6);
wcstombs(ini_data.username_family,usernamefam,sizeof(ini_data.username_family));
wcstombs(ini_data.username_first,usernamefir,sizeof(ini_data.username_first));
ini_data.mailsendstatus = sendok > 0 ? 1 : (sendsim > 0 ? 2 : 3);
draw_process_text[statics_text_p[0]].lpchtext = *draw_process_text[statics_text_p[0]].lpchtext + L"\nsetup end inifile made...";
char tempwrite[512];
sprintf(
tempwrite ,
"%S%S\n%S%S\n%S%S" ,
INI_USERNAMFAM ,
ini_data.username_family ,
INI_USERNAMFIS ,
ini_data.username_first ,
INI_USERMAIL ,
ini_data.usermail);
write_ini(tempwrite,0);
}
}
/*mail initialize*/
//system(L"ping smtp.gmail.com");
char hellomessage[512] = "";
strcpy_s(hellomessage,512,"Hello message by [e-CAIS;see]\n");
sprintf(
temp ,
"Application version : %s\nApplication build version : %lld\nproduct by Ange;art://fairy canvas[soft laboratory]\n" ,
APP_VERSION ,
APP_BUILDVER);
strcat_s(hellomessage,512,temp);
memset(temp,'\0',512);
gettime(temp);
strcat_s(hellomessage,512,temp);
char sysinfo[512];
systeminfo(sysinfo);
sprintf(temp," : application running\nPC INFO : %s",sysinfo);
strcat_s(hellomessage,512,temp);
wchar_t whellomessage[512];
setlocale(LC_ALL,"japanese");
mbstowcs(whellomessage,hellomessage,sizeof(whellomessage));
wchar_t wmail[256];
mbstowcs(wmail,ini_data.usermail,sizeof(wmail));
wchar_t wlogdata[512];
char logdata[512];
sprintf(logdata,"Login : %s %s MailStatus : %d MailTo : %s",ini_data.username_family,ini_data.username_first,ini_data.mailsendstatus,ini_data.usermail);
mbstowcs(wlogdata,logdata,sizeof(wlogdata));
if(sendok == 1)
{
mailsend_preparater(L"gmail",wmail,L"HelloMessage by e-CAIS;see",whellomessage);
draw_process_text[statics_text_p[0]].lpchtext = *draw_process_text[statics_text_p[0]].lpchtext + L"\nstartup data & hello message sent";
}
}
LRESULT CALLBACK IniSetupDlgProc(HWND hDlgWnd, UINT msg, WPARAM wp, LPARAM lp)
{
switch (msg)
{
case WM_INITDIALOG:
SetDlgItemText(hDlgWnd, IDC_EDIT1, (LPWSTR)email);
SetDlgItemText(hDlgWnd, IDC_EDIT2, (LPWSTR)domain);
SetDlgItemText(hDlgWnd, IDC_EDIT3, (LPWSTR)usernamefam);
SetDlgItemText(hDlgWnd, IDC_EDIT4, (LPWSTR)usernamefir);
SendMessage(GetDlgItem(hDlgWnd, IDC_RADIO1), BM_SETCHECK, (WPARAM)sendok, 0L);
SendMessage(GetDlgItem(hDlgWnd, IDC_RADIO2), BM_SETCHECK, (WPARAM)sendsim, 0L);
SendMessage(GetDlgItem(hDlgWnd, IDC_RADIO2), BM_SETCHECK, (WPARAM)nosend, 0L);
SetWinCenter(hDlgWnd);
return TRUE;
case WM_COMMAND:
switch (LOWORD(wp))
{
case IDOK:
GetDlgItemText(
hDlgWnd ,
IDC_EDIT1 ,
(LPWSTR)email ,
sizeof(email));
GetDlgItemText(
hDlgWnd ,
IDC_EDIT2 ,
(LPWSTR)domain ,
sizeof(domain));
GetDlgItemText(
hDlgWnd ,
IDC_EDIT3 ,
(LPWSTR)usernamefam ,
sizeof(usernamefam));
GetDlgItemText(
hDlgWnd ,
IDC_EDIT4 ,
(LPWSTR)usernamefir ,
sizeof(usernamefir));
if(IsDlgButtonChecked(hDlgWnd ,IDC_RADIO1) == BST_CHECKED)
sendok = 1;
else
sendok = 0;
if(IsDlgButtonChecked(hDlgWnd ,IDC_RADIO2) == BST_CHECKED)
sendsim = 1;
else
sendsim = 0;
if(IsDlgButtonChecked(hDlgWnd ,IDC_RADIO3) == BST_CHECKED)
nosend = 1;
else
nosend = 0;
EndDialog(hDlgWnd, IDOK);
break;
case IDCANCEL:
EndDialog(hDlgWnd, IDCANCEL);
break;
default:
return FALSE;
}
default:
return FALSE;
}
return TRUE;
}
void initialize_interface(HWND hwnd)
{
static LOGFONTW lf001; // フォント情報の構造体
lf001.lfHeight = 12;
lf001.lfQuality = ANTIALIASED_QUALITY;
wcscpy_s(lf001.lfFaceName,sizeof(lf001.lfFaceName),L"Cambria Math");
HFONT hFont001 = CreateFontIndirect(&lf001);
SendMessage(GetDlgItem(hwnd, ID_EDIT), WM_SETFONT, (WPARAM)hFont001, MAKELPARAM(TRUE, 0));
}
どうかよろしくお願いします