zoukankan      html  css  js  c++  java
  • Create Window

    //.H

    #pragma once
    #include <Windows.h>

    LRESULT CALLBACK CaliperProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); //window procedure
    class CCaliperPage
    {
    public:
    //friend elements:
    friend LRESULT CALLBACK CaliperProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);

    CCaliperPage(HWND parentWnd, RECT rc);
    ~CCaliperPage();

    HWND GetParentWnd();
    HWND GetWnd();

    private:
    HWND m_hWndParent;
    HWND m_hWnd;

    void PaintPage(CDC * a_pDC);
    void LeftBtnDown(CPoint point);
    void LeftBtnUp(CPoint point);

    };

     

    #include "stdafx.h"
    #include "CaliperPage.h"

    static CCaliperPage* g_CaliperPage = NULL;

    LRESULT CALLBACK CaliperProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {

    switch (message)
    {
    case WM_PAINT:
    {
    PAINTSTRUCT ps;
    HDC hdc;
    hdc = BeginPaint(hWnd, &ps);
    CDC * pDC = new CDC;
    pDC->Attach(hdc);
    g_CaliperPage->PaintPage(pDC);
    pDC->DeleteDC();
    delete pDC;
    EndPaint(hWnd, &ps);
    }
    break;
    case WM_LBUTTONDOWN:
    {
    int xPos = GET_X_LPARAM(lParam);
    int yPos = GET_Y_LPARAM(lParam);
    g_CaliperPage->LeftBtnDown(CPoint(xPos,yPos));
    }
    break;
    case WM_LBUTTONUP:
    {
    int xPos = GET_X_LPARAM(lParam);
    int yPos = GET_Y_LPARAM(lParam);
    g_CaliperPage->LeftBtnUp(CPoint(xPos, yPos));
    }
    break;
    default:
    return DefWindowProc(hWnd, message, wParam, lParam);
    break;
    }
    return TRUE; //if not return true createwindow fail

    }

    CCaliperPage::CCaliperPage(HWND parentWnd, RECT rc)
    {
    m_hWndParent = parentWnd;

    //register window class
    WNDCLASSEX wcex;
    wcex.cbSize = sizeof(WNDCLASSEX);
    wcex.style = CS_HREDRAW | CS_VREDRAW;
    wcex.lpfnWndProc = CaliperProc;
    wcex.cbClsExtra = 0;
    wcex.cbWndExtra = 0;
    wcex.hInstance = NULL;
    wcex.hIcon = NULL;
    wcex.hCursor = LoadCursor(NULL,IDC_ARROW);
    wcex.hbrBackground = (HBRUSH)GetStockObject(HOLLOW_BRUSH);
    wcex.lpszMenuName = NULL;
    wcex.lpszClassName = _T("CaliperWindowClass");
    wcex.hIconSm = NULL;
    RegisterClassEx(&wcex);

    //create window:
    m_hWnd = CreateWindowEx(WS_EX_TRANSPARENT, _T("CaliperWindowClass"), NULL, (WS_POPUP | WS_VISIBLE), rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top,
    m_hWndParent,NULL,NULL,NULL);
    if (NULL == m_hWnd)
    {
    DWORD errID = GetLastError();
    m_hWndParent = NULL;
    }
    RegisterTouchWindow(m_hWnd, TWF_WANTPALM);   //D "WINVER=0x0601" 

    g_CaliperPage = this;
    }
    CCaliperPage::~CCaliperPage()
    {

    if (NULL != m_hWnd)
    {
    //UnregisterTouchWindow(m_hWnd);
    DestroyWindow(m_hWnd);
    g_CaliperPage = NULL;
    }

    }

    HWND CCaliperPage::GetParentWnd()
    {
    return m_hWndParent;
    }
    HWND CCaliperPage::GetWnd()
    {
    return m_hWnd;
    }

    ///////////////////////////////////////////

    //不占用焦点
    SetWindowLong(m_hWnd, GWL_EXSTYLE, 0x08000000L | GetWindowLong(m_hWnd, GWL_EXSTYLE));

    SetWindowPos(m_hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);

  • 相关阅读:
    学习redis-安装和基本一些命令
    Eclipse启动报错Java was started but returned exit code=13
    踩过的坑系列之InputStream.read(byte[])方法
    <<深入Java虚拟机>>-虚拟机类加载机制-学习笔记
    <<深入Java虚拟机>>-第三章-垃圾收集器与内存分配策略-学习笔记
    <<深入Java虚拟机>>-第二章-Java内存区域-学习笔记
    创建线程的两种方式比较Thread VS Runnable
    Java设计模式之--代理模式学习
    shell脚本中$参数的介绍
    (转)使用DataTime这个类来获取当前的时间
  • 原文地址:https://www.cnblogs.com/waterair/p/7094898.html
Copyright © 2011-2022 走看看