source: dev/ProjectEditor/Ruler.cpp@ 103

Last change on this file since 103 was 24, checked in by dai_9181, 18 years ago

保存されていないドキュメントのタブに(*)をつける機能に対応。
MDITEXTEDITINFOをCMdiTextEditに変更。今後、オブジェクト指向化を進める。

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