I want to add a button to my window..
And here's the code i've tried..
#include <Windows.h>
#include <tchar.h>
LRESULT CALLBACK winproc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR cmdLine, int cmdShow)
{
TCHAR className[] = _T("button test");
WNDCLASS winclass;
winclass.cbClsExtra = 0;
winclass.cbWndExtra = 0;
winclass.hbrBackground = static_cast<HBRUSH>(GetStockObject(LTGRAY_BRUSH));
winclass.hCursor = LoadCursor(NULL, IDC_CROSS);
winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
winclass.hInstance = hInstance;
winclass.lpfnWndProc = winproc;
winclass.lpszClassName = className;
winclass.lpszMenuName = NULL;
winclass.style = CS_VREDRAW | CS_HREDRAW;
RegisterClass(&winclass);
HWND hWnd = CreateWindow(className, className,
WS_OVERLAPPEDWINDOW,
100, 100, 500, 500,
NULL, NULL, hInstance, NULL);
ShowWindow(hWnd, cmdShow);
MSG msg;
while (GetMessage(&msg, hWnd, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK winproc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
if (message == WM_CREATE)
{
HWND hWndButton = CreateWindow(TEXT("BUTTON"), TEXT("btn"),
WS_CHILD | WS_VISIBLE | BS_PUSHBOX,
10, 10, 100, 25,
hWnd, NULL, (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE), NULL);
}
if (message == WM_COMMAND)
{
MessageBox(hWnd, _T(""), _T(""), MB_OK);
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
and here's a screen shot of my window
[IMG]http://i61.tinypic.com/2gxelxi.png[/IMG]
http://i61.tinypic.com/2gxelxi.png[
^]
it doesn't even send WM_COMMAND when I click on it.. what's the wrong with my code ?
thanks in advance !