#include <windows.h>
#include <stdio.h>
#include"resource.h"
HINSTANCE hInst;
LRESULT CALLBACK WindowsProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);
BOOL CALLBACK DlgProc(HWND hdlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
int WINAPI WinMain(
HINSTANCE hInstance, // handle to current instance
HINSTANCE hPrevInstance, // handle to previous instance
LPSTR lpCmdLine, // command line
int nCmdShow // show state
)
{
WNDCLASS wndcls;
wndcls.cbClsExtra=0;
wndcls.cbWndExtra=0;
wndcls.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndcls.hCursor=LoadCursor(NULL,IDC_ARROW);
wndcls.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndcls.hInstance=hInstance;
wndcls.lpfnWndProc=WindowsProc;
wndcls.lpszClassName="Windows6";
wndcls.lpszMenuName="My_Menu";
wndcls.style=CS_HREDRAW | CS_VREDRAW;
RegisterClass(&wndcls);
// WNDCLASS wndcls={CS_HREDRAW | CS_VREDRAW,WinSunProc,0,0,hInstance,LoadIcon(NULL,IDI_ERROR),LoadCursor(NULL,IDC_CROSS),(HBRUSH)GetStockObject(BLACK_BRUSH),NULL,"Weixin2003"};
HWND hwnd;
HMENU hmenu;
hmenu=LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU1));
hwnd=CreateWindow("Windows6","windows API 编程",WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,hmenu,hInstance,NULL);
/* HWND CreateWindow(
LPCTSTR lpClassName, // pointer to registered class name
LPCTSTR lpWindowName, // pointer to window name
DWORD dwStyle, // window style
int x, // horizontal position of window
int y, // vertical position of window
int nWidth, // window width
int nHeight, // window height
HWND hWndParent, // handle to parent or owner window
HMENU hMenu, // handle to menu or child-window identifier
HANDLE hInstance, // handle to application instance
LPVOID lpParam // pointer to window-creation data
);
*/
ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd);
hInst=hInstance;
MSG msg;
while(GetMessage(&msg,NULL,0,0))//消息循环;
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK WindowsProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
switch(uMsg)
{
// RECT rect;
case WM_CREATE:
PlaySound(TEXT("ding.wav"),NULL,SND_FILENAME | SND_ASYNC);//Windows multimedia-Windows多媒体
break;
case WM_CHAR:
char szChar[20];
sprintf(szChar,"char is %d",wParam);
MessageBox(hwnd,szChar,"Windows0",0);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,"mouse clicked","Windows0",0);
HDC hdc;
hdc=GetDC(hwnd);
TextOut(hdc,0,100,"hello,这是windows编程,的确很酷",strlen("hello,这是windows编程,的确很酷"));
ReleaseDC(hwnd,hdc);
break;
case WM_PAINT:
HDC hDC;
PAINTSTRUCT ps;
hDC=BeginPaint(hwnd,&ps);
TextOut(hDC,0,0,"hello,这是windows编程,的确很酷 ,重绘的测试",strlen("hello,这是windows编程,的确很酷 ,重绘的测试"));
EndPaint(hwnd,&ps);
break;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,"are you sure?","Windows0",MB_YESNO))
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDM_ADD1:
MessageBox(hwnd,"功能尚未完成!","菜单",MB_OK);
break;
case IDM_ADD2:
MessageBox(hwnd,"功能尚未完成!","菜单",MB_OK);
break;
case IDM_ADD3:
MessageBox(hwnd,"功能尚未完成!","菜单",MB_OK);
break;
case IDM_ADD4:
MessageBox(hwnd,"功能尚未完成!","菜单",MB_OK);
break;
case IDM_EXIT:
SendMessage(hwnd,WM_CLOSE,0,0);
break;
case IDM_DIALOG:
//((LPCREATESTRUCT) lParam)
DialogBox(hInst,LPCSTR(IDD_DIALOG1),hwnd,(DLGPROC)DlgProc);
break;
default:
return FALSE;
}
break;
default:
// return WinSunProc(hwnd,uMsg,wParam,lParam);
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}
BOOL CALLBACK DlgProc(HWND hdlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_INITDIALOG:
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDOK:
EndDialog(hdlg,0);
break;
case IDCANCEL:
EndDialog(hdlg,0);
break;
default:
return FALSE;
}
break;
case WM_CLOSE:
EndDialog(hdlg,0);
default:
return FALSE;
}
return 0;
}
没有合适的资源?快使用搜索试试~ 我知道了~
用Windows API创建简单的菜单和对话框。
共20个文件
pdb:2个
cpp:1个
h:1个
5星 · 超过95%的资源 需积分: 50 30 下载量 39 浏览量
2017-10-26
10:06:07
上传
评论 2
收藏 1.93MB RAR 举报
温馨提示
非常简单的Windows程序,对于菜单和对话框的编写一目了然。适合初学者对于Windows编程的学习。
资源推荐
资源详情
资源评论
收起资源包目录
WinMain.rar (20个子文件)
WinMain
WinMain.dsw 539B
WinResScript.rc 3KB
WinMain.ncb 137KB
WinMain.plg 248B
resource.h 788B
WinMain.cpp 5KB
WinMain.dsp 4KB
WinMain.opt 48KB
Debug
WinMain.sbr 0B
WinResScript.res 312B
WinMain.exe 172KB
WinMain.obj 19KB
vc60.idb 161KB
WinMain.pdb 449KB
WinMain.pch 4.28MB
WinMain.bsc 1.84MB
WinMain.ilk 225KB
vc60.pdb 84KB
WinResScript.aps 32KB
ding.wav 79KB
共 20 条
- 1
资源评论
- 初心是我2018-01-18很好的资源,适合我们学习。
宋哈娜
- 粉丝: 2
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- IMG_20240425_120538.jpg
- My Complete Genome_6k Base-Pairs of Phenotype SNPs_Complete Raw Data.zip
- qt 的mqtt测试demo
- 移动应用开发教程-zip.zip
- mosquitto-2.018-install-windows-x64
- FTPServer FTP 服务器,绿色免安装,单文件
- 梦畅语音点名软件,上课点名
- 利用ADNI数据集和标签,在tensorflow框架上使用tensorlayer接口,通过架构u-net实现海马体的分割
- Kutools for Word v9.0 office word 插件
- 修复Windows 10 LTSC 2021资源占用率高
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功