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

  • 相关阅读:
    Homework template (latex)
    Basic skill of searching
    国庆第三次集训: 2012 ACM-ICPC Asia Regional Contest Chengdu Site
    新学期随笔
    暑期集训感想
    暑期集训 DP 篇
    POJ 1195 Mobile Phones 二维树状数组
    51Nod1246 罐子和硬币,不能均分的题
    一维战舰,一道考区间的好题
    51NOD 1268 和为K的组合 搜索水题
  • 原文地址:https://www.cnblogs.com/waterair/p/7094898.html
Copyright © 2020-2023  润新知