15,979
社区成员
发帖
与我相关
我的任务
分享
#include <Windows.h>
#include <stdio.h>
LRESULT CALLBACK WinSunProc(
HWND hwnd, /*窗口句柄*/
UINT uMsg, /*信息标识*/
WPARAM wParam,
LPARAM lParam
);
int WINAPI WinMain(
HINSTANCE hInstance, /*当前实例句柄*/
HINSTANCE hPrevInstance, /*上一个实例句柄*/
LPSTR lpCmdLine, /*命令行*/
int nCmdShow /*显示状态*/
)
{
/*设计一个窗口类*/
WNDCLASS wndcle;
wndcle.cbClsExtra = 0;
wndcle.cbWndExtra = 0;
wndcle.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wndcle.hCursor = LoadCursor(NULL, IDC_CROSS);
wndcle.hIcon = LoadIcon(NULL, IDI_ERROR);
wndcle.hInstance = hInstance;
wndcle.lpfnWndProc = WinSunProc;
wndcle.lpszClassName = TEXT("lpl2018");
wndcle.lpszMenuName = NULL;
wndcle.style = CS_HREDRAW | CS_VREDRAW;
RegisterClass(&wndcle);
char pszErrMsg[128] = { 0 };
/*创建窗口,定义一个变量用来保存成功创建窗口后返回的句柄*/
HWND hwnd;
hwnd = CreateWindow(TEXT("LCK2018"), TEXT("http://www.baidu.com"), WS_OVERLAPPEDWINDOW, 0, 0, 600, 400, NULL, NULL, hInstance, NULL);
if (hwnd == NULL) {
snprintf(pszErrMsg,sizeof(pszErrMsg),TEXT("err[%d]"), GetLastError());
OutputDebugString(pszErrMsg);
MessageBox(NULL, "CreateWindow Err", "Error", 0);
}
/*显示及刷新窗口*/
ShowWindow(hwnd, SW_SHOWNORMAL);
UpdateWindow(hwnd);
/*定义消息结构体,开始消息循环*/
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
/*编写窗口过程函数*/
LRESULT CALLBACK WinSunProc(
HWND hwnd, /*窗口句柄*/
UINT uMsg, /*信息标识*/
WPARAM wParam,
LPARAM lParam
)
{
switch (uMsg)
{
case WM_CHAR:
char szChar[20];
sprintf_s(szChar, "char code is %d", wParam);
MessageBox(hwnd, szChar, TEXT("char"), 0);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd, "mouse clicked", "message", 0);
HDC hdc;
hdc = GetDC(hwnd); /*不能再相应WM_PAINT 消息时调用*/
TextOut(hdc, 0, 50, TEXT("LOL HOME"), strlen("LOL HOME"));
/*ReleaseDC(hwnd,hdc);*/
break;
case WM_PAINT:
HDC hDc;
PAINTSTRUCT ps;
hDc = BeginPaint(hwnd, &ps); /* BeginPaint 只能在响应 WM_PAINT 消息时调用*/
TextOut(hDc, 0, 0, "http://www.csdn.com", strlen("http://www.csdn.com"));
EndPaint(hwnd, &ps);
break;
case WM_CLOSE:
if (IDYES == MessageBox(hwnd, "Is End?", "message", MB_YESNO))
{
DestroyWindow(hwnd);
}
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
return 0;
}
wndcle.lpszClassName = TEXT("lpl2018");
hwnd = CreateWindow(TEXT("LCK2018"), TEXT("http://www.baidu.com"), WS_OVERLAPPEDWINDOW, 0, 0, 600, 400, NULL, NULL, hInstance, NULL);