/
/
dllmain.cpp : 定义 DLL 应用程序的入口点。
BOOL
APIENTRY DllMain(HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break
;
}
return
TRUE;
}
extern
"C"
__declspec(dllexport) LRESULT CALLBACK MyWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static HWND hwndUsername, hwndPassword, hwndButton;
switch (message)
{
case WM_CREATE:
hwndUsername
=
CreateWindow(TEXT(
"edit"
), NULL,
WS_CHILD | WS_VISIBLE | WS_BORDER,
50
,
50
,
200
,
25
,
hwnd, (HMENU)
1
, NULL, NULL);
hwndPassword
=
CreateWindow(TEXT(
"edit"
), NULL,
WS_CHILD | WS_VISIBLE | WS_BORDER | ES_PASSWORD,
50
,
100
,
200
,
25
,
hwnd, (HMENU)
2
, NULL, NULL);
hwndButton
=
CreateWindow(TEXT(
"button"
), TEXT(
"OK"
),
WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON,
100
,
150
,
80
,
25
,
hwnd, (HMENU)
3
, NULL, NULL);
break
;
case WM_COMMAND:
if
(LOWORD(wParam)
=
=
3
)
{
TCHAR username[
20
], password[
20
];
GetWindowText(hwndUsername, username,
20
);
GetWindowText(hwndPassword, password,
20
);
if
(lstrcmp(password, TEXT(
"test"
)) !
=
0
) {
MessageBox(hwnd, TEXT(
"密码错误,退出程序!"
), TEXT(
"Error"
), MB_OK);
exit(
0
);
}
else
{
MessageBox(hwnd, TEXT(
"密码正确,继续你的游戏!"
), TEXT(
"Success"
), MB_OK);
SendMessage(hwnd, WM_CLOSE,
0
,
0
);
}
}
break
;
case WM_DESTROY:
exit(
0
);
break
;
case WM_CLOSE:
exit(
0
);
break
;
}
return
DefWindowProc(hwnd, message, wParam, lParam);
}
extern
"C"
__declspec(dllexport)
int
WINAPI MyCreateWindow(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine,
int
iCmdShow)
{
static TCHAR szAppName[]
=
TEXT(
"HelloWin"
);
HWND hwnd2;
WNDCLASS wndclass;
wndclass.style
=
CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc
=
MyWndProc;
wndclass.cbClsExtra
=
0
;
wndclass.cbWndExtra
=
0
;
wndclass.hInstance
=
hInstance;
wndclass.hIcon
=
LoadIcon(NULL, IDI_APPLICATION);
wndclass.hCursor
=
LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground
=
(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName
=
NULL;
wndclass.lpszClassName
=
szAppName;
if
(!RegisterClass(&wndclass))
{
MessageBox(NULL, TEXT(
"This program requires Windows NT!"
),
szAppName, MB_ICONERROR);
return
0
;
}
hwnd2
=
CreateWindow(szAppName,
/
/
window
class
name
TEXT(
"The Hello Program"
),
/
/
window caption
WS_OVERLAPPEDWINDOW,
/
/
window style
CW_USEDEFAULT,
/
/
initial x position
CW_USEDEFAULT,
/
/
initial y position
500
,
/
/
initial x size
300
,
/
/
initial y size
NULL,
/
/
parent window handle
NULL,
/
/
window menu handle
hInstance,
/
/
program instance handle
NULL);
/
/
creation parameters
ShowWindow(hwnd2, iCmdShow);
UpdateWindow(hwnd2);
}