win32(002) 创建窗口和 子窗口 事件处理
不处理了自己上代码 我会上传
// win3202.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#define begbuttonid 0x100
#define stopbuttonid 0x101
#define actbuttonid 0x102
#define aboutbuttonid 0x103
#include <malloc.h>
#include <crtdbg.h>
HWND hmainwindow;
LRESULT CALLBACK WindowProc( HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
switch (uMsg)
{
case WM_MOVE :{
_RPT1(_CRT_WARN, "WM_MOVE:%x\r\n",uMsg);
}
break;
case WM_CREATE :
{
_RPT1(_CRT_WARN, "WM_CREATE:%x\r\n",uMsg);
CreateWindow(
"Button",
"开始记录",
WS_VISIBLE|WS_CHILD,
50,
50,
100,
30,
hwnd,
(HMENU)begbuttonid,
NULL,
NULL
);
CreateWindow(
"Button",
"停止播放记录",
WS_VISIBLE|WS_CHILD,
200,
50,
100,
30,
hwnd,
(HMENU)stopbuttonid,
NULL,
NULL
);
CreateWindow(
"Button",
"抖动窗口",
WS_VISIBLE|WS_CHILD,
50,
150,
100,
30,
hwnd,
(HMENU)actbuttonid,
NULL,
NULL
);
CreateWindow(
"Button",
"关于",
WS_VISIBLE|WS_CHILD,
200,
150,
100,
30,
hwnd,
(HMENU)aboutbuttonid,//一定要写
NULL,
NULL
);
}
break;
case WM_COMMAND:
{
int j=0;
static POINT point[MAXBYTE]={0};
WORD wID = LOWORD(wParam);
switch(wID){
case begbuttonid:
{
SetWindowText(hwnd,"开始记录");
for (int i=0;i<50;i++)
{
GetCursorPos(&point[j]);
Sleep(100);
_RPT2(_CRT_WARN, "begin:x坐标: %d y坐标: %d\r\n", point[j].x, point[j].y);
j++;
}
}
break;
case stopbuttonid:
{
SetWindowText(hwnd,"停止记录并播放");
for (int i=0;i<50;i++)
{
SetCursorPos(point[j].x,point[j].y);
Sleep(100);
_RPT2(_CRT_WARN, "stop:x坐标: %d y坐标: %d \r\n", point[j].x, point[j].y);
j++;
}
}
break;
case actbuttonid:
{
for(int i=0;i<500;i++){
MoveWindow(hmainwindow,150,150,400,400,TRUE);
MoveWindow(hmainwindow,100,100,400,400,TRUE);
}
}
break;
case aboutbuttonid:
{
MessageBox(NULL,"关于程序","提示",MB_ICONERROR);
}
break;
}
}
break;
case WM_CLOSE:
{
/* PostQuitMessage(0);*/
PostMessage(hwnd,WM_QUIT,0,0);
_RPT1(_CRT_WARN, "WM_CLOSE:%x\r\n",uMsg);
}
break;
default:
DefWindowProc(hwnd, uMsg, wParam, lParam);
}
return 1;
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
//必须初始化
WNDCLASS wmainclass={0};
wmainclass.style=CS_HREDRAW|CS_VREDRAW;
wmainclass.lpfnWndProc=WindowProc;
wmainclass.hbrBackground=(HBRUSH)COLOR_BACKGROUND;
wmainclass.lpszClassName="wmainclass";
ATOM atom=RegisterClass(&wmainclass);
if (atom==0)
{
MessageBox(NULL,"注册类失败","提示",MB_ICONERROR);
}
hmainwindow=CreateWindow(
"wmainclass",
"鼠标记录器",
WS_MAXIMIZEBOX|WS_MINIMIZEBOX|WS_VISIBLE|WS_CAPTION|WS_BORDER|WS_SYSMENU,
100,
100,
400,
400,
NULL,
NULL,
NULL,
NULL
);
//ShowWindow(hmainwindow, SW_SHOWNORMAL);
MSG msg={0};
while (GetMessage(&msg,hmainwindow,0,0))
{
DispatchMessage(&msg);
}
return 0;
}