• 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);

  • 相关阅读:
    如何修炼成某一领域的高手?
    宝宝为什么见生人就哭
    绩效管理
    《管理3.0》读书笔记
    卡特尔16PF性格测试与答案
    管理3.0
    偶感
    Javascript事件总结
    HTML5中与页面显示相关的API
    毕业了五年了--- 人生感想
  • 原文地址:https://www.cnblogs.com/waterair/p/7094898.html
Copyright © 2020-2023  润新知