--- np2/win9x/np2.cpp 2007/07/20 14:39:11 1.72 +++ np2/win9x/np2.cpp 2007/12/28 22:12:05 1.76 @@ -56,9 +56,9 @@ #endif static TCHAR szClassName[] = _T("NP2-MainWindow"); - HWND hWndMain; - HINSTANCE hInst; - HINSTANCE hPrev; + HWND g_hWndMain; + HINSTANCE g_hInstance; + HINSTANCE g_hPrevInst; #if !defined(_WIN64) int mmxflag; #endif @@ -93,44 +93,77 @@ static UINT framemax = 1; static UINT8 np2stopemulate = 0; static int np2opening = 1; static int np2quitmsg = 0; -static HMENU hStat = NULL; static UINT8 scrnmode; static WINLOCEX smwlex; -static HMODULE resmod; +static HMODULE s_hModResource; static const OEMCHAR np2help[] = OEMTEXT("np2.chm"); static const OEMCHAR np2flagext[] = OEMTEXT("S%02d"); -static const OEMCHAR np2resext[] = OEMTEXT(".%u"); +#if defined(_WIN64) +static const OEMCHAR szNp2ResDll[] = OEMTEXT("np2x64_%u.dll"); +#else // defined(_WIN64) +static const OEMCHAR szNp2ResDll[] = OEMTEXT("np2_%u.dll"); +#endif // defined(_WIN64) // ---- -static HINSTANCE loadextinst(HINSTANCE hInstance) { +static int messagebox(HWND hWnd, LPCTSTR lpcszText, UINT uType) +{ + int nRet; + LPTSTR lpszText; + +#if defined(OSLANG_UTF8) + TCHAR szCation[128]; + oemtotchar(szCaption, NELEMENTS(szCaption), np2oscfg.titles, -1); +#else // defined(OSLANG_UTF8) + LPCTSTR szCaption = np2oscfg.titles; +#endif // defined(OSLANG_UTF8) + + nRet = 0; + if (HIWORD(lpcszText)) + { + nRet = MessageBox(hWnd, lpcszText, szCaption, uType); + } + else + { + lpszText = lockstringresource(lpcszText); + nRet = MessageBox(hWnd, lpszText, szCaption, uType); + unlockstringresource(lpszText); + } + return nRet; +} - OEMCHAR path[MAX_PATH]; - OEMCHAR cpstr[16]; - HMODULE dll; +// ---- - file_cpyname(path, modulefile, NELEMENTS(path)); - file_cutext(path); - OEMSPRINTF(cpstr, np2resext, GetOEMCP()); - file_catname(path, cpstr, NELEMENTS(path)); - dll = LoadLibrary(path); - resmod = dll; - if (dll != NULL) { - hInstance = (HINSTANCE)dll; +static HINSTANCE loadextinst(HINSTANCE hInstance) +{ + OEMCHAR szPath[MAX_PATH]; + OEMCHAR szDllName[32]; + HMODULE hMod; + + file_cpyname(szPath, modulefile, NELEMENTS(szPath)); + file_cutname(szPath); + OEMSPRINTF(szDllName, szNp2ResDll, GetOEMCP()); + file_catname(szPath, szDllName, NELEMENTS(szPath)); + hMod = LoadLibrary(szPath); + s_hModResource = hMod; + if (hMod != NULL) + { + hInstance = (HINSTANCE)hMod; } return(hInstance); } -static void unloadextinst(void) { - - HMODULE dll; - - dll = resmod; - if (dll) { - resmod = 0; - FreeLibrary(dll); +static void unloadextinst(void) +{ + HMODULE hMod; + + hMod = s_hModResource; + s_hModResource = 0; + if (hMod) + { + FreeLibrary(hMod); } } @@ -158,7 +191,7 @@ WINLOCEX np2_winlocexallwin(HWND base) { HWND list[5]; cnt = 0; - list[cnt++] = hWndMain; + list[cnt++] = g_hWndMain; list[cnt++] = toolwin_gethwnd(); list[cnt++] = kdispwin_gethwnd(); list[cnt++] = skbdwin_gethwnd(); @@ -168,7 +201,7 @@ WINLOCEX np2_winlocexallwin(HWND base) { list[i] = NULL; } } - if (base != hWndMain) { // hWndMainのみ全体移動 + if (base != g_hWndMain) { // hWndMainのみ全体移動 base = NULL; } return(winlocex_create(base, list, cnt)); @@ -197,8 +230,8 @@ static void changescreen(UINT8 newmode) mdbgwin_destroy(); } else if (renewal & SCRNMODE_ROTATEMASK) { - wlex = np2_winlocexallwin(hWndMain); - winlocex_setholdwnd(wlex, hWndMain); + wlex = np2_winlocexallwin(g_hWndMain); + winlocex_setholdwnd(wlex, g_hWndMain); } soundmng_stop(); mousemng_disable(MOUSEPROC_WINUI); @@ -216,10 +249,10 @@ static void changescreen(UINT8 newmode) if (renewal & SCRNMODE_FULLSCREEN) { if (!scrnmng_isfullscreen()) { if (np2oscfg.toolwin) { - toolwin_create(); + toolwin_create(g_hInstance); } if (np2oscfg.keydisp) { - kdispwin_create(); + kdispwin_create(g_hInstance); } } } @@ -253,7 +286,7 @@ static void wincentering(HWND hWnd) { np2oscfg.winy = 0; } sysmng_update(SYS_UPDATEOSCFG); - MoveWindow(hWndMain, np2oscfg.winx, np2oscfg.winy, width, height, TRUE); + MoveWindow(g_hWndMain, np2oscfg.winx, np2oscfg.winy, width, height, TRUE); } void np2active_renewal(void) { // ver0.30 @@ -317,37 +350,47 @@ static void flagdelete(const OEMCHAR *ex file_delete(path); } -static int flagload(const OEMCHAR *ext, const OEMCHAR *title, BOOL force) { - - int ret; - int id; - OEMCHAR path[MAX_PATH]; - OEMCHAR buf[1024]; +static int flagload(HWND hWnd, const OEMCHAR *ext, LPCTSTR title, BOOL force) +{ + int nRet; + int nID; + OEMCHAR szPath[MAX_PATH]; + OEMCHAR szStat[1024]; + TCHAR szFormat[256]; + TCHAR szMessage[1024 + 256]; - getstatfilename(path, ext, NELEMENTS(path)); + getstatfilename(szPath, ext, NELEMENTS(szPath)); winuienter(); - id = IDYES; - ret = statsave_check(path, buf, NELEMENTS(buf)); - if (ret & (~STATFLAG_DISKCHG)) { - MessageBox(hWndMain, _T("Couldn't restart"), title, - MB_OK | MB_ICONSTOP); - id = IDNO; - } - else if ((!force) && (ret & STATFLAG_DISKCHG)) { - OEMCHAR buf2[1024 + 256]; - OEMSPRINTF(buf2, OEMTEXT("Conflict!\n\n%s\nContinue?"), buf); - id = MessageBox(hWndMain, buf2, title, - MB_YESNOCANCEL | MB_ICONQUESTION); - } - if (id == IDYES) { - statsave_load(path); + nID = IDYES; + nRet = statsave_check(szPath, szStat, NELEMENTS(szStat)); + if (nRet & (~STATFLAG_DISKCHG)) + { + messagebox(hWnd, MAKEINTRESOURCE(IDS_ERROR_RESUME), + MB_OK | MB_ICONSTOP); + nID = IDNO; + } + else if ((!force) && (nRet & STATFLAG_DISKCHG)) + { +#if defined(OSLANG_UTF8) + TCHAR szStat2[128]; + oemtotchar(szStat2, NELEMENTS(szStat2), szStat, -1); +#else // defined(OSLANG_UTF8) + LPCTSTR szStat2 = szStat; +#endif // defined(OSLANG_UTF8) + loadstringresource(IDS_CONFIRM_RESUME, szFormat, NELEMENTS(szFormat)); + wsprintf(szMessage, szFormat, szStat2); + nID = messagebox(hWnd, szMessage, MB_YESNOCANCEL | MB_ICONQUESTION); + } + if (nID == IDYES) + { + statsave_load(szPath); toolwin_setfdd(0, fdd_diskname(0)); toolwin_setfdd(1, fdd_diskname(1)); } sysmng_workclockreset(); sysmng_updatecaption(1); winuileave(); - return(id); + return nID; } #endif @@ -373,29 +416,36 @@ static void np2popup(HWND hWnd, LPARAM l DestroyMenu(hMenu); } -static void np2cmd(HWND hWnd, UINT16 cmd) { - - HINSTANCE hinst; +static void OnCommand(HWND hWnd, WPARAM wParam) +{ + HINSTANCE hInstance; UINT update; + UINT uID; BOOL b; - hinst = (HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE); + hInstance = (HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE);; update = 0; - switch(cmd) { + uID = LOWORD(wParam); + switch(uID) + { case IDM_RESET: b = FALSE; - if (!np2oscfg.comfirm) { + if (!np2oscfg.comfirm) + { b = TRUE; } - else if (sstpconfirm_reset()) { + else if (sstpconfirm_reset()) + { winuienter(); - if (MessageBox(hWnd, OEMTEXT("Sure?"), OEMTEXT("Reset"), - MB_ICONQUESTION | MB_YESNO) == IDYES) { + if (messagebox(hWnd, MAKEINTRESOURCE(IDS_CONFIRM_RESET), + MB_ICONQUESTION | MB_YESNO) == IDYES) + { b = TRUE; } winuileave(); } - if (b) { + if (b) + { sstpmsg_reset(); juliet_YMF288Reset(); pccore_cfgupdate(); @@ -406,7 +456,7 @@ static void np2cmd(HWND hWnd, UINT16 cmd case IDM_CONFIG: winuienter(); sstpmsg_config(); - DialogBox(hinst, MAKEINTRESOURCE(IDD_CONFIG), + DialogBox(hInstance, MAKEINTRESOURCE(IDD_CONFIG), hWnd, (DLGPROC)CfgDialogProc); if (!scrnmng_isfullscreen()) { UINT8 thick; @@ -793,6 +843,7 @@ static void np2cmd(HWND hWnd, UINT16 cmd update |= SYS_UPDATECFG; break; +#if defined(SUPPORT_PX) case IDM_PX1: xmenu_setsound(0x30); update |= SYS_UPDATECFG; @@ -802,6 +853,7 @@ static void np2cmd(HWND hWnd, UINT16 cmd xmenu_setsound(0x50); update |= SYS_UPDATECFG; break; +#endif // defined(SUPPORT_PX) case IDM_JASTSOUND: xmenu_setjastsound(np2oscfg.jastsnd ^ 1); @@ -857,7 +909,7 @@ static void np2cmd(HWND hWnd, UINT16 cmd case IDM_MPUPC98: winuienter(); - DialogBox(hinst, MAKEINTRESOURCE(IDD_MPUPC98), + DialogBox(hInstance, MAKEINTRESOURCE(IDD_MPUPC98), hWnd, (DLGPROC)MidiDialogProc); winuileave(); break; @@ -905,7 +957,7 @@ static void np2cmd(HWND hWnd, UINT16 cmd case IDM_CALENDAR: winuienter(); - DialogBox(hinst, MAKEINTRESOURCE(IDD_CALENDAR), + DialogBox(hInstance, MAKEINTRESOURCE(IDD_CALENDAR), hWnd, (DLGPROC)ClndDialogProc); winuileave(); break; @@ -953,7 +1005,7 @@ static void np2cmd(HWND hWnd, UINT16 cmd sstpmsg_about(); if (sstp_result() != SSTP_SENDING) { winuienter(); - DialogBox(hinst, MAKEINTRESOURCE(IDD_ABOUT), + DialogBox(hInstance, MAKEINTRESOURCE(IDD_ABOUT), hWnd, (DLGPROC)AboutDialogProc); winuileave(); } @@ -961,17 +1013,17 @@ static void np2cmd(HWND hWnd, UINT16 cmd default: #if defined(SUPPORT_STATSAVE) - if ((cmd >= IDM_FLAGSAVE) && - (cmd < (IDM_FLAGSAVE + SUPPORT_STATSAVE))) { + if ((uID >= IDM_FLAGSAVE) && + (uID < (IDM_FLAGSAVE + SUPPORT_STATSAVE))) { OEMCHAR ext[4]; - OEMSPRINTF(ext, np2flagext, cmd - IDM_FLAGSAVE); + OEMSPRINTF(ext, np2flagext, uID - IDM_FLAGSAVE); flagsave(ext); } - else if ((cmd >= IDM_FLAGLOAD) && - (cmd < (IDM_FLAGLOAD + SUPPORT_STATSAVE))) { + else if ((uID >= IDM_FLAGLOAD) && + (uID < (IDM_FLAGLOAD + SUPPORT_STATSAVE))) { OEMCHAR ext[4]; - OEMSPRINTF(ext, np2flagext, cmd - IDM_FLAGLOAD); - flagload(ext, OEMTEXT("Status Load"), TRUE); + OEMSPRINTF(ext, np2flagext, uID - IDM_FLAGLOAD); + flagload(hWnd, ext, _T("Status Load"), TRUE); } #endif break; @@ -1005,7 +1057,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT case IDM_TOOLWIN: sysmenu_settoolwin(np2oscfg.toolwin ^ 1); if (np2oscfg.toolwin) { - toolwin_create(); + toolwin_create(g_hInstance); } else { toolwin_destroy(); @@ -1017,7 +1069,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT case IDM_KEYDISP: sysmenu_setkeydisp(np2oscfg.keydisp ^ 1); if (np2oscfg.keydisp) { - kdispwin_create(); + kdispwin_create(g_hInstance); } else { kdispwin_destroy(); @@ -1026,12 +1078,12 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT #endif #if defined(SUPPORT_SOFTKBD) case IDM_SOFTKBD: - skbdwin_create(); + skbdwin_create(g_hInstance); break; #endif #if defined(CPUCORE_IA32) && defined(SUPPORT_MEMDBG32) case IDM_MEMDBG32: - mdbgwin_create(); + mdbgwin_create(g_hInstance); break; #endif case IDM_SCREENCENTER: @@ -1065,7 +1117,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT break; case IDM_DEBUGUTY: - viewer_open(); + viewer_open(g_hInstance); break; case IDM_SCRNMUL4: @@ -1075,7 +1127,8 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT case IDM_SCRNMUL12: case IDM_SCRNMUL16: if ((!scrnmng_isfullscreen()) && - !(GetWindowLong(hWndMain, GWL_STYLE) & WS_MINIMIZE)) { + !(GetWindowLong(g_hWndMain, GWL_STYLE) & WS_MINIMIZE)) + { sysmenu_setscrnmul((UINT8)(wParam - IDM_SCRNMUL)); scrnmng_setmultiple((int)(wParam - IDM_SCRNMUL)); } @@ -1113,7 +1166,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT break; case WM_COMMAND: - np2cmd(hWnd, LOWORD(wParam)); + OnCommand(hWnd, wParam); break; case WM_ACTIVATE: @@ -1133,7 +1186,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT case WM_PAINT: hdc = BeginPaint(hWnd, &ps); if (np2opening) { - HINSTANCE hinst; + HINSTANCE hInstance; RECT rect; int width; int height; @@ -1141,11 +1194,11 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT BITMAP bmp; HDC hmdc; HBRUSH hbrush; - hinst = (HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE); + hInstance = (HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE); GetClientRect(hWnd, &rect); width = rect.right - rect.left; height = rect.bottom - rect.top; - hbmp = LoadBitmap(hinst, _T("NP2BMP")); + hbmp = LoadBitmap(hInstance, _T("NP2BMP")); GetObject(hbmp, sizeof(BITMAP), &bmp); hbrush = (HBRUSH)SelectObject(hdc, GetStockObject(BLACK_BRUSH)); @@ -1221,7 +1274,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT case WM_KEYDOWN: if (wParam == VK_F11) { - np2class_enablemenu(hWndMain, TRUE); + np2class_enablemenu(g_hWndMain, TRUE); return(DefWindowProc(hWnd, WM_SYSKEYDOWN, VK_F10, lParam)); } if ((wParam == VK_F12) && (!np2oscfg.F12COPY)) { @@ -1354,8 +1407,9 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT } else if (sstpconfirm_exit()) { winuienter(); - if (MessageBox(hWnd, _T("Sure?"), _T("Exit"), - MB_ICONQUESTION | MB_YESNO) == IDYES) { + if (messagebox(hWnd, MAKEINTRESOURCE(IDS_CONFIRM_EXIT), + MB_ICONQUESTION | MB_YESNO) == IDYES) + { b = TRUE; } winuileave(); @@ -1367,7 +1421,6 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT break; case WM_DESTROY: - DestroyMenu(hStat); np2class_wmdestroy(hWnd); PostQuitMessage(0); break; @@ -1462,7 +1515,7 @@ static void processwait(UINT cnt) { soundmng_sync(); } -int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPreInst, +int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst, LPSTR lpszCmdLine, int nCmdShow) { WNDCLASS wc; MSG msg; @@ -1500,8 +1553,8 @@ int WINAPI WinMain(HINSTANCE hInstance, return(FALSE); } - hInst = loadextinst(hInstance); - hPrev = hPreInst; + g_hInstance = loadextinst(hInstance); + g_hPrevInst = hPrevInst; #if !defined(_WIN64) mmxflag = (havemmx())?0:MMXFLAG_NOTSUPPORT; mmxflag += (np2oscfg.disablemmx)?MMXFLAG_DISABLE:0; @@ -1526,14 +1579,14 @@ int WINAPI WinMain(HINSTANCE hInstance, winkbd_setf12(np2oscfg.F12COPY); keystat_initialize(); - np2class_initialize(hInst); - if (!hPreInst) { + np2class_initialize(g_hInstance); + if (!hPrevInst) { wc.style = CS_BYTEALIGNCLIENT | CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS; wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = NP2GWLP_SIZE; - wc.hInstance = hInst; - wc.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_ICON1)); + wc.hInstance = g_hInstance; + wc.hIcon = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_ICON1)); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH); wc.lpszMenuName = MAKEINTRESOURCE(IDR_MAIN); @@ -1544,12 +1597,13 @@ int WINAPI WinMain(HINSTANCE hInstance, dosio_term(); return(FALSE); } + + toolwin_initapp(g_hInstance); + kdispwin_initialize(g_hInstance); + skbdwin_initialize(g_hInstance); + mdbgwin_initialize(g_hInstance); + viewer_init(g_hInstance); } - toolwin_initapp(hInst); - kdispwin_initialize(hPreInst); - skbdwin_initialize(hPreInst); - mdbgwin_initialize(hPreInst); - viewer_init(hPreInst); mousemng_initialize(); @@ -1559,8 +1613,8 @@ int WINAPI WinMain(HINSTANCE hInstance, } hWnd = CreateWindowEx(0, szClassName, np2oscfg.titles, style, np2oscfg.winx, np2oscfg.winy, 640, 400, - NULL, NULL, hInst, NULL); - hWndMain = hWnd; + NULL, NULL, g_hInstance, NULL); + g_hWndMain = hWnd; scrnmng_initialize(); xmenu_setroltate(0); @@ -1618,9 +1672,10 @@ int WINAPI WinMain(HINSTANCE hInstance, if (scrnmng_create(scrnmode) != SUCCESS) { scrnmode ^= SCRNMODE_FULLSCREEN; if (scrnmng_create(scrnmode) != SUCCESS) { - if (sstpmsg_dxerror()) { - MessageBox(hWnd, _T("Couldn't create DirectDraw Object"), - np2oscfg.titles, MB_OK | MB_ICONSTOP); + if (sstpmsg_dxerror()) + { + messagebox(hWnd, MAKEINTRESOURCE(IDS_ERROR_DIRECTDRAW), + MB_OK | MB_ICONSTOP); } unloadextinst(); TRACETERM(); @@ -1668,7 +1723,7 @@ int WINAPI WinMain(HINSTANCE hInstance, if (np2oscfg.resume) { int id; - id = flagload(str_sav, str_resume, FALSE); + id = flagload(hWnd, str_sav, _T("Resume"), FALSE); if (id == IDYES) { for (i=0; i<4; i++) { np2arg.disk[i] = NULL; @@ -1700,10 +1755,10 @@ int WINAPI WinMain(HINSTANCE hInstance, if (!(scrnmode & SCRNMODE_FULLSCREEN)) { if (np2oscfg.toolwin) { - toolwin_create(); + toolwin_create(g_hInstance); } if (np2oscfg.keydisp) { - kdispwin_create(); + kdispwin_create(g_hInstance); } }