SDK3(note上)
搞了举个窗口设置还有鼠标处理的信息
注释写在代码中了
#include <windows.h>
#include<tchar.h>
#include <stdio.h>
#include <strsafe.h>
/*鼠标消息
* 键盘消息
快捷键消息
菜单消息
控件消息
自定义消息
窗口消息
客户区域的概念(Client Aera)
非客户区
*/
VOID showerrormassage()
{
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |/* 分别为FORMAT_MESSAGE_ALLOCATE_BUFFER由函数分配输出缓冲区,
FORMAT_MESSAGE_FROM_SYSTEM表示程序将会在系统消息表资源中搜索所需消息,FORMAT_MESSAGE_IGNORE_INSERTS程序将会忽略搜索到消息中的插入序列。 */
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR)&lpMsgBuf,
0, NULL);
MessageBox(NULL, (LPCTSTR)lpMsgBuf, TEXT("Error"), MB_OK | MB_ICONINFORMATION);
LocalFree(lpMsgBuf);
}
LRESULT OnCreate(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
//初始化
::MessageBox(NULL,_T("onCrate"), _T("asm"), MB_OK);
return TRUE;
}//消息处理
LRESULT OnClese(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
::MessageBox(NULL, _T("onClose"), _T("asm"), MB_OK);
DestroyWindow(hwnd);
return TRUE;
}
//消息处理
LRESULT OnDestroy(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
MessageBox(NULL, _T("onDestory"), _T("asm"), MB_OK);
PostMessage(hwnd, WM_QUIT, 0, NULL);
return TRUE;
}
LRESULT OnMove(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
TCHAR szBuf[MAXBYTE];
int xpos = (int)(short)LOWORD(lParam);
int ypos = (int)(short)HIWORD(lParam);
wsprintf(szBuf, _T("xpos:%d ypos:%d"), xpos, ypos);
MessageBox(NULL, _T("onDestory"), _T("asm"), MB_OK);
PostMessage(hwnd, WM_QUIT, 0, NULL);
return TRUE;
}
LRESULT OnLButtonnDown(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
int xpos = LOWORD(lParam);
int ypos = HIWORD(lParam);
TCHAR szBuf[MAXBYTE];
wsprintf(szBuf, _T("xpos:%d ypos:%d"), xpos, ypos);
MessageBox(NULL, szBuf, _T("asm"), MB_OK);
return FALSE;
}
//LRESULT onMouse(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
//{
// LRESULT lResult = FALSE;
// switch (uMsg)
// {
// case WM_LBUTTONDOWN:
// lResult= OnLButtonnDown(hwnd, uMsg, wParam, lParam);
// break;
// }
// return FALSE;
//}
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
LRESULT lResult = FALSE;
switch (uMsg)
{
case WM_CREATE:
lResult= OnCreate(hwnd, uMsg, wParam, lParam);
break;
case WM_CLOSE:
lResult = OnClese(hwnd, uMsg, wParam, lParam);
break;
case WM_DESTROY:
lResult = OnDestroy(hwnd, uMsg, wParam, lParam);
break;
case WM_LBUTTONDOWN:
lResult = OnLButtonnDown(hwnd, uMsg, wParam, lParam);
break;
case WM_LBUTTONUP:
}
if (!lResult) {
return DefWindowProc(hwnd, uMsg, wParam, lParam);//默认窗口过程处理
}
return lResult;
}
//图形界面,窗口
int WINAPI _tWinMain(HINSTANCE hInstance,//应用程序示例句柄
HINSTANCE hPrevInstance,//保留
TCHAR* lpCmdline, //命令行参数,LPSTR可能会变成Unicode
int nCmdShow) {//窗口显示方式
//比如我们启动这个窗口,最大化,最小化
/*MessageBoxA(NULL, "hell word ", "asm", MB_YESNO);*/\
//int res = MessageBoxW(NULL, L"hell unicode", L"asm", MB_YESNO);
//
//if (res == 0) {
///* MessageBoxW(NULL, L"错误", L"asm", MB_OK);*/
// showerrormassage();
// return 0;
//}
程序》实例化》进程》多个窗口
//1.注册窗口
TCHAR szWndclassName[] = { _T("chongmousyy") };
WNDCLASSEX wc = { 0 };
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_VREDRAW|CS_HREDRAW;//窗口类型
wc.lpfnWndProc = WindowProc;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL,IDC_HAND);//图标
wc.hCursor = LoadCursor(NULL,IDC_ARROW );//光标FDXX
wc.hbrBackground = CreateSolidBrush(RGB(255,255,255));//窗口背景颜色刷子
wc.lpszClassName = szWndclassName;//窗口类名,窗口名字不可以为空
wc.lpszMenuName = NULL;//窗口菜单
if (RegisterClassEx(&wc) == 0)
{
showerrormassage();
return 0;
};
//2.创建窗口
TCHAR szWndName[] = { _T("翀某人") };
HWND hwnd = CreateWindowEx(0,
szWndclassName,
szWndName,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL
);
if (hwnd == 0)
{
showerrormassage();
return 0;
}
//3.显示跟新窗口
ShowWindow(hwnd, SW_SHOWNORMAL);
//4.消息循环(消息队列)
BOOL bRET;
MSG msg;
while ((bRET=GetMessage(&msg, NULL, 0, 0))!=0) {
if (bRET==-1) {
break;
}
else
{
DispatchMessage(&msg);//派发消息
}
}
//5.消息处理
//资源
return 0;
}
#include <windows.h>
#include<tchar.h>
#include <stdio.h>
#include <strsafe.h>
/*鼠标消息
* 键盘消息
快捷键消息
菜单消息
控件消息
自定义消息
窗口消息
客户区域的概念(Client Aera)
非客户区
*/
VOID showerrormassage()
{
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |/* 分别为FORMAT_MESSAGE_ALLOCATE_BUFFER由函数分配输出缓冲区,
FORMAT_MESSAGE_FROM_SYSTEM表示程序将会在系统消息表资源中搜索所需消息,FORMAT_MESSAGE_IGNORE_INSERTS程序将会忽略搜索到消息中的插入序列。 */
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR)&lpMsgBuf,
0, NULL);
MessageBox(NULL, (LPCTSTR)lpMsgBuf, TEXT("Error"), MB_OK | MB_ICONINFORMATION);
LocalFree(lpMsgBuf);
}
LRESULT OnCreate(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
//初始化
::MessageBox(NULL,_T("onCrate"), _T("asm"), MB_OK);
return TRUE;
}//消息处理
LRESULT OnClese(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
::MessageBox(NULL, _T("onClose"), _T("asm"), MB_OK);
DestroyWindow(hwnd);
return TRUE;
}
//消息处理
LRESULT OnDestroy(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
MessageBox(NULL, _T("onDestory"), _T("asm"), MB_OK);
PostMessage(hwnd, WM_QUIT, 0, NULL);
return TRUE;
}
LRESULT OnMove(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
TCHAR szBuf[MAXBYTE];
int xpos = (int)(short)LOWORD(lParam);
int ypos = (int)(short)HIWORD(lParam);
wsprintf(szBuf, _T("xpos:%d ypos:%d"), xpos, ypos);
MessageBox(NULL, _T("onDestory"), _T("asm"), MB_OK);
PostMessage(hwnd, WM_QUIT, 0, NULL);
return TRUE;
}
LRESULT OnLButtonnDown(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
int xpos = LOWORD(lParam);
int ypos = HIWORD(lParam);
TCHAR szBuf[MAXBYTE];
wsprintf(szBuf, _T("xpos:%d ypos:%d"), xpos, ypos);
MessageBox(NULL, szBuf, _T("asm"), MB_OK);
return FALSE;
}
//LRESULT onMouse(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
//{
// LRESULT lResult = FALSE;
// switch (uMsg)
// {
// case WM_LBUTTONDOWN:
// lResult= OnLButtonnDown(hwnd, uMsg, wParam, lParam);
// break;
// }
// return FALSE;
//}
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
LRESULT lResult = FALSE;
switch (uMsg)
{
case WM_CREATE:
lResult= OnCreate(hwnd, uMsg, wParam, lParam);
break;
case WM_CLOSE:
lResult = OnClese(hwnd, uMsg, wParam, lParam);
break;
case WM_DESTROY:
lResult = OnDestroy(hwnd, uMsg, wParam, lParam);
break;
case WM_LBUTTONDOWN:
lResult = OnLButtonnDown(hwnd, uMsg, wParam, lParam);
break;
case WM_LBUTTONUP:
}
if (!lResult) {
return DefWindowProc(hwnd, uMsg, wParam, lParam);//默认窗口过程处理
}
return lResult;
}
//图形界面,窗口
int WINAPI _tWinMain(HINSTANCE hInstance,//应用程序示例句柄
HINSTANCE hPrevInstance,//保留
TCHAR* lpCmdline, //命令行参数,LPSTR可能会变成Unicode
int nCmdShow) {//窗口显示方式
//比如我们启动这个窗口,最大化,最小化
/*MessageBoxA(NULL, "hell word ", "asm", MB_YESNO);*/\
//int res = MessageBoxW(NULL, L"hell unicode", L"asm", MB_YESNO);
//
//if (res == 0) {
///* MessageBoxW(NULL, L"错误", L"asm", MB_OK);*/
// showerrormassage();
// return 0;
//}
程序》实例化》进程》多个窗口
//1.注册窗口
TCHAR szWndclassName[] = { _T("chongmousyy") };
WNDCLASSEX wc = { 0 };
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_VREDRAW|CS_HREDRAW;//窗口类型
wc.lpfnWndProc = WindowProc;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL,IDC_HAND);//图标
wc.hCursor = LoadCursor(NULL,IDC_ARROW );//光标FDXX
wc.hbrBackground = CreateSolidBrush(RGB(255,255,255));//窗口背景颜色刷子
wc.lpszClassName = szWndclassName;//窗口类名,窗口名字不可以为空
wc.lpszMenuName = NULL;//窗口菜单
if (RegisterClassEx(&wc) == 0)
{
showerrormassage();
return 0;
};
//2.创建窗口
TCHAR szWndName[] = { _T("翀某人") };
HWND hwnd = CreateWindowEx(0,
szWndclassName,
szWndName,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL
);
if (hwnd == 0)
{
showerrormassage();
return 0;
}
//3.显示跟新窗口
ShowWindow(hwnd, SW_SHOWNORMAL);
//4.消息循环(消息队列)
BOOL bRET;
MSG msg;
while ((bRET=GetMessage(&msg, NULL, 0, 0))!=0) {
if (bRET==-1) {
break;
}
else
{
DispatchMessage(&msg);//派发消息
}
}
//5.消息处理
//资源
return 0;
}