调用WINAPI 创建一个窗口并显示一些东西(create a window and display something)
2012-01-31 22:49
316 查看
#include <windows.h> LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM); int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { static TCHAR szAppName[] = TEXT ("HelloWin") ; HWND hwnd ; //窗口句柄 MSG msg; //消息结构 WNDCLASS wndclass ; //窗口类别结构 wndclass.style = CS_HREDRAW | CS_VREDRAW ; //设置窗体风格 wndclass.lpfnWndProc = WndProc ; //指定窗口消息处理程序 wndclass.cbClsExtra = 0 ; // wndclass.cbWndExtra = 0 ; wndclass.hInstance = hInstance ; //执行实体句柄 wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;//加载图标 wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;//加载鼠标图标 wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ; //设置窗口背景(颜色) wndclass.lpszMenuName = NULL ; //窗体菜单名 wndclass.lpszClassName = szAppName ; //窗体名 if (!RegisterClass (&wndclass)) //登记窗体 { MessageBox ( NULL, TEXT ("This program requires Windows NT!"), szAppName, MB_ICONERROR) ; return 0 ; } hwnd = CreateWindow( szAppName,//windows classname TEXT ("The Hello Progame"), //window caption WS_OVERLAPPEDWINDOW, //window style CW_USEDEFAULT, //inital x position CW_USEDEFAULT, //inital y position CW_USEDEFAULT, //inital x size CW_USEDEFAULT, //inital y size NULL, //parent windows hadle NULL, //windows menu handle hInstance, //program instance handle NULL) ; //creation paramenters ShowWindow(hwnd, iCmdShow) ; //show the window UpdateWindow(hwnd) ; //Update window itself while (GetMessage (&msg, NULL, 0, 0)) //Get a Message from window's message manage { TranslateMessage (&msg) ; //Translate some message from keyboard D 4000 ispatchMessage (&msg) ; //Send massage to massage process program } return msg.wParam; } LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc; //device contest handle PAINTSTRUCT ps; //print struct RECT rect ; //rect struct switch(message) { case WM_CREATE: //if the window create,this function will accept this massage //(WM_CREATE) //PlaySound (TEXT ("hellowin.wav"), NULL, SND_FILENAME | SND_ASYNC) ; return 0; case WM_PAINT: //window redraw hdc = BeginPaint (hwnd, &ps) ; //begin paint window GetClientRect (hwnd, &rect); //get rect of client DrawText (hdc, TEXT ("Hello, Windows XP!"), -1, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER) ; EndPaint (hwnd, &ps); //draw the text in centre of window return 0 ; case WM_DESTROY: //when the window destroy ,this function will accept this massage,then process it: PostQuitMessage (0); //Quit the program return 0 ; } return DefWindowProc (hwnd, message, wParam, lParam); }
相关文章推荐
- Sessions, Window Stations and Desktops(GetDesktopWindow函数得到的桌面句柄, 是Csrss.exe创建的一个窗口)
- Sessions, Window Stations and Desktops(GetDesktopWindow函数得到的桌面句柄, 是Csrss.exe创建的一个窗口)
- 一个简单的将GUI程序的log信息输出到关联的Console窗口中(AllocConsole SetConsoleTitle WriteConsole 最后用ShowWindow(GetConsoleWindow)进行显示)
- [转]Create a Lightbox with jQuery and CSS 创建一个简单的弹出层
- Window输出窗口运行时调试信息中没有显示调用的dll情况
- 百度地图创建麻点及解决显示最同一个窗口信息问题
- JavaScript基础 window.open(url,name,options) 弹出一个 新窗口 屏幕居中显示 获取屏幕的有效宽度
- iframe/window.open打开一个新窗口/子窗口中调用父窗口的方法
- C# 不用IDE 创建一个简单的Window窗口程序
- 判断一个窗口是否被挂起(发WM_NULL消息,或者调用IsHungAppWindow API进行测试)
- JavaScript基础 window.open(url,name,options) 弹出一个 新窗口 屏幕居中显示 获取屏幕的有效宽度
- 关于Cocoa的窗口创建调用-一个nib包含两个窗口
- OpenCV+中把cvNamedWindow(char*,int+flag)创建的窗口+同时显示QT性能+或+关闭掉Qt性能
- window.open打开一个新窗口/子窗口中调用父窗口的方法
- C# 创建、部署和调用WebService的简单示例 webservice 可以用于分布式应用程序之间的交互,和不同程序之间的交互。 概念性的东西就不说太多,下面开始创建一个简单的webservi
- Qt刷新机制的一些总结(Qt内部画的时候是相当于画在后台一个对象里,然后在刷新的时候调用bitblt统一画,调用window的api并不会影响到后面的那个对象)
- 创建一个不显示窗口的程序(2006-03-30修订)
- 【VC编程】笔记1--创建一个Win32的应用程序,并显示创建的窗口和菜单
- 使用UpdateLayeredWindow的窗口在某些系统上显示不出来的一个可能原因
- win32 api CreateWindow创建窗口控件及设置字体