|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include<windows.h>
#include<tchar.h>
#include<dos.h>
#include <mmsystem.h>
#pragma comment(lib, "winmm.lib ");
LRESULT CALLBACK MyWindProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam);
HINSTANCE hins;
int APIENTRY _tWinMain(HINSTANCE hinstance,HINSTANCE hprevinstance,LPTSTR IpCmdLine,int nCmdShow)
{
hins=hinstance;
WNDCLASSEX wcex;
wcex.cbWndExtra=0;
wcex.cbSize=sizeof(WNDCLASSEX);
wcex.cbClsExtra=0;
wcex.hbrBackground=(HBRUSH)GetStockObject(GRAY_BRUSH);
wcex.hCursor=LoadCursor(NULL,IDC_ARROW);
wcex.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wcex.hIconSm=wcex.hIcon;
wcex.hInstance=hinstance;
wcex.lpfnWndProc=MyWindProc;
wcex.lpszClassName=TEXT("MyWindCls");
wcex.lpszMenuName=NULL;
wcex.style=CS_HREDRAW|CS_VREDRAW;
RegisterClassEx(&wcex);
HWND hwnd=CreateWindow(TEXT("MyWindCls"),TEXT("第一个窗口程序"),WS_OVERLAPPEDWINDOW|WS_HSCROLL| WS_VSCROLL,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hinstance,NULL);
if(hwnd==NULL)return 0;
ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd);
MSG msg;
/*HWND HW;
HW=CreateWindow(TEXT("static"),TEXT("取消"),WS_CHILD|WS_VISIBLE,120,100,50,50,hwnd,HMENU(1002),hins,NULL);*/
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK MyWindProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
HICON ico;
/*ico=LoadIcon(NULL,IDI_ASTERISK);*/
PAINTSTRUCT ps;
HDC hd;
RECT rc;
HWND but;
HWND hh;
HWND edit;
char ch[100];
ch[0]='\0';
int n;
char ch2[100];
switch(uMsg)
{
case WM_CREATE:
but=CreateWindow(TEXT("button"),TEXT("确定"),WS_CHILD|WS_VISIBLE/*|BS_NOTIFY|BS_ICON,*/,1110,100,50,30,hwnd,HMENU(1001),hins,NULL);
edit=CreateWindow(TEXT("edit"),NULL,WS_CHILD|WS_VISIBLE,100,100,1000,30,hwnd,HMENU(1002),hins,NULL);
//PlaySound(TEXT("E:\\1.wav"),NULL,SND_FILENAME|SND_ASYNC);
if(edit==NULL)
{
MessageBox(NULL,TEXT("编辑框句柄提取失败"),TEXT("提示"),1);
}
//SendMessage(but,BM_SETIMAGE,IMAGE_ICON,(LPARAM)ico);
break;
case WM_COMMAND:
if(LOWORD(wParam)==1001)
{
n=GetWindowText(edit,ch,98);
if(n==0)
{
MessageBox(NULL,TEXT("取文本失败"),TEXT("提示"),1);
}
bool bool1;
MessageBox(NULL,TEXT(ch),TEXT("提示"),1);
lstrcpy(ch2,"E:\\");
lstrcat(ch2,ch);
lstrcat(ch2,".wav");
MessageBox(NULL,TEXT(ch2),TEXT("提示"),1);
bool1=PlaySound(TEXT(ch2),NULL,SND_FILENAME|SND_ASYNC);
if(bool1)
{
MessageBox(NULL,TEXT("成功"),TEXT("提示"),1);
}
}
/*if(LOWORD(wParam)==1001)
{
if(HIWORD(wParam)==BN_DOUBLECLICKED)
{
MessageBox(NULL,TEXT("按钮被双击"),TEXT("提示"),1);
hh=FindWindow(TEXT("CDlgAdSafeMain"),TEXT("ADSafe"));
if(!hh)
{
MessageBox(NULL,TEXT("未成功"),TEXT("计算"),1);
}
SendMessage(hh,WM_DESTROY,0,0);
}
break;
}*/break;
case WM_PAINT:
hd=BeginPaint(hwnd,&ps);
/*TextOut(hd,200,300,TEXT("hello window!"),lstrlen("hello window!"));
GetClientRect(hwnd,&rc);
DrawText(hd,TEXT("windows程序设计"),-1,&rc,DT_SINGLELINE|DT_CENTER|DT_VCENTER);*/
EndPaint(hwnd,&ps);
break;
case WM_DESTROY:
PostQuitMessage(0);break;
case WM_CLOSE:
int i;
i=MessageBox(NULL,TEXT("确定退出程序"),TEXT("提示"),1);
if(i==IDOK)
{
DestroyWindow(hwnd);
}
break;
}
return DefWindowProc(hwnd,uMsg,wParam,lParam);
} |
|