window实验
来源:互联网 发布:江宁人才网最新域名 编辑:程序博客网 时间:2024/06/07 06:14
第一次window实验:
实验代码:
#include <windows.h>
const char g_szClassName[] = "myWindowClass";
// Step 4: the Window Procedure
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_LBUTTONDOWN: // <-
{
char szFileName[MAX_PATH];
HINSTANCE hInstance = GetModuleHandle(NULL);
GetModuleFileName(hInstance, szFileName, MAX_PATH);
MessageBox(hwnd, "This program is:",szFileName, MB_OK | MB_ICONINFORMATION);
}
// <- we just added this stuff
break;
case WM_CLOSE:
{if(MessageBox(NULL, "Do you want to save your file?", "Warning", MB_OKCANCEL)==IDCANCEL)
{
//DestroyWindow(hwnd);
}
else
{DestroyWindow(hwnd);}
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
//MessageBox(NULL, "Goodbye, cruel world!", "Note", MB_OKCANCEL);
WNDCLASSEX wc;
HWND hwnd;
MSG Msg;
//Step 1: Registering the Window Class
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 2;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+9);
wc.lpszMenuName = NULL;
wc.lpszClassName = g_szClassName;
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if(!RegisterClassEx(&wc))
{
MessageBox(NULL, "Window Registration Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
// Step 2: Creating the Window
hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
g_szClassName,
"The title of my window",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 500, 500,
NULL, NULL, hInstance, NULL);
if(hwnd == NULL)
{
MessageBox(NULL, "Window Creation Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
// Step 3: The Message Loop
while(GetMessage(&Msg, NULL, 0, 0) > 0)
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
实现的功能:实现简单窗口类的注册和显示,在此次实验中我大致了解了用C语言编写简单窗口的实现代码,对于弹窗函数MessageBox的参数设置和控制语句的实现,
例如,在一个窗口打开过程中,如果点击了窗口的『x』按钮,则会弹窗警告(Warning)窗口,如果点击“是”,将destory窗口,如果点击“否”,将什么也不做,
具体是通过循环控制语句来实现的。代码如下:
case WM_CLOSE:
{if(MessageBox(NULL, "Do you want to save your file?", "Warning", MB_OKCANCEL)==IDCANCEL)
{
//DestroyWindow(hwnd);
}
else
{DestroyWindow(hwnd);}
}
break;case WM_CLOSE:
{if(MessageBox(NULL, "Do you want to save your file?", "Warning", MB_OKCANCEL)==IDCANCEL)
{
//DestroyWindow(hwnd);
}
else
{DestroyWindow(hwnd);}
}
break;
- window实验
- window实验
- window第一次实验3
- Window CE 6.0流驱动开发实验
- Window CE 6.0流驱动开发动态加载实验
- 实验楼sql进阶之成绩管理系统的数据操作(window)
- Github上传代码实验过程(Window XP环境下实验)
- Window
- window
- window
- window
- window
- window
- window
- Window
- window
- Window
- ‘Window’
- PAT A1101. Quick Sort
- php pdo类总结
- Python安装完毕后,提示找不到ssl模块的解决步骤
- 机器学习算法——条件随机场CRF
- sftp.sh
- window实验
- sdutacm-顺序表应用2:多余元素删除之建表算法
- 各种数据源的ConnectString【转】
- Solution for link error:Cannot Open File 'python27_d.lib'
- 设计模式 策略模式 以角色游戏为背景
- linux常用命令sed
- 设计模式——简单工厂模式分析
- Beautiful Soup
- UIViewController 相关生命周期总结 和 UIView 总结