MOVE WINDOW

67 篇文章 0 订阅
#include <windows.h>
#include <wchar.h>


LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
void CreateLabels(HWND);

HWND hwndSta1;
HWND hwndSta2;

int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, 
                    PWSTR pCmdLine, int CmdShow)
{
  HWND hwnd;
  MSG  msg;

  WNDCLASSW wc = {0};
  wc.lpszClassName = L"Moving";
  wc.hInstance     = hInstance ;
  wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
  wc.lpfnWndProc   = WndProc;
  wc.hCursor       = LoadCursor(0, IDC_ARROW);
  
  RegisterClassW(&wc);
  hwnd = CreateWindowW(wc.lpszClassName, L"Moving",
                WS_OVERLAPPEDWINDOW | WS_VISIBLE,
                150, 150, 250, 180, 0, 0, hInstance, 0);
		
  CreateLabels(hwnd);

  while( GetMessage(&msg, NULL, 0, 0)) {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
  }
  return (int) msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, 
    WPARAM wParam, LPARAM lParam)
{

  wchar_t buf[10];
  RECT rect;

  switch(msg)  
  {
    case WM_MOVE:
      GetWindowRect(hwnd, &rect);

      _itow(rect.left, buf, 10);// 把整型值rect.left转换成字符
      SetWindowTextW(hwndSta1, buf); // 更新窗口hwndSta1的标题为buf  ------(1)

      _itow(rect.top, buf, 10);
      SetWindowTextW(hwndSta2, buf);

      break;

    case WM_DESTROY:
      PostQuitMessage(0);
      break; 
  }

  return DefWindowProcW(hwnd, msg, wParam, lParam);
}

void CreateLabels(HWND hwnd){

  CreateWindowW(L"static", L"x: ",
      WS_CHILD | WS_VISIBLE,
      10, 10, 25, 25, 
      hwnd, (HMENU) 1, NULL, NULL);

  hwndSta1 = CreateWindowW(L"static", L"150", // 150 会被更新----------(1)
      WS_CHILD | WS_VISIBLE,
      40, 10, 55, 25, 
      hwnd, (HMENU) 2, NULL, NULL);

  CreateWindowW(L"static", L"y: ",
      WS_CHILD | WS_VISIBLE,
      10, 30, 25, 25, 
      hwnd, (HMENU) 3, NULL, NULL);

  hwndSta2 = CreateWindowW(L"static", L"150",
      WS_CHILD | WS_VISIBLE,
      40, 30, 55, 25, 
      hwnd, (HMENU) 4, NULL, NULL);
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值