LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId;
switch (message)
{
[COLOR=DarkRed]case WM_COMMAND:
wmId = LOWORD(wParam);
if (wmId == 1)
MessageBox (hWnd, TEXT("Clicked"), TEXT("You Clicked!"), MB_OK);[/COLOR]
break;
[COLOR=Blue]case WM_CREATE:
CreateWindow (TEXT ("BUTTON"), TEXT ("Click Me!"), WS_CHILD | WS_VISIBLE, 60, 80, 60, 20, hWnd, (HMENU) 1, NULL, NULL);[/COLOR]
break;
//--------further code------
The
blue code creates a button. Note that a button is also a window. The code given by Vishnu priya also creates a button and is similar to the blue code above. Notice the 'third last' parameter passed to the CreateWindow function, it is the ID passed in the WM_COMMAND message when the button is clicked. We created the button when our window receives a WM_CREATE message (this msg is received when the window is created)
The
brown code is the handler for button click. The ID is always present in the LOWORD of wParam. So check the Id (using if-else or switch-case) and do required tasks. Hence we have done this coding under case WM_COMMAND which our main window receives when the button is clicked.
Note that the above code is just a snippet of Window Procedure. If you are familiar with basic windows programming, then you may understand what I said.