// graphics5- // // This program demonstrates the use of round rectangles on a form. program graphics5; #linker( "comdlg32.lib" ) #linker( "comctl32.lib" ) ?@NoDisplay := true; ?@NoStackAlign := true; #includeOnce( "stdlib.hhf" ) #includeOnce( "howl.hhf" ) const applicationName := "Graphics #5"; formX := w.CW_USEDEFAULT; // Let Windows position this guy formY := w.CW_USEDEFAULT; formW := 600; formH := 600; // Forward declarations for the onClick widgetProcs that we're going to // call when an event occurs. proc hideShowRoundRect :widgetProc; @forward; proc moveRoundRect :widgetProc; @forward; proc resizeRoundRect :widgetProc; @forward; proc changeHeight :widgetProc; @forward; proc changeWidth :widgetProc; @forward; proc colorRoundRect :widgetProc; @forward; proc onClick :widgetProc; @forward; proc onQuit :widgetProc; @forward; // Here's the main form definition for the app: wForm( mainAppWindow ); var showState :boolean; align(4); wRoundRect ( roundRect1, // HLA identifier 10, // x 10, // y 200, // width 200, // height 40, // corner width 40, // corner height RGB( 0, 0, 0 ), // outline color (black) RGB( 255, 255, 255 ), // fill color (white) howl.bkgColor_g // background color ) wRoundRect ( roundRect2, 10, 250, 200, 200, 40, 40, RGB( 0, 0, 0 ), RGB( 255, 0, 0 ), howl.transparent_g ) wRoundRect ( roundRect3, 10, 250, 100, 100, 40, 40, RGB( 0, 0, 0 ), RGB( 0, 255, 0 ), howl.transparent_g ) wRoundRect ( roundRect4, 110, 350, 100, 100, 40, 40, RGB( 0, 0, 0 ), RGB( 0, 0, 255 ), howl.transparent_g ) wPushButton ( button2, // Field name in mainWindow object "Hide roundRect", // Caption for push button 250, // x position 10, // y position 175, // width 25, // height hideShowRoundRect // initial "on click" event handler ) wPushButton ( button3, // Field name in mainWindow object "Move RoundRect", // Caption for push button 250, // x position 40, // y position 175, // width 25, // height moveRoundRect // initial "on click" event handler ) wPushButton ( button4, // Field name in mainWindow object "Resize RoundRect", // Caption for push button 250, // x position 70, // y position 175, // width 25, // height resizeRoundRect // initial "on click" event handler ) wPushButton ( button5, // Field name in mainWindow object "Change width", // Caption for push button 250, // x position 100, // y position 175, // width 25, // height changeWidth // initial "on click" event handler ) wPushButton ( button6, // Field name in mainWindow object "Change height", // Caption for push button 250, // x position 130, // y position 175, // width 25, // height changeHeight // initial "on click" event handler ) wPushButton ( button7, // Field name in mainWindow object "Change Color", // Caption for push button 250, // x position 160, // y position 175, // width 25, // height colorRoundRect // initial "on click" event handler ) // Place a quit button in the lower-right-hand corner of the form: wPushButton ( quitButton, // Field name in mainWindow object "Quit", // Caption for push button 450, // x position 525, // y position 125, // width 25, // height onQuit // "on click" event handler ) endwForm // Must invoke the following macro to emit the code generated by // the wForm macro: mainAppWindow_implementation(); // The colorRoundRect widget proc will change the foreground and background color. proc colorRoundRect:widgetProc; begin colorRoundRect; mov( mainAppWindow.roundRect1, esi ); (type wRoundRect_t [esi]).get_lineColor(); if( eax = RGB( 0, 0, 0 )) then (type wRoundRect_t [esi]).set_lineColor( RGB( 0, 255, 0 )); (type wRoundRect_t [esi]).set_fillColor( RGB( 255, 0, 0 )); else (type wRoundRect_t [esi]).set_lineColor( RGB( 0, 0, 0 )); (type wRoundRect_t [esi]).set_fillColor( RGB( 255, 255, 255 )); endif; end colorRoundRect; // The resizeRoundRect widget proc will resize label1 between widths 150 and 200. proc resizeRoundRect:widgetProc; begin resizeRoundRect; mov( mainAppWindow.roundRect1, esi ); (type wRoundRect_t [esi]).get_width(); if( eax = 200 ) then stdout.put( "Resizing roundRect to width/height 150" nl ); (type wRoundRect_t [esi]).resize( 150, 150 ); else stdout.put( "Resizing label to width/height 200" nl ); (type wRoundRect_t [esi]).resize( 200, 200 ); endif; end resizeRoundRect; // The changeWidth widget proc will set the roundRect between widths 150 and 200. proc changeWidth:widgetProc; begin changeWidth; mov( mainAppWindow.roundRect1, esi ); (type wRoundRect_t [esi]).get_width(); if( eax = 200 ) then stdout.put( "Resizing roundRect to width 150" nl ); (type wRoundRect_t [esi]).set_width( 150 ); else stdout.put( "Resizing label to width 200" nl ); (type wRoundRect_t [esi]).set_width( 200 ); endif; end changeWidth; // The changeHeight widget proc will set the roundRect between Heights 150 and 200. proc changeHeight:widgetProc; begin changeHeight; mov( mainAppWindow.roundRect1, esi ); (type wRoundRect_t [esi]).get_height(); if( eax = 200 ) then stdout.put( "Resizing roundRect to height 150" nl ); (type wRoundRect_t [esi]).set_height( 150 ); else stdout.put( "Resizing label to height 200" nl ); (type wRoundRect_t [esi]).set_height( 200 ); endif; end changeHeight; // The moveRoundRect widget proc will move label // between y positions 10 and 40. proc moveRoundRect:widgetProc; begin moveRoundRect; mov( mainAppWindow.roundRect1, esi ); (type wRoundRect_t [esi]).get_y(); if( eax = 10 ) then stdout.put( "Moving roundRect to y-position 40" nl ); (type wRoundRect_t [esi]).set_y( 40 ); else stdout.put( "Moving roundRect to y-position 10" nl ); (type wRoundRect_t [esi]).set_y( 10 ); endif; end moveRoundRect; // The hideShowRoundRect widget proc will hide and show roundRect1. proc hideShowRoundRect:widgetProc; begin hideShowRoundRect; mov( thisPtr, esi ); if( mainAppWindow.showState ) then (type wPushButton_t [esi]).set_text( "Hide RoundRect" ); mov( false, mainAppWindow.showState ); stdout.put( "Showing roundRect 1" nl ); mov( mainAppWindow.roundRect1, esi ); (type wRoundRect_t [esi]).show(); else (type wPushButton_t [esi]).set_text( "Show RoundRect" ); mov( true, mainAppWindow.showState ); stdout.put( "Hiding roundRect 1" nl ); mov( mainAppWindow.roundRect1, esi ); (type wRoundRect_t [esi]).hide(); endif; end hideShowRoundRect; // Here's the onClick event handler the graphic object: proc onClick:widgetProc; begin onClick; stdout.put( "Clicked on graphic object" nl ); mov( thisPtr, esi ); (type wRoundRect_t [esi]).set_lineColor( RGB( 0, 0, 255 )); (type wRoundRect_t [esi]).set_fillColor( RGB( 255, 0, 255 )); end onClick; // Here's the onClick event handler for our quit button on the form. // This handler will simply quit the application: proc onQuit:widgetProc; begin onQuit; // Quit the app: w.PostQuitMessage( 0 ); end onQuit; // We'll use the main application form's onCreate method to initialize // the various buttons on the form. // // This could be done in appStart, but better to leave appStart mainly // as boilerplate code. Also, putting this code here allows us to use // "this" to access the mainAppWindow fields (a minor convenience). method mainAppWindow_t.onCreate; begin onCreate; // Initialize the showState data field: mov( false, this.showState ); // Install onClick handler for the graphic object: mov( (type mainAppWindow_t [esi]).roundRect1, esi ); (type wRoundRect_t [esi]).set_onClick( &onClick ); end onCreate; /////////////////////////////////////////////////////////////////////////////// // // // The following is mostly boilerplate code for all apps (about the only thing // you would change is the size of the main app's form) // // /////////////////////////////////////////////////////////////////////////////// // // When the main application window closes, we need to terminate the // application. This overridden method handles that situation. Notice the // override declaration for onClose in the wForm declaration given earlier. // Without that, mainAppWindow_t would default to using the wVisual_t.onClose // method (which does nothing). method mainAppWindow_t.onClose; begin onClose; // Tell the winmain main program that it's time to terminate. // Note that this message will (ultimately) cause the appTerminate // procedure to be called. w.PostQuitMessage( 0 ); end onClose; // When the application begins execution, the following procedure // is called. This procedure must create the main // application window in order to kick off the execution of the // GUI application: procedure appStart; begin appStart; push( esi ); // Create the main application window: mainAppWindow.create_mainAppWindow ( applicationName, // Window title w.WS_EX_CONTROLPARENT, // Need this to support TAB control selection w.WS_OVERLAPPEDWINDOW, // Style NULL, // No parent window formX, // x-coordinate for window. formY, // y-coordinate for window. formW, // Width formH, // Height howl.bkgColor_g, // Background color true // Make visible on creation ); mov( esi, pmainAppWindow ); // Save pointer to main window object. pop( esi ); end appStart; // appTerminate- // // Called when the application is quitting, giving the app a chance // to clean up after itself. // // Note that this is called *after* the mainAppWindow_t.onClose method // executes (indeed, mainAppWindow_t.onClose, by posting the quit message, // is what actually causes the program to begin terminating, which leads // to the execution of this procedure). procedure appTerminate; begin appTerminate; // Clean up the main application's form. // Note that this will recursively clean up all the widgets on the form. mainAppWindow.destroy(); end appTerminate; // appException- // // Gives the application the opportunity to clean up before // aborting when an unhandled exception comes along: procedure appException( theException:dword in eax ); begin appException; raise( eax ); end appException; // The main program for a HOWL application must simply // call the HowlMainApp procedure. begin graphics5; // Set up the background and transparent colors that the // form will use when registering the window_t class: w.GetSysColor( w.COLOR_MENU ); mov( eax, howl.bkgColor_g ); or( $FF00_0000, eax ); mov( eax, howl.transparent_g ); w.CreateSolidBrush( howl.bkgColor_g ); mov( eax, howl.bkgBrush_g ); HowlMainApp(); // Delete the brush we created earlier: w.DeleteObject( howl.bkgBrush_g ); end graphics5;