Guidance
指路人
g.yi.org
Guidance Forums / Reginald Rexx / Setting the color of a text window

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. Setting the color of a text window
#11781
Posted by: chucksim 2007-09-09 09:12:51
I'm retying to create an input form window where I want to make the background color of the text entry of a certain column different than the default. But when I try to use

if substr(varname,1,13)="!GLOBAL_EXIST" then do
  SetBkColor(ARG(1), 1255)
  RETURN GetStockObject(5)
end

It just changes the color of the background of the text in the text window, not the entire width of my text window. How can I change the color of the entire text window?
Chuck Simmons
Message2.
#11782
Posted by: Jeff Glatt 2007-09-09 12:29:51
There are 2 ways to handle this. If you're handling the PAINT event, then it's easiest to do the window background drawing there. If not, then handle the ERASEBKGND event.

In either case, if you're drawing the background yourself, then pass a Color arg of 0 to GuiWindowDefaults().

To handle ERASEBKGND, you need to FUNCDEF a few Windows OS functions at the start of your script. You also need to create a "brush" of the desired color. (You can alternately use one of the system brushes returned by RxGdi's GdiStockObj, if one of those available colors are what you want. In your above snippet, you're using a system brush, but we'll assume you want a special color).
/*
GUIBEGIN
WINDOW , 0, 0, 400, 200, POPUP|CAPTION|SYSMENU|MINBOX|MAXBOX|THICK, , Custom Background Color
	FONT 8, 400, MS Shell Dlg
DEND
GUIEND
*/

/* An example of a custom background color for the window. */

LIBRARY rexxgui
guierr = "SYNTAX"
guiheading = 1

/* FUNCDEF some stuff */
DO
  FUNCDEF("CreateSolidBrush", "32u, 32u", "gdi32")
  FUNCDEF("SelectObject", "32u, 32u, 32u", "gdi32")
  rect = "32u, 32u, 32u, 32u"
  FUNCDEF("FillRect", ", 32u, struct RECT, 32u", "user32")
  FUNCDEF("DeleteBrush", ", 32u", "gdi32", "DeleteObject")

  CATCH FAILURE
    CONDITION('M')
    RETURN
END

/* Get a custom brush with an RGB color of  100, 175, 150 */
color = (100 * 65536) + (175 * 256) + 150
brush = createsolidbrush(color)

/* Since we'll be doing our own painting of windows, then don't let the
 * operating system automatically erase the window background. We also
 * need our PAINT handler called whenever the window is resized, so we
 * specify the VREDRAW|HREDRAW styles
 */
guiwindowdefaults(, , 0, 'VREDRAW|HREDRAW')

guicreatewindow('NORMAL')

again:
DO FOREVER
  guigetmsg()
  CATCH SYNTAX
    CONDITION('M')
    SIGNAL again

  CATCH HALT
  FINALLY
    guidestroywindow()

    /* Destroy our custom brush */
    deletebrush(brush)
END
RETURN


/* Called by Reginald whenever our window needs its background drawn. This
 * handler is tricky. It should never, never create another window nor display a
 * message box. All it should ever do is draw our window background. And that's it.
 */

wm_erasebkgnd:
  context = ARG(1)

  /* Get the window's width/height */
  guigetctlplacement(guiwindow, , , 'Width', 'Height')

  /* Use our custom brush */
  temp = selectobject(context, brush)

  /* Fill in the window */
  rect.1 = 0
  rect.2 = 0
  rect.3 = width
  rect.4 = height
  fillrect(context, rect, brush)

  /* Restore orig brush */
  selectobject(context, temp)

  /* Indicate we did the background */
  RETURN 1
Incidentally, you'll likely want to use the same custom brush for your text control's background, so change your:
setbkcolor(ARG(1), 1255)
RETURN getstockobject(5)
to...
setbkcolor(ARG(1), 1255)
RETURN brush
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Fri 2024-3-29  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0