The syntax of CreateWindowEx() function is:
There are 7 parameters out of 12 which are important to us. Remaining can be set to NULL as shown in following examples.
How to create a Button
How to create Static(Label) control
How to Create Edit control
Similarly you can create other controls by giving thier predefined class names as second parameter.
As I told first, there are some expections in creating some controls like ProgressBar and ComboBox.To Create a progress bar you must add "ComCtl32.Lib" to your project. If you are using VC++, you can do it by adding following line:
After adding ComCtl32.Lib, you should Initiate it like this.
Now you can create ProgressBar using CreateWindowEx() function.
When creating ComboBox, note that height must be greater than 50. Else it won't show dropdown list.
Handling Events, Setting States, and Reading Values.
As we know that WndProc function recieves different messages, these include Events from control items like button, Editbox, combobox, etc. the WndProc function recieves WM_COMMAND message, when control item events are occured. The information about these events can be obtained from WPARAM and LPARAM parameters, by performing bit shifting operations like HIWORD() and LOWORD(). extracting information about events is not same for all events. therefore you have to refer MSDN to know about them.
We can set States of control items by using SendMessage() function. This is reciprocal to the method of handling events.
There we get messages and process them, here we are sending messages. The Syntax of SendMessage() function is:
First Parameter(HWND) is the handle to the control to which we are sending message.
Second Parameter(UINT) is the message to be sent. and WPARAM and LPARAM should contain Additional Informations.
An Example of Setting ProgressBar's Progress is shown below:
This will set it's progress to 50% complete state. You can find out more messages in commctrl.h header file, or at MSDN.
To read values from control items like Edit, Combo, etc. you can use SendMessage(), GetDlgItemText(), GetDlgItemInt() etc functions. commonly the Message to be sent is WM_GETTEXT. Here is an example:
In the above example Third parameter of SendMessage() indicates the size of data to be read, and last param is the variable that holds the data.
this is the one which i was searching for.. Thanks a lot dude..
ReplyDelete