Questions about using the WinAPI with ABL (and .NET, Excel)

Posted by Haikarainen on 27-Apr-2012 03:42

Now this is an ugly fix, I know, but there is no other way to do it afaik. I have an excel window wich I have successfully embedded into a WinForms application (in architect), by creating an instance of Microsoft.Office.Interop.Excel.Application, and then using the Windows API to set the parent of the window to the appropriate panel using SetParent, as well as removing borders, titlebar etc with SetWindowLong.

I had to do a lot of tampering to get this to work (especially with the SetWindowLong), but I finally did and it seemed stable! I am generating an overview of data in the excelobject several times per usersession, but this generation was really really slow so I decided to optimize it a bit.

What I had done was to recreate the excel object each time I regenerated the sheet, ( involving killing and creating a new window, setting these parameters every time, as well as loading a template file every time) , wich caused the slow performance and generationtimes. So what I'm now doing instead is;

At startup: Create excelobject, set window parameters, load template file

At generation: Remove all sheets except for template, copy templatesheet to new sheet(WorkingSheet), set WorkingSheet as active and generate data on it.

It now generates really fast, but it has become VERY unstable. I think it has to do with how I set the window parameters with SetWindowLong, The borders and titlebar sometimes comes back after a generation, sometimes the window becomes hidden, sometimes the window refuses to take input, every time I regenerate the data I get new random results on the window parameters. I tried to fix this by calling SetWindowLong with the same integer(long) as it created when I first set it (to just reset the GWL_STYLE as it was when I first fixed it), but this seemed to make it more unstable.

Thing is, I'm not sure I'm doing this the right way, in other languages, you do it something like this:

LONG lStyle = GetWindowLong(hwnd, GWL_STYLE);
lStyle
&= ~(WS_CAPTION | WS_THICKFRAME | WS_MINIMIZE | WS_MAXIMIZE | WS_SYSMENU);
SetWindowLong(hwnd, GWL_STYLE, lStyle);

See the &, | and ~ operators? How do I correctly translate this behaviour to ABL? Right now I'm doing this (Wich i think is VERY wrong):

DEFINE VARIABLE style AS INTEGER NO-UNDO.

RUN GetWindowLongA IN WinApi(INPUT THIS-OBJECT:ExcelAppHandle:Hwnd, {&GWL_STYLE}, OUTPUT style).
style = style - {&WS_CAPTION} - {&WS_THICKFRAME} - {&WS_BORDER} - {&WS_MAXIMIZEBOX} - {&WS_MINIMIZEBOX}.
RUN SetWindowLongA IN WinApi (INPUT THIS-OBJECT:ExcelAppHandle:Hwnd, INPUT {&GWL_STYLE}, INPUT style, OUTPUT oldhWnd).

This worked when I recreated the excel object everytime I regenerated data(with some flicker, if I hid the window while I was doing it it would be just as unstable as it is now), but now it just will not work.

Any help is greatly appreciated! Even if it means I'd have to recreate my excelcontrol from scratch!

Thanks in advance

PS. I have also tried to create the winapi functions in visual studio, then create a reference assembly from that and use those functions, but its basically the same results

All Replies

Posted by jquerijero on 30-Apr-2012 10:04

~ = Progress.Util.EnumHelper:Complement()

& = Progress.Util.EnumHelper:And()

| =Progress.Util.EnumHelper:Or()

This thread is closed