在日常的学习、工作、生活中,肯定对各类范文都很熟悉吧。范文书写有哪些要求呢?我们怎样才能写好一篇范文呢?以下是小编为大家收集的优秀范文,欢迎大家分享阅读。
c语言怎么创建一个窗口篇一
耐得住寂寞,禁得起诱惑,这就是程序人生
步骤:
1.在winmain中定义各种变量
2.注册窗口类registerclass
3.创建窗口createwindow
4.显示窗口和更新窗口
复制代码 代码如下:
showwindow (hwnd, icmdshow) ;
updatewindow (hwnd) ;
5.消息循环
复制代码 代码如下:
while (getmessage (&msg, null, 0, 0))
{
translatemessage (&msg) ;
dispatchmessage (&msg) ;
}
完整代码:
复制代码 代码如下:
#include
lresult callback myproc(hwnd hwnd,uint message,wparam wparam,lparam lparam);
int winapi winmain(hinstance hinstance, hinstance hprevinstance, lpstr lpcmdline, int nshowcmd )
{
msg msg;
hwnd hwnd;
static tchar szappname[] = "hl";
wndclass wndclass;
= cs_hredraw | cs_vredraw;
xtra = 0;
xtra = 0;
dproc = myproc;
nce = hinstance;
= loadicon(null,idi_application);
r = loadcursor(null,idc_arrow);
kground= (hbrush)getstockobject(white_brush);
nuname = null;
assname= szappname;
if(!registerclass(&wndclass))
{
messagebox(null,text("error"),text("title"),mb_iconerror);
return 0;
}
hwnd = createwindow(szappname,
text("hello"),
ws_overlappedwindow,
cw_usedefault,
cw_usedefault,
cw_usedefault,
cw_usedefault,
null,
null,
hinstance,
null
);
showwindow(hwnd,nshowcmd);
updatewindow(hwnd);
while(getmessage(&msg,hwnd,0,0))
{
translatemessage(&msg);
dispatchmessage(&msg);
}
return ;
}
lresult callback myproc(hwnd hwnd,uint message,wparam wparam,lparam lparam)
{
switch(message)
{
case wm_destroy:
postquitmessage(0);
return 0;
}
return defwindowproc(hwnd,message,wparam,lparam);
}
s("content_relate");