| version 1.72, 2007/07/20 14:39:11 | version 1.77, 2011/02/17 10:36:05 | 
| Line 1 | Line 1 | 
| #include        "compiler.h" | /** | 
| #include        <time.h> | * @file        np2.cpp | 
|  | * @brief       main window | 
|  | * | 
|  | * @author      $Author$ | 
|  | * @date        $Date$ | 
|  | */ | 
|  |  | 
|  | #include "compiler.h" | 
|  | #include <time.h> | 
|  | #include <winsock.h> | 
 | #ifndef __GNUC__ | #ifndef __GNUC__ | 
| #include        <winnls32.h> | #include <winnls32.h> | 
 | #endif | #endif | 
| #include        "resource.h" | #include "resource.h" | 
| #include        "strres.h" | #include "strres.h" | 
| #include        "parts.h" | #include "parts.h" | 
| #include        "np2.h" | #include "np2.h" | 
| #include        "np2arg.h" | #include "np2arg.h" | 
| #include        "dosio.h" | #include "dosio.h" | 
| #include        "extromio.h" | #include "extromio.h" | 
| #include        "commng.h" | #include "commng.h" | 
| #include        "joymng.h" | #include "joymng.h" | 
| #include        "mousemng.h" | #include "mousemng.h" | 
| #include        "scrnmng.h" | #include "scrnmng.h" | 
| #include        "soundmng.h" | #include "soundmng.h" | 
| #include        "sysmng.h" | #include "sysmng.h" | 
| #include        "winkbd.h" | #include "winkbd.h" | 
| #include        "ini.h" | #include "ini.h" | 
| #include        "menu.h" | #include "menu.h" | 
| #include        "winloc.h" | #include "winloc.h" | 
| #include        "sstp.h" | #include "sstp.h" | 
| #include        "sstpmsg.h" | #include "sstpmsg.h" | 
| #include        "toolwin.h" | #include "toolwin.h" | 
| #include        "juliet.h" | #include "juliet.h" | 
| #include        "np2class.h" | #include "np2class.h" | 
| #include        "dialog.h" | #include "dialog.h" | 
| #include        "cpucore.h" | #include "cpucore.h" | 
| #include        "pccore.h" | #include "pccore.h" | 
| #include        "iocore.h" | #include "iocore.h" | 
| #include        "pc9861k.h" | #include "pc9861k.h" | 
| #include        "mpu98ii.h" | #include "mpu98ii.h" | 
| #include        "bios.h" | #include "bios.h" | 
| #include        "scrndraw.h" | #include "scrndraw.h" | 
| #include        "sound.h" | #include "sound.h" | 
| #include        "beep.h" | #include "beep.h" | 
| #include        "s98.h" | #include "s98.h" | 
| #include        "diskdrv.h" | #include "diskdrv.h" | 
| #include        "fddfile.h" | #include "fddfile.h" | 
| #include        "timing.h" | #include "timing.h" | 
| #include        "keystat.h" | #include "keystat.h" | 
| #include        "debugsub.h" | #include "debugsub.h" | 
| #include        "subwind.h" | #include "subwind.h" | 
| #include        "viewer.h" | #include "viewer.h" | 
 | #if !defined(_WIN64) | #if !defined(_WIN64) | 
| #include        "cputype.h" | #include "cputype.h" | 
 | #endif | #endif | 
 | #if defined(SUPPORT_DCLOCK) | #if defined(SUPPORT_DCLOCK) | 
| #include        "dclock.h" | #include "dclock.h" | 
 | #endif | #endif | 
 |  |  | 
 |  |  | 
 | #ifdef BETA_RELEASE | #ifdef BETA_RELEASE | 
 | #define         OPENING_WAIT            1500 | #define         OPENING_WAIT            1500 | 
 | #endif | #endif | 
 |  |  | 
 | static  TCHAR           szClassName[] = _T("NP2-MainWindow"); | static  TCHAR           szClassName[] = _T("NP2-MainWindow"); | 
| HWND            hWndMain; | HWND            g_hWndMain; | 
| HINSTANCE       hInst; | HINSTANCE       g_hInstance; | 
| HINSTANCE       hPrev; | HINSTANCE       g_hPrevInst; | 
 | #if !defined(_WIN64) | #if !defined(_WIN64) | 
 | int                     mmxflag; | int                     mmxflag; | 
 | #endif | #endif | 
| Line 93  static UINT  framemax = 1; | Line 101  static UINT  framemax = 1; | 
 | static  UINT8           np2stopemulate = 0; | static  UINT8           np2stopemulate = 0; | 
 | static  int                     np2opening = 1; | static  int                     np2opening = 1; | 
 | static  int                     np2quitmsg = 0; | static  int                     np2quitmsg = 0; | 
 | static  HMENU           hStat = NULL; |  | 
 | static  UINT8           scrnmode; | static  UINT8           scrnmode; | 
 | static  WINLOCEX        smwlex; | static  WINLOCEX        smwlex; | 
| static  HMODULE         resmod; | static  HMODULE         s_hModResource; | 
 |  |  | 
 | static const OEMCHAR np2help[] = OEMTEXT("np2.chm"); | static const OEMCHAR np2help[] = OEMTEXT("np2.chm"); | 
 | static const OEMCHAR np2flagext[] = OEMTEXT("S%02d"); | 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)); | static HINSTANCE loadextinst(HINSTANCE hInstance) | 
| file_cutext(path); | { | 
| OEMSPRINTF(cpstr, np2resext, GetOEMCP()); | OEMCHAR szPath[MAX_PATH]; | 
| file_catname(path, cpstr, NELEMENTS(path)); | OEMCHAR szDllName[32]; | 
| dll = LoadLibrary(path); | HMODULE hMod; | 
| resmod = dll; |  | 
| if (dll != NULL) { | file_cpyname(szPath, modulefile, NELEMENTS(szPath)); | 
| hInstance = (HINSTANCE)dll; | 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); | return(hInstance); | 
 | } | } | 
 |  |  | 
| static void unloadextinst(void) { | static void unloadextinst(void) | 
|  | { | 
| HMODULE dll; | HMODULE hMod; | 
|  |  | 
| dll = resmod; | hMod = s_hModResource; | 
| if (dll) { | s_hModResource = 0; | 
| resmod = 0; | if (hMod) | 
| FreeLibrary(dll); | { | 
|  | FreeLibrary(hMod); | 
 | } | } | 
 | } | } | 
 |  |  | 
| Line 158  WINLOCEX np2_winlocexallwin(HWND base) { | Line 199  WINLOCEX np2_winlocexallwin(HWND base) { | 
 | HWND    list[5]; | HWND    list[5]; | 
 |  |  | 
 | cnt = 0; | cnt = 0; | 
| list[cnt++] = hWndMain; | list[cnt++] = g_hWndMain; | 
 | list[cnt++] = toolwin_gethwnd(); | list[cnt++] = toolwin_gethwnd(); | 
 | list[cnt++] = kdispwin_gethwnd(); | list[cnt++] = kdispwin_gethwnd(); | 
 | list[cnt++] = skbdwin_gethwnd(); | list[cnt++] = skbdwin_gethwnd(); | 
| Line 168  WINLOCEX np2_winlocexallwin(HWND base) { | Line 209  WINLOCEX np2_winlocexallwin(HWND base) { | 
 | list[i] = NULL; | list[i] = NULL; | 
 | } | } | 
 | } | } | 
| if (base != hWndMain) {         // hWndMainのみ全体移動 | if (base != g_hWndMain) {               // hWndMainのみ全体移動 | 
 | base = NULL; | base = NULL; | 
 | } | } | 
 | return(winlocex_create(base, list, cnt)); | return(winlocex_create(base, list, cnt)); | 
| Line 197  static void changescreen(UINT8 newmode) | Line 238  static void changescreen(UINT8 newmode) | 
 | mdbgwin_destroy(); | mdbgwin_destroy(); | 
 | } | } | 
 | else if (renewal & SCRNMODE_ROTATEMASK) { | else if (renewal & SCRNMODE_ROTATEMASK) { | 
| wlex = np2_winlocexallwin(hWndMain); | wlex = np2_winlocexallwin(g_hWndMain); | 
| winlocex_setholdwnd(wlex, hWndMain); | winlocex_setholdwnd(wlex, g_hWndMain); | 
 | } | } | 
 | soundmng_stop(); | soundmng_stop(); | 
 | mousemng_disable(MOUSEPROC_WINUI); | mousemng_disable(MOUSEPROC_WINUI); | 
| Line 216  static void changescreen(UINT8 newmode) | Line 257  static void changescreen(UINT8 newmode) | 
 | if (renewal & SCRNMODE_FULLSCREEN) { | if (renewal & SCRNMODE_FULLSCREEN) { | 
 | if (!scrnmng_isfullscreen()) { | if (!scrnmng_isfullscreen()) { | 
 | if (np2oscfg.toolwin) { | if (np2oscfg.toolwin) { | 
| toolwin_create(); | toolwin_create(g_hInstance); | 
 | } | } | 
 | if (np2oscfg.keydisp) { | if (np2oscfg.keydisp) { | 
| kdispwin_create(); | kdispwin_create(g_hInstance); | 
 | } | } | 
 | } | } | 
 | } | } | 
| Line 253  static void wincentering(HWND hWnd) { | Line 294  static void wincentering(HWND hWnd) { | 
 | np2oscfg.winy = 0; | np2oscfg.winy = 0; | 
 | } | } | 
 | sysmng_update(SYS_UPDATEOSCFG); | 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 | void np2active_renewal(void) {                                                                          // ver0.30 | 
| Line 317  static void flagdelete(const OEMCHAR *ex | Line 358  static void flagdelete(const OEMCHAR *ex | 
 | file_delete(path); | file_delete(path); | 
 | } | } | 
 |  |  | 
| static int flagload(const OEMCHAR *ext, const OEMCHAR *title, BOOL force) { | 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]; | 
 |  |  | 
| int             ret; | getstatfilename(szPath, ext, NELEMENTS(szPath)); | 
| int             id; |  | 
| OEMCHAR path[MAX_PATH]; |  | 
| OEMCHAR buf[1024]; |  | 
|  |  | 
| getstatfilename(path, ext, NELEMENTS(path)); |  | 
 | winuienter(); | winuienter(); | 
| id = IDYES; | nID = IDYES; | 
| ret = statsave_check(path, buf, NELEMENTS(buf)); | nRet = statsave_check(szPath, szStat, NELEMENTS(szStat)); | 
| if (ret & (~STATFLAG_DISKCHG)) { | if (nRet & (~STATFLAG_DISKCHG)) | 
| MessageBox(hWndMain, _T("Couldn't restart"), title, | { | 
| MB_OK | MB_ICONSTOP); | messagebox(hWnd, MAKEINTRESOURCE(IDS_ERROR_RESUME), | 
| id = IDNO; | MB_OK | MB_ICONSTOP); | 
| } | nID = IDNO; | 
| else if ((!force) && (ret & STATFLAG_DISKCHG)) { | } | 
| OEMCHAR buf2[1024 + 256]; | else if ((!force) && (nRet & STATFLAG_DISKCHG)) | 
| OEMSPRINTF(buf2, OEMTEXT("Conflict!\n\n%s\nContinue?"), buf); | { | 
| id = MessageBox(hWndMain, buf2, title, | #if defined(OSLANG_UTF8) | 
| MB_YESNOCANCEL | MB_ICONQUESTION); | TCHAR szStat2[128]; | 
| } | oemtotchar(szStat2, NELEMENTS(szStat2), szStat, -1); | 
| if (id == IDYES) { | #else   // defined(OSLANG_UTF8) | 
| statsave_load(path); | 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(0, fdd_diskname(0)); | 
 | toolwin_setfdd(1, fdd_diskname(1)); | toolwin_setfdd(1, fdd_diskname(1)); | 
 | } | } | 
 | sysmng_workclockreset(); | sysmng_workclockreset(); | 
 | sysmng_updatecaption(1); | sysmng_updatecaption(1); | 
 | winuileave(); | winuileave(); | 
| return(id); | return nID; | 
 | } | } | 
 | #endif | #endif | 
 |  |  | 
| Line 373  static void np2popup(HWND hWnd, LPARAM l | Line 424  static void np2popup(HWND hWnd, LPARAM l | 
 | DestroyMenu(hMenu); | DestroyMenu(hMenu); | 
 | } | } | 
 |  |  | 
| static void np2cmd(HWND hWnd, UINT16 cmd) { | static void OnCommand(HWND hWnd, WPARAM wParam) | 
|  | { | 
| HINSTANCE       hinst; | HINSTANCE       hInstance; | 
 | UINT            update; | UINT            update; | 
 |  | UINT            uID; | 
 | BOOL            b; | BOOL            b; | 
 |  |  | 
| hinst = (HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE); | hInstance = (HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE);; | 
 | update = 0; | update = 0; | 
| switch(cmd) { | uID = LOWORD(wParam); | 
|  | switch(uID) | 
|  | { | 
 | case IDM_RESET: | case IDM_RESET: | 
 | b = FALSE; | b = FALSE; | 
| if (!np2oscfg.comfirm) { | if (!np2oscfg.comfirm) | 
|  | { | 
 | b = TRUE; | b = TRUE; | 
 | } | } | 
| else if (sstpconfirm_reset()) { | else if (sstpconfirm_reset()) | 
|  | { | 
 | winuienter(); | winuienter(); | 
| if (MessageBox(hWnd, OEMTEXT("Sure?"), OEMTEXT("Reset"), | if (messagebox(hWnd, MAKEINTRESOURCE(IDS_CONFIRM_RESET), | 
| MB_ICONQUESTION | MB_YESNO) == IDYES) { | MB_ICONQUESTION | MB_YESNO) == IDYES) | 
|  | { | 
 | b = TRUE; | b = TRUE; | 
 | } | } | 
 | winuileave(); | winuileave(); | 
 | } | } | 
| if (b) { | if (b) | 
|  | { | 
 | sstpmsg_reset(); | sstpmsg_reset(); | 
 | juliet_YMF288Reset(); | juliet_YMF288Reset(); | 
 | pccore_cfgupdate(); | pccore_cfgupdate(); | 
| Line 406  static void np2cmd(HWND hWnd, UINT16 cmd | Line 464  static void np2cmd(HWND hWnd, UINT16 cmd | 
 | case IDM_CONFIG: | case IDM_CONFIG: | 
 | winuienter(); | winuienter(); | 
 | sstpmsg_config(); | sstpmsg_config(); | 
| DialogBox(hinst, MAKEINTRESOURCE(IDD_CONFIG), | DialogBox(hInstance, MAKEINTRESOURCE(IDD_CONFIG), | 
 | hWnd, (DLGPROC)CfgDialogProc); | hWnd, (DLGPROC)CfgDialogProc); | 
 | if (!scrnmng_isfullscreen()) { | if (!scrnmng_isfullscreen()) { | 
 | UINT8 thick; | UINT8 thick; | 
| Line 793  static void np2cmd(HWND hWnd, UINT16 cmd | Line 851  static void np2cmd(HWND hWnd, UINT16 cmd | 
 | update |= SYS_UPDATECFG; | update |= SYS_UPDATECFG; | 
 | break; | break; | 
 |  |  | 
 |  | #if defined(SUPPORT_PX) | 
 | case IDM_PX1: | case IDM_PX1: | 
 | xmenu_setsound(0x30); | xmenu_setsound(0x30); | 
 | update |= SYS_UPDATECFG; | update |= SYS_UPDATECFG; | 
| Line 802  static void np2cmd(HWND hWnd, UINT16 cmd | Line 861  static void np2cmd(HWND hWnd, UINT16 cmd | 
 | xmenu_setsound(0x50); | xmenu_setsound(0x50); | 
 | update |= SYS_UPDATECFG; | update |= SYS_UPDATECFG; | 
 | break; | break; | 
 |  | #endif  // defined(SUPPORT_PX) | 
 |  |  | 
 | case IDM_JASTSOUND: | case IDM_JASTSOUND: | 
 | xmenu_setjastsound(np2oscfg.jastsnd ^ 1); | xmenu_setjastsound(np2oscfg.jastsnd ^ 1); | 
| Line 857  static void np2cmd(HWND hWnd, UINT16 cmd | Line 917  static void np2cmd(HWND hWnd, UINT16 cmd | 
 |  |  | 
 | case IDM_MPUPC98: | case IDM_MPUPC98: | 
 | winuienter(); | winuienter(); | 
| DialogBox(hinst, MAKEINTRESOURCE(IDD_MPUPC98), | DialogBox(hInstance, MAKEINTRESOURCE(IDD_MPUPC98), | 
 | hWnd, (DLGPROC)MidiDialogProc); | hWnd, (DLGPROC)MidiDialogProc); | 
 | winuileave(); | winuileave(); | 
 | break; | break; | 
| Line 905  static void np2cmd(HWND hWnd, UINT16 cmd | Line 965  static void np2cmd(HWND hWnd, UINT16 cmd | 
 |  |  | 
 | case IDM_CALENDAR: | case IDM_CALENDAR: | 
 | winuienter(); | winuienter(); | 
| DialogBox(hinst, MAKEINTRESOURCE(IDD_CALENDAR), | DialogBox(hInstance, MAKEINTRESOURCE(IDD_CALENDAR), | 
 | hWnd, (DLGPROC)ClndDialogProc); | hWnd, (DLGPROC)ClndDialogProc); | 
 | winuileave(); | winuileave(); | 
 | break; | break; | 
| Line 953  static void np2cmd(HWND hWnd, UINT16 cmd | Line 1013  static void np2cmd(HWND hWnd, UINT16 cmd | 
 | sstpmsg_about(); | sstpmsg_about(); | 
 | if (sstp_result() != SSTP_SENDING) { | if (sstp_result() != SSTP_SENDING) { | 
 | winuienter(); | winuienter(); | 
| DialogBox(hinst, MAKEINTRESOURCE(IDD_ABOUT), | DialogBox(hInstance, MAKEINTRESOURCE(IDD_ABOUT), | 
 | hWnd, (DLGPROC)AboutDialogProc); | hWnd, (DLGPROC)AboutDialogProc); | 
 | winuileave(); | winuileave(); | 
 | } | } | 
| Line 961  static void np2cmd(HWND hWnd, UINT16 cmd | Line 1021  static void np2cmd(HWND hWnd, UINT16 cmd | 
 |  |  | 
 | default: | default: | 
 | #if defined(SUPPORT_STATSAVE) | #if defined(SUPPORT_STATSAVE) | 
| if ((cmd >= IDM_FLAGSAVE) && | if ((uID >= IDM_FLAGSAVE) && | 
| (cmd < (IDM_FLAGSAVE + SUPPORT_STATSAVE))) { | (uID < (IDM_FLAGSAVE + SUPPORT_STATSAVE))) { | 
 | OEMCHAR ext[4]; | OEMCHAR ext[4]; | 
| OEMSPRINTF(ext, np2flagext, cmd - IDM_FLAGSAVE); | OEMSPRINTF(ext, np2flagext, uID - IDM_FLAGSAVE); | 
 | flagsave(ext); | flagsave(ext); | 
 | } | } | 
| else if ((cmd >= IDM_FLAGLOAD) && | else if ((uID >= IDM_FLAGLOAD) && | 
| (cmd < (IDM_FLAGLOAD + SUPPORT_STATSAVE))) { | (uID < (IDM_FLAGLOAD + SUPPORT_STATSAVE))) { | 
 | OEMCHAR ext[4]; | OEMCHAR ext[4]; | 
| OEMSPRINTF(ext, np2flagext, cmd - IDM_FLAGLOAD); | OEMSPRINTF(ext, np2flagext, uID - IDM_FLAGLOAD); | 
| flagload(ext, OEMTEXT("Status Load"), TRUE); | flagload(hWnd, ext, _T("Status Load"), TRUE); | 
 | } | } | 
 | #endif | #endif | 
 | break; | break; | 
| Line 1005  LRESULT CALLBACK WndProc(HWND hWnd, UINT | Line 1065  LRESULT CALLBACK WndProc(HWND hWnd, UINT | 
 | case IDM_TOOLWIN: | case IDM_TOOLWIN: | 
 | sysmenu_settoolwin(np2oscfg.toolwin ^ 1); | sysmenu_settoolwin(np2oscfg.toolwin ^ 1); | 
 | if (np2oscfg.toolwin) { | if (np2oscfg.toolwin) { | 
| toolwin_create(); | toolwin_create(g_hInstance); | 
 | } | } | 
 | else { | else { | 
 | toolwin_destroy(); | toolwin_destroy(); | 
| Line 1017  LRESULT CALLBACK WndProc(HWND hWnd, UINT | Line 1077  LRESULT CALLBACK WndProc(HWND hWnd, UINT | 
 | case IDM_KEYDISP: | case IDM_KEYDISP: | 
 | sysmenu_setkeydisp(np2oscfg.keydisp ^ 1); | sysmenu_setkeydisp(np2oscfg.keydisp ^ 1); | 
 | if (np2oscfg.keydisp) { | if (np2oscfg.keydisp) { | 
| kdispwin_create(); | kdispwin_create(g_hInstance); | 
 | } | } | 
 | else { | else { | 
 | kdispwin_destroy(); | kdispwin_destroy(); | 
| Line 1026  LRESULT CALLBACK WndProc(HWND hWnd, UINT | Line 1086  LRESULT CALLBACK WndProc(HWND hWnd, UINT | 
 | #endif | #endif | 
 | #if defined(SUPPORT_SOFTKBD) | #if defined(SUPPORT_SOFTKBD) | 
 | case IDM_SOFTKBD: | case IDM_SOFTKBD: | 
| skbdwin_create(); | skbdwin_create(g_hInstance); | 
 | break; | break; | 
 | #endif | #endif | 
 | #if defined(CPUCORE_IA32) && defined(SUPPORT_MEMDBG32) | #if defined(CPUCORE_IA32) && defined(SUPPORT_MEMDBG32) | 
 | case IDM_MEMDBG32: | case IDM_MEMDBG32: | 
| mdbgwin_create(); | mdbgwin_create(g_hInstance); | 
 | break; | break; | 
 | #endif | #endif | 
 | case IDM_SCREENCENTER: | case IDM_SCREENCENTER: | 
| Line 1065  LRESULT CALLBACK WndProc(HWND hWnd, UINT | Line 1125  LRESULT CALLBACK WndProc(HWND hWnd, UINT | 
 | break; | break; | 
 |  |  | 
 | case IDM_DEBUGUTY: | case IDM_DEBUGUTY: | 
| viewer_open(); | viewer_open(g_hInstance); | 
 | break; | break; | 
 |  |  | 
 | case IDM_SCRNMUL4: | case IDM_SCRNMUL4: | 
| Line 1075  LRESULT CALLBACK WndProc(HWND hWnd, UINT | Line 1135  LRESULT CALLBACK WndProc(HWND hWnd, UINT | 
 | case IDM_SCRNMUL12: | case IDM_SCRNMUL12: | 
 | case IDM_SCRNMUL16: | case IDM_SCRNMUL16: | 
 | if ((!scrnmng_isfullscreen()) && | if ((!scrnmng_isfullscreen()) && | 
| !(GetWindowLong(hWndMain, GWL_STYLE) & WS_MINIMIZE)) { | !(GetWindowLong(g_hWndMain, GWL_STYLE) & WS_MINIMIZE)) | 
|  | { | 
 | sysmenu_setscrnmul((UINT8)(wParam - IDM_SCRNMUL)); | sysmenu_setscrnmul((UINT8)(wParam - IDM_SCRNMUL)); | 
 | scrnmng_setmultiple((int)(wParam - IDM_SCRNMUL)); | scrnmng_setmultiple((int)(wParam - IDM_SCRNMUL)); | 
 | } | } | 
| Line 1113  LRESULT CALLBACK WndProc(HWND hWnd, UINT | Line 1174  LRESULT CALLBACK WndProc(HWND hWnd, UINT | 
 | break; | break; | 
 |  |  | 
 | case WM_COMMAND: | case WM_COMMAND: | 
| np2cmd(hWnd, LOWORD(wParam)); | OnCommand(hWnd, wParam); | 
 | break; | break; | 
 |  |  | 
 | case WM_ACTIVATE: | case WM_ACTIVATE: | 
| Line 1133  LRESULT CALLBACK WndProc(HWND hWnd, UINT | Line 1194  LRESULT CALLBACK WndProc(HWND hWnd, UINT | 
 | case WM_PAINT: | case WM_PAINT: | 
 | hdc = BeginPaint(hWnd, &ps); | hdc = BeginPaint(hWnd, &ps); | 
 | if (np2opening) { | if (np2opening) { | 
| HINSTANCE       hinst; | HINSTANCE       hInstance; | 
 | RECT            rect; | RECT            rect; | 
 | int                     width; | int                     width; | 
 | int                     height; | int                     height; | 
| Line 1141  LRESULT CALLBACK WndProc(HWND hWnd, UINT | Line 1202  LRESULT CALLBACK WndProc(HWND hWnd, UINT | 
 | BITMAP          bmp; | BITMAP          bmp; | 
 | HDC                     hmdc; | HDC                     hmdc; | 
 | HBRUSH          hbrush; | HBRUSH          hbrush; | 
| hinst = (HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE); | hInstance = (HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE); | 
 | GetClientRect(hWnd, &rect); | GetClientRect(hWnd, &rect); | 
 | width = rect.right - rect.left; | width = rect.right - rect.left; | 
 | height = rect.bottom - rect.top; | height = rect.bottom - rect.top; | 
| hbmp = LoadBitmap(hinst, _T("NP2BMP")); | hbmp = LoadBitmap(hInstance, _T("NP2BMP")); | 
 | GetObject(hbmp, sizeof(BITMAP), &bmp); | GetObject(hbmp, sizeof(BITMAP), &bmp); | 
 | hbrush = (HBRUSH)SelectObject(hdc, | hbrush = (HBRUSH)SelectObject(hdc, | 
 | GetStockObject(BLACK_BRUSH)); | GetStockObject(BLACK_BRUSH)); | 
| Line 1221  LRESULT CALLBACK WndProc(HWND hWnd, UINT | Line 1282  LRESULT CALLBACK WndProc(HWND hWnd, UINT | 
 |  |  | 
 | case WM_KEYDOWN: | case WM_KEYDOWN: | 
 | if (wParam == VK_F11) { | if (wParam == VK_F11) { | 
| np2class_enablemenu(hWndMain, TRUE); | np2class_enablemenu(g_hWndMain, TRUE); | 
 | return(DefWindowProc(hWnd, WM_SYSKEYDOWN, VK_F10, lParam)); | return(DefWindowProc(hWnd, WM_SYSKEYDOWN, VK_F10, lParam)); | 
 | } | } | 
 | if ((wParam == VK_F12) && (!np2oscfg.F12COPY)) { | if ((wParam == VK_F12) && (!np2oscfg.F12COPY)) { | 
| Line 1354  LRESULT CALLBACK WndProc(HWND hWnd, UINT | Line 1415  LRESULT CALLBACK WndProc(HWND hWnd, UINT | 
 | } | } | 
 | else if (sstpconfirm_exit()) { | else if (sstpconfirm_exit()) { | 
 | winuienter(); | winuienter(); | 
| if (MessageBox(hWnd, _T("Sure?"), _T("Exit"), | if (messagebox(hWnd, MAKEINTRESOURCE(IDS_CONFIRM_EXIT), | 
| MB_ICONQUESTION | MB_YESNO) == IDYES) { | MB_ICONQUESTION | MB_YESNO) == IDYES) | 
|  | { | 
 | b = TRUE; | b = TRUE; | 
 | } | } | 
 | winuileave(); | winuileave(); | 
| Line 1367  LRESULT CALLBACK WndProc(HWND hWnd, UINT | Line 1429  LRESULT CALLBACK WndProc(HWND hWnd, UINT | 
 | break; | break; | 
 |  |  | 
 | case WM_DESTROY: | case WM_DESTROY: | 
 | DestroyMenu(hStat); |  | 
 | np2class_wmdestroy(hWnd); | np2class_wmdestroy(hWnd); | 
 | PostQuitMessage(0); | PostQuitMessage(0); | 
 | break; | break; | 
| Line 1462  static void processwait(UINT cnt) { | Line 1523  static void processwait(UINT cnt) { | 
 | soundmng_sync(); | soundmng_sync(); | 
 | } | } | 
 |  |  | 
| int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPreInst, | int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst, | 
 | LPSTR lpszCmdLine, int nCmdShow) { | LPSTR lpszCmdLine, int nCmdShow) { | 
 | WNDCLASS        wc; | WNDCLASS        wc; | 
 | MSG                     msg; | MSG                     msg; | 
| Line 1500  int WINAPI WinMain(HINSTANCE hInstance, | Line 1561  int WINAPI WinMain(HINSTANCE hInstance, | 
 | return(FALSE); | return(FALSE); | 
 | } | } | 
 |  |  | 
| hInst = loadextinst(hInstance); | g_hInstance = loadextinst(hInstance); | 
| hPrev = hPreInst; | g_hPrevInst = hPrevInst; | 
 | #if !defined(_WIN64) | #if !defined(_WIN64) | 
 | mmxflag = (havemmx())?0:MMXFLAG_NOTSUPPORT; | mmxflag = (havemmx())?0:MMXFLAG_NOTSUPPORT; | 
 | mmxflag += (np2oscfg.disablemmx)?MMXFLAG_DISABLE:0; | mmxflag += (np2oscfg.disablemmx)?MMXFLAG_DISABLE:0; | 
| Line 1526  int WINAPI WinMain(HINSTANCE hInstance, | Line 1587  int WINAPI WinMain(HINSTANCE hInstance, | 
 | winkbd_setf12(np2oscfg.F12COPY); | winkbd_setf12(np2oscfg.F12COPY); | 
 | keystat_initialize(); | keystat_initialize(); | 
 |  |  | 
| np2class_initialize(hInst); | np2class_initialize(g_hInstance); | 
| if (!hPreInst) { | if (!hPrevInst) { | 
 | wc.style = CS_BYTEALIGNCLIENT | CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS; | wc.style = CS_BYTEALIGNCLIENT | CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS; | 
 | wc.lpfnWndProc = WndProc; | wc.lpfnWndProc = WndProc; | 
 | wc.cbClsExtra = 0; | wc.cbClsExtra = 0; | 
 | wc.cbWndExtra = NP2GWLP_SIZE; | wc.cbWndExtra = NP2GWLP_SIZE; | 
| wc.hInstance = hInst; | wc.hInstance = g_hInstance; | 
| wc.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_ICON1)); | wc.hIcon = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_ICON1)); | 
 | wc.hCursor = LoadCursor(NULL, IDC_ARROW); | wc.hCursor = LoadCursor(NULL, IDC_ARROW); | 
 | wc.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH); | wc.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH); | 
 | wc.lpszMenuName = MAKEINTRESOURCE(IDR_MAIN); | wc.lpszMenuName = MAKEINTRESOURCE(IDR_MAIN); | 
| Line 1544  int WINAPI WinMain(HINSTANCE hInstance, | Line 1605  int WINAPI WinMain(HINSTANCE hInstance, | 
 | dosio_term(); | dosio_term(); | 
 | return(FALSE); | 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(); | mousemng_initialize(); | 
 |  |  | 
| Line 1559  int WINAPI WinMain(HINSTANCE hInstance, | Line 1621  int WINAPI WinMain(HINSTANCE hInstance, | 
 | } | } | 
 | hWnd = CreateWindowEx(0, szClassName, np2oscfg.titles, style, | hWnd = CreateWindowEx(0, szClassName, np2oscfg.titles, style, | 
 | np2oscfg.winx, np2oscfg.winy, 640, 400, | np2oscfg.winx, np2oscfg.winy, 640, 400, | 
| NULL, NULL, hInst, NULL); | NULL, NULL, g_hInstance, NULL); | 
| hWndMain = hWnd; | g_hWndMain = hWnd; | 
 | scrnmng_initialize(); | scrnmng_initialize(); | 
 |  |  | 
 | xmenu_setroltate(0); | xmenu_setroltate(0); | 
| Line 1618  int WINAPI WinMain(HINSTANCE hInstance, | Line 1680  int WINAPI WinMain(HINSTANCE hInstance, | 
 | if (scrnmng_create(scrnmode) != SUCCESS) { | if (scrnmng_create(scrnmode) != SUCCESS) { | 
 | scrnmode ^= SCRNMODE_FULLSCREEN; | scrnmode ^= SCRNMODE_FULLSCREEN; | 
 | if (scrnmng_create(scrnmode) != SUCCESS) { | if (scrnmng_create(scrnmode) != SUCCESS) { | 
| if (sstpmsg_dxerror()) { | if (sstpmsg_dxerror()) | 
| MessageBox(hWnd, _T("Couldn't create DirectDraw Object"), | { | 
| np2oscfg.titles, MB_OK | MB_ICONSTOP); | messagebox(hWnd, MAKEINTRESOURCE(IDS_ERROR_DIRECTDRAW), | 
|  | MB_OK | MB_ICONSTOP); | 
 | } | } | 
 | unloadextinst(); | unloadextinst(); | 
 | TRACETERM(); | TRACETERM(); | 
| Line 1668  int WINAPI WinMain(HINSTANCE hInstance, | Line 1731  int WINAPI WinMain(HINSTANCE hInstance, | 
 | if (np2oscfg.resume) { | if (np2oscfg.resume) { | 
 | int             id; | int             id; | 
 |  |  | 
| id = flagload(str_sav, str_resume, FALSE); | id = flagload(hWnd, str_sav, _T("Resume"), FALSE); | 
 | if (id == IDYES) { | if (id == IDYES) { | 
 | for (i=0; i<4; i++) { | for (i=0; i<4; i++) { | 
 | np2arg.disk[i] = NULL; | np2arg.disk[i] = NULL; | 
| Line 1700  int WINAPI WinMain(HINSTANCE hInstance, | Line 1763  int WINAPI WinMain(HINSTANCE hInstance, | 
 |  |  | 
 | if (!(scrnmode & SCRNMODE_FULLSCREEN)) { | if (!(scrnmode & SCRNMODE_FULLSCREEN)) { | 
 | if (np2oscfg.toolwin) { | if (np2oscfg.toolwin) { | 
| toolwin_create(); | toolwin_create(g_hInstance); | 
 | } | } | 
 | if (np2oscfg.keydisp) { | if (np2oscfg.keydisp) { | 
| kdispwin_create(); | kdispwin_create(g_hInstance); | 
 | } | } | 
 | } | } | 
 |  |  |