#include <Windows.h>
HINSTANCE g_hInstance;
HWND hChild, DengLu;
HWND hWndEdit;//这个变量接收编辑框的hwnd用来获取内容用的
//获取内容用getwindowtext比getdlgitemtext省事
LRESULT CALLBACK WndProc(HWND hWnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam);
LRESULT CALLBACK ChildProc(HWND hWnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam);
void RegisterWnd(LPCTSTR lpClassName,UINT Style,WNDPROC proc)
{
WNDCLASSEX wce;
wce.style = Style;
wce.lpfnWndProc = proc;
wce.cbSize = sizeof(WNDCLASSEX);
wce.cbClsExtra = 0;
wce.cbWndExtra = 0;
wce.hInstance = g_hInstance;
wce.hIcon = 0;
wce.hCursor = 0;
wce.hIconSm = 0;
wce.hbrBackground = HBRUSH(COLOR_BTNFACE + 1);
wce.lpszClassName = lpClassName;
wce.lpszMenuName = 0;
if(!RegisterClassEx(&wce))
{
MessageBox(NULL,TEXT("注册失败"),TEXT("提示"),MB_OK);
}
}
HWND CreateWnd(LPCTSTR lpClassName,LPCTSTR name,DWORD Style,HWND hParent)
{
HWND hWnd = CreateWindowEx(0,lpClassName,name,
Style,CW_USEDEFAULT,CW_USEDEFAULT,
CW_USEDEFAULT,CW_USEDEFAULT,hParent,NULL,g_hInstance,NULL);
return hWnd;
}
void DisplayWnd(HWND hWnd)
{
ShowWindow(hWnd,SW_SHOW);
UpdateWindow(hWnd);
}
void Message()
{
MSG msg;
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
g_hInstance = hInstance;
RegisterWnd(L"denglu",CS_HREDRAW|CS_VREDRAW,WndProc);
DengLu = CreateWnd(L"denglu",TEXT("登录"),WS_OVERLAPPED|WS_SYSMENU,NULL);
MoveWindow(DengLu,600,300,280,160,TRUE);
DisplayWnd(DengLu);
RegisterWnd(L"Child",CS_HREDRAW|CS_VREDRAW,ChildProc);
Message();
return 0;
}
LRESULT CALLBACK WndProc(HWND hWnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
switch(uMsg)
{
case WM_CREATE:
{
hWndEdit = CreateWindowExW(WS_EX_CLIENTEDGE,TEXT("EDIT"),TEXT("bbs.fishc.com"),
WS_CHILD|WS_VISIBLE,40,20,200,30,hWnd,HMENU(1001),g_hInstance,NULL);
CreateWindowEx(WS_EX_CLIENTEDGE,TEXT("BUTTON"),TEXT("登录"),
WS_CHILD|WS_VISIBLE,40,80,200,30,hWnd,HMENU(1002),g_hInstance,NULL);
ShowWindow(hWnd,SW_SHOW);
break;
}
case WM_COMMAND:
{
switch(wParam)
{
case 1002:
{
TCHAR szText[100];
GetWindowText(hWndEdit,szText,-1);
if(lstrcmp(szText,TEXT("bbs.fishc.com"))!=0)//输入和预置的不对应
return 0;//就返回
//正确就执行下面
MessageBox(NULL,TEXT("输入正确,可以登录"),TEXT("Go"),MB_OK|MB_ICONINFORMATION);
hChild = CreateWnd(L"Child",TEXT("窗口风格管理"),WS_OVERLAPPED|WS_SYSMENU,DengLu);
MoveWindow(hChild,500,300,500,300,TRUE);
DisplayWnd(hChild);
}
}
break;//你这里忘了写break
}
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWnd,uMsg,wParam,lParam);
}
LRESULT CALLBACK ChildProc(HWND hWnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
switch(uMsg)
{
case WM_MOUSEWHEEL:
{
RECT rc,rc1;//rc获得窗口相对于桌面的矩形 rc1要调整的矩形
GetWindowRect(hWnd,&rc);
rc1=rc;//调整用的矩形先弄的和窗口矩形一样大
if((int)wParam<0) //往下滚轮,让窗口扩大
{
rc1.right=rc.right-rc.left +10;
rc1.bottom=rc.bottom-rc.top+10;
}
else
{
rc1.right=rc.right-rc.left-10;
rc1.bottom=rc.bottom-rc.top-10;
}
MoveWindow(hWnd,rc1.left, rc1.top,rc1.right,rc1.bottom,TRUE);
break;
}
case WM_CREATE:
{
ShowWindow(DengLu,SW_HIDE);
break;
}
case WM_SYSCOMMAND:
{
switch(wParam)
{
case SC_CLOSE:
{
ShowWindow(DengLu,SW_SHOW);
break;
}
}
}
break;
}
return DefWindowProc(hWnd,uMsg,wParam,lParam);
}