Code:
#include <windows.h> //include all the basics
#include <tchar.h> //string and other mapping macros
#include <string>
//=============================================================================
//message processing function declarations
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
HWND button;
HWND Button2;
//=============================================================================
int WINAPI WinMain(HINSTANCE hInst,HINSTANCE,LPSTR pStr,int nCmd)
{
LPCTSTR classname = "Window";
WNDCLASSEX wcx={0};
wcx.cbSize = sizeof(WNDCLASSEX);
wcx.lpfnWndProc = WndProc;
wcx.hInstance = hInst;
wcx.hIcon = reinterpret_cast<HICON>(LoadImage(0,IDI_APPLICATION,
IMAGE_ICON,0,0,LR_SHARED));
wcx.hCursor = reinterpret_cast<HCURSOR>(LoadImage(0,IDC_ARROW,
IMAGE_CURSOR,0,0,LR_SHARED));
wcx.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_BTNFACE+1);
wcx.lpszClassName = classname;
wcx.style = CS_HREDRAW | CS_VREDRAW;
if (!RegisterClassEx(&wcx))
{
MessageBox(NULL,"Register failed.","",MB_OK);
return -1;
}
int desktopwidth=GetSystemMetrics(SM_CXSCREEN);
int desktopheight=GetSystemMetrics(SM_CYSCREEN);
HWND hwnd=CreateWindowEx(0, //extended styles
classname, //name: wnd 'class'
_T("ButtonProg"), //wnd title
WS_OVERLAPPEDWINDOW, //wnd style
desktopwidth/4, //position:left
desktopheight/4, //position: top
desktopwidth/2, //width
desktopheight/2, //height
0, //parent wnd handle
0, //menu handle/wnd id
hInst, //app instance
0); //user defined info
if (!hwnd)
{
MessageBox(NULL,"Wnd failed.","",MB_OK);
return -1;
}
button = CreateWindowEx(0,
"button",
"MessageBox",
WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,
20,
40,
100,
20,
hwnd,
NULL,
hInst,
NULL);
Button2 = CreateWindowEx(0,
"Button2",
"Button2",
WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,
20,
80,
200,
20,
hwnd,
NULL,
hInst,
NULL);
DWORD Error = GetLastError();
char ErrorBuffer[1024];
wsprintf(ErrorBuffer, "Error creating. Error Code %d, Hex: %X.", Error, Error);
MessageBox(NULL,ErrorBuffer,"",MB_OK);
if(!radioButton){MessageBox(NULL,"radio failed.","",MB_OK);}
ShowWindow(hwnd,nCmd);
UpdateWindow(hwnd);
MSG msg;
while (GetMessage(&msg,0,0,0)>0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return static_cast<int>(msg.wParam);
}
//=============================================================================
LRESULT CALLBACK WndProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
HWND hWndCtl = (HWND)lParam;
switch (uMsg)
{
case WM_COMMAND:
switch(wParam){
case BN_CLICKED:
if(hWndCtl == button){
MessageBox(NULL,"MsgBox","",MB_OK);
}
break;
}
break;
case WM_CREATE:
break;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
}
//=============================================================================