win_sys.c
来自「经典的老游戏digger的源代码.提起digger相信很多人会回忆起曾经为了它挑」· C语言 代码 · 共 1,185 行 · 第 1/3 页
C
1,185 行
openplay(drf_filename);
started=FALSE;
// restore level data after DLF playback is finished
memcpy(leveldat,backup_leveldat,8*MHEIGHT*MWIDTH);
strcpy(levfname,backup_levfname);
bonusscore=backup_bonusscore;
levfflag=backup_levfflag;
reset_main_menu_screen=TRUE;
}
break;
case ID_RECORDING_SAVE:
if (gotgame)
recsavedrf();
break;
case ID_RECORDING_INSTANTREPLAY:
if (gotgame)
{
drf_filename[0]='\0';
recsavedrf();
if (drf_filename[0]!='\0')
{
started=FALSE;
openplay(drf_filename);
started=FALSE;
reset_main_menu_screen=TRUE;
}
}
break;
}
return 0;
case WM_MENUSELECT:
refresh_menu_items(); /* it isn't neccessary to do this for every WM_MENUSELECT... Should only do this when the menu is first activated. */
pause_windows_sound_playback();
if (!g_bWindowed)
{
if (!(((UINT) HIWORD(wParam))==0xFFFF && lParam==(LPARAM) NULL ))
{
if (!GetCursor())
{
if (!g_bWindowed)
IDirectDrawSurface_SetPalette(g_pDDSPrimary, NULL); // restore default palette, so that the colors of menus and dialog boxes are correct.
SetMenu(hWnd, GetMenu(hWnd));
show_mouse_cursor();
}
break;
}
else
{
if (preferred_video_mode.height<=400)
SetMenu(hWnd,NULL);
hide_mouse_cursor();
resume_windows_sound_playback();
if (!g_bWindowed)
gpal(cur_palette);
/* repaint the window once the menu is deactivated */
}
}
else
break;
case WM_PAINT:
if (g_bReady)
{
if (g_bWindowed || preferred_video_mode.bpp > 8)
{
blit_to_window_dc(hWnd);
}
else
{
while (TRUE)
{
hRet = blit_to_window();
if (hRet == DDERR_SURFACELOST)
{
hRet = restore_surface();
}
else
if (hRet != DDERR_WASSTILLDRAWING)
{
if (hRet==DD_OK)
if (cur_dialog_box!=NULL)
{
InvalidateRect(cur_dialog_box, NULL, TRUE);
UpdateWindow(cur_dialog_box);
}
break;
}
}
}
}
break;
case WM_MOVE:
if (g_bActive && g_bReady && g_bWindowed)
{
GetWindowRect(hWnd, &g_rcWindow);
GetClientRect(hWnd, &g_rcViewport);
GetClientRect(hWnd, &g_rcScreen);
ClientToScreen(hWnd, (POINT*)&g_rcScreen.left);
ClientToScreen(hWnd, (POINT*)&g_rcScreen.right);
}
break;
case WM_SIZE:
window_size.cx=LOWORD(lParam);
window_size.cy=HIWORD(lParam);
InvalidateRect(hWnd, NULL, FALSE);
if (SIZE_MAXHIDE==wParam || SIZE_MINIMIZED==wParam)
g_bActive = FALSE;
else
g_bActive = TRUE;
break;
case WM_SETCURSOR:
/* Display the cursor in the window if windowed */
if (g_bActive && g_bReady && !g_bWindowed)
{
SetCursor((HCURSOR) NULL);
return TRUE;
}
break;
case WM_CLOSE:
case WM_DESTROY:
PostQuitMessage(0);
return 0;
case WM_POWERBROADCAST:
switch (wParam)
{
case PBT_APMQUERYSTANDBY:
case PBT_APMQUERYSUSPEND:
return BROADCAST_QUERY_DENY;
}
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
/* This creates the main window, then calls another function to create */
/* the back buffer that is to be used, and set up other graphics stuff. */
bool create_window(HINSTANCE hInstance, int nShowCmd)
{
WNDCLASS wndClass;
int width;
int height;
width = 640 + GetSystemMetrics(SM_CXBORDER) * 2;
width+= GetSystemMetrics(SM_CXEDGE)*2;
height = 400 + GetSystemMetrics(SM_CYBORDER) * 2 + GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CYMENU);
height += GetSystemMetrics(SM_CYEDGE)*2;
wndClass.style = CS_HREDRAW | CS_VREDRAW;
wndClass.lpfnWndProc = WndProc;
wndClass.cbClsExtra = 0;
wndClass.cbWndExtra = 0;
wndClass.hInstance = hInstance;
wndClass.hIcon = LoadIcon (hInstance, MAKEINTRESOURCE(IDI_ICON1));
wndClass.hCursor = LoadCursor ((HINSTANCE) NULL, IDC_ARROW);
wndClass.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH);
wndClass.lpszMenuName = MAKEINTRESOURCE(IDR_MAINMENU);
wndClass.lpszClassName = "Digger";
RegisterClass(&wndClass);
hWnd = CreateWindowEx(
WS_EX_WINDOWEDGE,
"Digger",
"Digger",
DIGGER_WS_WINDOWED,
(GetSystemMetrics(SM_CXFULLSCREEN) - 640) / 2,
(GetSystemMetrics(SM_CYFULLSCREEN) - 400) / 2,
width,
height,
(HWND) NULL,
(HMENU) NULL,
(HINSTANCE) hInstance,
(void FAR*) NULL );
window_size.cx=0;
window_size.cy=0;
ShowWindow(hWnd, nShowCmd);
GetWindowRect(hWnd, &g_rcWindow);
GetClientRect(hWnd, &g_rcViewport);
GetClientRect(hWnd, &g_rcScreen);
ClientToScreen(hWnd, (POINT*)&g_rcScreen.left);
ClientToScreen(hWnd, (POINT*)&g_rcScreen.right);
UpdateWindow(hWnd);
return TRUE; /* TO DO - add error checking */
}
void windows_finish()
{
int i;
shutting_down=TRUE;
/* save the current settings */
WriteINIBool(INI_SOUND_SETTINGS, "SoundOn", soundflag, ININAME);
WriteINIBool(INI_SOUND_SETTINGS, "MusicOn", musicflag, ININAME);
WriteINIBool(INI_GRAPHICS_SETTINGS, "FullScreen", !g_bWindowed, ININAME);
WriteINIBool(INI_GRAPHICS_SETTINGS, "Async", use_async_screen_updates, ININAME);
if (diggers>1)
WriteINIString(INI_GAME_SETTINGS, "Players", "2S", ININAME);
else
WriteINIInt(INI_GAME_SETTINGS, "Players", nplayers, ININAME);
WriteINIBool(INI_GAME_SETTINGS, "GauntletMode", gauntlet, ININAME);
WriteINIInt(INI_GAME_SETTINGS, "Speed", ftime, ININAME);
WriteINIBool(INI_GRAPHICS_SETTINGS, "CGA", (video_mode==VIDEO_MODE_CGA), ININAME);
WriteINIInt(INI_GAME_SETTINGS,"StartLevel", startlev, ININAME);
WriteINIString(INI_GAME_SETTINGS,"LevelFile", levfname, ININAME);
release_sound_card(); /* see if this solves Brandon's NT problem */
/* destroy variables */
destroy_back_buffer();
destroy_sound_buffers();
for (i=0;i<param_count;i++)
free(params[i]);
release_direct_x();
if (title_bitmap[0])
DeleteObject(title_bitmap[0]);
if (title_bitmap[1])
DeleteObject(title_bitmap[1]);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
g_hInstance=hInstance;
memcpy(orig_leveldat,leveldat,8*MHEIGHT*MWIDTH); // Make a backup copy of the original level data so
orig_bonusscore=bonusscore;
GetCurrentDirectory(255,digger_dir);
if (strlen(digger_dir)>0)
{
if (digger_dir[strlen(digger_dir)-1]!="\\")
strcat(digger_dir,"\\");
}
check_for_direct_x = !GetINIBool("TROUBLESHOOTING","NoDirectX", FALSE, ININAME);
init_direct_x();
//LoadSpriteFile("vga.spr");
InitCommonControls();
wave_device_available=FALSE;
hMenu=LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MAINMENU));
create_window(hInstance, nShowCmd);
init_graphics();
load_title_bitmaps();
main_function_started=TRUE;
maininit();
g_bReady = TRUE;
g_bActive = TRUE;
mainprog();
return 0;
}
void toggle_screen_mode()
{
//if (g_bActive && g_bReady)
//{
//g_bReady = FALSE;
g_bWindowed = !g_bWindowed;
pause_windows_sound_playback();
ChangeCoopLevel();
resume_windows_sound_playback();
g_bReady = TRUE;
if (g_bWindowed)
SetMenu(hWnd,hMenu);
//if (g_bWindowed)
// GetWindowRect(hWnd, &g_rcWindow);
//}
//InvalidateRect(hWnd,NULL,TRUE);
//UpdateWindow(hWnd);
}
/* This function is called from various places in Digger to allow Windows */
/* to perform its tasks. */
void do_windows_events()
{
MSG msg;
//if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE | PM_NOYIELD ))
//if (PeekMessage(&msg, hWnd, 0, 0, PM_REMOVE | PM_NOYIELD ))
//do
//{
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE /*| PM_NOYIELD */))
{
if (g_hDlg)
if (IsDialogMessage(g_hDlg,&msg))
return;
if (msg.message == WM_QUIT)
{
if (main_function_started)
finish();
else
windows_finish();
exit(0);
}
TranslateMessage(&msg);
DispatchMessage(&msg);
}
//}
//while (suspend_game);
}
int do_dialog_box(HANDLE hInstance, LPCTSTR lpTemplate, HWND hWndParent, DLGPROC lpDialogFunc)
{
int result;
pause_windows_sound_playback();
if (!g_bWindowed)
{
attach_clipper();
IDirectDrawSurface_SetPalette(g_pDDSPrimary, NULL);
}
SetMenu(hWnd, GetMenu(hWnd));
show_mouse_cursor();
result=DialogBox(hInstance, lpTemplate, hWndParent, lpDialogFunc);
cur_dialog_box=(HWND) NULL;
hide_mouse_cursor();
if (!g_bWindowed)
{
release_clipper();
gpal(cur_palette);
}
resume_windows_sound_playback();
InvalidateRect(NULL, NULL, FALSE);
//UpdateWindow(hWnd);
return result;
}
void show_mouse_cursor()
{
POINT cursor_pos;
SetCursor(LoadCursor((HINSTANCE) NULL, (LPCSTR) IDC_ARROW));
GetCursorPos(&cursor_pos);
SetCursorPos(cursor_pos.x-1, cursor_pos.y-1);
SetCursorPos(cursor_pos.x, cursor_pos.y);
}
void hide_mouse_cursor()
{
SetCursor((HCURSOR) NULL);
}
LRESULT CALLBACK gauntlet_settings_dialog_proc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
BOOL success;
UINT rval;
switch (uMsg)
{
case WM_INITDIALOG:
cur_dialog_box=hDlg;
SetDlgItemInt(hDlg, IDC_EDIT_TIME, gtime, FALSE);
return TRUE;
case WM_SYSCOMMAND:
switch (wParam)
{
case SC_CLOSE:
EndDialog(hDlg, FALSE);
return TRUE;
}
break;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDCANCEL:
EndDialog(hDlg, FALSE);
return TRUE;
case IDOK:
rval=GetDlgItemInt(hDlg, IDC_EDIT_TIME, &success, FALSE);
if (success)
gtime=rval;
if (gtime>3599)
gtime=3599;
if (gtime==0)
gtime=120;
EndDialog(hDlg, TRUE);
return TRUE;
}
break;
}
return FALSE;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?