| 1 | #include "stdafx.h"
|
|---|
| 2 |
|
|---|
| 3 | #include "common.h"
|
|---|
| 4 |
|
|---|
| 5 | LRESULT CALLBACK RulerProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam){
|
|---|
| 6 | switch(message){
|
|---|
| 7 | case WM_PAINT:
|
|---|
| 8 | CRuler *pobj_Ruler;
|
|---|
| 9 | pobj_Ruler=(CRuler *)GetWindowLongPtr(hwnd,GWLP_USERDATA);
|
|---|
| 10 |
|
|---|
| 11 | HDC hdc;
|
|---|
| 12 | PAINTSTRUCT ps;
|
|---|
| 13 | hdc=BeginPaint(hwnd,&ps);
|
|---|
| 14 |
|
|---|
| 15 | pobj_Ruler->draw(hdc);
|
|---|
| 16 |
|
|---|
| 17 | EndPaint(hwnd,&ps);
|
|---|
| 18 | break;
|
|---|
| 19 | }
|
|---|
| 20 | return DefWindowProc(hwnd,message,wParam,lParam);
|
|---|
| 21 | }
|
|---|
| 22 |
|
|---|
| 23 | CRuler::CRuler(HWND hParent,MDIINFO *pMdiInfo)
|
|---|
| 24 | : pMdiInfo( pMdiInfo )
|
|---|
| 25 | {
|
|---|
| 26 | hRulerWnd=CreateWindowEx(0,"Ruler","Ruler",
|
|---|
| 27 | WS_CHILD|WS_CLIPCHILDREN|WS_VISIBLE,
|
|---|
| 28 | 0,0,0,0,
|
|---|
| 29 | hParent,0,hInst,0);
|
|---|
| 30 | SetWindowLongPtr(hRulerWnd,GWLP_USERDATA,(long)this);
|
|---|
| 31 |
|
|---|
| 32 | HDC hdc;
|
|---|
| 33 | hdc=GetDC(hRulerWnd);
|
|---|
| 34 |
|
|---|
| 35 | memdc=CreateCompatibleDC(hdc);
|
|---|
| 36 | hMemBmp=CreateCompatibleBitmap(hdc,ScreenX,HEIGHT_RULER);
|
|---|
| 37 | SelectObject(memdc,hMemBmp);
|
|---|
| 38 |
|
|---|
| 39 | ReleaseDC(hRulerWnd,hdc);
|
|---|
| 40 | }
|
|---|
| 41 | CRuler::~CRuler(){
|
|---|
| 42 | DeleteDC(memdc);
|
|---|
| 43 | DeleteObject(hMemBmp);
|
|---|
| 44 |
|
|---|
| 45 | DestroyWindow(hRulerWnd);
|
|---|
| 46 | }
|
|---|
| 47 |
|
|---|
| 48 | void CRuler::resize(int x,int y,int cx,int cy){
|
|---|
| 49 | MoveWindow(hRulerWnd,x,y,cx,cy,1);
|
|---|
| 50 | }
|
|---|
| 51 | void CRuler::draw(HDC hdc){
|
|---|
| 52 | int i;
|
|---|
| 53 |
|
|---|
| 54 | //スクロールバーによるベースポジションを取得
|
|---|
| 55 | int BaseX,BaseY;
|
|---|
| 56 | BaseX=0;
|
|---|
| 57 | BaseY=0;
|
|---|
| 58 | GetScrollBaseCaretPos(this->pMdiInfo,&BaseX,&BaseY);
|
|---|
| 59 |
|
|---|
| 60 | int iControlTabSpace;
|
|---|
| 61 | iControlTabSpace=this->pMdiInfo->pMdiTextEdit->iWidth_ControlTabSpace;
|
|---|
| 62 |
|
|---|
| 63 | HBRUSH hBrush,hOldBrush;
|
|---|
| 64 | hBrush=CreateSolidBrush(RGB(230,230,230));
|
|---|
| 65 |
|
|---|
| 66 | HPEN hPen,hOldPen;
|
|---|
| 67 | hPen=CreatePen(PS_SOLID,0,RGB(60,60,60));
|
|---|
| 68 |
|
|---|
| 69 | //背景色を塗りつぶす
|
|---|
| 70 | hOldBrush=(HBRUSH)SelectObject(memdc,hBrush);
|
|---|
| 71 | PatBlt(memdc,0,0,ScreenX,HEIGHT_RULER,PATCOPY);
|
|---|
| 72 | SelectObject(memdc,hOldBrush);
|
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 | extern HFONT hRulerFont;
|
|---|
| 76 | HFONT hOldFont;
|
|---|
| 77 | hOldFont=(HFONT)SelectObject(memdc,hRulerFont);
|
|---|
| 78 |
|
|---|
| 79 | hOldPen=(HPEN)SelectObject(memdc,hPen);
|
|---|
| 80 |
|
|---|
| 81 | //ラインを描画
|
|---|
| 82 | extern int font_width;
|
|---|
| 83 | int x;
|
|---|
| 84 | for(x=iControlTabSpace,i=-BaseX;x<ScreenX;x+=font_width,i++){
|
|---|
| 85 | if(i%10==0){
|
|---|
| 86 | MoveToEx(memdc,x,0,NULL);
|
|---|
| 87 | LineTo(memdc,x,HEIGHT_RULER);
|
|---|
| 88 | }
|
|---|
| 89 | else if(i%5==0){
|
|---|
| 90 | MoveToEx(memdc,x,HEIGHT_RULER/2,NULL);
|
|---|
| 91 | LineTo(memdc,x,HEIGHT_RULER);
|
|---|
| 92 | }
|
|---|
| 93 | else{
|
|---|
| 94 | MoveToEx(memdc,x,HEIGHT_RULER-3,NULL);
|
|---|
| 95 | LineTo(memdc,x,HEIGHT_RULER);
|
|---|
| 96 | }
|
|---|
| 97 | }
|
|---|
| 98 |
|
|---|
| 99 | //桁番号を描画
|
|---|
| 100 | char temporary[32];
|
|---|
| 101 | SetBkColor(memdc,RGB(230,230,230));
|
|---|
| 102 | SetTextColor(memdc,RGB(60,60,60));
|
|---|
| 103 | for(x=iControlTabSpace,i=-BaseX;x<ScreenX;x+=font_width,i++){
|
|---|
| 104 | if(i%10==0){
|
|---|
| 105 | sprintf(temporary,"%d",i);
|
|---|
| 106 | TextOut(memdc,x+2,0,temporary,lstrlen(temporary));
|
|---|
| 107 | }
|
|---|
| 108 | }
|
|---|
| 109 |
|
|---|
| 110 | SelectObject(memdc,hOldPen);
|
|---|
| 111 | SelectObject(memdc,hOldFont);
|
|---|
| 112 |
|
|---|
| 113 |
|
|---|
| 114 | //画面に描画
|
|---|
| 115 | BitBlt(hdc,0,0,ScreenX,HEIGHT_RULER,memdc,0,0,SRCCOPY);
|
|---|
| 116 |
|
|---|
| 117 | DeleteObject(hBrush);
|
|---|
| 118 | DeleteObject(hPen);
|
|---|
| 119 | }
|
|---|