首页 > 编程地带 > 建立第一个可视化程序

建立第一个可视化程序

2007年12月22日 发表评论 阅读评论

前几天买了本书,花了很多的生活费,,伤死了。。
写了第一个可视化的程序:
建立一个窗口要四步:
1、WinMin的建立。
2、创建一个窗口。
3、进行消息循环。
4、编写窗口过程函数。

<br />#include <windows.h><br />#include <stdio.h><br /><br />LRESULT CALLBACK WinSunProc(<br />  HWND hwnd,      // handle to window<br />  UINT uMsg,      // message identifier<br />  WPARAM wParam,  // first message parameter<br />  LPARAM lParam   // second message parameter<br />);<br /><br />int WINAPI WinMain(                                                 //主函数定义<br />  HINSTANCE hInstance,      // handle to current instance<br />  HINSTANCE hPrevInstance,  // handle to previous instance<br />  LPSTR lpCmdLine,          // command line<br />  int nCmdShow              // show state<br />)<br />{<br />  //创建一个窗口类<br />  WNDCLASS wndcls,WOYIGUI;<br />  wndcls.cbClsExtra=0;<br />  wndcls.cbWndExtra=0;<br />  wndcls.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);<br />  wndcls.hCursor=LoadCursor(NULL,IDC_CROSS);<br />  wndcls.hIcon=LoadIcon(NULL,IDI_ERROR);<br />  wndcls.hInstance=hInstance;<br />  wndcls.lpfnWndProc=WinSunProc;<br />  wndcls.lpszClassName="woyigui2007";<br />  wndcls.lpszMenuName=NULL;<br />  wndcls.style=CS_HREDRAW &#124; CS_VREDRAW;<br /><br />  //WOYIGUI定义<br />  WOYIGUI.cbClsExtra  = 0;<br />  WOYIGUI.cbWndExtra = 0;<br />  WOYIGUI.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);<br />  WOYIGUI.hCursor = LoadCursor(NULL,IDC_CROSS);<br />  WOYIGUI.hIcon = LoadIcon(NULL,IDI_ERROR);<br />  WOYIGUI.hInstance=hInstance;<br />  WOYIGUI.lpfnWndProc=WinSunProc;<br />  WOYIGUI.lpszClassName="woyigui";<br />  WOYIGUI.lpszMenuName=NULL;<br />  WOYIGUI.style=CS_HREDRAW &#124; CS_VREDRAW;<br />  <br />  RegisterClass(&wndcls);            //注册窗口<br />  RegisterClass(&WOYIGUI);<br /><br />  //创建窗口,定义一个变量用来保存成功创建窗口后返回的句柄<br />  HWND hwnd,hwnd1;<br />  hwnd=CreateWindow("woyigui2007","非常批处理专用版         by woyigui",WS_OVERLAPPEDWINDOW,<br />    400,0,600,600,NULL,NULL,hInstance,NULL);<br />  hwnd1=CreateWindow("woyigui","第二个测试。。。              by woyigui",WS_OVERLAPPEDWINDOW,<br />    400,500,600,600,NULL,NULL,hInstance,NULL);<br /><br />  //显示刷新窗口<br />  ShowWindow(hwnd,SW_SHOWNORMAL);<br />  ShowWindow(hwnd1,SW_SHOWNORMAL);<br />  UpdateWindow(hwnd1);<br />  UpdateWindow(hwnd);<br /><br />  //定义消息结构体,开始消息循环<br />  MSG msg;<br />  while(GetMessage(&msg,NULL,0,0))<br />  {<br />    TranslateMessage(&msg);<br />    DispatchMessage(&msg);<br />  }<br />  return msg.wParam;<br />}<br /><br />//编写 woyigui窗口过程函数<br />LRESULT CALLBACK WinSunProc1(<br />  HWND WOYIGUI,<br />  UINT uMsg,<br />  WPARAM wParam,<br />  LPARAM lParam<br />  )<br />{<br />  switch(uMsg)<br />  {<br />  case WM_CHAR:<br />    CHAR szChar&#91;20&#93;;<br />    sprintf(szChar,"按下的字符为:",wParam);<br />    MessageBox(WOYIGUI,szChar,"字符为:",0);<br />    break;<br />  case WM_LBUTTONDOWN:<br />    MessageBox(WOYIGUI,"哈哈,点的是第二个窗口,","haha",0);<br />    HDC hdc1;<br />    hdc1=GetDC(WOYIGUI);<br />    TextOut(hdc1,500,500,"woyigui &#039;s blog",strlen("woyigui&#039;s blog"));<br />    ReleaseDC(WOYIGUI,hdc1);<br />    break;<br />  case WM_PAINT:<br />    HDC hDC;<br />    PAINTSTRUCT PT;<br />    hDC=BeginPaint(WOYIGUI,&PT);<br />    TextOut(hDC,0,0,"woyigui &#039;s blog",strlen("http://www.woyigui.cn"));<br />    EndPaint(WOYIGUI,&PT);<br />    break;<br />  case WM_CLOSE:    <br />    if(IDYES==MessageBox(WOYIGUI,"您真的想退出吗?","message",MB_YESNO))<br />    {<br />      DestroyWindow(WOYIGUI);<br />    }<br />    break;<br />  case WM_DESTROY:<br />    PostQuitMessage(0);<br />    break;<br />  default:<br />    return DefWindowProc(WOYIGUI,uMsg,wParam,lParam);<br />  }<br />  return 0;<br />}<br /><br /><br />//编写窗口过程函数<br />LRESULT CALLBACK WinSunProc(<br />  HWND hwnd,      // handle to window<br />  UINT uMsg,      // message identifier<br />  WPARAM wParam,  // first message parameter<br />  LPARAM lParam   // second message parameter<br />)<br />{<br />  switch(uMsg)<br />  {<br />  case WM_CHAR:<br />    char szChar&#91;20&#93;;<br />    sprintf(szChar,"char code is %d",wParam);<br />    MessageBox(hwnd,szChar,"char",0);<br />    break;<br />  case WM_RBUTTONDOWN:<br />    MessageBox(hwnd,"点了一上。。。","提示!",256);<br />    HDC hdc;<br />    hdc=GetDC(hwnd);<br />    TextOut(hdc,200,200,"非常批处理交流论坛",strlen("非常批处理交流论坛"));<br />    TextOut(hdc,200,300,"http://www.verybat.cn",strlen("http://www.verybat.cn"));<br />    ReleaseDC(hwnd,hdc);<br />    break;<br />  case WM_PAINT:<br />    HDC hDC;<br />    PAINTSTRUCT ps;<br />    hDC=BeginPaint(hwnd,&ps);<br />    TextOut(hDC,0,0,"http://www.verybat.cn",strlen("http://www.verybat.cn"));<br />    EndPaint(hwnd,&ps);<br />    break;<br />  case WM_CLOSE:<br />    if(IDYES==MessageBox(hwnd,"您真的想退出吗?","message",MB_YESNO))<br />    {<br />      DestroyWindow(hwnd);<br />    }<br />    break;<br />  case WM_DESTROY:<br />    PostQuitMessage(0);<br />    break;<br />  default:<br />    return DefWindowProc(hwnd,uMsg,wParam,lParam);<br />  }<br />  return 0;<br />}

转载请注明:woyigui's blog [http://www.woyigui.cn/]
本文标题:建立第一个可视化程序
本文地址:http://www.woyigui.cn/2007/12/22/%E5%BB%BA%E7%AB%8B%E7%AC%AC%E4%B8%80%E4%B8%AA%E5%8F%AF%E8%A7%86%E5%8C%96%E7%A8%8B%E5%BA%8F/

分类: 编程地带 标签: ,
  1. 本文目前尚无任何评论.
  1. 本文目前尚无任何 trackbacks 和 pingbacks.
*