知了博客

集天地之精华,吸日月之灵气

« vc中error LNK2001:unresolved external symbol _WinMain@16的解决方法衷悼钱学森爷爷 »

第一个win32程序

#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;
}

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

日历

最新评论及回复

最近发表

Powered By Z-Blog 1.8 Arwen Build 90619 Code detection by Codefense  theme by BokeZhuti

Copyright know blog. Some Rights Reserved.站长(msn):webmaster#webgou.info(#换成@) 粤ICP备09183716号