牛骨文教育服务平台(让学习变的简单)
博文笔记

最简单的win32的窗口程序

创建时间:2016-05-08 投稿人: 浏览次数:1170
// win32004.cpp : Defines the entry point for the application.
//


#include "stdafx.h"




LRESULT CALLBACK WindowProc(  HWND hwnd,      // handle to window
UINT uMsg,      // message identifier
WPARAM wParam,  // first message parameter
  LPARAM lParam   // second message parameter
  
  )
{


switch (uMsg)
{
//窗口关闭
case WM_CLOSE:
{


PostQuitMessage(-1);
}


break;
}
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}


int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{


WNDCLASS swc={0};
swc.lpszClassName="mc";


swc.style=CS_HREDRAW|CS_VREDRAW;
swc.lpfnWndProc=WindowProc;



ATOM atom=RegisterClass(&swc);


//主窗口
HWND hmainwind=CreateWindow(
"mc",
"主窗口",
WS_OVERLAPPEDWINDOW|WS_VISIBLE,
300,
300,
400,
400,
NULL,
NULL,hInstance,NULL
);
ShowWindow(hmainwind,SW_SHOWNORMAL);
UpdateWindow(hmainwind);


    //获取消息
MSG msg={0};
while(GetMessage(&msg,0,0,0))
{
     
DispatchMessage(&msg);


}
return 0;
}





声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。