Reformat all C files.

I'll push a formatting guide at some point. There may still be
outstanding changes, but please feel free to resolve those as you arrive
a them.

To the best of my knowledge, there is no changes to the actual code
content, but the formatter does have the occasional bug. If you run into
an issue, please fix it!
This commit is contained in:
Sean Hunt
2015-05-09 13:43:16 -04:00
parent 167800afdf
commit 97d6fade74
270 changed files with 182649 additions and 173878 deletions
+7 -7
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 mhaskyn.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
/* NetHack 3.6 mhaskyn.c $NHDT-Date: 1431192776 2015/05/09 17:32:56 $ $NHDT-Branch: master $:$NHDT-Revision: 1.9 $ */
/* NetHack 3.6 mhaskyn.c $Date: 2009/05/06 10:59:46 $ $Revision: 1.5 $ */
/* SCCS Id: @(#)mhaskyn.c 3.5 2005/01/23 */
/* Copyright (C) 2001 by Alex Kompel */
@@ -8,11 +8,11 @@
#include "winMS.h"
#include "mhaskyn.h"
int mswin_yes_no_dialog( const char *question, const char *choices, int def)
int
mswin_yes_no_dialog(const char *question, const char *choices, int def)
{
UNREFERENCED_PARAMETER(question);
UNREFERENCED_PARAMETER(choices);
UNREFERENCED_PARAMETER(def);
return '\032';
UNREFERENCED_PARAMETER(question);
UNREFERENCED_PARAMETER(choices);
UNREFERENCED_PARAMETER(def);
return '\032';
}
+679 -631
View File
File diff suppressed because it is too large Load Diff
+182 -162
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 mhfont.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
/* NetHack 3.6 mhfont.c $NHDT-Date: 1431192776 2015/05/09 17:32:56 $ $NHDT-Branch: master $:$NHDT-Revision: 1.22 $ */
/* NetHack 3.6 mhfont.c $Date: 2009/05/06 10:59:46 $ $Revision: 1.17 $ */
/* SCCS Id: @(#)mhfont.c 3.5 2005/01/23 */
/* Copyright (C) 2001 by Alex Kompel */
@@ -8,201 +8,221 @@
#include "mhfont.h"
#define MAXFONTS 64
#define MAXFONTS 64
/* font table - 64 fonts ought to be enough */
static struct font_table_entry {
int code;
HFONT hFont;
} font_table[MAXFONTS] ;
int code;
HFONT hFont;
} font_table[MAXFONTS];
static int font_table_size = 0;
HFONT version_splash_font;
#define NHFONT_CODE(win, attr) (((attr&0xFF)<<8)|(win_type&0xFF))
#define NHFONT_CODE(win, attr) (((attr & 0xFF) << 8) | (win_type & 0xFF))
static void __cdecl font_table_cleanup(void);
void mswin_init_splashfonts(HWND hWnd)
void
mswin_init_splashfonts(HWND hWnd)
{
HDC hdc = GetDC(hWnd);
LOGFONT lgfnt;
ZeroMemory( &lgfnt, sizeof(lgfnt) );
lgfnt.lfHeight = -80; // height of font
lgfnt.lfWidth = 0; // average character width
lgfnt.lfEscapement = 0; // angle of escapement
lgfnt.lfOrientation = 0; // base-line orientation angle
lgfnt.lfWeight = FW_BOLD; // font weight
lgfnt.lfItalic = FALSE; // italic attribute option
lgfnt.lfUnderline = FALSE; // underline attribute option
lgfnt.lfStrikeOut = FALSE; // strikeout attribute option
lgfnt.lfCharSet = ANSI_CHARSET; // character set identifier
lgfnt.lfOutPrecision = OUT_DEFAULT_PRECIS; // output precision
lgfnt.lfClipPrecision = CLIP_DEFAULT_PRECIS; // clipping precision
lgfnt.lfQuality = DEFAULT_QUALITY; // output quality
lgfnt.lfPitchAndFamily = DEFAULT_PITCH; // pitch and family
NH_A2W( "Times New Roman", lgfnt.lfFaceName, LF_FACESIZE);
version_splash_font = CreateFontIndirect(&lgfnt);
ReleaseDC(hWnd, hdc);
HDC hdc = GetDC(hWnd);
LOGFONT lgfnt;
ZeroMemory(&lgfnt, sizeof(lgfnt));
lgfnt.lfHeight = -80; // height of font
lgfnt.lfWidth = 0; // average character width
lgfnt.lfEscapement = 0; // angle of escapement
lgfnt.lfOrientation = 0; // base-line orientation angle
lgfnt.lfWeight = FW_BOLD; // font weight
lgfnt.lfItalic = FALSE; // italic attribute option
lgfnt.lfUnderline = FALSE; // underline attribute option
lgfnt.lfStrikeOut = FALSE; // strikeout attribute option
lgfnt.lfCharSet = ANSI_CHARSET; // character set identifier
lgfnt.lfOutPrecision = OUT_DEFAULT_PRECIS; // output precision
lgfnt.lfClipPrecision = CLIP_DEFAULT_PRECIS; // clipping precision
lgfnt.lfQuality = DEFAULT_QUALITY; // output quality
lgfnt.lfPitchAndFamily = DEFAULT_PITCH; // pitch and family
NH_A2W("Times New Roman", lgfnt.lfFaceName, LF_FACESIZE);
version_splash_font = CreateFontIndirect(&lgfnt);
ReleaseDC(hWnd, hdc);
}
void mswin_destroy_splashfonts()
void
mswin_destroy_splashfonts()
{
DeleteObject (version_splash_font);
DeleteObject(version_splash_font);
}
/* create font based on window type, charater attributes and
window device context */
HGDIOBJ mswin_get_font(int win_type, int attr, HDC hdc, BOOL replace)
HGDIOBJ
mswin_get_font(int win_type, int attr, HDC hdc, BOOL replace)
{
HFONT fnt = NULL;
LOGFONT lgfnt;
int font_size;
int font_index;
static BOOL once = FALSE;
HFONT fnt = NULL;
LOGFONT lgfnt;
int font_size;
int font_index;
static BOOL once = FALSE;
if( !once ) {
once = TRUE;
atexit(font_table_cleanup);
}
if (!once) {
once = TRUE;
atexit(font_table_cleanup);
}
ZeroMemory( &lgfnt, sizeof(lgfnt) );
ZeroMemory(&lgfnt, sizeof(lgfnt));
/* try find font in the table */
for(font_index=0; font_index<font_table_size; font_index++)
if(NHFONT_CODE(win_type, attr)==font_table[font_index].code)
break;
/* try find font in the table */
for (font_index = 0; font_index < font_table_size; font_index++)
if (NHFONT_CODE(win_type, attr) == font_table[font_index].code)
break;
if( !replace && font_index<font_table_size )
return font_table[font_index].hFont;
if (!replace && font_index < font_table_size)
return font_table[font_index].hFont;
switch(win_type) {
case NHW_STATUS:
font_size = (attr==ATR_BOLD)? iflags.wc_fontsiz_status+1 : iflags.wc_fontsiz_status;
lgfnt.lfHeight = -font_size*GetDeviceCaps(hdc, LOGPIXELSY)/72; // height of font
lgfnt.lfWidth = 0; // average character width
lgfnt.lfEscapement = 0; // angle of escapement
lgfnt.lfOrientation = 0; // base-line orientation angle
lgfnt.lfWeight = (attr==ATR_BOLD)? FW_BOLD : FW_NORMAL; // font weight
lgfnt.lfItalic = FALSE; // italic attribute option
lgfnt.lfUnderline = FALSE; // underline attribute option
lgfnt.lfStrikeOut = FALSE; // strikeout attribute option
lgfnt.lfCharSet = mswin_charset(); // character set identifier
lgfnt.lfOutPrecision = OUT_DEFAULT_PRECIS; // output precision
lgfnt.lfClipPrecision = CLIP_DEFAULT_PRECIS; // clipping precision
lgfnt.lfQuality = DEFAULT_QUALITY; // output quality
if( iflags.wc_font_status &&
*iflags.wc_font_status ) {
lgfnt.lfPitchAndFamily = DEFAULT_PITCH; // pitch and family
NH_A2W( iflags.wc_font_status, lgfnt.lfFaceName, LF_FACESIZE);
} else {
lgfnt.lfPitchAndFamily = FIXED_PITCH; // pitch and family
}
break;
switch (win_type) {
case NHW_STATUS:
font_size = (attr == ATR_BOLD) ? iflags.wc_fontsiz_status + 1
: iflags.wc_fontsiz_status;
lgfnt.lfHeight = -font_size * GetDeviceCaps(hdc, LOGPIXELSY)
/ 72; // height of font
lgfnt.lfWidth = 0; // average character width
lgfnt.lfEscapement = 0; // angle of escapement
lgfnt.lfOrientation = 0; // base-line orientation angle
lgfnt.lfWeight =
(attr == ATR_BOLD) ? FW_BOLD : FW_NORMAL; // font weight
lgfnt.lfItalic = FALSE; // italic attribute option
lgfnt.lfUnderline = FALSE; // underline attribute option
lgfnt.lfStrikeOut = FALSE; // strikeout attribute option
lgfnt.lfCharSet = mswin_charset(); // character set identifier
lgfnt.lfOutPrecision = OUT_DEFAULT_PRECIS; // output precision
lgfnt.lfClipPrecision = CLIP_DEFAULT_PRECIS; // clipping precision
lgfnt.lfQuality = DEFAULT_QUALITY; // output quality
if (iflags.wc_font_status && *iflags.wc_font_status) {
lgfnt.lfPitchAndFamily = DEFAULT_PITCH; // pitch and family
NH_A2W(iflags.wc_font_status, lgfnt.lfFaceName, LF_FACESIZE);
} else {
lgfnt.lfPitchAndFamily = FIXED_PITCH; // pitch and family
}
break;
case NHW_MENU:
lgfnt.lfHeight = -iflags.wc_fontsiz_menu*GetDeviceCaps(hdc, LOGPIXELSY)/72; // height of font
lgfnt.lfWidth = 0; // average character width
lgfnt.lfEscapement = 0; // angle of escapement
lgfnt.lfOrientation = 0; // base-line orientation angle
lgfnt.lfWeight = (attr==ATR_BOLD || attr==ATR_INVERSE)? FW_BOLD : FW_NORMAL; // font weight
lgfnt.lfItalic = (attr==ATR_BLINK)? TRUE: FALSE; // italic attribute option
lgfnt.lfUnderline = (attr==ATR_ULINE)? TRUE : FALSE; // underline attribute option
lgfnt.lfStrikeOut = FALSE; // strikeout attribute option
lgfnt.lfCharSet = mswin_charset(); // character set identifier
lgfnt.lfOutPrecision = OUT_DEFAULT_PRECIS; // output precision
lgfnt.lfClipPrecision = CLIP_DEFAULT_PRECIS; // clipping precision
lgfnt.lfQuality = DEFAULT_QUALITY; // output quality
if( iflags.wc_font_menu &&
*iflags.wc_font_menu ) {
lgfnt.lfPitchAndFamily = DEFAULT_PITCH; // pitch and family
NH_A2W( iflags.wc_font_menu, lgfnt.lfFaceName, LF_FACESIZE);
} else {
lgfnt.lfPitchAndFamily = FIXED_PITCH; // pitch and family
}
break;
case NHW_MENU:
lgfnt.lfHeight = -iflags.wc_fontsiz_menu
* GetDeviceCaps(hdc, LOGPIXELSY)
/ 72; // height of font
lgfnt.lfWidth = 0; // average character width
lgfnt.lfEscapement = 0; // angle of escapement
lgfnt.lfOrientation = 0; // base-line orientation angle
lgfnt.lfWeight = (attr == ATR_BOLD || attr == ATR_INVERSE)
? FW_BOLD
: FW_NORMAL; // font weight
lgfnt.lfItalic =
(attr == ATR_BLINK) ? TRUE : FALSE; // italic attribute option
lgfnt.lfUnderline =
(attr == ATR_ULINE) ? TRUE : FALSE; // underline attribute option
lgfnt.lfStrikeOut = FALSE; // strikeout attribute option
lgfnt.lfCharSet = mswin_charset(); // character set identifier
lgfnt.lfOutPrecision = OUT_DEFAULT_PRECIS; // output precision
lgfnt.lfClipPrecision = CLIP_DEFAULT_PRECIS; // clipping precision
lgfnt.lfQuality = DEFAULT_QUALITY; // output quality
if (iflags.wc_font_menu && *iflags.wc_font_menu) {
lgfnt.lfPitchAndFamily = DEFAULT_PITCH; // pitch and family
NH_A2W(iflags.wc_font_menu, lgfnt.lfFaceName, LF_FACESIZE);
} else {
lgfnt.lfPitchAndFamily = FIXED_PITCH; // pitch and family
}
break;
case NHW_MESSAGE:
font_size = (attr==ATR_INVERSE)? iflags.wc_fontsiz_message+1 : iflags.wc_fontsiz_message;
lgfnt.lfHeight = -font_size*GetDeviceCaps(hdc, LOGPIXELSY)/72; // height of font
lgfnt.lfWidth = 0; // average character width
lgfnt.lfEscapement = 0; // angle of escapement
lgfnt.lfOrientation = 0; // base-line orientation angle
lgfnt.lfWeight = (attr==ATR_BOLD || attr==ATR_INVERSE)? FW_BOLD : FW_NORMAL; // font weight
lgfnt.lfItalic = (attr==ATR_BLINK)? TRUE: FALSE; // italic attribute option
lgfnt.lfUnderline = (attr==ATR_ULINE)? TRUE : FALSE; // underline attribute option
lgfnt.lfStrikeOut = FALSE; // strikeout attribute option
lgfnt.lfCharSet = mswin_charset(); // character set identifier
lgfnt.lfOutPrecision = OUT_DEFAULT_PRECIS; // output precision
lgfnt.lfClipPrecision = CLIP_DEFAULT_PRECIS; // clipping precision
lgfnt.lfQuality = DEFAULT_QUALITY; // output quality
if( iflags.wc_font_message &&
*iflags.wc_font_message ) {
lgfnt.lfPitchAndFamily = DEFAULT_PITCH; // pitch and family
NH_A2W( iflags.wc_font_message, lgfnt.lfFaceName, LF_FACESIZE);
} else {
lgfnt.lfPitchAndFamily = VARIABLE_PITCH; // pitch and family
}
break;
case NHW_MESSAGE:
font_size = (attr == ATR_INVERSE) ? iflags.wc_fontsiz_message + 1
: iflags.wc_fontsiz_message;
lgfnt.lfHeight = -font_size * GetDeviceCaps(hdc, LOGPIXELSY)
/ 72; // height of font
lgfnt.lfWidth = 0; // average character width
lgfnt.lfEscapement = 0; // angle of escapement
lgfnt.lfOrientation = 0; // base-line orientation angle
lgfnt.lfWeight = (attr == ATR_BOLD || attr == ATR_INVERSE)
? FW_BOLD
: FW_NORMAL; // font weight
lgfnt.lfItalic =
(attr == ATR_BLINK) ? TRUE : FALSE; // italic attribute option
lgfnt.lfUnderline =
(attr == ATR_ULINE) ? TRUE : FALSE; // underline attribute option
lgfnt.lfStrikeOut = FALSE; // strikeout attribute option
lgfnt.lfCharSet = mswin_charset(); // character set identifier
lgfnt.lfOutPrecision = OUT_DEFAULT_PRECIS; // output precision
lgfnt.lfClipPrecision = CLIP_DEFAULT_PRECIS; // clipping precision
lgfnt.lfQuality = DEFAULT_QUALITY; // output quality
if (iflags.wc_font_message && *iflags.wc_font_message) {
lgfnt.lfPitchAndFamily = DEFAULT_PITCH; // pitch and family
NH_A2W(iflags.wc_font_message, lgfnt.lfFaceName, LF_FACESIZE);
} else {
lgfnt.lfPitchAndFamily = VARIABLE_PITCH; // pitch and family
}
break;
case NHW_TEXT:
lgfnt.lfHeight = -iflags.wc_fontsiz_text*GetDeviceCaps(hdc, LOGPIXELSY)/72; // height of font
lgfnt.lfWidth = 0; // average character width
lgfnt.lfEscapement = 0; // angle of escapement
lgfnt.lfOrientation = 0; // base-line orientation angle
lgfnt.lfWeight = (attr==ATR_BOLD || attr==ATR_INVERSE)? FW_BOLD : FW_NORMAL; // font weight
lgfnt.lfItalic = (attr==ATR_BLINK)? TRUE: FALSE; // italic attribute option
lgfnt.lfUnderline = (attr==ATR_ULINE)? TRUE : FALSE; // underline attribute option
lgfnt.lfStrikeOut = FALSE; // strikeout attribute option
lgfnt.lfCharSet = mswin_charset(); // character set identifier
lgfnt.lfOutPrecision = OUT_DEFAULT_PRECIS; // output precision
lgfnt.lfClipPrecision = CLIP_DEFAULT_PRECIS; // clipping precision
lgfnt.lfQuality = DEFAULT_QUALITY; // output quality
if( iflags.wc_font_text &&
*iflags.wc_font_text ) {
lgfnt.lfPitchAndFamily = DEFAULT_PITCH; // pitch and family
NH_A2W( iflags.wc_font_text, lgfnt.lfFaceName, LF_FACESIZE);
} else {
lgfnt.lfPitchAndFamily = FIXED_PITCH; // pitch and family
}
break;
}
case NHW_TEXT:
lgfnt.lfHeight = -iflags.wc_fontsiz_text
* GetDeviceCaps(hdc, LOGPIXELSY)
/ 72; // height of font
lgfnt.lfWidth = 0; // average character width
lgfnt.lfEscapement = 0; // angle of escapement
lgfnt.lfOrientation = 0; // base-line orientation angle
lgfnt.lfWeight = (attr == ATR_BOLD || attr == ATR_INVERSE)
? FW_BOLD
: FW_NORMAL; // font weight
lgfnt.lfItalic =
(attr == ATR_BLINK) ? TRUE : FALSE; // italic attribute option
lgfnt.lfUnderline =
(attr == ATR_ULINE) ? TRUE : FALSE; // underline attribute option
lgfnt.lfStrikeOut = FALSE; // strikeout attribute option
lgfnt.lfCharSet = mswin_charset(); // character set identifier
lgfnt.lfOutPrecision = OUT_DEFAULT_PRECIS; // output precision
lgfnt.lfClipPrecision = CLIP_DEFAULT_PRECIS; // clipping precision
lgfnt.lfQuality = DEFAULT_QUALITY; // output quality
if (iflags.wc_font_text && *iflags.wc_font_text) {
lgfnt.lfPitchAndFamily = DEFAULT_PITCH; // pitch and family
NH_A2W(iflags.wc_font_text, lgfnt.lfFaceName, LF_FACESIZE);
} else {
lgfnt.lfPitchAndFamily = FIXED_PITCH; // pitch and family
}
break;
}
fnt = CreateFontIndirect(&lgfnt);
fnt = CreateFontIndirect(&lgfnt);
/* add font to the table */
if( font_index==font_table_size ) {
if( font_table_size>=MAXFONTS ) panic( "font table overflow!" );
font_table_size++;
} else {
DeleteObject(font_table[font_index].hFont);
}
/* add font to the table */
if (font_index == font_table_size) {
if (font_table_size >= MAXFONTS)
panic("font table overflow!");
font_table_size++;
} else {
DeleteObject(font_table[font_index].hFont);
}
font_table[font_index].code = NHFONT_CODE(win_type, attr);
font_table[font_index].hFont = fnt;
return fnt;
font_table[font_index].code = NHFONT_CODE(win_type, attr);
font_table[font_index].hFont = fnt;
return fnt;
}
UINT mswin_charset()
UINT
mswin_charset()
{
CHARSETINFO cis;
if( SYMHANDLING(H_IBM) )
if( TranslateCharsetInfo((DWORD*)GetOEMCP(), &cis, TCI_SRCCODEPAGE) )
return cis.ciCharset;
else
return OEM_CHARSET;
else
if( TranslateCharsetInfo((DWORD*)GetACP(), &cis, TCI_SRCCODEPAGE) )
return cis.ciCharset;
else
return ANSI_CHARSET;
CHARSETINFO cis;
if (SYMHANDLING(H_IBM))
if (TranslateCharsetInfo((DWORD *) GetOEMCP(), &cis, TCI_SRCCODEPAGE))
return cis.ciCharset;
else
return OEM_CHARSET;
else if (TranslateCharsetInfo((DWORD *) GetACP(), &cis, TCI_SRCCODEPAGE))
return cis.ciCharset;
else
return ANSI_CHARSET;
}
void __cdecl font_table_cleanup(void)
{
int i;
for(i=0; i<font_table_size; i++) {
DeleteObject(font_table[i].hFont);
}
font_table_size = 0;
int i;
for (i = 0; i < font_table_size; i++) {
DeleteObject(font_table[i].hFont);
}
font_table_size = 0;
}
+64 -58
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 mhinput.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
/* NetHack 3.6 mhinput.c $NHDT-Date: 1431192776 2015/05/09 17:32:56 $ $NHDT-Branch: master $:$NHDT-Revision: 1.10 $ */
/* NetHack 3.6 mhinput.c $Date: 2009/05/06 10:59:48 $ $Revision: 1.7 $ */
/* SCCS Id: @(#)mhinput.c 3.5 2005/01/23 */
/* Copyright (C) 2001 by Alex Kompel */
@@ -10,9 +10,9 @@
/* nethack input queue functions */
#define NH_INPUT_BUFFER_SIZE 64
#define NH_INPUT_BUFFER_SIZE 64
/* as it stands right now we need only one slot
/* as it stands right now we need only one slot
since events are processed almost the same time as
they occur but I like large round numbers */
@@ -22,93 +22,99 @@ static int nhi_read_pos = 0;
static int nhi_write_pos = 0;
/* initialize input queue */
void mswin_nh_input_init(void)
void
mswin_nh_input_init(void)
{
if( !nhi_init_input ) {
nhi_init_input = 1;
if (!nhi_init_input) {
nhi_init_input = 1;
ZeroMemory( nhi_input_buffer, sizeof(nhi_input_buffer) );
nhi_read_pos = 0;
nhi_write_pos = 0;
}
ZeroMemory(nhi_input_buffer, sizeof(nhi_input_buffer));
nhi_read_pos = 0;
nhi_write_pos = 0;
}
}
/* check for input */
int mswin_have_input()
int
mswin_have_input()
{
return
return
#ifdef SAFERHANGUP
/* we always have input (ESC) if hangup was requested */
program_state.done_hup ||
/* we always have input (ESC) if hangup was requested */
program_state.done_hup ||
#endif
(nhi_read_pos!=nhi_write_pos);
(nhi_read_pos != nhi_write_pos);
}
/* add event to the queue */
void mswin_input_push(PMSNHEvent event)
void
mswin_input_push(PMSNHEvent event)
{
int new_write_pos;
int new_write_pos;
if( !nhi_init_input ) mswin_nh_input_init();
if (!nhi_init_input)
mswin_nh_input_init();
new_write_pos = (nhi_write_pos+1) % NH_INPUT_BUFFER_SIZE;
if(new_write_pos!=nhi_read_pos) {
memcpy(nhi_input_buffer+nhi_write_pos, event, sizeof(*event));
nhi_write_pos = new_write_pos;
}
new_write_pos = (nhi_write_pos + 1) % NH_INPUT_BUFFER_SIZE;
if (new_write_pos != nhi_read_pos) {
memcpy(nhi_input_buffer + nhi_write_pos, event, sizeof(*event));
nhi_write_pos = new_write_pos;
}
}
/* get event from the queue and delete it */
PMSNHEvent mswin_input_pop()
PMSNHEvent
mswin_input_pop()
{
PMSNHEvent retval;
PMSNHEvent retval;
#ifdef SAFERHANGUP
/* always return ESC when hangup was requested */
if( program_state.done_hup ) {
static MSNHEvent hangup_event;
hangup_event.type = NHEVENT_CHAR;
hangup_event.kbd.ch = '\033';
return &hangup_event;
}
/* always return ESC when hangup was requested */
if (program_state.done_hup) {
static MSNHEvent hangup_event;
hangup_event.type = NHEVENT_CHAR;
hangup_event.kbd.ch = '\033';
return &hangup_event;
}
#endif
if( !nhi_init_input ) mswin_nh_input_init();
if (!nhi_init_input)
mswin_nh_input_init();
if( nhi_read_pos!=nhi_write_pos ) {
retval = &nhi_input_buffer[nhi_read_pos];
nhi_read_pos = (nhi_read_pos+1) % NH_INPUT_BUFFER_SIZE;
} else {
retval = NULL;
}
if (nhi_read_pos != nhi_write_pos) {
retval = &nhi_input_buffer[nhi_read_pos];
nhi_read_pos = (nhi_read_pos + 1) % NH_INPUT_BUFFER_SIZE;
} else {
retval = NULL;
}
return retval;
return retval;
}
/* get event from the queue but leave it there */
PMSNHEvent mswin_input_peek()
PMSNHEvent
mswin_input_peek()
{
PMSNHEvent retval;
PMSNHEvent retval;
#ifdef SAFERHANGUP
/* always return ESC when hangup was requested */
if( program_state.done_hup ) {
static MSNHEvent hangup_event;
hangup_event.type = NHEVENT_CHAR;
hangup_event.kbd.ch = '\033';
return &hangup_event;
}
/* always return ESC when hangup was requested */
if (program_state.done_hup) {
static MSNHEvent hangup_event;
hangup_event.type = NHEVENT_CHAR;
hangup_event.kbd.ch = '\033';
return &hangup_event;
}
#endif
if( !nhi_init_input ) mswin_nh_input_init();
if (!nhi_init_input)
mswin_nh_input_init();
if( nhi_read_pos!=nhi_write_pos ) {
retval = &nhi_input_buffer[nhi_read_pos];
} else {
retval = NULL;
}
return retval;
if (nhi_read_pos != nhi_write_pos) {
retval = &nhi_input_buffer[nhi_read_pos];
} else {
retval = NULL;
}
return retval;
}
+947 -992
View File
File diff suppressed because it is too large Load Diff
+845 -812
View File
File diff suppressed because it is too large Load Diff
+1360 -1312
View File
File diff suppressed because it is too large Load Diff
+745 -696
View File
File diff suppressed because it is too large Load Diff
+231 -224
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 mhrip.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
/* NetHack 3.6 mhrip.c $NHDT-Date: 1431192777 2015/05/09 17:32:57 $ $NHDT-Branch: master $:$NHDT-Revision: 1.18 $ */
/* NetHack 3.6 mhrip.c $Date: 2012/01/11 01:45:02 $ $Revision: 1.13 $ */
/* Copyright (C) 2001 by Alex Kompel */
/* NetHack may be freely redistributed. See license for details. */
@@ -9,260 +9,267 @@
#include "mhmsg.h"
#include "mhfont.h"
#define RIP_WIDTH 400
#define RIP_HEIGHT 200
#define RIP_WIDTH 400
#define RIP_HEIGHT 200
#define RIP_GRAVE_HEIGHT 120
#define RIP_GRAVE_WIDTH 115
#define RIP_GRAVE_X 90
#define RIP_GRAVE_Y 60
#define RIP_GRAVE_HEIGHT 120
#define RIP_GRAVE_WIDTH 115
#define RIP_GRAVE_X 90
#define RIP_GRAVE_Y 60
#define RIP_OFFSET_X 10
#define RIP_OFFSET_Y 10
#define RIP_OFFSET_X 10
#define RIP_OFFSET_Y 10
PNHWinApp GetNHApp(void);
typedef struct mswin_nethack_text_window {
HANDLE rip_bmp;
TCHAR* window_text;
TCHAR* rip_text;
HANDLE rip_bmp;
TCHAR *window_text;
TCHAR *rip_text;
} NHRIPWindow, *PNHRIPWindow;
INT_PTR CALLBACK NHRIPWndProc(HWND, UINT, WPARAM, LPARAM);
static void onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam);
HWND mswin_init_RIP_window () {
HWND ret;
PNHRIPWindow data;
ret = CreateDialog(
GetNHApp()->hApp,
MAKEINTRESOURCE(IDD_NHRIP),
GetNHApp()->hMainWnd,
NHRIPWndProc
);
if( !ret ) panic("Cannot create rip window");
data = (PNHRIPWindow)malloc(sizeof(NHRIPWindow));
if( !data ) panic("out of memory");
ZeroMemory(data, sizeof(NHRIPWindow));
SetWindowLongPtr(ret, GWLP_USERDATA, (LONG_PTR)data);
return ret;
}
void mswin_display_RIP_window (HWND hWnd)
HWND
mswin_init_RIP_window()
{
MSG msg;
RECT rt;
PNHRIPWindow data;
HWND mapWnd;
RECT riprt;
RECT clientrect;
RECT textrect;
HDC hdc;
HFONT OldFont;
HWND ret;
PNHRIPWindow data;
data = (PNHRIPWindow)GetWindowLongPtr(hWnd, GWLP_USERDATA);
ret = CreateDialog(GetNHApp()->hApp, MAKEINTRESOURCE(IDD_NHRIP),
GetNHApp()->hMainWnd, NHRIPWndProc);
if (!ret)
panic("Cannot create rip window");
GetNHApp()->hPopupWnd = hWnd;
mapWnd = mswin_hwnd_from_winid(WIN_MAP);
if( !IsWindow(mapWnd) ) mapWnd = GetNHApp()->hMainWnd;
GetWindowRect(mapWnd, &rt);
GetWindowRect(hWnd, &riprt);
GetClientRect (hWnd, &clientrect);
textrect = clientrect;
textrect.top += RIP_OFFSET_Y;
textrect.left += RIP_OFFSET_X;
textrect.right -= RIP_OFFSET_X;
if (data->window_text)
{
hdc = GetDC (hWnd);
OldFont = SelectObject (hdc, mswin_get_font(NHW_TEXT, 0, hdc, FALSE));
DrawText (hdc, data->window_text, strlen(data->window_text), &textrect,
DT_LEFT | DT_NOPREFIX | DT_CALCRECT);
SelectObject (hdc, OldFont);
ReleaseDC(hWnd, hdc);
}
if (textrect.right - textrect.left > RIP_WIDTH)
clientrect.right = textrect.right + RIP_OFFSET_X - clientrect.right;
else
clientrect.right = textrect.left + 2 * RIP_OFFSET_X + RIP_WIDTH - clientrect.right;
clientrect.bottom = textrect.bottom + RIP_HEIGHT + RIP_OFFSET_Y - clientrect.bottom;
GetWindowRect (GetDlgItem(hWnd, IDOK), &textrect);
textrect.right -= textrect.left;
textrect.bottom -= textrect.top;
clientrect.bottom += textrect.bottom + RIP_OFFSET_Y;
riprt.right -= riprt.left;
riprt.bottom -= riprt.top;
riprt.right += clientrect.right;
riprt.bottom += clientrect.bottom;
rt.left += (rt.right - rt.left - riprt.right) / 2;
rt.top += (rt.bottom - rt.top - riprt.bottom) / 2;
data = (PNHRIPWindow) malloc(sizeof(NHRIPWindow));
if (!data)
panic("out of memory");
MoveWindow(hWnd, rt.left, rt.top, riprt.right, riprt.bottom, TRUE);
GetClientRect (hWnd, &clientrect);
MoveWindow (GetDlgItem(hWnd, IDOK),
(clientrect.right - clientrect.left - textrect.right) / 2,
clientrect.bottom - textrect.bottom - RIP_OFFSET_Y, textrect.right, textrect.bottom, TRUE);
ShowWindow(hWnd, SW_SHOW);
while( IsWindow(hWnd) &&
GetMessage(&msg, NULL, 0, 0)!=0 ) {
if( !IsDialogMessage(hWnd, &msg) ) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
GetNHApp()->hPopupWnd = NULL;
ZeroMemory(data, sizeof(NHRIPWindow));
SetWindowLongPtr(ret, GWLP_USERDATA, (LONG_PTR) data);
return ret;
}
INT_PTR CALLBACK NHRIPWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
void
mswin_display_RIP_window(HWND hWnd)
{
HDC hdc;
PNHRIPWindow data;
MSG msg;
RECT rt;
PNHRIPWindow data;
HWND mapWnd;
RECT riprt;
RECT clientrect;
RECT textrect;
HDC hdc;
HFONT OldFont;
data = (PNHRIPWindow)GetWindowLongPtr(hWnd, GWLP_USERDATA);
switch (message)
{
case WM_INITDIALOG:
/* set text control font */
hdc = GetDC(hWnd);
SendMessage(hWnd, WM_SETFONT,
(WPARAM)mswin_get_font(NHW_TEXT, ATR_NONE, hdc, FALSE), 0);
ReleaseDC(hWnd, hdc);
data = (PNHRIPWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA);
SetFocus(GetDlgItem(hWnd, IDOK));
return FALSE;
GetNHApp()->hPopupWnd = hWnd;
mapWnd = mswin_hwnd_from_winid(WIN_MAP);
if (!IsWindow(mapWnd))
mapWnd = GetNHApp()->hMainWnd;
GetWindowRect(mapWnd, &rt);
GetWindowRect(hWnd, &riprt);
GetClientRect(hWnd, &clientrect);
textrect = clientrect;
textrect.top += RIP_OFFSET_Y;
textrect.left += RIP_OFFSET_X;
textrect.right -= RIP_OFFSET_X;
if (data->window_text) {
hdc = GetDC(hWnd);
OldFont = SelectObject(hdc, mswin_get_font(NHW_TEXT, 0, hdc, FALSE));
DrawText(hdc, data->window_text, strlen(data->window_text), &textrect,
DT_LEFT | DT_NOPREFIX | DT_CALCRECT);
SelectObject(hdc, OldFont);
ReleaseDC(hWnd, hdc);
}
if (textrect.right - textrect.left > RIP_WIDTH)
clientrect.right = textrect.right + RIP_OFFSET_X - clientrect.right;
else
clientrect.right =
textrect.left + 2 * RIP_OFFSET_X + RIP_WIDTH - clientrect.right;
clientrect.bottom =
textrect.bottom + RIP_HEIGHT + RIP_OFFSET_Y - clientrect.bottom;
GetWindowRect(GetDlgItem(hWnd, IDOK), &textrect);
textrect.right -= textrect.left;
textrect.bottom -= textrect.top;
clientrect.bottom += textrect.bottom + RIP_OFFSET_Y;
riprt.right -= riprt.left;
riprt.bottom -= riprt.top;
riprt.right += clientrect.right;
riprt.bottom += clientrect.bottom;
rt.left += (rt.right - rt.left - riprt.right) / 2;
rt.top += (rt.bottom - rt.top - riprt.bottom) / 2;
case WM_MSNH_COMMAND:
onMSNHCommand(hWnd, wParam, lParam);
break;
MoveWindow(hWnd, rt.left, rt.top, riprt.right, riprt.bottom, TRUE);
GetClientRect(hWnd, &clientrect);
MoveWindow(GetDlgItem(hWnd, IDOK),
(clientrect.right - clientrect.left - textrect.right) / 2,
clientrect.bottom - textrect.bottom - RIP_OFFSET_Y,
textrect.right, textrect.bottom, TRUE);
ShowWindow(hWnd, SW_SHOW);
case WM_PAINT:
{
int bitmap_offset;
RECT clientrect;
RECT textrect;
HDC hdcBitmap;
HANDLE OldBitmap;
PAINTSTRUCT ps;
HFONT OldFont;
while (IsWindow(hWnd) && GetMessage(&msg, NULL, 0, 0) != 0) {
if (!IsDialogMessage(hWnd, &msg)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
hdc = BeginPaint (hWnd, &ps);
OldFont = SelectObject (hdc, mswin_get_font(NHW_TEXT, 0, hdc, FALSE));
hdcBitmap = CreateCompatibleDC(hdc);
SetBkMode (hdc, TRANSPARENT);
GetClientRect (hWnd, &clientrect);
textrect = clientrect;
textrect.top += RIP_OFFSET_Y;
textrect.left += RIP_OFFSET_X;
textrect.right -= RIP_OFFSET_X;
if (data->window_text)
{
DrawText (hdc, data->window_text, strlen(data->window_text), &textrect,
DT_LEFT | DT_NOPREFIX | DT_CALCRECT);
DrawText (hdc, data->window_text, strlen(data->window_text), &textrect,
DT_LEFT | DT_NOPREFIX);
}
OldBitmap = SelectObject(hdcBitmap, GetNHApp()->bmpRip);
SetBkMode (hdc, OPAQUE);
bitmap_offset = (textrect.right - textrect.left - RIP_WIDTH) / 2;
BitBlt (hdc, textrect.left + bitmap_offset, textrect.bottom, RIP_WIDTH,
RIP_HEIGHT, hdcBitmap, 0, 0, SRCCOPY);
SetBkMode (hdc, TRANSPARENT);
if (data->rip_text)
{
textrect.left += RIP_GRAVE_X + bitmap_offset;
textrect.top = textrect.bottom + RIP_GRAVE_Y;
textrect.right = textrect.left + RIP_GRAVE_WIDTH;
textrect.bottom = textrect.top + RIP_GRAVE_HEIGHT;
DrawText (hdc, data->rip_text, strlen(data->rip_text), &textrect,
DT_CENTER | DT_VCENTER | DT_NOPREFIX | DT_WORDBREAK);
}
SelectObject (hdcBitmap, OldBitmap);
SelectObject (hdc, OldFont);
DeleteDC (hdcBitmap);
EndPaint (hWnd, &ps);
}
break;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDOK:
mswin_window_mark_dead(mswin_winid_from_handle(hWnd));
if( GetNHApp()->hMainWnd==hWnd )
GetNHApp()->hMainWnd=NULL;
DestroyWindow(hWnd);
SetFocus(GetNHApp()->hMainWnd);
return TRUE;
}
break;
case WM_CLOSE:
/* if we get this here, we saved the bones so we can just force a quit */
mswin_window_mark_dead(mswin_winid_from_handle(hWnd));
if( GetNHApp()->hMainWnd==hWnd )
GetNHApp()->hMainWnd=NULL;
DestroyWindow(hWnd);
SetFocus(GetNHApp()->hMainWnd);
program_state.stopprint++;
return TRUE;
case WM_DESTROY:
if( data ) {
if( data->window_text ) free(data->window_text);
if( data->rip_text ) free(data->rip_text);
if (data->rip_bmp != NULL) DeleteObject(data->rip_bmp);
free(data);
SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR)0);
}
break;
}
return FALSE;
GetNHApp()->hPopupWnd = NULL;
}
void onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
INT_PTR CALLBACK
NHRIPWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PNHRIPWindow data;
static int InRipText = 1;
data = (PNHRIPWindow)GetWindowLongPtr(hWnd, GWLP_USERDATA);
switch( wParam ) {
case MSNH_MSG_PUTSTR: {
PMSNHMsgPutstr msg_data = (PMSNHMsgPutstr)lParam;
TCHAR wbuf[BUFSZ];
size_t text_size;
HDC hdc;
PNHRIPWindow data;
if( !data->window_text ) {
text_size = strlen(msg_data->text) + 4;
data->window_text = (TCHAR*)malloc(text_size*sizeof(data->window_text[0]));
ZeroMemory(data->window_text, text_size*sizeof(data->window_text[0]));
} else {
text_size = _tcslen(data->window_text) + strlen(msg_data->text) + 4;
data->window_text = (TCHAR*)realloc(data->window_text, text_size*sizeof(data->window_text[0]));
}
if( !data->window_text ) break;
data = (PNHRIPWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA);
switch (message) {
case WM_INITDIALOG:
/* set text control font */
hdc = GetDC(hWnd);
SendMessage(hWnd, WM_SETFONT,
(WPARAM) mswin_get_font(NHW_TEXT, ATR_NONE, hdc, FALSE),
0);
ReleaseDC(hWnd, hdc);
_tcscat(data->window_text, NH_A2W(msg_data->text, wbuf, BUFSZ));
_tcscat(data->window_text, TEXT("\r\n"));
break;
}
case MSNH_MSG_DIED:
{
data->rip_text = data->window_text;
data->window_text = NULL;
break;
}
SetFocus(GetDlgItem(hWnd, IDOK));
return FALSE;
}
case WM_MSNH_COMMAND:
onMSNHCommand(hWnd, wParam, lParam);
break;
case WM_PAINT: {
int bitmap_offset;
RECT clientrect;
RECT textrect;
HDC hdcBitmap;
HANDLE OldBitmap;
PAINTSTRUCT ps;
HFONT OldFont;
hdc = BeginPaint(hWnd, &ps);
OldFont = SelectObject(hdc, mswin_get_font(NHW_TEXT, 0, hdc, FALSE));
hdcBitmap = CreateCompatibleDC(hdc);
SetBkMode(hdc, TRANSPARENT);
GetClientRect(hWnd, &clientrect);
textrect = clientrect;
textrect.top += RIP_OFFSET_Y;
textrect.left += RIP_OFFSET_X;
textrect.right -= RIP_OFFSET_X;
if (data->window_text) {
DrawText(hdc, data->window_text, strlen(data->window_text),
&textrect, DT_LEFT | DT_NOPREFIX | DT_CALCRECT);
DrawText(hdc, data->window_text, strlen(data->window_text),
&textrect, DT_LEFT | DT_NOPREFIX);
}
OldBitmap = SelectObject(hdcBitmap, GetNHApp()->bmpRip);
SetBkMode(hdc, OPAQUE);
bitmap_offset = (textrect.right - textrect.left - RIP_WIDTH) / 2;
BitBlt(hdc, textrect.left + bitmap_offset, textrect.bottom, RIP_WIDTH,
RIP_HEIGHT, hdcBitmap, 0, 0, SRCCOPY);
SetBkMode(hdc, TRANSPARENT);
if (data->rip_text) {
textrect.left += RIP_GRAVE_X + bitmap_offset;
textrect.top = textrect.bottom + RIP_GRAVE_Y;
textrect.right = textrect.left + RIP_GRAVE_WIDTH;
textrect.bottom = textrect.top + RIP_GRAVE_HEIGHT;
DrawText(hdc, data->rip_text, strlen(data->rip_text), &textrect,
DT_CENTER | DT_VCENTER | DT_NOPREFIX | DT_WORDBREAK);
}
SelectObject(hdcBitmap, OldBitmap);
SelectObject(hdc, OldFont);
DeleteDC(hdcBitmap);
EndPaint(hWnd, &ps);
} break;
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDOK:
mswin_window_mark_dead(mswin_winid_from_handle(hWnd));
if (GetNHApp()->hMainWnd == hWnd)
GetNHApp()->hMainWnd = NULL;
DestroyWindow(hWnd);
SetFocus(GetNHApp()->hMainWnd);
return TRUE;
}
break;
case WM_CLOSE:
/* if we get this here, we saved the bones so we can just force a quit
*/
mswin_window_mark_dead(mswin_winid_from_handle(hWnd));
if (GetNHApp()->hMainWnd == hWnd)
GetNHApp()->hMainWnd = NULL;
DestroyWindow(hWnd);
SetFocus(GetNHApp()->hMainWnd);
program_state.stopprint++;
return TRUE;
case WM_DESTROY:
if (data) {
if (data->window_text)
free(data->window_text);
if (data->rip_text)
free(data->rip_text);
if (data->rip_bmp != NULL)
DeleteObject(data->rip_bmp);
free(data);
SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR) 0);
}
break;
}
return FALSE;
}
void mswin_finish_rip_text(winid wid)
void
onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
SendMessage (mswin_hwnd_from_winid(wid), WM_MSNH_COMMAND, MSNH_MSG_DIED, 0);
PNHRIPWindow data;
static int InRipText = 1;
data = (PNHRIPWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA);
switch (wParam) {
case MSNH_MSG_PUTSTR: {
PMSNHMsgPutstr msg_data = (PMSNHMsgPutstr) lParam;
TCHAR wbuf[BUFSZ];
size_t text_size;
if (!data->window_text) {
text_size = strlen(msg_data->text) + 4;
data->window_text =
(TCHAR *) malloc(text_size * sizeof(data->window_text[0]));
ZeroMemory(data->window_text,
text_size * sizeof(data->window_text[0]));
} else {
text_size =
_tcslen(data->window_text) + strlen(msg_data->text) + 4;
data->window_text = (TCHAR *) realloc(
data->window_text, text_size * sizeof(data->window_text[0]));
}
if (!data->window_text)
break;
_tcscat(data->window_text, NH_A2W(msg_data->text, wbuf, BUFSZ));
_tcscat(data->window_text, TEXT("\r\n"));
break;
}
case MSNH_MSG_DIED: {
data->rip_text = data->window_text;
data->window_text = NULL;
break;
}
}
}
void
mswin_finish_rip_text(winid wid)
{
SendMessage(mswin_hwnd_from_winid(wid), WM_MSNH_COMMAND, MSNH_MSG_DIED,
0);
}
+203 -209
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 mhsplash.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
/* NetHack 3.6 mhsplash.c $NHDT-Date: 1431192777 2015/05/09 17:32:57 $ $NHDT-Branch: master $:$NHDT-Revision: 1.24 $ */
/* NetHack 3.6 mhsplash.c $Date: 2012/01/11 01:15:37 $ $Revision: 1.17 $ */
/* Copyright (C) 2001 by Alex Kompel */
/* NetHack may be freely redistributed. See license for details. */
@@ -18,236 +18,230 @@ PNHWinApp GetNHApp(void);
INT_PTR CALLBACK NHSplashWndProc(HWND, UINT, WPARAM, LPARAM);
#define SPLASH_WIDTH 440
#define SPLASH_HEIGHT 322
#define SPLASH_VERSION_X 290
#define SPLASH_VERSION_Y 10
#define SPLASH_OFFSET_X 10
#define SPLASH_OFFSET_Y 10
#define SPLASH_WIDTH 440
#define SPLASH_HEIGHT 322
#define SPLASH_VERSION_X 290
#define SPLASH_VERSION_Y 10
#define SPLASH_OFFSET_X 10
#define SPLASH_OFFSET_Y 10
extern HFONT version_splash_font;
void mswin_display_splash_window (BOOL show_ver)
void
mswin_display_splash_window(BOOL show_ver)
{
MSG msg;
int left, top;
RECT splashrt;
RECT clientrt;
RECT controlrt;
HWND hWnd;
int buttop;
int strsize = 0;
int bufsize = BUFSZ;
char *buf = malloc(bufsize);
if (buf == NULL)
panic("out of memory");
buf[0] = '\0';
MSG msg;
int left, top;
RECT splashrt;
RECT clientrt;
RECT controlrt;
HWND hWnd;
int buttop;
int strsize = 0;
int bufsize = BUFSZ;
char *buf = malloc(bufsize);
hWnd = CreateDialog(GetNHApp()->hApp, MAKEINTRESOURCE(IDD_SPLASH),
GetNHApp()->hMainWnd, NHSplashWndProc);
if( !hWnd ) panic("Cannot create Splash window");
mswin_init_splashfonts(hWnd);
GetNHApp()->hPopupWnd = hWnd;
/* Get control size */
GetWindowRect (GetDlgItem(hWnd, IDOK), &controlrt);
controlrt.right -= controlrt.left;
controlrt.bottom -= controlrt.top;
/* Get current client area */
GetClientRect (hWnd, &clientrt);
/* Get window size */
GetWindowRect(hWnd, &splashrt);
splashrt.right -= splashrt.left;
splashrt.bottom -= splashrt.top;
/* Get difference between requested client area and current value */
splashrt.right += SPLASH_WIDTH + SPLASH_OFFSET_X * 2 - clientrt.right;
splashrt.bottom += SPLASH_HEIGHT + controlrt.bottom + SPLASH_OFFSET_Y * 3 - clientrt.bottom;
/* Place the window centered */
/* On the screen, not on the parent window */
left = (GetSystemMetrics(SM_CXSCREEN) - splashrt.right) / 2;
top = (GetSystemMetrics(SM_CYSCREEN) - splashrt.bottom) / 2;
MoveWindow(hWnd, left, top, splashrt.right, splashrt.bottom, TRUE);
/* Place the OK control */
GetClientRect (hWnd, &clientrt);
MoveWindow (GetDlgItem(hWnd, IDOK),
(clientrt.right - clientrt.left - controlrt.right) / 2,
clientrt.bottom - controlrt.bottom - SPLASH_OFFSET_Y,
controlrt.right, controlrt.bottom, TRUE);
buttop = clientrt.bottom - controlrt.bottom - SPLASH_OFFSET_Y;
/* Place the text control */
GetWindowRect (GetDlgItem(hWnd, IDC_EXTRAINFO), &controlrt);
controlrt.right -= controlrt.left;
controlrt.bottom -= controlrt.top;
GetClientRect (hWnd, &clientrt);
MoveWindow (GetDlgItem(hWnd, IDC_EXTRAINFO),
clientrt.left + SPLASH_OFFSET_X,
buttop - controlrt.bottom - SPLASH_OFFSET_Y,
clientrt.right - 2 * SPLASH_OFFSET_X, controlrt.bottom, TRUE);
if (buf == NULL)
panic("out of memory");
buf[0] = '\0';
/* Fill the text control */
Sprintf (buf, "%s\r\n%s\r\n%s\r\n%s\r\n\r\n", COPYRIGHT_BANNER_A, COPYRIGHT_BANNER_B,
COPYRIGHT_BANNER_C, COPYRIGHT_BANNER_D);
strsize = strlen(buf);
hWnd = CreateDialog(GetNHApp()->hApp, MAKEINTRESOURCE(IDD_SPLASH),
GetNHApp()->hMainWnd, NHSplashWndProc);
if (!hWnd)
panic("Cannot create Splash window");
mswin_init_splashfonts(hWnd);
GetNHApp()->hPopupWnd = hWnd;
/* Get control size */
GetWindowRect(GetDlgItem(hWnd, IDOK), &controlrt);
controlrt.right -= controlrt.left;
controlrt.bottom -= controlrt.top;
/* Get current client area */
GetClientRect(hWnd, &clientrt);
/* Get window size */
GetWindowRect(hWnd, &splashrt);
splashrt.right -= splashrt.left;
splashrt.bottom -= splashrt.top;
/* Get difference between requested client area and current value */
splashrt.right += SPLASH_WIDTH + SPLASH_OFFSET_X * 2 - clientrt.right;
splashrt.bottom += SPLASH_HEIGHT + controlrt.bottom + SPLASH_OFFSET_Y * 3
- clientrt.bottom;
/* Place the window centered */
/* On the screen, not on the parent window */
left = (GetSystemMetrics(SM_CXSCREEN) - splashrt.right) / 2;
top = (GetSystemMetrics(SM_CYSCREEN) - splashrt.bottom) / 2;
MoveWindow(hWnd, left, top, splashrt.right, splashrt.bottom, TRUE);
/* Place the OK control */
GetClientRect(hWnd, &clientrt);
MoveWindow(GetDlgItem(hWnd, IDOK),
(clientrt.right - clientrt.left - controlrt.right) / 2,
clientrt.bottom - controlrt.bottom - SPLASH_OFFSET_Y,
controlrt.right, controlrt.bottom, TRUE);
buttop = clientrt.bottom - controlrt.bottom - SPLASH_OFFSET_Y;
/* Place the text control */
GetWindowRect(GetDlgItem(hWnd, IDC_EXTRAINFO), &controlrt);
controlrt.right -= controlrt.left;
controlrt.bottom -= controlrt.top;
GetClientRect(hWnd, &clientrt);
MoveWindow(GetDlgItem(hWnd, IDC_EXTRAINFO),
clientrt.left + SPLASH_OFFSET_X,
buttop - controlrt.bottom - SPLASH_OFFSET_Y,
clientrt.right - 2 * SPLASH_OFFSET_X, controlrt.bottom, TRUE);
if (show_ver) {
/* Show complete version information */
dlb *f;
/* Fill the text control */
Sprintf(buf, "%s\r\n%s\r\n%s\r\n%s\r\n\r\n", COPYRIGHT_BANNER_A,
COPYRIGHT_BANNER_B, COPYRIGHT_BANNER_C, COPYRIGHT_BANNER_D);
strsize = strlen(buf);
getversionstring(buf + strsize);
strcat(buf, "\r\n\r\n");
strsize = strlen(buf);
if (show_ver) {
/* Show complete version information */
dlb *f;
/* Add compile options */
f = dlb_fopen(OPTIONS_USED, RDTMODE);
if (f) {
char line[LLEN + 1];
while (dlb_fgets(line, LLEN, f)) {
size_t len;
len = strlen(line);
if (len > 0 && line[len - 1] == '\n') {
line[len - 1] = '\r';
line[len] = '\n';
line[len + 1] = '\0';
len++;
}
if (strsize + (int)len + 1 > bufsize)
{
bufsize += BUFSZ;
buf = realloc(buf, bufsize);
if (buf == NULL)
panic("out of memory");
}
strcat(buf, line);
strsize += len;
}
(void) dlb_fclose(f);
}
} else {
/* Show news, if any */
if (iflags.news) {
FILE *nf;
getversionstring(buf + strsize);
strcat(buf, "\r\n\r\n");
strsize = strlen(buf);
iflags.news = 0; /* prevent newgame() from re-displaying news */
nf = fopen(NEWS, "r");
if (nf != NULL) {
char line[LLEN + 1];
while (fgets(line, LLEN, nf)) {
size_t len;
len = strlen(line);
if (len > 0 && line[len - 1] == '\n') {
line[len - 1] = '\r';
line[len] = '\n';
line[len + 1] = '\0';
len++;
}
if (strsize + (int)len + 1 > bufsize)
{
bufsize += BUFSZ;
buf = realloc(buf, bufsize);
if (buf == NULL)
panic("out of memory");
}
strcat(buf, line);
strsize += len;
}
(void) fclose(nf);
}
else
{
strcat(buf, "No news.");
}
}
}
SetWindowText(GetDlgItem(hWnd, IDC_EXTRAINFO), buf);
free(buf);
ShowWindow(hWnd, SW_SHOW);
/* Add compile options */
f = dlb_fopen(OPTIONS_USED, RDTMODE);
if (f) {
char line[LLEN + 1];
while( IsWindow(hWnd) &&
GetMessage(&msg, NULL, 0, 0)!=0 ) {
if( !IsDialogMessage(hWnd, &msg) ) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
GetNHApp()->hPopupWnd = NULL;
mswin_destroy_splashfonts();
while (dlb_fgets(line, LLEN, f)) {
size_t len;
len = strlen(line);
if (len > 0 && line[len - 1] == '\n') {
line[len - 1] = '\r';
line[len] = '\n';
line[len + 1] = '\0';
len++;
}
if (strsize + (int) len + 1 > bufsize) {
bufsize += BUFSZ;
buf = realloc(buf, bufsize);
if (buf == NULL)
panic("out of memory");
}
strcat(buf, line);
strsize += len;
}
(void) dlb_fclose(f);
}
} else {
/* Show news, if any */
if (iflags.news) {
FILE *nf;
iflags.news = 0; /* prevent newgame() from re-displaying news */
nf = fopen(NEWS, "r");
if (nf != NULL) {
char line[LLEN + 1];
while (fgets(line, LLEN, nf)) {
size_t len;
len = strlen(line);
if (len > 0 && line[len - 1] == '\n') {
line[len - 1] = '\r';
line[len] = '\n';
line[len + 1] = '\0';
len++;
}
if (strsize + (int) len + 1 > bufsize) {
bufsize += BUFSZ;
buf = realloc(buf, bufsize);
if (buf == NULL)
panic("out of memory");
}
strcat(buf, line);
strsize += len;
}
(void) fclose(nf);
} else {
strcat(buf, "No news.");
}
}
}
SetWindowText(GetDlgItem(hWnd, IDC_EXTRAINFO), buf);
free(buf);
ShowWindow(hWnd, SW_SHOW);
while (IsWindow(hWnd) && GetMessage(&msg, NULL, 0, 0) != 0) {
if (!IsDialogMessage(hWnd, &msg)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
GetNHApp()->hPopupWnd = NULL;
mswin_destroy_splashfonts();
}
INT_PTR CALLBACK NHSplashWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
INT_PTR CALLBACK
NHSplashWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
HDC hdc;
UNREFERENCED_PARAMETER(lParam);
UNREFERENCED_PARAMETER(lParam);
switch (message)
{
case WM_INITDIALOG:
/* set text control font */
hdc = GetDC(hWnd);
SendMessage(hWnd, WM_SETFONT,
(WPARAM)mswin_get_font(NHW_TEXT, ATR_NONE, hdc, FALSE), 0);
ReleaseDC(hWnd, hdc);
switch (message) {
case WM_INITDIALOG:
/* set text control font */
hdc = GetDC(hWnd);
SendMessage(hWnd, WM_SETFONT,
(WPARAM) mswin_get_font(NHW_TEXT, ATR_NONE, hdc, FALSE),
0);
ReleaseDC(hWnd, hdc);
SetFocus(GetDlgItem(hWnd, IDOK));
return FALSE;
SetFocus(GetDlgItem(hWnd, IDOK));
return FALSE;
case WM_PAINT:
{
char VersionString[BUFSZ];
RECT rt;
HDC hdcBitmap;
HANDLE OldBitmap;
HANDLE OldFont;
PAINTSTRUCT ps;
case WM_PAINT: {
char VersionString[BUFSZ];
RECT rt;
HDC hdcBitmap;
HANDLE OldBitmap;
HANDLE OldFont;
PAINTSTRUCT ps;
hdc = BeginPaint (hWnd, &ps);
/* Show splash graphic */
hdc = BeginPaint(hWnd, &ps);
/* Show splash graphic */
hdcBitmap = CreateCompatibleDC(hdc);
SetBkMode (hdc, OPAQUE);
OldBitmap = SelectObject(hdcBitmap, GetNHApp()->bmpSplash);
nhapply_image_transparent(hdc, SPLASH_OFFSET_X, SPLASH_OFFSET_Y,
SPLASH_WIDTH, SPLASH_HEIGHT,
hdcBitmap, 0, 0, SPLASH_WIDTH, SPLASH_HEIGHT,
TILE_BK_COLOR);
hdcBitmap = CreateCompatibleDC(hdc);
SetBkMode(hdc, OPAQUE);
OldBitmap = SelectObject(hdcBitmap, GetNHApp()->bmpSplash);
nhapply_image_transparent(hdc, SPLASH_OFFSET_X, SPLASH_OFFSET_Y,
SPLASH_WIDTH, SPLASH_HEIGHT, hdcBitmap, 0,
0, SPLASH_WIDTH, SPLASH_HEIGHT,
TILE_BK_COLOR);
SelectObject (hdcBitmap, OldBitmap);
DeleteDC (hdcBitmap);
SelectObject(hdcBitmap, OldBitmap);
DeleteDC(hdcBitmap);
SetBkMode (hdc, TRANSPARENT);
/* Print version number */
SetBkMode(hdc, TRANSPARENT);
/* Print version number */
SetTextColor (hdc, RGB(0, 0, 0));
rt.right = rt.left = SPLASH_VERSION_X;
rt.bottom = rt.top = SPLASH_VERSION_Y;
Sprintf (VersionString, "%d.%d.%d", VERSION_MAJOR, VERSION_MINOR,
PATCHLEVEL);
OldFont = SelectObject(hdc, version_splash_font);
DrawText (hdc, VersionString, strlen(VersionString), &rt,
DT_LEFT | DT_NOPREFIX | DT_CALCRECT);
DrawText (hdc, VersionString, strlen(VersionString), &rt,
DT_LEFT | DT_NOPREFIX);
EndPaint (hWnd, &ps);
}
break;
SetTextColor(hdc, RGB(0, 0, 0));
rt.right = rt.left = SPLASH_VERSION_X;
rt.bottom = rt.top = SPLASH_VERSION_Y;
Sprintf(VersionString, "%d.%d.%d", VERSION_MAJOR, VERSION_MINOR,
PATCHLEVEL);
OldFont = SelectObject(hdc, version_splash_font);
DrawText(hdc, VersionString, strlen(VersionString), &rt,
DT_LEFT | DT_NOPREFIX | DT_CALCRECT);
DrawText(hdc, VersionString, strlen(VersionString), &rt,
DT_LEFT | DT_NOPREFIX);
EndPaint(hWnd, &ps);
} break;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDOK:
mswin_window_mark_dead(mswin_winid_from_handle(hWnd));
if( GetNHApp()->hMainWnd==hWnd )
GetNHApp()->hMainWnd=NULL;
DestroyWindow(hWnd);
SetFocus(GetNHApp()->hMainWnd);
return TRUE;
}
break;
}
return FALSE;
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDOK:
mswin_window_mark_dead(mswin_winid_from_handle(hWnd));
if (GetNHApp()->hMainWnd == hWnd)
GetNHApp()->hMainWnd = NULL;
DestroyWindow(hWnd);
SetFocus(GetNHApp()->hMainWnd);
return TRUE;
}
break;
}
return FALSE;
}
+297 -283
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 mhstatus.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
/* NetHack 3.6 mhstatus.c $NHDT-Date: 1431192775 2015/05/09 17:32:55 $ $NHDT-Branch: master $:$NHDT-Revision: 1.21 $ */
/* NetHack 3.6 mhstatus.c $Date: 2012/01/11 01:45:02 $ $Revision: 1.14 $ */
/* Copyright (C) 2001 by Alex Kompel */
/* NetHack may be freely redistributed. See license for details. */
@@ -8,342 +8,356 @@
#include "mhmsg.h"
#include "mhfont.h"
#define NHSW_LINES 2
#define NHSW_LINES 2
#define MAXWINDOWTEXT BUFSZ
extern COLORREF nhcolor_to_RGB (int c); /* from mhmap */
extern COLORREF nhcolor_to_RGB(int c); /* from mhmap */
typedef struct mswin_nethack_status_window {
int index;
char window_text[NHSW_LINES][MAXWINDOWTEXT+1];
int n_fields;
const char** vals;
boolean* activefields;
int* colors;
int index;
char window_text[NHSW_LINES][MAXWINDOWTEXT + 1];
int n_fields;
const char **vals;
boolean *activefields;
int *colors;
} NHStatusWindow, *PNHStatusWindow;
#ifdef STATUS_VIA_WINDOWPORT
static int fieldorder1[] = {
BL_TITLE, BL_STR, BL_DX,BL_CO, BL_IN,
BL_WI, BL_CH,BL_ALIGN, BL_SCORE, -1
};
static int fieldorder2[] = {
BL_LEVELDESC, BL_GOLD, BL_HP, BL_HPMAX,
BL_ENE, BL_ENEMAX, BL_AC, BL_XP, BL_EXP, BL_HD,
BL_TIME, BL_HUNGER,BL_CAP, BL_CONDITION, -1
};
static int* fieldorders[] = {fieldorder1, fieldorder2, NULL};
static int fieldorder1[] = { BL_TITLE, BL_STR, BL_DX, BL_CO, BL_IN,
BL_WI, BL_CH, BL_ALIGN, BL_SCORE, -1 };
static int fieldorder2[] = { BL_LEVELDESC, BL_GOLD, BL_HP, BL_HPMAX,
BL_ENE, BL_ENEMAX, BL_AC, BL_XP,
BL_EXP, BL_HD, BL_TIME, BL_HUNGER,
BL_CAP, BL_CONDITION, -1 };
static int *fieldorders[] = { fieldorder1, fieldorder2, NULL };
#endif /* STATUS_VIA_WINDOWPORT */
static TCHAR szStatusWindowClass[] = TEXT("MSNHStatusWndClass");
LRESULT CALLBACK StatusWndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK StatusWndProc(HWND, UINT, WPARAM, LPARAM);
static void register_status_window_class(void);
static LRESULT onWMPaint(HWND hWnd, WPARAM wParam, LPARAM lParam);
static LRESULT onWMPaint(HWND hWnd, WPARAM wParam, LPARAM lParam);
#define DEFAULT_COLOR_BG_STATUS COLOR_WINDOW
#define DEFAULT_COLOR_FG_STATUS COLOR_WINDOWTEXT
#define DEFAULT_COLOR_BG_STATUS COLOR_WINDOW
#define DEFAULT_COLOR_FG_STATUS COLOR_WINDOWTEXT
HWND mswin_init_status_window () {
static int run_once = 0;
HWND ret;
NHStatusWindow* data;
RECT rt;
HWND
mswin_init_status_window()
{
static int run_once = 0;
HWND ret;
NHStatusWindow *data;
RECT rt;
if( !run_once ) {
register_status_window_class( );
run_once = 1;
}
if (!run_once) {
register_status_window_class();
run_once = 1;
}
/* get window position */
if( GetNHApp()->bAutoLayout ) {
SetRect( &rt, 0, 0, 0, 0);
} else {
mswin_get_window_placement(NHW_STATUS, &rt);
}
/* get window position */
if (GetNHApp()->bAutoLayout) {
SetRect(&rt, 0, 0, 0, 0);
} else {
mswin_get_window_placement(NHW_STATUS, &rt);
}
/* create status window object */
ret = CreateWindow(
szStatusWindowClass,
NULL,
WS_CHILD | WS_CLIPSIBLINGS | WS_SIZEBOX,
rt.left, /* horizontal position of window */
rt.top, /* vertical position of window */
rt.right - rt.left, /* window width */
rt.bottom - rt.top, /* window height */
GetNHApp()->hMainWnd,
NULL,
GetNHApp()->hApp,
NULL );
if( !ret ) panic("Cannot create status window");
/* create status window object */
ret = CreateWindow(szStatusWindowClass, NULL,
WS_CHILD | WS_CLIPSIBLINGS | WS_SIZEBOX,
rt.left, /* horizontal position of window */
rt.top, /* vertical position of window */
rt.right - rt.left, /* window width */
rt.bottom - rt.top, /* window height */
GetNHApp()->hMainWnd, NULL, GetNHApp()->hApp, NULL);
if (!ret)
panic("Cannot create status window");
/* Set window caption */
SetWindowText(ret, "Status");
/* Set window caption */
SetWindowText(ret, "Status");
/* create window data */
data = (PNHStatusWindow)malloc(sizeof(NHStatusWindow));
if( !data ) panic("out of memory");
/* create window data */
data = (PNHStatusWindow) malloc(sizeof(NHStatusWindow));
if (!data)
panic("out of memory");
ZeroMemory(data, sizeof(NHStatusWindow));
SetWindowLongPtr(ret, GWLP_USERDATA, (LONG_PTR)data);
return ret;
ZeroMemory(data, sizeof(NHStatusWindow));
SetWindowLongPtr(ret, GWLP_USERDATA, (LONG_PTR) data);
return ret;
}
void register_status_window_class()
void
register_status_window_class()
{
WNDCLASS wcex;
ZeroMemory( &wcex, sizeof(wcex));
WNDCLASS wcex;
ZeroMemory(&wcex, sizeof(wcex));
wcex.style = CS_NOCLOSE;
wcex.lpfnWndProc = (WNDPROC)StatusWndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = GetNHApp()->hApp;
wcex.hIcon = NULL;
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = status_bg_brush
? status_bg_brush : SYSCLR_TO_BRUSH(DEFAULT_COLOR_BG_STATUS);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = szStatusWindowClass;
wcex.style = CS_NOCLOSE;
wcex.lpfnWndProc = (WNDPROC) StatusWndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = GetNHApp()->hApp;
wcex.hIcon = NULL;
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = status_bg_brush
? status_bg_brush
: SYSCLR_TO_BRUSH(DEFAULT_COLOR_BG_STATUS);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = szStatusWindowClass;
RegisterClass(&wcex);
RegisterClass(&wcex);
}
LRESULT CALLBACK StatusWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PNHStatusWindow data;
data = (PNHStatusWindow)GetWindowLongPtr(hWnd, GWLP_USERDATA);
switch (message)
{
case WM_MSNH_COMMAND: {
switch( wParam ) {
case MSNH_MSG_PUTSTR: {
PMSNHMsgPutstr msg_data = (PMSNHMsgPutstr)lParam;
strncpy(data->window_text[data->index], msg_data->text,
MAXWINDOWTEXT);
data->index = (data->index+1) % NHSW_LINES;
InvalidateRect(hWnd, NULL, TRUE);
} break;
case MSNH_MSG_CLEAR_WINDOW: {
data->index = 0;
ZeroMemory(data->window_text, sizeof(data->window_text));
InvalidateRect(hWnd, NULL, TRUE);
} break;
case MSNH_MSG_GETTEXT: {
PMSNHMsgGetText msg_data = (PMSNHMsgGetText)lParam;
LRESULT CALLBACK
StatusWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PNHStatusWindow data;
data = (PNHStatusWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA);
switch (message) {
case WM_MSNH_COMMAND: {
switch (wParam) {
case MSNH_MSG_PUTSTR: {
PMSNHMsgPutstr msg_data = (PMSNHMsgPutstr) lParam;
strncpy(data->window_text[data->index], msg_data->text,
MAXWINDOWTEXT);
data->index = (data->index + 1) % NHSW_LINES;
InvalidateRect(hWnd, NULL, TRUE);
} break;
case MSNH_MSG_CLEAR_WINDOW: {
data->index = 0;
ZeroMemory(data->window_text, sizeof(data->window_text));
InvalidateRect(hWnd, NULL, TRUE);
} break;
case MSNH_MSG_GETTEXT: {
PMSNHMsgGetText msg_data = (PMSNHMsgGetText) lParam;
#ifdef STATUS_VIA_WINDOWPORT
int **fop;
int *f;
msg_data->buffer[0] = '\0';
if( data->n_fields>0 ) {
for(fop = fieldorders; *fop; fop++) {
for(f=*fop; *f!=-1; f++) {
if (data->activefields[*f])
strncat(msg_data->buffer, data->vals[*f], msg_data->max_size - strlen(msg_data->buffer));
}
strncat(msg_data->buffer, "\r\n", msg_data->max_size - strlen(msg_data->buffer) );
}
}
#else /* STATUS_VIA_WINDOWPORT */
strncpy(msg_data->buffer, data->window_text[0], msg_data->max_size);
strncat(msg_data->buffer, "\r\n", msg_data->max_size - strlen(msg_data->buffer) );
strncat(msg_data->buffer, data->window_text[1], msg_data->max_size - strlen(msg_data->buffer) );
int **fop;
int *f;
msg_data->buffer[0] = '\0';
if (data->n_fields > 0) {
for (fop = fieldorders; *fop; fop++) {
for (f = *fop; *f != -1; f++) {
if (data->activefields[*f])
strncat(msg_data->buffer, data->vals[*f],
msg_data->max_size
- strlen(msg_data->buffer));
}
strncat(msg_data->buffer, "\r\n",
msg_data->max_size - strlen(msg_data->buffer));
}
}
#else /* STATUS_VIA_WINDOWPORT */
strncpy(msg_data->buffer, data->window_text[0],
msg_data->max_size);
strncat(msg_data->buffer, "\r\n",
msg_data->max_size - strlen(msg_data->buffer));
strncat(msg_data->buffer, data->window_text[1],
msg_data->max_size - strlen(msg_data->buffer));
#endif /* STATUS_VIA_WINDOWPORT */
} break;
} break;
case MSNH_MSG_UPDATE_STATUS: {
PMSNHMsgUpdateStatus msg_data = (PMSNHMsgUpdateStatus)lParam;
data->n_fields = msg_data->n_fields;
data->vals = msg_data->vals;
data->activefields = msg_data->activefields;
data->colors = msg_data->colors;
InvalidateRect(hWnd, NULL, TRUE);
} break;
} /* end switch( wParam ) { */
} break;
case MSNH_MSG_UPDATE_STATUS: {
PMSNHMsgUpdateStatus msg_data = (PMSNHMsgUpdateStatus) lParam;
data->n_fields = msg_data->n_fields;
data->vals = msg_data->vals;
data->activefields = msg_data->activefields;
data->colors = msg_data->colors;
InvalidateRect(hWnd, NULL, TRUE);
} break;
} /* end switch( wParam ) { */
} break;
case WM_PAINT:
return onWMPaint(hWnd, wParam, lParam);
case WM_PAINT:
return onWMPaint(hWnd, wParam, lParam);
case WM_SIZE: {
RECT rt;
GetWindowRect(hWnd, &rt);
ScreenToClient(GetNHApp()->hMainWnd, (LPPOINT)&rt);
ScreenToClient(GetNHApp()->hMainWnd, ((LPPOINT)&rt)+1);
mswin_update_window_placement(NHW_STATUS, &rt);
} return FALSE;
case WM_SIZE: {
RECT rt;
GetWindowRect(hWnd, &rt);
ScreenToClient(GetNHApp()->hMainWnd, (LPPOINT) &rt);
ScreenToClient(GetNHApp()->hMainWnd, ((LPPOINT) &rt) + 1);
mswin_update_window_placement(NHW_STATUS, &rt);
}
return FALSE;
case WM_MOVE: {
RECT rt;
GetWindowRect(hWnd, &rt);
ScreenToClient(GetNHApp()->hMainWnd, (LPPOINT)&rt);
ScreenToClient(GetNHApp()->hMainWnd, ((LPPOINT)&rt)+1);
mswin_update_window_placement(NHW_STATUS, &rt);
} return FALSE;
case WM_MOVE: {
RECT rt;
GetWindowRect(hWnd, &rt);
ScreenToClient(GetNHApp()->hMainWnd, (LPPOINT) &rt);
ScreenToClient(GetNHApp()->hMainWnd, ((LPPOINT) &rt) + 1);
mswin_update_window_placement(NHW_STATUS, &rt);
}
return FALSE;
case WM_DESTROY:
free(data);
SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR)0);
break;
case WM_DESTROY:
free(data);
SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR) 0);
break;
case WM_SETFOCUS:
SetFocus(GetNHApp()->hMainWnd);
break;
case WM_SETFOCUS:
SetFocus(GetNHApp()->hMainWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
#ifdef STATUS_VIA_WINDOWPORT
static LRESULT onWMPaint(HWND hWnd, WPARAM wParam, LPARAM lParam)
static LRESULT
onWMPaint(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
int* f;
int** fop;
SIZE sz;
HGDIOBJ oldFont, normalFont, boldFont;
TCHAR wbuf[BUFSZ];
COLORREF OldBg, OldFg, Bg, Fg;
RECT rt;
PAINTSTRUCT ps;
HDC hdc;
PNHStatusWindow data;
data = (PNHStatusWindow)GetWindowLongPtr(hWnd, GWLP_USERDATA);
int *f;
int **fop;
SIZE sz;
HGDIOBJ oldFont, normalFont, boldFont;
TCHAR wbuf[BUFSZ];
COLORREF OldBg, OldFg, Bg, Fg;
RECT rt;
PAINTSTRUCT ps;
HDC hdc;
PNHStatusWindow data;
hdc = BeginPaint(hWnd, &ps);
GetClientRect(hWnd, &rt);
normalFont = mswin_get_font(NHW_STATUS, ATR_NONE, hdc, FALSE);
boldFont = mswin_get_font(NHW_STATUS, ATR_BOLD, hdc, FALSE);
oldFont = SelectObject(hdc, normalFont);
data = (PNHStatusWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA);
Bg = status_bg_brush? status_bg_color : (COLORREF)GetSysColor(DEFAULT_COLOR_BG_STATUS);
OldBg = SetBkColor(hdc, Bg);
Fg = status_fg_brush? status_fg_color : (COLORREF)GetSysColor(DEFAULT_COLOR_FG_STATUS);
OldFg = SetTextColor(hdc, Fg);
for(fop = fieldorders; *fop; fop++) {
LONG left = rt.left;
LONG cy = 0;
int vlen;
for(f=*fop; *f!=-1; f++) {
if( ((*f)>= data->n_fields) || (!data->activefields[*f])) continue;
vlen = strlen(data->vals[*f]);
NH_A2W(data->vals[*f], wbuf, SIZE(wbuf));
if(data->colors[*f]==CLR_MAX || data->colors[*f]==BL_HILITE_NONE) {
SelectObject(hdc, normalFont);
SetBkColor(hdc, Bg);
SetTextColor(hdc, Fg);
} else if(data->colors[*f]>0) {
SelectObject(hdc, normalFont);
SetBkColor(hdc, Bg);
SetTextColor(hdc, nhcolor_to_RGB(data->colors[*f]));
} else if(data->colors[*f]==BL_HILITE_INVERSE) {
SelectObject(hdc, normalFont);
SetBkColor(hdc, Fg);
SetTextColor(hdc, Bg);
} else if(data->colors[*f]==BL_HILITE_BOLD) {
SelectObject(hdc, boldFont);
SetBkColor(hdc, Bg);
SetTextColor(hdc, Fg);
} else {
SelectObject(hdc, normalFont);
SetBkColor(hdc, Bg);
SetTextColor(hdc, Fg);
}
GetTextExtentPoint32(hdc, wbuf, vlen, &sz);
DrawText(hdc, wbuf, vlen, &rt, DT_LEFT);
rt.left += sz.cx;
cy = max(cy, sz.cy);
}
rt.left = left;
rt.top += cy;
}
hdc = BeginPaint(hWnd, &ps);
GetClientRect(hWnd, &rt);
SelectObject(hdc, oldFont);
SetTextColor (hdc, OldFg);
SetBkColor (hdc, OldBg);
EndPaint(hWnd, &ps);
return 0;
normalFont = mswin_get_font(NHW_STATUS, ATR_NONE, hdc, FALSE);
boldFont = mswin_get_font(NHW_STATUS, ATR_BOLD, hdc, FALSE);
oldFont = SelectObject(hdc, normalFont);
Bg = status_bg_brush ? status_bg_color
: (COLORREF) GetSysColor(DEFAULT_COLOR_BG_STATUS);
OldBg = SetBkColor(hdc, Bg);
Fg = status_fg_brush ? status_fg_color
: (COLORREF) GetSysColor(DEFAULT_COLOR_FG_STATUS);
OldFg = SetTextColor(hdc, Fg);
for (fop = fieldorders; *fop; fop++) {
LONG left = rt.left;
LONG cy = 0;
int vlen;
for (f = *fop; *f != -1; f++) {
if (((*f) >= data->n_fields) || (!data->activefields[*f]))
continue;
vlen = strlen(data->vals[*f]);
NH_A2W(data->vals[*f], wbuf, SIZE(wbuf));
if (data->colors[*f] == CLR_MAX
|| data->colors[*f] == BL_HILITE_NONE) {
SelectObject(hdc, normalFont);
SetBkColor(hdc, Bg);
SetTextColor(hdc, Fg);
} else if (data->colors[*f] > 0) {
SelectObject(hdc, normalFont);
SetBkColor(hdc, Bg);
SetTextColor(hdc, nhcolor_to_RGB(data->colors[*f]));
} else if (data->colors[*f] == BL_HILITE_INVERSE) {
SelectObject(hdc, normalFont);
SetBkColor(hdc, Fg);
SetTextColor(hdc, Bg);
} else if (data->colors[*f] == BL_HILITE_BOLD) {
SelectObject(hdc, boldFont);
SetBkColor(hdc, Bg);
SetTextColor(hdc, Fg);
} else {
SelectObject(hdc, normalFont);
SetBkColor(hdc, Bg);
SetTextColor(hdc, Fg);
}
GetTextExtentPoint32(hdc, wbuf, vlen, &sz);
DrawText(hdc, wbuf, vlen, &rt, DT_LEFT);
rt.left += sz.cx;
cy = max(cy, sz.cy);
}
rt.left = left;
rt.top += cy;
}
SelectObject(hdc, oldFont);
SetTextColor(hdc, OldFg);
SetBkColor(hdc, OldBg);
EndPaint(hWnd, &ps);
return 0;
}
#else
static LRESULT onWMPaint(HWND hWnd, WPARAM wParam, LPARAM lParam)
static LRESULT
onWMPaint(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
int i;
SIZE sz;
HGDIOBJ oldFont;
TCHAR wbuf[BUFSZ];
COLORREF OldBg, OldFg;
RECT rt;
PAINTSTRUCT ps;
HDC hdc;
PNHStatusWindow data;
data = (PNHStatusWindow)GetWindowLongPtr(hWnd, GWLP_USERDATA);
int i;
SIZE sz;
HGDIOBJ oldFont;
TCHAR wbuf[BUFSZ];
COLORREF OldBg, OldFg;
RECT rt;
PAINTSTRUCT ps;
HDC hdc;
PNHStatusWindow data;
hdc = BeginPaint(hWnd, &ps);
GetClientRect(hWnd, &rt);
oldFont = SelectObject(hdc, mswin_get_font(NHW_STATUS, ATR_NONE, hdc, FALSE));
data = (PNHStatusWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA);
OldBg = SetBkColor(hdc, status_bg_brush
? status_bg_color : (COLORREF)GetSysColor(DEFAULT_COLOR_BG_STATUS));
OldFg = SetTextColor(hdc, status_fg_brush
? status_fg_color : (COLORREF)GetSysColor(DEFAULT_COLOR_FG_STATUS));
for(i=0; i<NHSW_LINES; i++ ) {
int wlen = strlen(data->window_text[i]);
NH_A2W(data->window_text[i], wbuf, SIZE(wbuf));
GetTextExtentPoint32(hdc, wbuf, wlen, &sz);
DrawText(hdc, wbuf, wlen, &rt, DT_LEFT | DT_END_ELLIPSIS);
rt.top += sz.cy;
}
hdc = BeginPaint(hWnd, &ps);
GetClientRect(hWnd, &rt);
SelectObject(hdc, oldFont);
SetTextColor (hdc, OldFg);
SetBkColor (hdc, OldBg);
EndPaint(hWnd, &ps);
return 0;
oldFont =
SelectObject(hdc, mswin_get_font(NHW_STATUS, ATR_NONE, hdc, FALSE));
OldBg = SetBkColor(hdc, status_bg_brush ? status_bg_color
: (COLORREF) GetSysColor(
DEFAULT_COLOR_BG_STATUS));
OldFg = SetTextColor(hdc, status_fg_brush ? status_fg_color
: (COLORREF) GetSysColor(
DEFAULT_COLOR_FG_STATUS));
for (i = 0; i < NHSW_LINES; i++) {
int wlen = strlen(data->window_text[i]);
NH_A2W(data->window_text[i], wbuf, SIZE(wbuf));
GetTextExtentPoint32(hdc, wbuf, wlen, &sz);
DrawText(hdc, wbuf, wlen, &rt, DT_LEFT | DT_END_ELLIPSIS);
rt.top += sz.cy;
}
SelectObject(hdc, oldFont);
SetTextColor(hdc, OldFg);
SetBkColor(hdc, OldBg);
EndPaint(hWnd, &ps);
return 0;
}
#endif /*STATUS_VIA_WINDOWPORT*/
void mswin_status_window_size (HWND hWnd, LPSIZE sz)
void
mswin_status_window_size(HWND hWnd, LPSIZE sz)
{
TEXTMETRIC tm;
HGDIOBJ saveFont;
HDC hdc;
PNHStatusWindow data;
RECT rt;
SIZE text_sz;
GetClientRect(hWnd, &rt);
HGDIOBJ saveFont;
HDC hdc;
PNHStatusWindow data;
RECT rt;
SIZE text_sz;
data = (PNHStatusWindow)GetWindowLongPtr(hWnd, GWLP_USERDATA);
if(data) {
hdc = GetDC(hWnd);
saveFont = SelectObject(hdc, mswin_get_font(NHW_STATUS, ATR_NONE, hdc, FALSE));
GetTextExtentPoint32(hdc, _T("W"), 1, &text_sz);
GetTextMetrics(hdc, &tm);
GetClientRect(hWnd, &rt);
rt.bottom = rt.top + text_sz.cy*NHSW_LINES;
data = (PNHStatusWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA);
if (data) {
hdc = GetDC(hWnd);
saveFont = SelectObject(
hdc, mswin_get_font(NHW_STATUS, ATR_NONE, hdc, FALSE));
GetTextExtentPoint32(hdc, _T("W"), 1, &text_sz);
GetTextMetrics(hdc, &tm);
SelectObject(hdc, saveFont);
ReleaseDC(hWnd, hdc);
}
AdjustWindowRect(&rt, GetWindowLong(hWnd, GWL_STYLE), FALSE);
sz->cx = rt.right - rt.left;
sz->cy = rt.bottom - rt.top;
rt.bottom = rt.top + text_sz.cy * NHSW_LINES;
SelectObject(hdc, saveFont);
ReleaseDC(hWnd, hdc);
}
AdjustWindowRect(&rt, GetWindowLong(hWnd, GWL_STYLE), FALSE);
sz->cx = rt.right - rt.left;
sz->cy = rt.bottom - rt.top;
}
+232 -214
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 mhtext.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
/* NetHack 3.6 mhtext.c $NHDT-Date: 1431192777 2015/05/09 17:32:57 $ $NHDT-Branch: master $:$NHDT-Revision: 1.24 $ */
/* NetHack 3.6 mhtext.c $Date: 2012/01/11 01:53:44 $ $Revision: 1.17 $ */
/* Copyright (C) 2001 by Alex Kompel */
/* NetHack may be freely redistributed. See license for details. */
@@ -12,264 +12,283 @@
PNHWinApp GetNHApp(void);
typedef struct mswin_nethack_text_window {
TCHAR* window_text;
TCHAR *window_text;
} NHTextWindow, *PNHTextWindow;
static WNDPROC editControlWndProc = 0;
#define DEFAULT_COLOR_BG_TEXT COLOR_WINDOW
#define DEFAULT_COLOR_FG_TEXT COLOR_WINDOWTEXT
static WNDPROC editControlWndProc = 0;
#define DEFAULT_COLOR_BG_TEXT COLOR_WINDOW
#define DEFAULT_COLOR_FG_TEXT COLOR_WINDOWTEXT
INT_PTR CALLBACK NHTextWndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK NHEditHookWndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK NHTextWndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK NHEditHookWndProc(HWND, UINT, WPARAM, LPARAM);
static void onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam);
static void LayoutText(HWND hwnd);
HWND mswin_init_text_window () {
HWND ret;
PNHTextWindow data;
RECT rt;
HWND
mswin_init_text_window()
{
HWND ret;
PNHTextWindow data;
RECT rt;
/* get window position */
if( GetNHApp()->bAutoLayout ) {
SetRect( &rt, 0, 0, 0, 0);
} else {
mswin_get_window_placement(NHW_TEXT, &rt);
}
/* get window position */
if (GetNHApp()->bAutoLayout) {
SetRect(&rt, 0, 0, 0, 0);
} else {
mswin_get_window_placement(NHW_TEXT, &rt);
}
/* create text widnow object */
ret = CreateDialog(
GetNHApp()->hApp,
MAKEINTRESOURCE(IDD_NHTEXT),
GetNHApp()->hMainWnd,
NHTextWndProc
);
if( !ret ) panic("Cannot create text window");
/* create text widnow object */
ret = CreateDialog(GetNHApp()->hApp, MAKEINTRESOURCE(IDD_NHTEXT),
GetNHApp()->hMainWnd, NHTextWndProc);
if (!ret)
panic("Cannot create text window");
/* move it in the predefined position */
if( !GetNHApp()->bAutoLayout ) {
MoveWindow(ret, rt.left, rt.top, rt.right - rt.left, rt.bottom - rt.top, TRUE);
}
/* move it in the predefined position */
if (!GetNHApp()->bAutoLayout) {
MoveWindow(ret, rt.left, rt.top, rt.right - rt.left,
rt.bottom - rt.top, TRUE);
}
/* Set window caption */
SetWindowText(ret, "Text");
if( !GetNHApp()->bWindowsLocked ) {
DWORD style;
style = GetWindowLong(ret, GWL_STYLE);
style |= WS_CAPTION;
SetWindowLong(ret, GWL_STYLE, style);
SetWindowPos(ret, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
}
/* Set window caption */
SetWindowText(ret, "Text");
if (!GetNHApp()->bWindowsLocked) {
DWORD style;
style = GetWindowLong(ret, GWL_STYLE);
style |= WS_CAPTION;
SetWindowLong(ret, GWL_STYLE, style);
SetWindowPos(ret, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE
| SWP_NOZORDER
| SWP_FRAMECHANGED);
}
/* create and set window data */
data = (PNHTextWindow)malloc(sizeof(NHTextWindow));
if( !data ) panic("out of memory");
ZeroMemory(data, sizeof(NHTextWindow));
SetWindowLongPtr(ret, GWLP_USERDATA, (LONG_PTR)data);
return ret;
/* create and set window data */
data = (PNHTextWindow) malloc(sizeof(NHTextWindow));
if (!data)
panic("out of memory");
ZeroMemory(data, sizeof(NHTextWindow));
SetWindowLongPtr(ret, GWLP_USERDATA, (LONG_PTR) data);
return ret;
}
void mswin_display_text_window (HWND hWnd)
void
mswin_display_text_window(HWND hWnd)
{
PNHTextWindow data;
data = (PNHTextWindow)GetWindowLongPtr(hWnd, GWLP_USERDATA);
if( data && data->window_text ) {
HWND control;
control = GetDlgItem(hWnd, IDC_TEXT_CONTROL);
SendMessage(control, EM_FMTLINES, 1, 0 );
SetWindowText(control, data->window_text);
}
PNHTextWindow data;
mswin_popup_display(hWnd, NULL);
mswin_popup_destroy(hWnd);
data = (PNHTextWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA);
if (data && data->window_text) {
HWND control;
control = GetDlgItem(hWnd, IDC_TEXT_CONTROL);
SendMessage(control, EM_FMTLINES, 1, 0);
SetWindowText(control, data->window_text);
}
mswin_popup_display(hWnd, NULL);
mswin_popup_destroy(hWnd);
}
INT_PTR CALLBACK NHTextWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
INT_PTR CALLBACK
NHTextWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HWND control;
HDC hdc;
PNHTextWindow data;
HWND control;
HDC hdc;
PNHTextWindow data;
TCHAR title[MAX_LOADSTRING];
data = (PNHTextWindow)GetWindowLongPtr(hWnd, GWLP_USERDATA);
switch (message)
{
case WM_INITDIALOG:
/* set text control font */
control = GetDlgItem(hWnd, IDC_TEXT_CONTROL);
if( !control ) {
panic("cannot get text view window");
}
hdc = GetDC(control);
SendMessage(control, WM_SETFONT, (WPARAM)mswin_get_font(NHW_TEXT, ATR_NONE, hdc, FALSE), 0);
ReleaseDC(control, hdc);
data = (PNHTextWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA);
switch (message) {
case WM_INITDIALOG:
/* set text control font */
control = GetDlgItem(hWnd, IDC_TEXT_CONTROL);
if (!control) {
panic("cannot get text view window");
}
/* subclass edit control */
editControlWndProc = (WNDPROC)GetWindowLongPtr(control, GWLP_WNDPROC);
SetWindowLongPtr(control, GWLP_WNDPROC, (LONG_PTR)NHEditHookWndProc);
hdc = GetDC(control);
SendMessage(control, WM_SETFONT,
(WPARAM) mswin_get_font(NHW_TEXT, ATR_NONE, hdc, FALSE),
0);
ReleaseDC(control, hdc);
SetFocus(control);
/* subclass edit control */
editControlWndProc =
(WNDPROC) GetWindowLongPtr(control, GWLP_WNDPROC);
SetWindowLongPtr(control, GWLP_WNDPROC, (LONG_PTR) NHEditHookWndProc);
/* Even though the dialog has no caption, you can still set the title
SetFocus(control);
/* Even though the dialog has no caption, you can still set the title
which shows on Alt-Tab */
LoadString(GetNHApp()->hApp, IDS_APP_TITLE, title, MAX_LOADSTRING);
SetWindowText(hWnd, title);
return FALSE;
return FALSE;
case WM_MSNH_COMMAND:
onMSNHCommand(hWnd, wParam, lParam);
break;
case WM_MSNH_COMMAND:
onMSNHCommand(hWnd, wParam, lParam);
break;
case WM_SIZE: {
RECT rt;
case WM_SIZE: {
RECT rt;
GetWindowRect(hWnd, &rt);
ScreenToClient(GetNHApp()->hMainWnd, (LPPOINT)&rt);
ScreenToClient(GetNHApp()->hMainWnd, ((LPPOINT)&rt)+1);
mswin_update_window_placement(NHW_TEXT, &rt);
GetWindowRect(hWnd, &rt);
ScreenToClient(GetNHApp()->hMainWnd, (LPPOINT) &rt);
ScreenToClient(GetNHApp()->hMainWnd, ((LPPOINT) &rt) + 1);
mswin_update_window_placement(NHW_TEXT, &rt);
LayoutText(hWnd);
} return FALSE;
LayoutText(hWnd);
}
return FALSE;
case WM_MOVE: {
RECT rt;
GetWindowRect(hWnd, &rt);
ScreenToClient(GetNHApp()->hMainWnd, (LPPOINT)&rt);
ScreenToClient(GetNHApp()->hMainWnd, ((LPPOINT)&rt)+1);
mswin_update_window_placement(NHW_TEXT, &rt);
} return FALSE;
case WM_MOVE: {
RECT rt;
GetWindowRect(hWnd, &rt);
ScreenToClient(GetNHApp()->hMainWnd, (LPPOINT) &rt);
ScreenToClient(GetNHApp()->hMainWnd, ((LPPOINT) &rt) + 1);
mswin_update_window_placement(NHW_TEXT, &rt);
}
return FALSE;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDOK:
case IDCANCEL:
mswin_window_mark_dead(mswin_winid_from_handle(hWnd));
if( GetNHApp()->hMainWnd==hWnd )
GetNHApp()->hMainWnd=NULL;
DestroyWindow(hWnd);
SetFocus(GetNHApp()->hMainWnd);
return TRUE;
}
break;
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDOK:
case IDCANCEL:
mswin_window_mark_dead(mswin_winid_from_handle(hWnd));
if (GetNHApp()->hMainWnd == hWnd)
GetNHApp()->hMainWnd = NULL;
DestroyWindow(hWnd);
SetFocus(GetNHApp()->hMainWnd);
return TRUE;
}
break;
case WM_CTLCOLORSTATIC: { /* sent by edit control before it is drawn */
HDC hdcEdit = (HDC) wParam;
HWND hwndEdit = (HWND) lParam;
if( hwndEdit == GetDlgItem(hWnd, IDC_TEXT_CONTROL) ) {
SetBkColor(hdcEdit,
text_bg_brush ? text_bg_color : (COLORREF)GetSysColor(DEFAULT_COLOR_BG_TEXT)
);
SetTextColor(hdcEdit,
text_fg_brush ? text_fg_color : (COLORREF)GetSysColor(DEFAULT_COLOR_FG_TEXT)
);
return (INT_PTR)(text_bg_brush
? text_bg_brush : SYSCLR_TO_BRUSH(DEFAULT_COLOR_BG_TEXT));
}
} return FALSE;
case WM_CTLCOLORSTATIC: { /* sent by edit control before it is drawn */
HDC hdcEdit = (HDC) wParam;
HWND hwndEdit = (HWND) lParam;
if (hwndEdit == GetDlgItem(hWnd, IDC_TEXT_CONTROL)) {
SetBkColor(hdcEdit, text_bg_brush ? text_bg_color
: (COLORREF) GetSysColor(
DEFAULT_COLOR_BG_TEXT));
SetTextColor(hdcEdit, text_fg_brush ? text_fg_color
: (COLORREF) GetSysColor(
DEFAULT_COLOR_FG_TEXT));
return (INT_PTR)(text_bg_brush
? text_bg_brush
: SYSCLR_TO_BRUSH(DEFAULT_COLOR_BG_TEXT));
}
}
return FALSE;
case WM_DESTROY:
if( data ) {
if( data->window_text ) free(data->window_text);
free(data);
SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR)0);
}
break;
}
return FALSE;
case WM_DESTROY:
if (data) {
if (data->window_text)
free(data->window_text);
free(data);
SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR) 0);
}
break;
}
return FALSE;
}
void onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
void
onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
PNHTextWindow data;
data = (PNHTextWindow)GetWindowLongPtr(hWnd, GWLP_USERDATA);
switch( wParam ) {
case MSNH_MSG_PUTSTR: {
PMSNHMsgPutstr msg_data = (PMSNHMsgPutstr)lParam;
TCHAR wbuf[BUFSZ];
size_t text_size;
PNHTextWindow data;
if( !data->window_text ) {
text_size = strlen(msg_data->text) + 4;
data->window_text = (TCHAR*)malloc(text_size*sizeof(data->window_text[0]));
ZeroMemory(data->window_text, text_size*sizeof(data->window_text[0]));
} else {
text_size = _tcslen(data->window_text) + strlen(msg_data->text) + 4;
data->window_text = (TCHAR*)realloc(data->window_text, text_size*sizeof(data->window_text[0]));
}
if( !data->window_text ) break;
_tcscat(data->window_text, NH_A2W(msg_data->text, wbuf, BUFSZ));
_tcscat(data->window_text, TEXT("\r\n"));
break;
}
}
data = (PNHTextWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA);
switch (wParam) {
case MSNH_MSG_PUTSTR: {
PMSNHMsgPutstr msg_data = (PMSNHMsgPutstr) lParam;
TCHAR wbuf[BUFSZ];
size_t text_size;
if (!data->window_text) {
text_size = strlen(msg_data->text) + 4;
data->window_text =
(TCHAR *) malloc(text_size * sizeof(data->window_text[0]));
ZeroMemory(data->window_text,
text_size * sizeof(data->window_text[0]));
} else {
text_size =
_tcslen(data->window_text) + strlen(msg_data->text) + 4;
data->window_text = (TCHAR *) realloc(
data->window_text, text_size * sizeof(data->window_text[0]));
}
if (!data->window_text)
break;
_tcscat(data->window_text, NH_A2W(msg_data->text, wbuf, BUFSZ));
_tcscat(data->window_text, TEXT("\r\n"));
break;
}
}
}
void LayoutText(HWND hWnd)
void
LayoutText(HWND hWnd)
{
HWND btn_ok;
HWND text;
RECT clrt, rt;
POINT pt_elem, pt_ok;
SIZE sz_elem, sz_ok;
HWND btn_ok;
HWND text;
RECT clrt, rt;
POINT pt_elem, pt_ok;
SIZE sz_elem, sz_ok;
text = GetDlgItem(hWnd, IDC_TEXT_CONTROL);
btn_ok = GetDlgItem(hWnd, IDOK);
text = GetDlgItem(hWnd, IDC_TEXT_CONTROL);
btn_ok = GetDlgItem(hWnd, IDOK);
/* get window coordinates */
GetClientRect(hWnd, &clrt );
/* set window placements */
GetWindowRect(btn_ok, &rt);
sz_ok.cx = clrt.right - clrt.left;
sz_ok.cy = rt.bottom-rt.top;
pt_ok.x = clrt.left;
pt_ok.y = clrt.bottom - sz_ok.cy;
/* get window coordinates */
GetClientRect(hWnd, &clrt);
pt_elem.x = clrt.left;
pt_elem.y = clrt.top;
sz_elem.cx = clrt.right - clrt.left;
sz_elem.cy = pt_ok.y;
/* set window placements */
GetWindowRect(btn_ok, &rt);
sz_ok.cx = clrt.right - clrt.left;
sz_ok.cy = rt.bottom - rt.top;
pt_ok.x = clrt.left;
pt_ok.y = clrt.bottom - sz_ok.cy;
MoveWindow(text, pt_elem.x, pt_elem.y, sz_elem.cx, sz_elem.cy, TRUE );
MoveWindow(btn_ok, pt_ok.x, pt_ok.y, sz_ok.cx, sz_ok.cy, TRUE );
pt_elem.x = clrt.left;
pt_elem.y = clrt.top;
sz_elem.cx = clrt.right - clrt.left;
sz_elem.cy = pt_ok.y;
MoveWindow(text, pt_elem.x, pt_elem.y, sz_elem.cx, sz_elem.cy, TRUE);
MoveWindow(btn_ok, pt_ok.x, pt_ok.y, sz_ok.cx, sz_ok.cy, TRUE);
}
/* Edit box hook */
LRESULT CALLBACK NHEditHookWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
LRESULT CALLBACK
NHEditHookWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hDC;
RECT rc;
HDC hDC;
RECT rc;
switch(message) {
case WM_ERASEBKGND:
hDC = (HDC) wParam;
GetClientRect(hWnd, &rc);
FillRect(hDC, &rc, text_bg_brush? text_bg_brush : SYSCLR_TO_BRUSH(DEFAULT_COLOR_BG_TEXT));
return 1;
switch (message) {
case WM_ERASEBKGND:
hDC = (HDC) wParam;
GetClientRect(hWnd, &rc);
FillRect(hDC, &rc, text_bg_brush
? text_bg_brush
: SYSCLR_TO_BRUSH(DEFAULT_COLOR_BG_TEXT));
return 1;
case WM_KEYDOWN:
switch (wParam)
{
/* close on space in Windows mode
case WM_KEYDOWN:
switch (wParam) {
/* close on space in Windows mode
page down on space in NetHack mode */
case VK_SPACE:
{
case VK_SPACE: {
SCROLLINFO si;
si.cbSize = sizeof(SCROLLINFO);
si.fMask = SIF_POS | SIF_RANGE | SIF_PAGE;
GetScrollInfo(hWnd, SB_VERT, &si);
/* If nethackmode and not at the end of the list */
if (GetNHApp()->regNetHackMode &&
(si.nPos + (int)si.nPage) <= (si.nMax - si.nMin))
if (GetNHApp()->regNetHackMode
&& (si.nPos + (int) si.nPage) <= (si.nMax - si.nMin))
SendMessage(hWnd, EM_SCROLL, SB_PAGEDOWN, 0);
else
PostMessage(GetParent(hWnd), WM_COMMAND, MAKELONG(IDOK, 0), 0);
PostMessage(GetParent(hWnd), WM_COMMAND, MAKELONG(IDOK, 0),
0);
return 0;
}
case VK_NEXT:
@@ -284,20 +303,19 @@ LRESULT CALLBACK NHEditHookWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARA
case VK_DOWN:
SendMessage(hWnd, EM_SCROLL, SB_LINEDOWN, 0);
return 0;
}
break;
}
break;
/* edit control needs to know nothing of focus. We will take care of it
* for it */
case WM_SETFOCUS:
HideCaret(hWnd);
return 0;
}
/* edit control needs to know nothing of focus. We will take care of it for it */
case WM_SETFOCUS:
HideCaret(hWnd);
return 0;
}
if( editControlWndProc )
return CallWindowProc(editControlWndProc, hWnd, message, wParam, lParam);
else
return 0;
if (editControlWndProc)
return CallWindowProc(editControlWndProc, hWnd, message, wParam,
lParam);
else
return 0;
}
+2006 -1929
View File
File diff suppressed because it is too large Load Diff
+175 -162
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 winhack.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
/* NetHack 3.6 winhack.c $NHDT-Date: 1431192776 2015/05/09 17:32:56 $ $NHDT-Branch: master $:$NHDT-Revision: 1.39 $ */
/* NetHack 3.6 winhack.c $Date: 2009/05/06 11:00:43 $ $Revision: 1.32 $ */
/* SCCS Id: @(#)winhack.c 3.5 2006/04/01 */
/* Copyright (C) 2001 by Alex Kompel */
@@ -17,13 +17,12 @@
/* Borland and MinGW redefine "boolean" in shlwapi.h,
so just use the little bit we need */
typedef struct _DLLVERSIONINFO
{
typedef struct _DLLVERSIONINFO {
DWORD cbSize;
DWORD dwMajorVersion; // Major version
DWORD dwMinorVersion; // Minor version
DWORD dwBuildNumber; // Build number
DWORD dwPlatformID; // DLLVER_PLATFORM_*
DWORD dwMajorVersion; // Major version
DWORD dwMinorVersion; // Minor version
DWORD dwBuildNumber; // Build number
DWORD dwPlatformID; // DLLVER_PLATFORM_*
} DLLVERSIONINFO;
//
@@ -31,7 +30,7 @@ typedef struct _DLLVERSIONINFO
// implicitly link to it.
//
typedef HRESULT (CALLBACK* DLLGETVERSIONPROC)(DLLVERSIONINFO *);
typedef HRESULT(CALLBACK *DLLGETVERSIONPROC)(DLLVERSIONINFO *);
/* end of shlwapi.h */
@@ -47,120 +46,124 @@ Version _WIN_32IE Platform/IE
#define MIN_COMCTLMAJOR 4
#define MIN_COMCTLMINOR 71
#define INSTALL_NOTES "http://www.nethack.org/v340/ports/download-win.html#cc"
/*#define COMCTL_URL "http://www.microsoft.com/msdownload/ieplatform/ie/comctrlx86.asp"*/
/*#define COMCTL_URL
* "http://www.microsoft.com/msdownload/ieplatform/ie/comctrlx86.asp"*/
extern void FDECL(nethack_exit,(int));
static TCHAR* _get_cmd_arg(TCHAR* pCmdLine);
extern void FDECL(nethack_exit, (int));
static TCHAR *_get_cmd_arg(TCHAR *pCmdLine);
static HRESULT GetComCtlVersion(LPDWORD pdwMajor, LPDWORD pdwMinor);
// Global Variables:
NHWinApp _nethack_app;
#ifdef __BORLANDC__
#define _stricmp(s1,s2) stricmp(s1,s2)
#define _strdup(s1) strdup(s1)
#define _stricmp(s1, s2) stricmp(s1, s2)
#define _strdup(s1) strdup(s1)
#endif
// Foward declarations of functions included in this code module:
extern boolean FDECL(pcmain, (int,char **));
extern boolean FDECL(pcmain, (int, char **));
static void __cdecl mswin_moveloop(void *);
#define MAX_CMDLINE_PARAM 255
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
int APIENTRY
WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
int nCmdShow)
{
INITCOMMONCONTROLSEX InitCtrls;
int argc;
char* argv[MAX_CMDLINE_PARAM];
size_t len;
TCHAR *p;
TCHAR wbuf[BUFSZ];
char buf[BUFSZ];
INITCOMMONCONTROLSEX InitCtrls;
int argc;
char *argv[MAX_CMDLINE_PARAM];
size_t len;
TCHAR *p;
TCHAR wbuf[BUFSZ];
char buf[BUFSZ];
DWORD major, minor;
boolean resuming;
boolean resuming;
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
UNREFERENCED_PARAMETER(nCmdShow);
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
UNREFERENCED_PARAMETER(nCmdShow);
/* ensure that we don't access violate on a panic() */
windowprocs.win_raw_print = mswin_raw_print;
windowprocs.win_raw_print_bold = mswin_raw_print_bold;
/* ensure that we don't access violate on a panic() */
windowprocs.win_raw_print = mswin_raw_print;
windowprocs.win_raw_print_bold = mswin_raw_print_bold;
/* init applicatio structure */
_nethack_app.hApp = hInstance;
_nethack_app.hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_NETHACKW);
_nethack_app.hMainWnd = NULL;
_nethack_app.hPopupWnd = NULL;
_nethack_app.bmpTiles = LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_TILES));
if( _nethack_app.bmpTiles==NULL ) panic("cannot load tiles bitmap");
_nethack_app.bmpPetMark = LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_PETMARK));
if( _nethack_app.bmpPetMark==NULL ) panic("cannot load pet mark bitmap");
_nethack_app.bmpRip = LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_RIP));
if ( _nethack_app.bmpRip == NULL ) panic("cannot load rip bitmap");
_nethack_app.bmpSplash = LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_SPLASH));
if ( _nethack_app.bmpSplash == NULL ) panic("cannot load splash bitmap");
_nethack_app.bmpMapTiles = _nethack_app.bmpTiles;
_nethack_app.mapTile_X = TILE_X;
_nethack_app.mapTile_Y = TILE_Y;
_nethack_app.mapTilesPerLine = TILES_PER_LINE;
/* init applicatio structure */
_nethack_app.hApp = hInstance;
_nethack_app.hAccelTable =
LoadAccelerators(hInstance, (LPCTSTR) IDC_NETHACKW);
_nethack_app.hMainWnd = NULL;
_nethack_app.hPopupWnd = NULL;
_nethack_app.bmpTiles = LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_TILES));
if (_nethack_app.bmpTiles == NULL)
panic("cannot load tiles bitmap");
_nethack_app.bmpPetMark =
LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_PETMARK));
if (_nethack_app.bmpPetMark == NULL)
panic("cannot load pet mark bitmap");
_nethack_app.bmpRip = LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_RIP));
if (_nethack_app.bmpRip == NULL)
panic("cannot load rip bitmap");
_nethack_app.bmpSplash =
LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_SPLASH));
if (_nethack_app.bmpSplash == NULL)
panic("cannot load splash bitmap");
_nethack_app.bmpMapTiles = _nethack_app.bmpTiles;
_nethack_app.mapTile_X = TILE_X;
_nethack_app.mapTile_Y = TILE_Y;
_nethack_app.mapTilesPerLine = TILES_PER_LINE;
_nethack_app.bNoHScroll = FALSE;
_nethack_app.bNoVScroll = FALSE;
_nethack_app.saved_text = strdup("");
_nethack_app.bNoHScroll = FALSE;
_nethack_app.bNoVScroll = FALSE;
_nethack_app.saved_text = strdup("");
_nethack_app.bAutoLayout = TRUE;
_nethack_app.bWindowsLocked = TRUE;
_nethack_app.bAutoLayout = TRUE;
_nethack_app.bWindowsLocked = TRUE;
_nethack_app.bNoSounds = FALSE;
_nethack_app.bNoSounds = FALSE;
// init controls
if (FAILED(GetComCtlVersion(&major, &minor)))
{
if (FAILED(GetComCtlVersion(&major, &minor))) {
char buf[TBUFSZ];
Sprintf(buf, "Cannot load common control library.\n%s\n%s",
"For further information, refer to the installation notes at",
INSTALL_NOTES);
"For further information, refer to the installation notes at",
INSTALL_NOTES);
panic(buf);
}
if (major < MIN_COMCTLMAJOR
|| (major == MIN_COMCTLMAJOR && minor < MIN_COMCTLMINOR))
{
|| (major == MIN_COMCTLMAJOR && minor < MIN_COMCTLMINOR)) {
char buf[TBUFSZ];
Sprintf(buf, "Common control library is outdated.\n%s %d.%d\n%s\n%s",
"NetHack requires at least version ",
MIN_COMCTLMAJOR, MIN_COMCTLMINOR,
"For further information, refer to the installation notes at",
INSTALL_NOTES);
"NetHack requires at least version ", MIN_COMCTLMAJOR,
MIN_COMCTLMINOR,
"For further information, refer to the installation notes at",
INSTALL_NOTES);
panic(buf);
}
ZeroMemory(&InitCtrls, sizeof(InitCtrls));
InitCtrls.dwSize = sizeof(InitCtrls);
InitCtrls.dwICC = ICC_LISTVIEW_CLASSES;
InitCommonControlsEx(&InitCtrls);
/* get command line parameters */
p = _get_cmd_arg(GetCommandLine());
p = _get_cmd_arg(NULL); /* skip first paramter - command name */
for( argc = 1; p && argc<MAX_CMDLINE_PARAM; argc++ ) {
len = _tcslen(p);
if( len>0 ) {
argv[argc] = _strdup( NH_W2A(p, buf, BUFSZ) );
} else {
argv[argc] = "";
}
p = _get_cmd_arg(NULL);
}
GetModuleFileName(NULL, wbuf, BUFSZ);
argv[0] = _strdup(NH_W2A(wbuf, buf, BUFSZ));
ZeroMemory(&InitCtrls, sizeof(InitCtrls));
InitCtrls.dwSize = sizeof(InitCtrls);
InitCtrls.dwICC = ICC_LISTVIEW_CLASSES;
InitCommonControlsEx(&InitCtrls);
/* get command line parameters */
p = _get_cmd_arg(GetCommandLine());
p = _get_cmd_arg(NULL); /* skip first paramter - command name */
for (argc = 1; p && argc < MAX_CMDLINE_PARAM; argc++) {
len = _tcslen(p);
if (len > 0) {
argv[argc] = _strdup(NH_W2A(p, buf, BUFSZ));
} else {
argv[argc] = "";
}
p = _get_cmd_arg(NULL);
}
GetModuleFileName(NULL, wbuf, BUFSZ);
argv[0] = _strdup(NH_W2A(wbuf, buf, BUFSZ));
if (argc == 2) {
TCHAR *savefile = strdup(argv[1]);
TCHAR *plname;
TCHAR *savefile = strdup(argv[1]);
TCHAR *plname;
for (p = savefile; *p && *p != '-'; p++)
;
if (*p) {
@@ -179,100 +182,110 @@ int APIENTRY WinMain(HINSTANCE hInstance,
}
free(savefile);
}
resuming = pcmain(argc,argv);
resuming = pcmain(argc, argv);
moveloop(resuming);
moveloop(resuming);
return 0;
return 0;
}
PNHWinApp GetNHApp()
PNHWinApp
GetNHApp()
{
return &_nethack_app;
return &_nethack_app;
}
TCHAR* _get_cmd_arg(TCHAR* pCmdLine)
TCHAR *
_get_cmd_arg(TCHAR *pCmdLine)
{
static TCHAR* pArgs = NULL;
TCHAR *pRetArg;
BOOL bQuoted;
static TCHAR *pArgs = NULL;
TCHAR *pRetArg;
BOOL bQuoted;
if( !pCmdLine && !pArgs ) return NULL;
if( !pArgs ) pArgs = pCmdLine;
if (!pCmdLine && !pArgs)
return NULL;
if (!pArgs)
pArgs = pCmdLine;
/* skip whitespace */
for(pRetArg = pArgs; *pRetArg && _istspace(*pRetArg); pRetArg = CharNext(pRetArg));
if( !*pRetArg ) {
pArgs = NULL;
return NULL;
}
/* skip whitespace */
for (pRetArg = pArgs; *pRetArg && _istspace(*pRetArg);
pRetArg = CharNext(pRetArg))
;
if (!*pRetArg) {
pArgs = NULL;
return NULL;
}
/* check for quote */
if( *pRetArg==TEXT('"') ) {
bQuoted = TRUE;
pRetArg = CharNext(pRetArg);
pArgs = _tcschr(pRetArg, TEXT('"'));
} else {
/* skip to whitespace */
for(pArgs = pRetArg; *pArgs && !_istspace(*pArgs); pArgs = CharNext(pArgs));
}
if( pArgs && *pArgs ) {
TCHAR* p;
p = pArgs;
pArgs = CharNext(pArgs);
*p = (TCHAR)0;
} else {
pArgs = NULL;
}
/* check for quote */
if (*pRetArg == TEXT('"')) {
bQuoted = TRUE;
pRetArg = CharNext(pRetArg);
pArgs = _tcschr(pRetArg, TEXT('"'));
} else {
/* skip to whitespace */
for (pArgs = pRetArg; *pArgs && !_istspace(*pArgs);
pArgs = CharNext(pArgs))
;
}
return pRetArg;
if (pArgs && *pArgs) {
TCHAR *p;
p = pArgs;
pArgs = CharNext(pArgs);
*p = (TCHAR) 0;
} else {
pArgs = NULL;
}
return pRetArg;
}
/* Get the version of the Common Control library on this machine.
Copied from the Microsoft SDK
*/
HRESULT GetComCtlVersion(LPDWORD pdwMajor, LPDWORD pdwMinor)
HRESULT
GetComCtlVersion(LPDWORD pdwMajor, LPDWORD pdwMinor)
{
HINSTANCE hComCtl;
HRESULT hr = S_OK;
DLLGETVERSIONPROC pDllGetVersion;
HINSTANCE hComCtl;
HRESULT hr = S_OK;
DLLGETVERSIONPROC pDllGetVersion;
if(IsBadWritePtr(pdwMajor, sizeof(DWORD)) ||
IsBadWritePtr(pdwMinor, sizeof(DWORD)))
return E_INVALIDARG;
//load the DLL
hComCtl = LoadLibrary(TEXT("comctl32.dll"));
if (!hComCtl) return E_FAIL;
if (IsBadWritePtr(pdwMajor, sizeof(DWORD))
|| IsBadWritePtr(pdwMinor, sizeof(DWORD)))
return E_INVALIDARG;
// load the DLL
hComCtl = LoadLibrary(TEXT("comctl32.dll"));
if (!hComCtl)
return E_FAIL;
/*
You must get this function explicitly because earlier versions of the DLL
don't implement this function. That makes the lack of implementation of the
function a version marker in itself.
*/
pDllGetVersion = (DLLGETVERSIONPROC)GetProcAddress(hComCtl, TEXT("DllGetVersion"));
if(pDllGetVersion) {
DLLVERSIONINFO dvi;
ZeroMemory(&dvi, sizeof(dvi));
dvi.cbSize = sizeof(dvi);
hr = (*pDllGetVersion)(&dvi);
if(SUCCEEDED(hr)) {
*pdwMajor = dvi.dwMajorVersion;
*pdwMinor = dvi.dwMinorVersion;
} else {
hr = E_FAIL;
}
/*
You must get this function explicitly because earlier versions of the DLL
don't implement this function. That makes the lack of implementation of
the
function a version marker in itself.
*/
pDllGetVersion =
(DLLGETVERSIONPROC) GetProcAddress(hComCtl, TEXT("DllGetVersion"));
if (pDllGetVersion) {
DLLVERSIONINFO dvi;
ZeroMemory(&dvi, sizeof(dvi));
dvi.cbSize = sizeof(dvi);
hr = (*pDllGetVersion)(&dvi);
if (SUCCEEDED(hr)) {
*pdwMajor = dvi.dwMajorVersion;
*pdwMinor = dvi.dwMinorVersion;
} else {
/*
If GetProcAddress failed, then the DLL is a version previous to the one
shipped with IE 3.x.
*/
*pdwMajor = 4;
*pdwMinor = 0;
}
FreeLibrary(hComCtl);
return hr;
hr = E_FAIL;
}
} else {
/*
If GetProcAddress failed, then the DLL is a version previous to the
one
shipped with IE 3.x.
*/
*pdwMajor = 4;
*pdwMinor = 0;
}
FreeLibrary(hComCtl);
return hr;
}