Creating a button at runtime?

Discussion forum about all things Team Developer 5.x and 6.x
TPo

Creating a button at runtime?

Post by TPo » 02 Jan 2008, 13:05

Hi!

Since we cannot use user32.dll functions anymore at TD 5.1 , how we can create a button at runtime...

Here's an old sample where CreateWindowExA was used to create a button control to datafield (originally from ComboDF.apt by Jörg Ellinghaus).
This works fine at TD 3.1 but not at all at TD 5.1.

***********************************************
Function: _CreateButtonControl
Description: Creates the button control.
Returns
Parameters
Static Variables
Local variables
Number: nL
Number: nT
Number: nB
Number: nR
Actions
!
! //-- get the size in pixels --//
Call GetWindowRect( iv_hWndSelf, nL, nT, nR, nB )
Call ScreenToClient( SalParentWindow( iv_hWndSelf ), nL, nT )
Call ScreenToClient( SalParentWindow( iv_hWndSelf ), nR, nB )
!
! //-- create control --//
Set iv_hWndControl = CreateWindowExA( 0,
"Button",
STRING_Null,
WS_VISIBLE | WS_CHILD,
nR - nL - 21,
0,
16,
nB - nT - 7,
iv_hWndSelf,
0,
GetWindowLongA( SalParentWindow( iv_hWndSelf ),
GWL_HINSTANCE ),
0 )
!
! //-- set the margins of the edit field, so that the text will not override the button --//
Call SalSendMsg( iv_hWndSelf, EM_SETMARGINS, 0x0001 | 0x0002, VisNumberMakeLong( 0, 16 ) )
!
! //-- set the pushbutton text --//
Call SetWindowTextA( iv_hWndControl, "..." )
!

***************


So if there's a way to do this with TD 5.1 (Vis* functions ? ), please let me know!

Thank's in advance...


Cheers,

Teuvo

Jean-Marc Gemperle

Re: Creating a button at runtime?

Post by Jean-Marc Gemperle » 11 Jan 2008, 17:42

Hi Teuvo,

From the the MSDN the second last parameter HINSTANCE hInstance, of CreateWindowEx() is ignored : "for Windows NT/2000: This value is ignored."
You are using for this parameter the result of GetWindowLongA( SalParentWindow( iv_hWndSelf ), GWL_HINSTANCE ).

So I've set this parameter to 0 and now the button get created in TD 5.1. It is odd this value should be ignored but for some reason it is not and even more odd that with TD 4.2 this does not cause a problem...I did not look what is the results of it in TD 4.2 and TD 5.1... Anyway you can create dynamic buttons basically CreateWindowEx() seems to work.

I have a question though maybe stupid, but how then are you getting the events of the button then ? What are you doing with it?

Also to ANYONE ELSE that might know: I though one could CHANGE DYNAMICALLY THE CLASS OF A CONTROL...I must have dream...I don't see a way to do that : ie SalCreateWindowEx() then changing the class dynamically to be a BUTTON, I can always dream :-)
Since we cannot use user32.dll functions anymore at TD 5.1
For me this statment is over stated, there are many function that should work, we do know we have problem with menu, also keep in mind that the windows hierachy has changed and explain why certain call no longer works or behaves differently. Using SPY helps in figuring out what is going on.


Cheers
Jean-Marc
You do not have the required permissions to view the files attached to this post.

cschubert
Germany
Posts: 867
Joined: 23 May 2018, 11:26
Location: Germany

Re: Creating a button at runtime?

Post by cschubert » 11 Jan 2008, 19:22

how then are you getting the events of the button then ? What are you doing with it?
-> Subclasser 8)

http://www.cschubert.net/html/subclasser.html

TPo

Re: Creating a button at runtime?

Post by TPo » 14 Jan 2008, 10:47

Thanks, Jean-Marc! Now it works....

It's is easy when you know what to do.... :)

Teuvo

Jean-Marc Gemperle

Re: Creating a button at runtime?

Post by Jean-Marc Gemperle » 15 Jan 2008, 15:27

Hi Teuvo and Christian,

Glad it works for you now.

Christian, thanks for your sample, can I post it to the sample forum? I knew about subclassing :-) and have done sometimes ago a sample using a C++ MFC DLL using subclassing that works fine. It is just that I was confused at the moment I repply to Teuvo cause I searched the internet, I know about SetClassWord and also wrongly found some reference to SetClassName that as nothing to do with it, but got me confused... Anyway I can subclass fine in TD 5.1, but there are other ways to do that if I'm correct. I did sometimes ago also a sample were I want to register window messages. This sample works fine with TD 4.2 but does not with TD 5., instead of sublassing I use a hook... and this cause me problem in TD 5.1 :

void __declspec(dllexport) Hook( HWND myHandle, unsigned int SalMsg)
{
OldProc = SetWindowLong (myHandle, GWL_WNDPROC,(LONG)HookProc );
MyMsgID=RegisterWindowMessage("WM_MyMessage");
SalMsgID=SalMsg;
SalWhndl=myHandle;

}

It does not crash in the DLL, not in the call to SetWindowLong () nor in RegisterWindowMessage() but does in TD in the rerturn....

See attached if you want to have a look at it, again this works fine with TD 4.2:-) I could anyway subclass I believe to use RegisterWindowMessage(), I wanted to put a sample for that for TD 5.1

Cheers
JM
You do not have the required permissions to view the files attached to this post.

cschubert
Germany
Posts: 867
Joined: 23 May 2018, 11:26
Location: Germany

Re: Creating a button at runtime?

Post by cschubert » 16 Jan 2008, 12:29

Hi Jean-Marc,

I don't know what the problem is with your app (just had a quick look) but "Subclasser" also works with TD 5.1. In fact it is not dependent of TD libraries at all, so the "RegisterWindowMessage" sample works, too. Feel free to post it to the samples forum. This also applies to any of my samples...

Regards,

Christian Schubert

Return to “General Discussion”

Who is online

Users browsing this forum: [Applebot], [Ccbot] and 0 guests