// 16.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
LRESULT CALLBACK WindowProc (HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam);
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
char szOutBuff[0x80];
//1.定义窗口
TCHAR className[] = TEXT("第一个应用程序");
WNDCLASS wndclass = {0};
wndclass.hbrBackground = (HBRUSH)COLOR_BACKGROUND;
wndclass.lpszClassName = className ;
wndclass.hInstance = hInstance;
wndclass.lpfnWndProc = WindowProc;
RegisterClass(&wndclass);
//2.创建并显示窗口
HWND hwnd = CreateWindow(
className,
TEXT("我的第一个窗口"),
WS_OVERLAPPEDWINDOW,
100,
100,
600,
300,
NULL,
NULL,
hInstance,
NULL
);
if (hwnd == NULL)
{
sprintf(szOutBuff," %x \n",GetLastError());
OutputDebugString(szOutBuff);
return 0;
}
ShowWindow(hwnd,SW_SHOW);
MSG msg;
BOOL bRet;
while ((bRet = GetMessage(&msg,0,0,0)) != 0)
{
if (bRet == -1)
{
sprintf(szOutBuff," %x \n",GetLastError());
OutputDebugString(szOutBuff);
return 0;
}
else
{
//TranslateMessage(&msg);//转换消息
DispatchMessage(&msg);//分发消息
}
}
return 0;
}
LRESULT CALLBACK WindowProc (HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
网友评论