1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
// Drawer.cpp*: définit le point d'entrée pour l'application.
//
#include "stdafx.h"
BOOL Drawer::Create(TMainFrame* pMainFrame)
{
// classe de fenêtre
TCHAR szWndClass[] = _T("Paint_ChildView");
// initialisation classe de fenêtre
WNDCLASS wc;
ZeroMemory(&wc, sizeof(WNDCLASS));
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.hInstance = pMainFrame->GetProgramme()->GetHInst();
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.lpszClassName = szWndClass;
// enregistrement classe de fenêtre
if(!RegisterClass(&wc))
return FALSE;
this->_hParent = pMainFrame->getHSelf();
_hSelf = CreateWindowEx(0, szWndClass, NULL, WS_CHILD,
0, 0, 0, 0, pMainFrame->getHSelf(), NULL, pMainFrame->GetProgramme()->GetHInst(), this);
return (_hSelf != NULL);
}
LRESULT CALLBACK Drawer::WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
// affecter l'objet Drawer lors de la création de la vue, contenu dans la
// structure CREATESTRUCT pointée par lParam
if(msg == WM_CREATE)
{
LPCREATESTRUCT lpcs = (LPCREATESTRUCT) lParam;
SetWindowLong(hWnd, GWL_USERDATA, (LONG)lpcs->lpCreateParams);
}
// récupération objet Drawer associé à la fenêtre
Drawer* pWnd = (Drawer*) GetWindowLong(hWnd, GWL_USERDATA);
if(!pWnd)
return DefWindowProc(hWnd, msg, wParam, lParam);
// en fonction du message
switch(msg)
{
case WM_MOUSEMOVE : return pWnd->MsgMouseMove (wParam, lParam);
default : return FALSE;
}
}
LRESULT Drawer::MsgMouseMove (WPARAM wParam, LPARAM lParam)
{
POINT point;
PAINTSTRUCT ps;
HDC hdc= BeginPaint(_hSelf,&ps);
TCHAR bf2[5];
TCHAR bf1[5];
GetCursorPos(&point);
ScreenToClient(_hSelf,&point);
_itow_s(point.x,bf1,5,10);
_itow_s(point.y,bf2,5,10);
TCHAR aText[MAX_LOADSTRING] =TEXT("Coordonnée cliente :");
wcscat(aText,bf1);
wcscat(aText,TEXT(","));
wcscat(aText,bf2);
SetWindowText(this->getHParent(),aText);
MoveToEx(hdc,0,0,NULL);
LineTo(hdc,point.x,point.y);
EndPaint(this->getHSelf(), &ps);
return 0;
}
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
Programme Apps;
if(Apps.Init(hInstance,nCmdShow))
return Apps.Run();
else return 0;
} |
Partager