本文整理汇总了C++中DrawText函数的典型用法代码示例。如果您正苦于以下问题:C++ DrawText函数的具体用法?C++ DrawText怎么用?C++ DrawText使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了DrawText函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DisViewBox_OnPaint
LRESULT DisViewBox_OnPaint(HWND hwnd, disview_struct *win, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
SIZE fontsize;
TCHAR text[100];
TCHAR txt[100];
RECT rect;
int lg;
int ht;
HDC mem_dc;
HBITMAP mem_bmp;
u32 nbligne;
GetClientRect(hwnd, &rect);
lg = rect.right - rect.left;
ht = rect.bottom - rect.top;
hdc = BeginPaint(hwnd, &ps);
mem_dc = CreateCompatibleDC(hdc);
mem_bmp = CreateCompatibleBitmap(hdc, lg, ht);
SelectObject(mem_dc, mem_bmp);
FillRect(mem_dc, &rect, (HBRUSH)GetStockObject(WHITE_BRUSH));
SelectObject(mem_dc, GetStockObject(SYSTEM_FIXED_FONT));
GetTextExtentPoint32(mem_dc, "0", 1, &fontsize);
nbligne = ht/fontsize.cy;
SetTextColor(mem_dc, RGB(0,0,0));
if((win->mode==1) || ((win->mode==0) && (win->cpu->CPSR.bits.T == 0)))
{
u32 i;
u32 adr;
if (win->autoup||win->autogo)
win->curr_ligne = (win->cpu->instruct_adr >> 2);
adr = win->curr_ligne*4;
for(i = 0; i < nbligne; ++i)
{
u32 ins = _MMU_read32(win->cpu->proc_ID, MMU_AT_DEBUG, adr);
des_arm_instructions_set[INDEX(ins)](adr, ins, txt);
sprintf(text, "%04X:%04X %08X %s", (int)(adr>>16), (int)(adr&0xFFFF), (int)ins, txt);
DrawText(mem_dc, text, -1, &rect, DT_TOP | DT_LEFT | DT_NOPREFIX);
rect.top+=fontsize.cy;
adr += 4;
}
if(((win->cpu->instruct_adr&0x0FFFFFFF) >= (win->curr_ligne<<2))&&((win->cpu->instruct_adr&0x0FFFFFFF) <= (win->curr_ligne+(nbligne<<2))))
{
HBRUSH brjaune = CreateSolidBrush(RGB(255, 255, 0));
SetBkColor(mem_dc, RGB(255, 255, 0));
rect.top = (((win->cpu->instruct_adr&0x0FFFFFFF)>>2) - win->curr_ligne)*fontsize.cy;
rect.bottom = rect.top + fontsize.cy;
FillRect(mem_dc, &rect, brjaune);
des_arm_instructions_set[INDEX(win->cpu->instruction)](win->cpu->instruct_adr, win->cpu->instruction, txt);
sprintf(text, "%04X:%04X %08X %s", (int)((win->cpu->instruct_adr&0x0FFFFFFF)>>16), (int)(win->cpu->instruct_adr&0xFFFF), (int)win->cpu->instruction, txt);
DrawText(mem_dc, text, -1, &rect, DT_TOP | DT_LEFT | DT_NOPREFIX);
DeleteObject(brjaune);
}
示例2: RenderText
static int RenderText( filter_t *p_filter, subpicture_region_t *p_region_out,
subpicture_region_t *p_region_in )
{
filter_sys_t *p_sys = p_filter->p_sys;
int i_font_color, i_font_alpha, i_font_size;
uint8_t *p_bitmap;
TCHAR *psz_string;
int i, i_width, i_height;
HBITMAP bitmap, bitmap_bak;
BITMAPINFO *p_bmi;
RECT rect = { 0, 0, 0, 0 };
/* Sanity check */
if( !p_region_in || !p_region_out ) return VLC_EGENERIC;
if( !p_region_in->psz_text || !*p_region_in->psz_text )
return VLC_EGENERIC;
psz_string = malloc( (strlen( p_region_in->psz_text )+1) * sizeof(TCHAR) );
if( !psz_string )
return VLC_ENOMEM;
#ifdef UNICODE
if( mbstowcs( psz_string, p_region_in->psz_text,
strlen( p_region_in->psz_text ) * sizeof(TCHAR) ) < 0 )
{
free( psz_string );
return VLC_EGENERIC;
}
#else
strcpy( psz_string, p_region_in->psz_text );
#endif
if( !*psz_string )
{
free( psz_string );
return VLC_EGENERIC;
}
if( p_region_in->p_style )
{
i_font_color = __MAX( __MIN( p_region_in->p_style->i_font_color, 0xFFFFFF ), 0 );
i_font_alpha = __MAX( __MIN( p_region_in->p_style->i_font_alpha, 255 ), 0 );
i_font_size = __MAX( __MIN( p_region_in->p_style->i_font_size, 255 ), 0 );
}
else
{
i_font_color = p_sys->i_font_color;
i_font_alpha = 255 - p_sys->i_font_opacity;
i_font_size = p_sys->i_default_font_size;
}
SetFont( p_filter, i_font_size );
SetTextColor( p_sys->hcdc, RGB( (i_font_color >> 16) & 0xff,
(i_font_color >> 8) & 0xff, i_font_color & 0xff) );
DrawText( p_sys->hcdc, psz_string, -1, &rect,
DT_CALCRECT | DT_CENTER | DT_NOPREFIX );
i_width = rect.right; i_height = rect.bottom;
p_bmi = malloc(sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD)*16);
memset( p_bmi, 0, sizeof(BITMAPINFOHEADER) );
p_bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
p_bmi->bmiHeader.biWidth = (i_width+3) & ~3;
p_bmi->bmiHeader.biHeight = - i_height;
p_bmi->bmiHeader.biPlanes = 1;
p_bmi->bmiHeader.biBitCount = 8;
p_bmi->bmiHeader.biCompression = BI_RGB;
p_bmi->bmiHeader.biClrUsed = 16;
for( i = 0; i < 16; i++ )
{
p_bmi->bmiColors[i].rgbBlue =
p_bmi->bmiColors[i].rgbGreen =
p_bmi->bmiColors[i].rgbRed = pi_gamma[i];
}
bitmap = CreateDIBSection( p_sys->hcdc, p_bmi, DIB_RGB_COLORS,
(void **)&p_bitmap, NULL, 0 );
if( !bitmap )
{
msg_Err( p_filter, "could not create bitmap" );
free( psz_string );
return VLC_EGENERIC;
}
bitmap_bak = SelectObject( p_sys->hcdc, bitmap );
FillRect( p_sys->hcdc, &rect, (HBRUSH)GetStockObject(BLACK_BRUSH) );
if( !DrawText( p_sys->hcdc, psz_string, -1, &rect,
DT_CENTER | DT_NOPREFIX ) )
{
msg_Err( p_filter, "could not draw text" );
}
p_region_out->i_x = p_region_in->i_x;
p_region_out->i_y = p_region_in->i_y;
Render( p_filter, p_region_out, p_bitmap, i_width, i_height );
SelectObject( p_sys->hcdc, bitmap_bak );
DeleteObject( bitmap );
free( psz_string );
//.........这里部分代码省略.........
示例3: ASSERT
void CNSDateEdit::LayoutSubWindows( RECT *pRect )
{
HDC hDC = ::GetDC( m_hWnd );
ASSERT( hDC );
int w = pRect->right - pRect->left;
RECT r, rcSep, rcNum;
TCHAR szSeparator[2], szFormat[30], *s;
HFONT hFont = (HFONT)::GetStockObject( ANSI_VAR_FONT );
CFont *fontCur = CFont::FromHandle( hFont );
LOGFONT lf;
GetObject( hFont, sizeof(lf), &lf);
// Get locale info
#ifdef WIN32
VERIFY( GetLocaleInfo( LOCALE_USER_DEFAULT, LOCALE_SSHORTDATE, szFormat, 30 ) > 0 );
VERIFY( GetLocaleInfo( LOCALE_USER_DEFAULT, LOCALE_SDATE, szSeparator, 2 ) > 0 );
#else
static char cName [] = "intl" ;
GetProfileString (cName, "sDate", "/", szSeparator, 2) ;
int iDate = GetProfileInt (cName, "iDate", 0) ;
sprintf( szFormat, "%c%s%c%s%c",
iDate == 1 ? 'd' : iDate == 2 ? 'y' : 'M', szSeparator,
iDate == 1 ? 'M' : iDate == 2 ? 'M' : 'd', szSeparator,
iDate == 1 ? 'y' : iDate == 2 ? 'd' : 'y' );
#endif
// Get font info
::SetRectEmpty(&rcSep);
::SetRectEmpty(&rcNum);
DrawText( hDC, szSeparator, -1, &rcSep,
DT_NOCLIP | DT_NOPREFIX | DT_SINGLELINE | DT_CALCRECT );
DrawText( hDC, _T("0"), -1, &rcNum,
DT_NOCLIP | DT_NOPREFIX | DT_SINGLELINE | DT_CALCRECT );
ASSERT( w >= ( rcSep.right * 2 + rcNum.right * 8 ) );
// Start on the left
int iHeight = lf.lfHeight;
int iWidth = 0;
r.top = pRect->top - ((pRect->top-pRect->bottom)+iHeight)/2 - 1;
r.bottom = r.top + iHeight + 2;
r.right = pRect->left + 1;
// this loop parses the short date format, creating the fields as it goes
s = strtok( szFormat, szSeparator );
for( int i = 0; (i < 3) && (s != NULL); i++ )
{
switch ( s[0] )
{
case 'M':
case 'm':
r.left = r.right + 1;
r.right = r.left + rcNum.right * 2 + iWidth; // room for two characters
m_MonthField.MoveWindow( &r );
m_MonthField.SetFont( fontCur );
m_pFields[i] = &m_MonthField;
break;
case 'Y':
case 'y':
r.left = r.right + 1;
r.right = r.left + rcNum.right * 4 + iWidth; // room for four characters
m_YearField.MoveWindow( &r );
m_YearField.SetFont( fontCur );
m_pFields[i] = &m_YearField;
break;
case 'D':
case 'd':
r.left = r.right + 1;
r.right = r.left + rcNum.right * 2 + iWidth; // room for two characters
m_DayField.MoveWindow( &r );
m_DayField.SetFont( fontCur );
m_pFields[i] = &m_DayField;
break;
default:
DebugBreak();
}
if ( i == 0 )
{
r.left = r.right + 1;
r.right = r.left + rcSep.right;
m_Sep1 = r;
}
else if ( i == 1 )
{
r.left = r.right + 1;
r.right = r.left + rcSep.right;
m_Sep2 = r;
}
s = strtok( NULL, szSeparator );
}
r = *pRect;
//.........这里部分代码省略.........
示例4: Run
//.........这里部分代码省略.........
moveList[steps].cmd=menuItem;
moveList[steps].num=menuNum;
PlaySound(SOUND_BEEP);
}
}
if(keystate & KEY_MENU) {
//Switch to second menu
mode=2;
menuItem=1;
menuNum=1;
PlaySound(SOUND_BEEP);
}
} else if (mode == 2) {
if(keystate & KEY_INPUT1) {
//Switch back to first menu
mode=1;
menuItem=1;
menuNum=1;
PlaySound(SOUND_BEEP);
}
if (keystate & KEY_INPUT2) {
//Menu select
switch(menuItem) {
case 1: { //Free Roam
mode=4;
PlaySound(SOUND_BEEP);
CloseMotors();
} break;
case 2: { //Load route
LoadRoute();
ClearScreen();
PlaySound(SOUND_BEEP);
SetTextColor(white);
DrawText(5, 65, "Loading...");
Show();
Sleep(500); //Just so they notice...
mode=2;
} break;
case 3: { //Save route
PlaySound(SOUND_BEEP);
SaveRoute();
ClearScreen();
SetTextColor(white);
DrawText(5, 65, "Saving...");
Show();
Sleep(500); //Just so they notice...
mode=2;
} break;
case 4: { //Recalibrate
PlaySound(SOUND_BEEP);
mode=3; //Recalibration mode
menuNum=1; //Use menuNum as steps throught the process - 1=ready, 2=working
} break;
case 5: { //About
PlaySound(SOUND_GO);
mode=5;
CloseMotors();
} break;
}
}
if(keystate & KEY_MENU) {
//Switch back to first menu
mode=1;
menuItem=1;
menuNum=1;
示例5: thread_proc
LRESULT CALLBACK thread_proc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
RECT rc = {0};
UINT notify_duration = 0;
HFONT hOldFont = NULL;
switch (message)
{
case WM_LIBNOTIFYSHOW:
if(notification_data)
{
/* deduce the allowed text width from the max width; see geometry for rationale */
rc.right = notification_window_width_max - (icon_size + (icon_padding * 3));
hdc = GetDC(hWnd);
if(hdc)
{
HFONT hOldFont = NULL;
HRGN hRgn = NULL;
hOldFont = (HFONT) SelectObject(hdc, font_body);
if(hOldFont)
{
DrawText(hdc, notification_data->body, -1, &rc, DT_CALCRECT | DT_WORDBREAK | DT_EDITCONTROL | DT_NOCLIP | DT_NOPREFIX | DT_EXTERNALLEADING);
SelectObject(hdc, hOldFont);
}
ReleaseDC(hWnd, hdc);
if(!hOldFont) return 0; /* exit if font selection failed */
/* calculate the actual bounding rectangle from the DrawText output */
notification_window_height = summary_body_divider + rc.bottom + (icon_padding * 3);
notification_window_width = rc.right + icon_size + (icon_padding * 3);
/* word count * milliseconds per word */
notify_duration = word_count(notification_data->body) * milliseconds_per_word;
/* in case the calculation renders too low a value, replace it with a de facto minimum */
notify_duration = MAX(notify_duration, min_notification_timeout);
/* get the screen area uncluttered by the taskbar */
if(SystemParametersInfo(SPI_GETWORKAREA, 0, &rc, 0))
{
LONG window_x = 0, window_y = 0;
/* system tray @ right bottom */
if((rc.bottom != GetSystemMetrics(SM_CYSCREEN)) ||
(rc.right != GetSystemMetrics(SM_CXSCREEN)))
{
window_x = rc.right - (GetSystemMetrics(SM_CXSCREEN) / window_offset_factor) - notification_window_width;
window_y = rc.bottom - (GetSystemMetrics(SM_CYSCREEN) / window_offset_factor) - notification_window_height;
}
else if(rc.left != 0) /* left bottom */
{
window_x = rc.left + (GetSystemMetrics(SM_CXSCREEN) / window_offset_factor);
window_y = rc.bottom - (GetSystemMetrics(SM_CYSCREEN) / window_offset_factor) - notification_window_height;
}
else /* right top */
{
window_x = rc.right - (GetSystemMetrics(SM_CXSCREEN) / window_offset_factor) - notification_window_width;
window_y = rc.top + (GetSystemMetrics(SM_CYSCREEN) / window_offset_factor);
}
/* resize and reposition the window */
MoveWindow(hWnd, window_x, window_y, notification_window_width, notification_window_height, TRUE);
/* set the new positions to be used by the mouse over hook */
notification_window_rect.left = window_x;
notification_window_rect.top = window_y;
notification_window_rect.right = window_x + notification_window_width;
notification_window_rect.bottom = window_y + notification_window_height;
/* make it as a rounded rect. */
hRgn = CreateRoundRectRgn(0, 0, notification_window_width, notification_window_height, rounded_rect_edge, rounded_rect_edge);
SetWindowRgn(notification_window, hRgn, TRUE);
/* since bRedraw is set to TRUE in SetWindowRgn invalidation isn't required */
/*InvalidateRect(hWnd, NULL, TRUE);*/
/* show the window and set the timers for animation and overall visibility */
ShowWindow(hWnd, SW_SHOWNOACTIVATE);
SetTimer(notification_window, TIMER_ANIMATION, fade_duration, NULL);
SetTimer(notification_window, TIMER_NOTIFICATION, notify_duration, NULL);
}
}
}
break;
case WM_LIBNOTIFYCLOSE:
/* clean up and reset flags */
{
if(hook_mouse_over)
{
UnhookWindowsHookEx(hook_mouse_over);
hook_mouse_over = NULL;
}
KillTimer(hWnd, TIMER_ANIMATION);
//.........这里部分代码省略.........
示例6: onDrawItem
LRESULT onDrawItem(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
LPDRAWITEMSTRUCT lpdis;
PNHMenuItem item;
PNHMenuWindow data;
TEXTMETRIC tm;
HGDIOBJ saveFont;
HDC tileDC;
short ntile;
int t_x, t_y;
int x, y;
TCHAR wbuf[BUFSZ];
RECT drawRect;
COLORREF OldBg, OldFg, NewBg;
char *p, *p1;
int column;
lpdis = (LPDRAWITEMSTRUCT) lParam;
/* If there are no list box items, skip this message. */
if (lpdis->itemID == -1) return FALSE;
data = (PNHMenuWindow)GetWindowLong(hWnd, GWL_USERDATA);
item = &data->menu.items[lpdis->itemID];
tileDC = CreateCompatibleDC(lpdis->hDC);
saveFont = SelectObject(lpdis->hDC, mswin_get_font(NHW_MENU, item->attr, lpdis->hDC, FALSE));
NewBg = mswin_get_color(NHW_MENU, MSWIN_COLOR_BG);
OldBg = SetBkColor(lpdis->hDC, NewBg);
OldFg = SetTextColor(lpdis->hDC, mswin_get_color(NHW_MENU, MSWIN_COLOR_FG));
GetTextMetrics(lpdis->hDC, &tm);
x = lpdis->rcItem.left + 1;
/* print check mark if it is a "selectable" menu */
if( data->how!=PICK_NONE ) {
if( NHMENU_IS_SELECTABLE(*item) ) {
HGDIOBJ saveBrush;
HBRUSH hbrCheckMark;
char buf[2];
switch(item->count) {
case -1: hbrCheckMark = CreatePatternBrush(data->bmpChecked); break;
case 0: hbrCheckMark = CreatePatternBrush(data->bmpNotChecked); break;
default: hbrCheckMark = CreatePatternBrush(data->bmpCheckedCount); break;
}
y = (lpdis->rcItem.bottom + lpdis->rcItem.top - TILE_Y) / 2;
SetBrushOrgEx(lpdis->hDC, x, y, NULL);
saveBrush = SelectObject(lpdis->hDC, hbrCheckMark);
PatBlt(lpdis->hDC, x, y, TILE_X, TILE_Y, PATCOPY);
SelectObject(lpdis->hDC, saveBrush);
DeleteObject(hbrCheckMark);
x += TILE_X + 5;
if(item->accelerator!=0) {
buf[0] = item->accelerator;
buf[1] = '\x0';
SetRect( &drawRect, x, lpdis->rcItem.top, lpdis->rcItem.right, lpdis->rcItem.bottom );
/*JP
DrawText(lpdis->hDC, NH_A2W(buf, wbuf, 2), 1, &drawRect, DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX);
*/
DrawText(lpdis->hDC, NH_A2W(buf, wbuf, 2), -1, &drawRect, DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX);
}
x += tm.tmAveCharWidth + tm.tmOverhang + 5;
} else {
x += TILE_X + tm.tmAveCharWidth + tm.tmOverhang + 10;
}
}
/* print glyph if present */
if( item->glyph != NO_GLYPH ) {
HGDIOBJ saveBmp;
saveBmp = SelectObject(tileDC, GetNHApp()->bmpTiles);
ntile = glyph2tile[ item->glyph ];
t_x = (ntile % TILES_PER_LINE)*TILE_X;
t_y = (ntile / TILES_PER_LINE)*TILE_Y;
y = (lpdis->rcItem.bottom + lpdis->rcItem.top - TILE_Y) / 2;
nhapply_image_transparent(
lpdis->hDC, x, y, TILE_X, TILE_Y,
tileDC, t_x, t_y, TILE_X, TILE_Y, TILE_BK_COLOR );
SelectObject(tileDC, saveBmp);
}
x += TILE_X + 5;
/* draw item text */
if( item->has_tab ) {
p1 = item->str;
p = strchr(item->str, '\t');
column = 0;
SetRect( &drawRect, x, lpdis->rcItem.top, min(x + data->menu.tab_stop_size[0], lpdis->rcItem.right),
lpdis->rcItem.bottom );
//.........这里部分代码省略.........
示例7: MonSelPaintMonitor
static VOID
MonSelPaintMonitor(IN OUT PMONITORSELWND infoPtr,
IN HDC hDC,
IN DWORD Index,
IN OUT PRECT prc,
IN COLORREF crDefFontColor,
IN BOOL bHideNumber)
{
HFONT hFont, hPrevFont;
COLORREF crPrevText;
if ((INT)Index == infoPtr->SelectedMonitor)
{
FillRect(hDC,
prc,
(HBRUSH)(COLOR_HIGHLIGHT + 1));
if (infoPtr->HasFocus && !(infoPtr->UIState & UISF_HIDEFOCUS))
{
/* NOTE: We need to switch the text color to the default, because
DrawFocusRect draws a solid line if the text is white! */
crPrevText = SetTextColor(hDC,
crDefFontColor);
DrawFocusRect(hDC,
prc);
SetTextColor(hDC,
crPrevText);
}
}
InflateRect(prc,
-infoPtr->SelectionFrame.cx,
-infoPtr->SelectionFrame.cy);
Rectangle(hDC,
prc->left,
prc->top,
prc->right,
prc->bottom);
InflateRect(prc,
-1,
-1);
if (!bHideNumber)
{
hFont = MonSelGetMonitorFont(infoPtr,
hDC,
Index);
if (hFont != NULL)
{
hPrevFont = SelectObject(hDC,
hFont);
DrawText(hDC,
infoPtr->Monitors[Index].szCaption,
-1,
prc,
DT_VCENTER | DT_CENTER | DT_NOPREFIX | DT_SINGLELINE);
SelectObject(hDC,
hPrevFont);
}
}
if (infoPtr->MonitorInfo[Index].Flags & MSL_MIF_DISABLED)
{
InflateRect(prc,
1,
1);
MonSelDrawDisabledRect(infoPtr,
hDC,
prc);
}
}
示例8: A4
A4(PRIVATE, void, dobuttons, INTEGER, id, INTEGER, offsetx,
INTEGER, offsety, BOOLEAN, demo_button_p)
{
struct bdef *bp;
struct sdef *sp;
struct pdef *pp;
int i;
EventRecord evt;
int done;
int tcnt, twid;
Point p;
#define BILLBUTTONS /* */
#if defined (BILLBUTTONS)
INTEGER h, v;
#endif /* BILLBUTTONS */
char *textp;
if ((bp = (struct bdef *) findid(id))) {
for (i = 0; i < Cx(bp->nbut); i++) {
/* Offset buttons; this hack is to center the splash screen
* on non-512x342 root windows...yuck!
*/
C_OffsetRect (&bp->buts[i].butloc, offsetx, offsety);
if ((sp = (struct sdef *)findid(CW(bp->buts[i].butstrid)))) {
if (demo_button_p && sp->text[0] == 'O' && sp->text[1] == 'K')
textp = "Demo";
else
textp = sp->text;
tcnt = strlen(textp);
twid = TextWidth((Ptr) textp, 0, tcnt);
MoveTo((CW(bp->buts[i].butloc.left) +
CW(bp->buts[i].butloc.right) - twid) / 2,
(CW(bp->buts[i].butloc.top) +
CW(bp->buts[i].butloc.bottom)) / 2 + 4);
DrawText((Ptr) textp, 0, tcnt);
}
#if defined (BILLBUTTONS)
h = CW(bp->buts[i].butloc.right) - CW(bp->buts[i].butloc.left);
v = (CW(bp->buts[i].butloc.bottom) - CW(bp->buts[i].butloc.top))/2;
if (h > v)
h = v;
if (!(ROMlib_options & ROMLIB_RECT_SCREEN_BIT))
FrameRoundRect(&bp->buts[i].butloc, h, v);
else
FrameRect(&bp->buts[i].butloc);
#else /* BILLBUTTONS */
if (!(ROMlib_options & ROMLIB_RECT_SCREEN_BIT))
FrameRoundRect(&bp->buts[i].butloc, 10, 10);
else
FrameRect(&bp->buts[i].butloc);
#endif /* BILLBUTTONS */
}
for (done = 0; !done;) {
C_GetNextEvent(mDownMask|keyDownMask, &evt);
if (evt.what == CWC(mouseDown) || evt.what == CWC(keyDown)) {
p.h = CW(evt.where.h);
p.v = CW(evt.where.v);
for (i = 0; !done && i < CW(bp->nbut); i++) {
if (PtInRect(p, &bp->buts[i].butloc) ||
((evt.what == CWC(keyDown)) &&
(((CL(evt.message) & charCodeMask) == '\r') ||
((CL(evt.message) & charCodeMask) == NUMPAD_ENTER)))
) {
if ((pp = (struct pdef *)
findid(CW(bp->buts[i].butprocid))))
/* NOTE: we will have to do a better
job here sometime */
(*(void (*)(void))MR(pp->proc))();
done = 1;
}
}
if (!done)
SysBeep(1);
}
}
if (evt.what == CWC(mouseDown))
while (!C_GetNextEvent(mUpMask, &evt))
;
/* Move all buttons back. */
for (i = 0; i < Cx(bp->nbut); i++)
C_OffsetRect (&bp->buts[i].butloc, -offsetx, -offsety);
}
}
示例9: MsgProc
//.........这里部分代码省略.........
// To play a zero-latency cue:
// 1) prepare it
// 2) wait for it to be prepared
// 3) play it with using the cue instance returned from the Prepare() function.
if( wParam == 'A' )
{
// The Play() call on a cue will only succeed if the cue is either preparing or
// prepared meaning it can not be playing, etc.
DWORD dwState;
g_audioState.pZeroLatencyRevCue->GetState( &dwState );
if( ( dwState & ( XACT_CUESTATE_PREPARING | XACT_CUESTATE_PREPARED ) ) != 0 )
g_audioState.pZeroLatencyRevCue->Play();
}
if( wParam == VK_ESCAPE )
PostQuitMessage( 0 );
break;
}
case WM_TIMER:
{
// Update message string every so often
WCHAR szState[512];
if( g_audioState.pZeroLatencyRevCue )
{
DWORD dwState;
g_audioState.pZeroLatencyRevCue->GetState( &dwState );
switch( dwState )
{
case XACT_CUESTATE_CREATED:
StringCchCopy( szState, 512, L"Created, but nothing else" ); break;
case XACT_CUESTATE_PREPARING:
StringCchCopy( szState, 512, L"Preparing to play" ); break;
case XACT_CUESTATE_PREPARED:
StringCchCopy( szState, 512, L"Prepared, but not yet played" ); break;
case XACT_CUESTATE_PLAYING:
StringCchCopy( szState, 512, L"Playing, but can be paused" ); break;
case XACT_CUESTATE_STOPPING:
StringCchCopy( szState, 512, L"Stopping" ); break;
case XACT_CUESTATE_STOPPED:
StringCchCopy( szState, 512, L"Stopped" ); break;
case XACT_CUESTATE_PAUSED:
StringCchCopy( szState, 512, L"Paused" ); break;
}
}
else
{
StringCchCopy( szState, 512, L"Not created" );
}
EnterCriticalSection( &g_audioState.cs );
WCHAR sz[512];
StringCchPrintf( sz, 512,
L"Press space to play an XACT cue called 'zap' which plays\n"
L"from an in-memory wave bank\n"
L"\n"
L"Press 'A' to play a zero-latency cue when it is preparing or prepared.\n"
L"When this cue stops, the tutorial releases it and prepares a new cue\n"
L"Cue state: %s\n"
L"\n"
L"This tutorial is also playing background music in that is\n"
L"contained in a streaming wave bank. When the background\n"
L"music stops, a new song cue is played by the tutorial.\n"
L"Currently playing: Song %d\n", szState, g_audioState.nCurSongPlaying + 1 );
LeaveCriticalSection( &g_audioState.cs );
if( wcscmp( sz, s_szMessage ) != 0 )
{
// Repaint the window if needed
StringCchCopy( s_szMessage, 1024, sz );
InvalidateRect( g_hWnd, NULL, TRUE );
UpdateWindow( g_hWnd );
}
break;
}
case WM_PAINT:
{
// Paint some simple explanation text
PAINTSTRUCT ps;
HDC hDC = BeginPaint( hWnd, &ps );
SetBkColor( hDC, 0xFF0000 );
SetTextColor( hDC, 0xFFFFFF );
RECT rect;
GetClientRect( hWnd, &rect );
rect.top = 70;
DrawText( hDC, s_szMessage, -1, &rect, DT_CENTER );
EndPaint( hWnd, &ps );
return 0;
}
case WM_DESTROY:
{
PostQuitMessage( 0 );
break;
}
}
return DefWindowProc( hWnd, msg, wParam, lParam );
}
示例10: DisplayNumericStat
/*
* DisplayNumericStat: Display the given numeric type stat from the current group on the
* main window.
*/
void DisplayNumericStat(Statistic *s)
{
RECT r;
HDC hdc;
HFONT hOldFont;
char *name, *str;
AREA stats_area;
AREA a;
// ajw - Avoid drawing if Inventory is selected as the "group".
if( StatsGetCurrentGroup() == STATS_INVENTORY )
return;
StatsGetArea(&stats_area);
r.left = 0;
r.right = stats_area.cx / 2;
r.top = s->y;
r.bottom = r.top + s->cy;
/* If stat is out of stats area, abort */
if (r.bottom > stats_area.cy || s->num <= top_stat)
return;
hdc = GetDC(hStats);
// DrawWindowBackground(hdc, &r, stats_area.x + r.left, stats_area.y + r.top);
DrawWindowBackgroundColor( pinventory_bkgnd(), hdc, &r, stats_area.x + r.left, stats_area.y + r.top, -1 );
hOldFont = (HFONT) SelectObject(hdc, GetFont(FONT_STATS));
SetBkMode(hdc, TRANSPARENT);
name = LookupNameRsc(s->name_res);
// Draw with drop shadow
SetTextColor(hdc, GetColor(COLOR_STATSBGD));
DrawText(hdc, name, strlen(name), &r, DT_LEFT);
OffsetRect(&r, 1, 1);
SetTextColor(hdc, GetColor(COLOR_STATSFGD));
DrawText(hdc, name, strlen(name), &r, DT_LEFT);
switch (s->numeric.tag)
{
case STAT_RES:
r.left = stats_area.cx / 2;
r.right = stats_area.cx;
DrawWindowBackgroundColor( pinventory_bkgnd(), hdc, &r, stats_area.x + r.left, stats_area.y + r.top, -1 );
str = LookupNameRsc(s->numeric.value);
DrawText(hdc, str, strlen(str), &r, DT_RIGHT);
break;
case STAT_INT:
// Draw background around stat bar
a.x = stats_area.cx / 2;
a.cx = stats_bar_width;
a.y = s->y + (s->cy - STATS_BAR_HEIGHT) / 2;
a.cy = STATS_BAR_HEIGHT;
InterfaceDrawBarBorder( pinventory_bkgnd(), hdc, &a );
break;
}
SelectObject(hdc, hOldFont);
ReleaseDC(hStats, hdc);
InvalidateRect( s->hControl, NULL, FALSE );
}
示例11: WinProc
//.........这里部分代码省略.........
break;
case SB_LINEDOWN: // The down arrow of the scroll bar has been clicked
// If the scrollAmt is already at the maximum Y position then we can't move
// down anymore so simply return
if(scrollAmt == scrollInfo.nMax)
return 0;
else
scrollAmt = scrollAmt + 1; // Otherwise we want to scroll down by one unit
break;
// The user has dragged the thumb (that's the box inbetween the left and right arrows on
// the scroll bar) by clicking it, dragging it, and then releasing the mouse button
case SB_THUMBPOSITION:
// We need to know the new position of the scroll bar. It is given to us
// by the HIWORD of the WPARAM
scrollAmt = HIWORD(wparam);
break;
default:
// **NOTE** There are other messages that could be sent but we're not
// going to do anything if we receive 'em. As always, for the
// full unedited scoop, check out MSDN.
break;
} // end of switch(LOWORD(wparam))
// Alright if we get here, we know that we've updated our scroll bar's position
// so we need to fill the SCROLLINFO with that information and then tell the
// window about it
scrollInfo.nPos = scrollAmt; // Set the new position
scrollInfo.fMask = SIF_POS; // Set the flag saying "We're use the nPos value in SCROLLINFO"
// Set the new position.
// **NOTE** We pass true because we want the scroll bar redrawn to update it's
// thumb position
SetScrollInfo(hwnd, SB_VERT, &scrollInfo, true);
// Lastly, we need to redraw the window to display the correct portion of the
// text. What InvalidateRect does for us is specify a "dirty" region of
// the window that needs to be repainted. When the window doesn't have any other messages
// in it's message queue, it will generate a WM_PAINT message, and repaint all the
// areas in it's dirty region.
// By parameter:
// hwnd -- Handle to the window who is to be repainted
// NULL -- Rectangle area of the window to repaint. By passing NULL we are requesting
// that the entire client area of the window be repainted
// TRUE -- This is a boolean value that says whether the background should be redrawn
// or not. For us, our background is solid white, and we want it redrawn so
// the text doesn't draw over itself. Typically, this value will be set
// to true.
InvalidateRect(hwnd,NULL,TRUE);
return 0;
// This message is sent when the window needs to be repainted
case WM_PAINT:
// Begin painting to the window and get the HDC associated
// with the window
hdc = BeginPaint(hwnd, &ps);
// The paint struct contains the area of the window for redrawing. We
// want to subtract off the amount we've scrolled down, so that we show the
// correct portion of text based on where we have vertically scrolled.
ps.rcPaint.top -= scrollAmt;
if(gText)
{
// DrawText(), as the name implies, this function draws text to the screen
// By parameter:
// hdc -- The handle to the device context to draw to
// gText -- Pointer to the string for drawing
// strlen(gText) -- Length of the string to draw
// &(ps.rcPaint) -- Pointer to the bounding rectangle of where to draw the text
// DT_WORDBREAK -- This parameter is for optional flags to DrawText(). This
// specific flag says that if the text extends past the right
// side of it's bounding rectangle, do a word wrap and continue
// the text on the next line.
DrawText(hdc, gText, strlen(gText), &(ps.rcPaint), DT_WORDBREAK);
}
// We've finished painting to the window
EndPaint(hwnd, &ps);
return 0;
// When the program is destroyed
case WM_DESTROY:
PostQuitMessage(0);
return 0;
} // end of switch(message)
return DefWindowProc(hwnd, message, wparam, lparam);
}
示例12: WndProc
//.........这里部分代码省略.........
DeleteObject(hFont);
PostQuitMessage(0);
return 0;
}
case WM_ERASEBKGND:
{
// Don't do any erasing here. It's done in WM_PAINT to avoid flicker.
return 1;
}
case WM_VOLUMECHANGE:
{
// get the new volume level
g_pVolumeMonitor->GetLevelInfo(&g_currentVolume);
// make window visible for 2 seconds
ShowWindow(hWnd, SW_SHOW);
InvalidateRect(hWnd, NULL, TRUE);
nTimerId = SetTimer(hWnd, 101, 2000, NULL);
return 0;
}
case WM_ENDPOINTCHANGE:
{
g_pVolumeMonitor->ChangeEndpoint();
return 0;
}
case WM_TIMER:
{
// make the window go away
ShowWindow(hWnd, SW_HIDE);
KillTimer(hWnd, nTimerId);
return 0;
}
case WM_PAINT:
{
PAINTSTRUCT ps;
HPAINTBUFFER hBufferedPaint = NULL;
RECT rc;
GetClientRect(hWnd, &rc);
HDC hdc = BeginPaint(hWnd, &ps);
if (g_bDblBuffered)
{
// Get doublebuffered DC
HDC hdcMem;
hBufferedPaint = BeginBufferedPaint(hdc, &rc, BPBF_COMPOSITED, NULL, &hdcMem);
if (hBufferedPaint)
{
hdc = hdcMem;
}
}
// black background (transparency color)
FillRect(hdc, &rc, (HBRUSH)GetStockObject(BLACK_BRUSH));
// Draw LEDs
for (UINT i = 0; i < (g_currentVolume.cSteps-1); i++)
{
RECT const rcLed = { DPIScale(i * 10), DPIScale(10), DPIScale(i * 10 + 8), rc.bottom-DPIScale(15) };
if ((i < g_currentVolume.nStep) && (!g_currentVolume.bMuted))
FillRect(hdc, &rcLed, hbrLit);
else
FillRect(hdc, &rcLed, hbrUnlit);
}
if (g_currentVolume.bMuted)
{
HGDIOBJ hof = SelectObject(hdc, hFont);
SetBkMode(hdc, TRANSPARENT);
SetTextColor(hdc, RGB(255, 64, 64));
RECT rcText = rc;
rcText.bottom -= DPIScale(11);
DrawText(hdc, L"MUTED", -1, &rcText, DT_CENTER | DT_SINGLELINE | DT_VCENTER);
SelectObject(hdc, hof);
}
if (hBufferedPaint)
{
// end painting
BufferedPaintMakeOpaque(hBufferedPaint, NULL);
EndBufferedPaint(hBufferedPaint, TRUE);
}
EndPaint(hWnd, &ps);
return 0;
}
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
示例13: Draw
/*-----------------------------------------------------------------------------
* Draw
* The Draw function is the main loop for the Graphics process. Draws each
* viewport and the lines within them
*-----------------------------------------------------------------------------*/
void Draw( void )
{
char buf[BUF_SIZ];
GLdouble answer[MATRIX_SIZE];
GLdouble attempt[MATRIX_SIZE];
/* Clear the screen ... */
glClear( GL_COLOR_BUFFER_BIT );
if(gameComplete)
{
DrawText(-25.0, -25.0, DEFAULT_FONT, "GAME OVER! YOU WIN!");
}
else if(levelComplete)
{
DrawText(-25.0, -25.0, DEFAULT_FONT, "LEVEL COMPLETE!");
}
else
{
glPushMatrix( );
/* Draw the Outlines for Transforms */
glCallList('a');
glCallList('s');
/* Draw the Axes */
glBegin( GL_LINES );
glColor3f( 0.5, 0.5, 0.5 );
glVertex3f( 100.0, 0.0, 0.0 );
glVertex3f(-100.0, 0.0, 0.0 );
glVertex3f( 0.0, 100.0, 0.0 );
glVertex3f( 0.0,-100.0, 0.0 );
glColor3f( 1.0, 1.0, 1.0 );
glEnd( );
glPopMatrix( );
/* Draw the first set of Available Transforms */
glPushMatrix( );
/* Move to origin of first list */
glTranslatef( 115.0, 90.0, 0.0 );
/* List drawing */
CreateTransforms( &tlAvailableTransforms, VERTICAL, AVAILABLE );
glPopMatrix( );
/* Draw the second set of Used Transforms */
glPushMatrix( );
/* Move to origin of first list */
glTranslatef( -85.0, -120.0, 0.0 );
/* List drawing */
CreateTransforms( &tlSelectedTransforms, HORIZONTAL, SELECTED );
glPopMatrix( );
glPushMatrix( );
/* Do all level transforms */
RunTransformList( &tlLevel );
/* Create model house */
glLoadName( 1 );
glCallList( 'l' );
/* Get the modelview matrix */
glGetDoublev( GL_MODELVIEW_MATRIX, answer );
glPopMatrix( );
/* Create the new house */
glPushMatrix( );
/* Do all user selected transforms */
RunTransformList( &tlSelectedTransforms );
/* Create attempt house */
glLoadName( HOUSE );
glCallList( 'h' );
/* Get the modelview matrix */
glGetDoublev( GL_MODELVIEW_MATRIX, attempt );
glPopMatrix( );
/* Compare the model */
if(CompareMatrices(answer, attempt))
{
levelComplete = TRUE;
glutPostRedisplay( );
}
}
/* Flush the buffer */
glutSwapBuffers();
return;
}
示例14: mswin_menu_window_size
void mswin_menu_window_size (HWND hWnd, LPSIZE sz)
{
TEXTMETRIC tm;
HWND control;
HGDIOBJ saveFont;
HDC hdc;
PNHMenuWindow data;
int i;
RECT rt, wrt;
int extra_cx;
GetClientRect(hWnd, &rt);
sz->cx = rt.right - rt.left;
sz->cy = rt.bottom - rt.top;
GetWindowRect(hWnd, &wrt);
extra_cx = (wrt.right-wrt.left) - sz->cx;
data = (PNHMenuWindow)GetWindowLong(hWnd, GWL_USERDATA);
if(data) {
control = GetMenuControl(hWnd);
hdc = GetDC(control);
if( data->type==MENU_TYPE_MENU ) {
/* Calculate the width of the list box. */
saveFont = SelectObject(hdc, mswin_get_font(NHW_MENU, ATR_NONE, hdc, FALSE));
GetTextMetrics(hdc, &tm);
for(i=0; i<data->menu.size; i++ ) {
LONG menuitemwidth = 0;
int column;
char *p, *p1;
p1 = data->menu.items[i].str;
p = strchr(data->menu.items[i].str, '\t');
column = 0;
for (;;) {
TCHAR wbuf[BUFSZ];
RECT tabRect;
SetRect ( &tabRect, 0, 0, 1, 1 );
if (p != NULL) *p = '\0'; /* for time being, view tab field as zstring */
DrawText(hdc,
NH_A2W(p1, wbuf, BUFSZ),
/*JP
strlen(p1),
*/
-1,
&tabRect,
DT_CALCRECT | DT_LEFT | DT_VCENTER | DT_SINGLELINE
);
/* it probably isn't necessary to recompute the tab width now, but do so
* just in case, honoring the previously computed value
*/
menuitemwidth += max(data->menu.tab_stop_size[column],
tabRect.right - tabRect.left);
if (p != NULL) *p = '\t';
else /* last string so, */ break;
/* add the separation only when not the last item */
/* in the last item, we break out of the loop, in the statement just above */
menuitemwidth += TAB_SEPARATION;
++column;
p1 = p + 1;
p = strchr(p1, '\t');
}
sz->cx = max(sz->cx,
(LONG)(2*TILE_X + menuitemwidth + tm.tmAveCharWidth*12 + tm.tmOverhang));
}
SelectObject(hdc, saveFont);
} else {
/* do not change size for text output - the text will be formatted to
fit any window */
}
sz->cx += extra_cx;
ReleaseDC(control, hdc);
}
}
示例15: onMSNHCommand
void onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
PNHMenuWindow data;
data = (PNHMenuWindow)GetWindowLong(hWnd, GWL_USERDATA);
switch( wParam ) {
case MSNH_MSG_PUTSTR:
{
PMSNHMsgPutstr msg_data = (PMSNHMsgPutstr)lParam;
HWND text_view;
if( data->type!=MENU_TYPE_TEXT )
SetMenuType(hWnd, MENU_TYPE_TEXT);
if( !data->text.text ) {
data->text.text = mswin_init_text_buffer(
program_state.gameover? FALSE : GetNHApp()->bWrapText
);
if( !data->text.text ) break;
}
mswin_add_text(data->text.text, msg_data->attr, msg_data->text);
text_view = GetDlgItem(hWnd, IDC_MENU_TEXT);
if( !text_view ) panic("cannot get text view window");
mswin_render_text(data->text.text, text_view);
} break;
case MSNH_MSG_STARTMENU:
{
int i;
if( data->type!=MENU_TYPE_MENU )
SetMenuType(hWnd, MENU_TYPE_MENU);
if( data->menu.items ) free(data->menu.items);
data->how = PICK_NONE;
data->menu.items = NULL;
data->menu.size = 0;
data->menu.allocated = 0;
data->done = 0;
data->result = 0;
for (i = 0; i < NUMTABS; ++i)
data->menu.tab_stop_size[i] = MIN_TABSTOP_SIZE;
} break;
case MSNH_MSG_ADDMENU:
{
PMSNHMsgAddMenu msg_data = (PMSNHMsgAddMenu)lParam;
char *p, *p1;
int new_item;
HDC hDC;
int column;
HFONT saveFont;
if( data->type!=MENU_TYPE_MENU ) break;
if( strlen(msg_data->str)==0 ) break;
if( data->menu.size==data->menu.allocated ) {
data->menu.allocated += 10;
data->menu.items = (PNHMenuItem)realloc(data->menu.items, data->menu.allocated*sizeof(NHMenuItem));
}
new_item = data->menu.size;
ZeroMemory( &data->menu.items[new_item], sizeof(data->menu.items[new_item]));
data->menu.items[new_item].glyph = msg_data->glyph;
data->menu.items[new_item].identifier = *msg_data->identifier;
data->menu.items[new_item].accelerator = msg_data->accelerator;
data->menu.items[new_item].group_accel = msg_data->group_accel;
data->menu.items[new_item].attr = msg_data->attr;
parse_menu_str(data->menu.items[new_item].str, msg_data->str, NHMENU_STR_SIZE);
data->menu.items[new_item].presel = msg_data->presel;
/* calculate tabstop size */
p = strchr(data->menu.items[new_item].str, '\t');
if( p ) {
data->menu.items[new_item].has_tab = TRUE;
hDC = GetDC(hWnd);
saveFont = SelectObject(hDC, mswin_get_font(NHW_MENU, msg_data->attr, hDC, FALSE));
p1 = data->menu.items[new_item].str;
column = 0;
for (;;) {
TCHAR wbuf[BUFSZ];
RECT drawRect;
SetRect ( &drawRect, 0, 0, 1, 1 );
if (p != NULL) *p = '\0'; /* for time being, view tab field as zstring */
DrawText(hDC,
NH_A2W(p1, wbuf, BUFSZ),
/*JP
strlen(p1),
*/
-1,
&drawRect,
DT_CALCRECT | DT_LEFT | DT_VCENTER | DT_EXPANDTABS | DT_SINGLELINE
);
data->menu.tab_stop_size[column] =
max( data->menu.tab_stop_size[column], drawRect.right - drawRect.left );
if (p != NULL) *p = '\t';
else /* last string so, */ break;
//.........这里部分代码省略.........