Click to See Complete Forum and Search --> : API code for creating Edit & push button


Suresh.hc
December 1st, 2006, 02:10 AM
Hello everyone,

I have just started learning win32 API coding,
I have created a dialog window and with all the properties. I am very much confused how to add text field and push button can anyone help me how to do this.

Thanking you,
Suresh HC

NoHero
December 1st, 2006, 02:27 AM
If you created the dialog from a resource simply edit this resource and drag and drop your controls into it. If not, use CreateWindowEx() to create the specified control. Just specify "BUTTON" for a button or "EDIT" for a textbox the class name for the control, and add WS_CHLD.

I hope that puts you into the right direction.

Suresh.hc
December 1st, 2006, 04:21 AM
Hi NoHero,,

Thank you very much for the response.

I am not using the wizard feature for creating dialog and buttons.

I have to create all the things by win 32 API coding only

I got this example for creating button but its not working.

PUSHBUTTON "&Cancel",IDCANCEL,174,35,50,14


Can please help and give one example how to create a button using API coding.

ovidiucucu
December 1st, 2006, 06:33 AM
I have to create all the things by win 32 API coding only

I got this example for creating button but its not working.

PUSHBUTTON "&Cancel",IDCANCEL,174,35,50,14
Your example is a resource-definition statement from a resource-definition script (.RC) file and is not "win 32 API coding".

To avoid further shooting in the dark, please zip and attach your project here, otherwise we cannot even guess what you have done in the rest and what is "not working".

Suresh.hc
December 1st, 2006, 07:04 AM
Hi ovidiucucu,

Thank you very much for yr response.

Actually I got the code as example I did not try that code.

Can u please tell me how to create a button using API coding.
Can u please give an example hw to create a button using API code.


thanking you,
Suresh hc.

ovidiucucu
December 1st, 2006, 08:06 AM
Actually I got the code as example I did not try that code.
Who doesn't let you try?
Can u please tell me how to create a button using API coding.
NoHero already told you.
Can u please give an example hw to create a button using API code.
Just one example (using CreateWindowEx (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/windows/windowreference/windowfunctions/createwindowex.asp))
HWND hWndButton =
CreateWindowEx(WS_EX_LEFT, // extended style
"BUTTON", // class name (pre-defined class BUTTON)
"Babasafta", // window text (caption text)
WS_CHILD|WS_VISIBLE|WS_TABSTOP|BS_PUSHBUTTON, // style
5, 5, // x, y coordinates
77, 30, // width, height
hWndParent, // parent window handle
(HMENU)10000, // control ID
hInstance, // instance handle (ignored for NT/2000/XP).
NULL); // lParam
An easier way is to make a dialog resource template and add buttons, edits, and other controls (NoHero also told that), then based on that dialog resource create a dialog box (for example) by a call of DialogBox (http://msdn2.microsoft.com/en-us/library/ms645452.aspx).
Examples: HERE (http://www.codeguru.com/forum/showpost.php?p=1496259).

Last but not the least: buy a book able to teach you Windows programming basics.