windows 制的轮子.
// 第一个窗口.cpp : 定义应用程序的入口点。
//
#include "stdafx.h"
#include "stdio.h"
#include "第一个窗口.h"
HINSTANCE ghInstance;
#define IDC_EDIT_TEXT 0x100
#define IDC_BOTTON_SEND 0x101
#define IDC_BOTTON_DECODE 0x102
LRESULT CALLBACK WindowProc( //窗口处理函数
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
){
//WM_CREATE;
TCHAR szOutBufferMessage[0x80];
//根据消息类型 做相关的操作
switch(uMsg){
case(WM_DESTROY): //退出窗口
{
sprintf((char *)szOutBufferMessage,"关闭窗口:%x\n",uMsg);
OutputDebugStringA((LPCSTR)szOutBufferMessage);
PostQuitMessage(NULL); //关闭程序
return 0;}
case (WM_KEYDOWN):
{
sprintf((char *)szOutBufferMessage,"按下键盘:%x - %x -%x\n",uMsg,wParam,lParam);
OutputDebugStringA((LPCSTR)szOutBufferMessage);
//MessageBox(0,TEXT("按下一个键盘"),0,0);
return 0;}
case (WM_CHAR):
{sprintf((char *)szOutBufferMessage,"按下键盘带char:%x - %x : %c -%x\n",uMsg,wParam,wParam,lParam);
OutputDebugStringA((LPCSTR)szOutBufferMessage);
return 0;}
case (WM_CREATE):
{
CreateWindow(
TEXT("EDIT"),
TEXT(""),
WS_CHILD|WS_VISIBLE|WS_VSCROLL|ES_PASSWORD,
5,
5,
400,
600,
hwnd,
(HMENU)IDC_EDIT_TEXT,
ghInstance,
NULL
);
CreateWindow(
TEXT("BUTTON"),
TEXT("发送"),
WS_CHILD|WS_VISIBLE,
450,
20,
80,
80,
hwnd,
(HMENU)IDC_BOTTON_SEND,
ghInstance,
NULL
);
CreateWindow(
TEXT("BUTTON"),
TEXT("解密"),
WS_CHILD|WS_VISIBLE,
450,
220,
80,
80,
hwnd,
(HMENU)IDC_BOTTON_DECODE,
ghInstance,
NULL
);
return 0;
}
case (WM_COMMAND):
{
switch (LOWORD(wParam))
{
case (IDC_BOTTON_SEND):
{
SetDlgItemText(hwnd,IDC_EDIT_TEXT,TEXT("FUCK"));
//SendDlgItemMessage(hwnd,IDC_EDIT_TEXT,uMsg,NULL,NULL);
//MessageBox(0,TEXT("SEND"),TEXT("SEND"),0);
break;
}
case (IDC_BOTTON_DECODE):
{
GetDlgItemText(hwnd,IDC_EDIT_TEXT,szOutBufferMessage,0x80);
MessageBox(0,szOutBufferMessage,TEXT("框内信息"),MB_OK);
break;
}
default:
return 0;
}
}
default:
//sprintf((char *)szOutBufferMessage,"hwnd :%x\n",hwnd);
//OutputDebugStringA((LPCSTR)szOutBufferMessage);
return DefWindowProc(hwnd,uMsg,wParam,lParam);
};
}
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
TCHAR szOutBuffer[0x80];
//1.第一步:定义你的窗口是什么样的?
TCHAR classname[] = TEXT("My First Window!");
WNDCLASS wndclass = {0};
wndclass.hbrBackground = (HBRUSH)COLOR_BACKGROUND;
wndclass.lpszClassName = (LPWSTR)classname;
wndclass.hInstance = hInstance;
wndclass.lpfnWndProc = WindowProc; //不是调用函数,是给操作系统调用的,不是你调用的
RegisterClass(&wndclass);//注册给操作系统,告诉我们操作系统的存在 win32k
//2.创建窗口对象并显示窗口
//class name 来标识你想要的窗口
HWND hwnd = CreateWindow(
classname,
TEXT("我的第一个窗口"),
WS_OVERLAPPEDWINDOW,
10,
10,
600,
600,
NULL,
NULL,
hInstance,
NULL
);
if (hwnd == NULL) //窗口是否创建成功
{
sprintf((char*)szOutBuffer,"Last error :%d",GetLastError());
OutputDebugString((LPWSTR)szOutBuffer);
return 0;
}
ShowWindow(hwnd,SW_SHOW);
//3. 接收消息并处理
MSG msg;
BOOL bReT;
//sprintf((char*)szOutBuffer,"WINMAIN hwnd :%x",hwnd);
//OutputDebugStringA((LPCSTR)szOutBuffer);
while((bReT = GetMessage(&msg,NULL,NULL,NULL)) !=0 ){
if (bReT == -1)
{
//handle the error and possibly exit.
}
else{
TranslateMessage(&msg);//转换消息 virtual-code -> character
DispatchMessage(&msg);//分发给消息处理函数处理消息
}
}
return 0;
}