comparison win/dw.c @ 49:bf42d08d72d7

Added font text extent querying code, and made it so winmain.c can be used without Dynamic Windows.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Fri, 09 Nov 2001 13:49:44 +0000
parents 16eac0f8b45f
children 0804483f6320
comparison
equal deleted inserted replaced
48:16eac0f8b45f 49:bf42d08d72d7
5398 DeleteObject(hFont); 5398 DeleteObject(hFont);
5399 if(!pixmap) 5399 if(!pixmap)
5400 ReleaseDC(handle, hdc); 5400 ReleaseDC(handle, hdc);
5401 } 5401 }
5402 5402
5403 /* Query the width and height of a text string.
5404 * Parameters:
5405 * handle: Handle to the window.
5406 * pixmap: Handle to the pixmap. (choose only one of these)
5407 * text: Text to be queried.
5408 * width: Pointer to a variable to be filled in with the width.
5409 * height Pointer to a variable to be filled in with the height.
5410 */
5411 void dw_font_text_extents(HWND handle, HPIXMAP pixmap, char *text, int *width, int *height)
5412 {
5413 HDC hdc;
5414 int mustdelete = 0;
5415 HFONT hFont, oldFont;
5416 SIZE sz;
5417
5418 if(handle)
5419 hdc = GetDC(handle);
5420 else if(pixmap)
5421 hdc = pixmap->hdc;
5422 else
5423 return;
5424
5425 {
5426 ColorInfo *cinfo;
5427
5428 if(handle)
5429 cinfo = (ColorInfo *)GetWindowLong(handle, GWL_USERDATA);
5430 else
5431 cinfo = (ColorInfo *)GetWindowLong(pixmap->handle, GWL_USERDATA);
5432
5433 if(cinfo)
5434 {
5435 hFont = _aquire_font(cinfo->fontname);
5436 mustdelete = 1;
5437 }
5438 }
5439 oldFont = SelectObject(hdc, hFont);
5440
5441 GetTextExtentPoint32(hdc, text, strlen(text), &sz);
5442
5443 if(width)
5444 *width = sz.cx;
5445
5446 if(height)
5447 *height = sz.cy;
5448
5449 SelectObject(hdc, oldFont);
5450 if(mustdelete)
5451 DeleteObject(hFont);
5452 if(!pixmap)
5453 ReleaseDC(handle, hdc);
5454 }
5455
5403 /* Call this after drawing to the screen to make sure 5456 /* Call this after drawing to the screen to make sure
5404 * anything you have drawn is visible. 5457 * anything you have drawn is visible.
5405 */ 5458 */
5406 void dw_flush(void) 5459 void dw_flush(void)
5407 { 5460 {