#include "Windows.h"
LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstatnce, LPSTR lpstrCmdLine, int nCmdShow = SW_SHOW)
{
MSG msg;
WNDCLASS ws;
ws.style = 0;
ws.lpfnWndProc = (WNDPROC)MainWndProc;
ws.cbClsExtra = 0;
ws.cbWndExtra = 0;
ws.hInstance = hInstance;
ws.hIcon = LoadIcon(NULL, IDI_APPLICATION);
ws.hCursor = LoadIcon(NULL, IDC_ARROW);
ws.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
ws.lpszClassName = L"my";
ws.lpszMenuName = NULL;
if(!RegisterClass(&ws))
return FALSE;
HWND hWndMain;
hWndMain = CreateWindow(
L"my",
L"显示window",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL
);
if(!hWndMain)
return FALSE;
ShowWindow(hWndMain,nCmdShow);
while(GetMessage(&msg, NULL, 0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK MainWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
static HDC hDc;
static LPPAINTSTRUCT pt;
HICON ghIcon = NULL;
HBITMAP ghbmMask = NULL;
HBITMAP ghbmColor = NULL;
RECT rt ={0,0,100,20};
static HDC dc;
HPEN hPen;
static int i = -10;
switch (uMsg)
{
case WM_PAINT:
PAINTSTRUCT ps;
HDC hdc;
COLORREF crTxt, crBk;
hDc = BeginPaint(hWnd, &ps);
EndPaint(hWnd, &ps);
break;
case WM_ERASEBKGND:
dc = ::GetDC(hWnd);
::FillRect(dc,&rt,(HBRUSH)::GetStockObject(BLACK_BRUSH));
::DrawText(dc,L"文字显示 ", -1, &rt, DT_VCENTER|DT_CENTER);
::ReleaseDC(hWnd,dc);
break;
case WM_LBUTTONDOWN:
i += 10;
rt.top += 3*i;
rt.bottom = rt.top + 20;
hPen=CreatePen(PS_INSIDEFRAME,1,RGB(0,255,255));
dc = ::GetDC(hWnd);
SelectObject(dc,hPen);
::DrawText(dc,L"文字显示 ", -1, &rt, DT_VCENTER|DT_CENTER);
MoveToEx(dc,0,i, NULL);
LineTo(dc,800,i);
::ReleaseDC(hWnd,dc);
//MessageBox(NULL,L"OK",NULL,NULL);
break;
case WM_RBUTTONDOWN:
//MessageBox(NULL,L"right OK",NULL,NULL);
break;
case WM_DESTROY:
PostQuitMessage(0);break;
default:
return (DefWindowProc(hWnd, uMsg, wParam, lParam));
}
return 0;
}