Win32多窗口程序的创建
来源:互联网 发布:视频剪辑软件推荐 编辑:程序博客网 时间:2024/04/29 02:12
本例演示如何在Win32应用程序中创建多个窗口
// Win32LevelRail1.5.cpp : Defines the entry point for the application.//#include "stdafx.h"#include "Win32LevelRail1.5.h"#define MAX_LOADSTRING 100// Global Variables:HINSTANCE hInst;// current instanceTCHAR szTitle[MAX_LOADSTRING]={L"主窗口"};// The title bar textTCHAR szWindowClass[MAX_LOADSTRING];// the main window class nameTCHAR szTitle2[MAX_LOADSTRING] = {L"第二窗口"};TCHAR szWindowClass2[MAX_LOADSTRING] = {L"Submarine"}; // 第二个窗口类的类名HWND hWnd, hWnd2; // Forward declarations of functions included in this code module:ATOMMyRegisterClass(HINSTANCE hInstance);BOOLInitInstance(HINSTANCE, int);LRESULT CALLBACKWndProc(HWND, UINT, WPARAM, LPARAM);LRESULT CALLBACK WndProc2(HWND, UINT, WPARAM, LPARAM);INT_PTR CALLBACKAbout(HWND, UINT, WPARAM, LPARAM);int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow){UNREFERENCED_PARAMETER(hPrevInstance);UNREFERENCED_PARAMETER(lpCmdLine); // TODO: Place code here.MSG msg;HACCEL hAccelTable;// Initialize global stringsLoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);LoadString(hInstance, IDC_WIN32LEVELRAIL15, szWindowClass, MAX_LOADSTRING);MyRegisterClass(hInstance);// Perform application initialization:if (!InitInstance (hInstance, nCmdShow)){return FALSE;}hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_WIN32LEVELRAIL15));// Main message loop:while (GetMessage(&msg, NULL, 0, 0)){if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)){TranslateMessage(&msg);DispatchMessage(&msg);}}return (int) msg.wParam;}//// FUNCTION: MyRegisterClass()//// PURPOSE: Registers the window class.//// COMMENTS://// This function and its usage are only necessary if you want this code// to be compatible with Win32 systems prior to the 'RegisterClassEx'// function that was added to Windows 95. It is important to call this function// so that the application will get 'well formed' small icons associated// with it.//ATOM MyRegisterClass(HINSTANCE hInstance){WNDCLASSEX wcex,wcex2;//第一个窗口类wcex.cbSize = sizeof(WNDCLASSEX);wcex.style= CS_HREDRAW | CS_VREDRAW;wcex.lpfnWndProc= WndProc;wcex.cbClsExtra= 0;wcex.cbWndExtra= 0;wcex.hInstance= hInstance;wcex.hIcon= LoadIcon(hInstance, MAKEINTRESOURCE(IDI_WIN32LEVELRAIL15));wcex.hCursor= LoadCursor(NULL, IDC_ARROW);wcex.hbrBackground= (HBRUSH)(COLOR_WINDOW+1);wcex.lpszMenuName= MAKEINTRESOURCE(IDC_WIN32LEVELRAIL15);wcex.lpszClassName= szWindowClass;wcex.hIconSm= LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));// 第二个窗口类的定义 wcex2.cbSize = sizeof(WNDCLASSEX); wcex2.style = CS_HREDRAW | CS_VREDRAW; wcex2.lpfnWndProc = (WNDPROC)WndProc2; wcex2.cbClsExtra = 0; wcex2.cbWndExtra = 0; wcex2.hInstance = hInstance; wcex2.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_WIN32LEVELRAIL15); wcex2.hCursor = LoadCursor(NULL, IDC_ARROW); wcex2.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wcex2.lpszMenuName = MAKEINTRESOURCE(IDC_WIN32LEVELRAIL15); wcex2.lpszClassName = szWindowClass2; wcex2.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);return (RegisterClassEx(&wcex)&&RegisterClassEx(&wcex2));}//// FUNCTION: InitInstance(HINSTANCE, int)//// PURPOSE: Saves instance handle and creates main window//// COMMENTS://// In this function, we save the instance handle in a global variable and// create and display the main program window.//BOOL InitInstance(HINSTANCE hInstance, int nCmdShow){ HWND hWnd; hInst = hInstance; // Store instance handle in our global variable //创建第一个窗口 hWnd = CreateWindow(szWindowClass, /*szTitle*/L"主窗口", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL); //创建第二个窗口 hWnd2 = CreateWindow(szWindowClass2, /*szTitle2*/L"第二窗口", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL); if (!hWnd || !hWnd2) { return FALSE; } ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); ShowWindow(hWnd2, nCmdShow); UpdateWindow(hWnd2); return TRUE;}//// FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)//// PURPOSE: Processes messages for the main window.//// WM_COMMAND- process the application menu// WM_PAINT- Paint the main window// WM_DESTROY- post a quit message and return////LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){int wmId, wmEvent;PAINTSTRUCT ps;HDC hdc;switch (message){case WM_COMMAND:wmId = LOWORD(wParam);wmEvent = HIWORD(wParam);// Parse the menu selections:switch (wmId){case IDM_HELP_ABOUT:DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);break;case IDM_FILE_EXIT:if(MessageBox(hWnd, L"确认离开程序", L"警告", MB_OKCANCEL)==IDOK){DestroyWindow(hWnd);}break;default:return DefWindowProc(hWnd, message, wParam, lParam);}break;case WM_PAINT:hdc = BeginPaint(hWnd, &ps);// TODO: Add any drawing code here...EndPaint(hWnd, &ps);break;case WM_DESTROY:PostQuitMessage(0);break;default:return DefWindowProc(hWnd, message, wParam, lParam);}return 0;}LRESULT CALLBACK WndProc2(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){int wmId, wmEvent;PAINTSTRUCT ps;HDC hdc;switch (message){case WM_COMMAND:wmId = LOWORD(wParam);wmEvent = HIWORD(wParam);// Parse the menu selections:switch (wmId){case IDM_HELP_ABOUT:DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);break;case IDM_FILE_EXIT:if(MessageBox(hWnd, L"确认离开窗口", L"警告", MB_OKCANCEL)==IDOK){DestroyWindow(hWnd);}break;default:return DefWindowProc(hWnd, message, wParam, lParam);}break;case WM_PAINT:hdc = BeginPaint(hWnd, &ps);// TODO: Add any drawing code here...EndPaint(hWnd, &ps);break;case WM_DESTROY:PostQuitMessage(0);break;default:return DefWindowProc(hWnd, message, wParam, lParam);}return 0;}// Message handler for about box.INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam){UNREFERENCED_PARAMETER(lParam);switch (message){case WM_INITDIALOG:return (INT_PTR)TRUE;case WM_COMMAND:if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL){EndDialog(hDlg, LOWORD(wParam));return (INT_PTR)TRUE;}break;}return (INT_PTR)FALSE;}
效果如下:
0 0
- Win32多窗口程序的创建
- win32程序窗口的创建
- win32程序窗口的创建
- 基于Win32的VTK多窗口程序创建
- win32下窗口程序的创建
- 创建一个win32窗口程序
- 创建一个不显示窗口的Win32程序
- Win32创建窗口的过程
- win32的创建窗口代码
- win32汇编--创建窗口程序(RadAsm)
- win32程序中创建一个DOS窗口
- MFC程序对win32的封装总结(窗口类的注册,窗口的创建,窗口的窗口过程指定)
- Win32程序的创建流程
- WIN32汇编: 3.创建简单的窗口
- Win32汇编:创建简单的窗口
- win32 的DLL中创建windows窗口
- win32 创建仅接收消息的窗口
- 基于SDK的Win32窗口创建
- XCode的一些调试技巧
- sql学习笔记(6)-----------sql函数(1)
- 枚举使用误区--iOS开发
- ios 数组赋值时取不到 数组赋值为空 奇葩问题
- 【golang】信号捕捉和处理
- Win32多窗口程序的创建
- Xcode导入静态库有时会出现莫名其妙的问题
- 单例传值(三个界面)
- 四十三、继承与派生:赋值兼容性规则
- 【STL源码剖析读书笔记】【第4章】序列式容器之heap和priority_queue
- jqgrid 4.8版本 Cannot read property 'decimalSeparator' of undefined 错误
- html css学习笔记-详解各种选择器
- 社説 20150516 財政健全化計画 成長頼みが過ぎては危うい
- SVM核函数