Good afternoon.
A customer had the "shining idea...". To show to graphs right-handers in the screen of a program progress.
I made the following one:
1º I declared gdi as one procedure external:
.
PROCEDURE Rectangle EXTERNAL “GDI.dll” :
DEFINE INPUT PARAMETER nLeftRectx AS LONG .
DEFINE INPUT PARAMETER nLeftRect AS LONG .
DEFINE INPUT PARAMETER nTopRect AS LONG .
DEFINE INPUT PARAMETER nRightRect AS LONG .
DEFINE INPUT PARAMETER nBottomRect AS LONG .
END PROCEDURE.
PROCEDURE PAINT :
/*----------------------------------------------------
------------------------------------------------------ */
DEFINE VARIABLE hdc AS INTEGER NO-UNDO.
DEFINE VARIABLE Okay AS INTEGER NO-UNDO.
RUN GetDC IN h-prog (INPUT FRAME {&frame-name}:HWND,
OUTPUT hdc).
RUN Rectangle IN h-prog (hdc,
0,
0,
FRAME {&frame-name}:WIDTH-PIXELS,
FRAME {&frame-name}:HEIGHT-PIXELS,
OUTPUT Okay ).
RUN ReleaseDC IN h-prog (INPUT FRAME {&frame-name}:HWND,
INPUT hdc,
OUTPUT Okay).
END PROCEDURE.
Everything functioned that is a wonder, but ai comes the problem as I make to paint the rectangle, for example, red, therefore the objective is to create a bar chart in screen.
Or as to each action of ‘choose’ in the button to generate graphs it cleans the screen and it generates the graph again.
Debtor for the attention.
Re: help GDI
Hi Carlos,
So you figured out how to draw a rectangle, and now you want to know how to make a red rectangle.
Drawing with GDI is just like drawing with pen and paper: first you select a red pen, then you draw the rectangle, then you unselect the red pen (or select the default pen).
If there is no red pen, you first have to create one. Don't forget to delete everything you create. You cannot delete a pen when it is selected, that is why you have to unselect it after use.
The pen is only used to draw the border. If you want the entire rectangle filled with red (or some other color), then you also have to select a brush. Brushes are used to fill the space inside the border. The procedure is similar: create a brush, select the brush, draw, unselect the brush (by selecting a different brush) and delete the brush.
You do not always have to create pens and brushes, because Windows has a few "stock objects" like a simple black pen and a simple solid fill brush.
But, although this is fun, I would recommend to NOT try this in Progress. I would buy a chart ActiveX control, or write an ActiveX control myself. I would certainly not do any advanced GDI in Progress, because with Progress you don't get sufficient access to Windows messages.
At some point in the future you will need to scale, scroll, print to paper, add series, user-defined colors, you know how customers are: when you give them one candy they want the whole bag. So, don't go near charting, get an ActiveX control.
Bye,
Jurjen.
Help
Good afternoon. The problem is exactly the customer not to want to buy a component OCX. I will have that to not only paint the interior of retangulo and the contour. He would have an example in progress, to pass? My English forgives the errors is not very good. I am very grateful.
re: Help GDI
Example: put a frame on your window and give that frame the name "frame-bargraph".
Then run procedure DrawRandomBargraph.
PROCEDURE DrawRandomBargraph: DEFINE VARIABLE numBars AS INTEGER NO-UNDO. DEFINE VARIABLE barwidth AS INTEGER NO-UNDO. DEFINE VARIABLE iBar AS INTEGER NO-UNDO. DEFINE VARIABLE xBar AS INTEGER NO-UNDO. DEFINE VARIABLE BarValue AS INTEGER NO-UNDO. DEFINE VARIABLE BarMinValue AS INTEGER NO-UNDO. DEFINE VARIABLE BarMaxValue AS INTEGER NO-UNDO. DEFINE VARIABLE hdc AS INTEGER NO-UNDO. DEFINE VARIABLE okay AS INTEGER NO-UNDO. DEFINE VARIABLE barColor AS INTEGER NO-UNDO. DEFINE VARIABLE hPen AS INTEGER NO-UNDO. DEFINE VARIABLE hOldPen AS INTEGER NO-UNDO. DEFINE VARIABLE hBrush AS INTEGER NO-UNDO. DEFINE VARIABLE hOldBrush AS INTEGER NO-UNDO. /* erase the previous graph */ frame frame-bargraph:visible = no. frame frame-bargraph:visible = yes. /* decide how many bars to draw */ numBars = RANDOM (6, 12). barWidth = FRAME frame-bargraph:WIDTH-PIXELS / numBars. barMaxValue = FRAME frame-bargraph:HEIGHT-PIXELS * 0.9. barMinValue = barMaxValue / 3. RUN GetDC (INPUT frame frame-bargraph:HWND, OUTPUT hdc). DO iBar = 1 TO numBars : /* select a color */ barColor = RANDOM(1, 255 * 255 * 255). /* create a pen and a brush in that color */ RUN CreatePen(0,1,barColor, OUTPUT hPen). RUN CreateSolidBrush(barColor, OUTPUT hBrush). RUN SelectObject(hdc, hPen, OUTPUT hOldpen). RUN SelectObject(hdc, hBrush, OUTPUT hOldBrush). /* draw the bar */ barValue = RANDOM(barMinValue, barMaxValue). RUN RECTANGLE (hdc, xBar, FRAME frame-bargraph:HEIGHT-PIXELS - barValue, xBar + barWidth, FRAME frame-bargraph:HEIGHT-PIXELS). xBar = xBar + barWidth. /* unselect the new pen and brush, so you can delete them */ RUN SelectObject(hdc, hOldPen, OUTPUT hPen). RUN SelectObject(hdc, hOldBrush, OUTPUT hBrush). RUN DeleteObject (hPen, OUTPUT Okay). RUN DeleteObject (hBrush, OUTPUT Okay). END. RUN ReleaseDC (INPUT frame frame-bargraph:HWND, INPUT hdc, OUTPUT Okay). END PROCEDURE. PROCEDURE Rectangle EXTERNAL "GDI32.dll" : DEFINE INPUT PARAMETER hdc AS LONG. DEFINE INPUT PARAMETER nLeftRect AS LONG. DEFINE INPUT PARAMETER nTopRect AS LONG. DEFINE INPUT PARAMETER nRightRect AS LONG. DEFINE INPUT PARAMETER nBottomRect AS LONG. END PROCEDURE. PROCEDURE GetDC EXTERNAL "user32.dll": DEFINE INPUT PARAMETER hWnd AS LONG. DEFINE RETURN PARAMETER hdc AS LONG. END PROCEDURE. PROCEDURE ReleaseDC EXTERNAL "user32.dll" : DEFINE INPUT PARAMETER hWnd AS LONG. DEFINE INPUT PARAMETER hdc AS LONG. DEFINE RETURN PARAMETER ReturnValue AS LONG. END PROCEDURE. PROCEDURE CreatePen EXTERNAL "gdi32.dll" : DEFINE INPUT PARAMETER fnPenStyle AS LONG. DEFINE INPUT PARAMETER nWidth AS LONG. DEFINE INPUT PARAMETER crColor AS LONG. DEFINE RETURN PARAMETER hPen AS LONG. END PROCEDURE. PROCEDURE CreateSolidBrush EXTERNAL "gdi32.dll" : DEFINE INPUT PARAMETER crColor AS LONG. DEFINE RETURN PARAMETER hBrush AS LONG. END PROCEDURE. PROCEDURE SelectObject EXTERNAL "gdi32.dll" : DEFINE INPUT PARAMETER hdc AS LONG. DEFINE INPUT PARAMETER hgdiobj AS LONG. DEFINE RETURN PARAMETER ReturnValue AS LONG. END PROCEDURE. PROCEDURE DeleteObject EXTERNAL "gdi32.dll" : DEFINE INPUT PARAMETER hObject AS LONG. DEFINE RETURN PARAMETER ReturnValue AS LONG. END PROCEDURE.Good luck.
Help GDI
Good afternoon. The problem is exactly the customer not to want to buy a component OCX. I will have that to not only paint the interior of retangulo and the contour. He would have an example in progress, to pass? My English forgives the errors is not very good. I am very grateful.