- 注册时间
- 2004-3-2
- 最后登录
- 2023-5-15
管理员
お嬢様
- 积分
- 22410
|
#include <windows.h>
#include<iostream>
using namespace std;
//-----------------------------------------------------------------------------
// Name: MsgProc()
// Desc: The window's message handler
//-----------------------------------------------------------------------------
LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
PAINTSTRUCT ps;
HDC hdc;
int intX = HIWORD(lParam);
int intY = LOWORD(lParam);
char temp[64];
switch( msg )
{
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: 在此添加任意绘图代码...
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage( 0 );
return 0;
case WM_MOUSEMOVE:
sprintf(temp,"X:%d,Y:%d",intX,intY);
SetWindowText(hWnd,temp);
break;
case WM_LBUTTONDOWN:
MessageBox(hWnd,"左键测试","标题",MB_OK);
break;
case WM_KEYDOWN:
{
switch(wParam)
{
case VK_F4:
{
MessageBox(hWnd,"F4测试","标题",MB_OK);
}
break;
}
}
break;
}
return DefWindowProc( hWnd, msg, wParam, lParam );
}
INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR, INT )
{
// Register the window class
WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L,
GetModuleHandle(NULL), NULL, NULL, (HBRUSH)(COLOR_WINDOW+1), NULL,
"Tutorial", NULL };
RegisterClassEx( &wc );
// Create the application's window
HWND hWnd = CreateWindow( "Tutorial", "纯净窗口",
WS_OVERLAPPEDWINDOW, 100, 100, 800, 600,
NULL, NULL, wc.hInstance, NULL );
// Show the window
ShowWindow( hWnd, SW_SHOWDEFAULT );
UpdateWindow( hWnd );
// Enter the message loop
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
UnregisterClass( "Tutorial", wc.hInstance );
return 0;
}
=======================分割线====================
学了2个月才这么点东西……
底层的东西确实麻烦些,比起JAVA难学多了= =.
正在啃DX ing.
这个代码 演示了一般窗口绘制。
有键盘(热键)鼠标 单击和移动事件(消息)的几个触发实例。
应该算是最省最省的代码了以后慢慢来= =学习道路好长…… |
|