这是在vs2010 中的一个窗口 编译没问题 ,程序在运行,但窗口没出现!!
#include <Windows.h>#include <stdio.h>
#include <tchar.h>
//#include "ATLCONV.H "
//#include <atlbase.h>
//#include <atlconv.h>
LRESULT CALLBACK WinProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPreInstance,LPSTR lpCmdLine,int nShowCmd)
{
WNDCLASS wndcls;
wndcls.cbClsExtra=0;
wndcls.cbWndExtra=0;
wndcls.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
wndcls.hCursor=LoadCursor(NULL,IDC_ARROW);
wndcls.hInstance=hInstance;
wndcls.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndcls.lpfnWndProc=WinProc;
wndcls.lpszClassName=_T("TEXT");
wndcls.lpszMenuName=NULL;
wndcls.style=CS_HREDRAW | CS_VREDRAW;
RegisterClass(&wndcls);
HWND hwnd;
hwnd=CreateWindow(_T("TEXT"),_T("TEXT"),WS_OVERLAPPEDWINDOW,0,0,600,400,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,SW_NORMAL);
UpdateWindow(hwnd);
MSG umsg;
while(GetMessage(&umsg,NULL,0,0))
{
TranslateMessage(&umsg);
DispatchMessage(&umsg);
}
return 0;
}
LRESULT CALLBACK WinProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lParam)
{
switch(umsg)
{
case WM_CHAR:
TCHAR szchar[20];
_stprintf(szchar,_T("char is %d"),wParam);
MessageBox(hwnd,szchar,_T("TEXT"),0);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,_T("mouse clicked!"),_T("TEXT"),0);
HDC hDc;
hDc=GetDC(hwnd);
TextOut(hDc,0,50,_T("This is my place "),wcslen(_T("This is my place ")));
ReleaseDC(hwnd,hDc);
break;
case WM_PAINT:
HDC hdc;
PAINTSTRUCT ps;
hdc=BeginPaint(hwnd,&ps);
TextOut(hdc,0,0,_T("I should stand up the place always "),wcslen(_T("I should stand up the place always ")));
EndPaint(hwnd,&ps);
break;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,_T("Are you sure close this window ?"),_T("TEXT"),MB_YESNO))
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
defalt:
return DefWindowProc(hwnd,umsg,wParam,lParam);
}
return 0;
}