SkinWin.cpp 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127
  1. // SkinWin.cpp: implementation of the CSkinWin class.
  2. //
  3. // A class to enable draw windows-blind style window
  4. //
  5. // ToDo:
  6. // how to popup system menu by my program??
  7. //
  8. // History:
  9. // 2002.11.24
  10. // CAN WORK NOW.
  11. // 2002.11.23 intial version
  12. //
  13. //
  14. //
  15. // AUthor:
  16. // szhao00@mails.tsinghua.edu.cn
  17. //
  18. //////////////////////////////////////////////////////////////////////
  19. #include "stdafx.h"
  20. #include "SkinWin.h"
  21. #ifdef _DEBUG
  22. #undef THIS_FILE
  23. static char THIS_FILE[]=__FILE__;
  24. #define new DEBUG_NEW
  25. #endif
  26. //////////////////////////////////////////////////////////////////////
  27. // Construction/Destruction
  28. //////////////////////////////////////////////////////////////////////
  29. CSkinWin::CSkinWin()
  30. {
  31. m_bInit = FALSE;
  32. m_winstate = 0;
  33. m_barcolor = RGB(207,207,207);
  34. m_menucolor = RGB(207,207,207);
  35. }
  36. CSkinWin::~CSkinWin()
  37. {
  38. }
  39. CString GetPathName( const char * filename );
  40. CString GetFileName( const char * filename, int ext = 0);
  41. char *next_token( char *buf, char *token, char *stopchars );
  42. COLORREF ReadColor( CString section, CString key, CString file, COLORREF defcolor )
  43. {
  44. char buf[1000];
  45. GetPrivateProfileString( section, key, "", buf, 1000, file );
  46. if ( *buf )
  47. {
  48. char token[255];
  49. char *p = buf;
  50. int r, g, b;
  51. p = next_token( p, token, NULL );
  52. r = atoi(token);
  53. p = next_token( p, token, NULL );
  54. g = atoi(token);
  55. p = next_token( p, token, NULL );
  56. b = atoi(token);
  57. return RGB(r, g, b );
  58. }
  59. else
  60. return defcolor;
  61. }
  62. BOOL CSkinWin::LoadSkin( const char * skinfile )
  63. {
  64. static const char * ps = "Personality";
  65. char buf[1000];
  66. CString path = GetPathName( skinfile );
  67. if ( m_bInit )
  68. {
  69. m_bmpDlg.DeleteObject();
  70. m_bmpTitle.DeleteObject();
  71. m_bmpLeft.DeleteObject();
  72. m_bmpRight.DeleteObject();
  73. m_bmpBottom.DeleteObject();
  74. m_bmpMaxBtn.DeleteObject();
  75. m_bmpRestoreBtn.DeleteObject();
  76. m_bmpMinBtn.DeleteObject();
  77. m_bmpCloseBtn.DeleteObject();
  78. //set deafult
  79. m_barcolor = RGB(207,207,207);
  80. m_menucolor = RGB(207,207,207);
  81. m_bInit = FALSE;
  82. }
  83. GetPrivateProfileString( ps, "DialogBmp", "", buf, 1000, skinfile );
  84. if ( *buf != 0 )
  85. m_bmpDlg.LoadBitmap( path + "/" + GetFileName( buf,1 ));
  86. GetPrivateProfileString( ps, "Top", "", buf, 1000, skinfile );
  87. if ( *buf == 0 || !m_bmpTitle.LoadBitmap( path + "/" + GetFileName( buf,1 )) )
  88. return FALSE;
  89. GetPrivateProfileString( ps, "Left", "", buf, 1000, skinfile );
  90. if ( *buf == 0 || !m_bmpLeft.LoadBitmap( path + "/" + GetFileName( buf,1 ) ))
  91. return FALSE;
  92. GetPrivateProfileString( ps, "Right", "", buf, 1000, skinfile );
  93. if ( *buf == 0 || !m_bmpRight.LoadBitmap( path + "/" + GetFileName( buf,1 ) ))
  94. return FALSE;
  95. GetPrivateProfileString( ps, "Bottom", "", buf, 1000, skinfile );
  96. if ( *buf == 0 || !m_bmpBottom.LoadBitmap( path + "/" + GetFileName( buf,1 ) ))
  97. return FALSE;
  98. m_TitleHeight = m_bmpTitle.Height()/2;
  99. m_BorderLeftWidth = m_bmpLeft.Width()/2;
  100. m_BorderRightWidth = m_bmpRight.Width()/2;
  101. m_BorderBottomHeight = m_bmpBottom.Height()/2;
  102. m_titleoff1 = GetPrivateProfileInt( ps, "TopTopHeight", 0, skinfile );
  103. m_titleoff2 = m_bmpTitle.Width() - GetPrivateProfileInt( ps, "TopBotHeight", 0, skinfile );
  104. if ( m_titleoff2 <= m_titleoff1 )
  105. m_titleoff2 = m_titleoff1 + 1;
  106. m_leftoff1 = GetPrivateProfileInt( ps, "LeftTopHeight", 0, skinfile );
  107. m_leftoff2 = m_bmpLeft.Height() - GetPrivateProfileInt( ps, "LeftBotHeight", 0, skinfile );
  108. if ( m_leftoff2 <= m_leftoff1 )
  109. m_leftoff2 = m_leftoff1 + 1;
  110. m_rightoff1 = GetPrivateProfileInt( ps, "RightTopHeight", 0, skinfile );
  111. m_rightoff2 = m_bmpRight.Height() - GetPrivateProfileInt( ps, "RightBotHeight", 0, skinfile );
  112. if ( m_rightoff2 <= m_rightoff1 )
  113. m_rightoff2 = m_rightoff1 + 1;
  114. m_bottomoff1 = GetPrivateProfileInt( ps, "BottomTopHeight", 0, skinfile );
  115. m_bottomoff2 = m_bmpBottom.Width() - GetPrivateProfileInt( ps, "BottomBotHeight", 0, skinfile );
  116. if ( m_bottomoff2 <= m_bottomoff1 )
  117. m_bottomoff2 = m_bottomoff1 + 1;
  118. //load buttons
  119. int count = GetPrivateProfileInt( ps, "ButtonCount", 0, skinfile );
  120. int icount = GetPrivateProfileInt( ps, "ButtonImgCount", 3, skinfile );
  121. for ( int i = 0; i < count; i++ )
  122. {
  123. CString sec;
  124. sec.Format( "Button%d", i );
  125. GetPrivateProfileString( sec, "ButtonImage", "", buf, 1000, skinfile );
  126. int action = GetPrivateProfileInt( sec, "Action", 0, skinfile );
  127. int x = GetPrivateProfileInt( sec, "XCoord", 0, skinfile );
  128. int y = GetPrivateProfileInt( sec, "YCoord", 0, skinfile );
  129. int state = icount;
  130. if ( action == 0 )
  131. {
  132. //close
  133. if ( !m_bmpCloseBtn.LoadBitmap( path + "/" + GetFileName( buf,1 )) )
  134. return FALSE;
  135. //state = m_bmpCloseBtn.Width()/m_bmpCloseBtn.Height();
  136. m_rectCloseBtn = CRect( x-m_bmpCloseBtn.Width()/state, y, x , y + m_bmpCloseBtn.Height() );
  137. }
  138. if ( action == 2 )
  139. {
  140. //min
  141. if ( !m_bmpMinBtn.LoadBitmap( path + "/" + GetFileName( buf,1 )) )
  142. return FALSE;
  143. //state = m_bmpMinBtn.Width()/m_bmpMinBtn.Height();
  144. m_rectMinBtn = CRect( x-m_bmpMinBtn.Width()/state, y, x, y + m_bmpMinBtn.Height() );
  145. }
  146. if ( action == 1 )
  147. {
  148. if ( !m_bmpMaxBtn.GetSafeHandle() )
  149. {
  150. //max
  151. if ( !m_bmpMaxBtn.LoadBitmap( path + "/" + GetFileName( buf,1 )) )
  152. return FALSE;
  153. //state = m_bmpMaxBtn.Width()/m_bmpMaxBtn.Height();
  154. m_rectMaxBtn = CRect( x-m_bmpMaxBtn.Width()/state, y, x , y + m_bmpMaxBtn.Height() );
  155. }
  156. else
  157. {
  158. //restore
  159. if ( !m_bmpRestoreBtn.LoadBitmap( path + "/" + GetFileName( buf,1 )) )
  160. return FALSE;
  161. //state = m_bmpRestoreBtn.Width()/m_bmpRestoreBtn.Height();
  162. m_rectRestoreBtn = CRect( x-m_bmpRestoreBtn.Width()/state, y, x , y + m_bmpRestoreBtn.Height() );
  163. }
  164. }
  165. if ( action == 4 )
  166. {
  167. }
  168. }
  169. m_textShift = GetPrivateProfileInt( ps, "TextShift", 0, skinfile );
  170. m_textShiftVer = GetPrivateProfileInt( ps, "TextShiftVert", 0, skinfile );
  171. char * colours = "Colours";
  172. m_colTitle1 = ReadColor(colours, "TitleText", skinfile, GetSysColor(COLOR_CAPTIONTEXT) );
  173. m_colTitle2 = ReadColor(colours, "InactiveTitleText", skinfile, GetSysColor(COLOR_CAPTIONTEXT) );
  174. m_bTrans = GetPrivateProfileInt( ps, "UsesTran", 0, skinfile );
  175. if ( m_bTrans )
  176. m_colTrans = ReadColor(colours, "TransColor", skinfile, RGB(255,0,255) );
  177. m_barcolor = ReadColor(colours, "BarColor", skinfile, RGB(207,207,207) );
  178. m_menucolor = ReadColor(colours, "MenuColor", skinfile, RGB(207,207,207) );
  179. m_btnbgcolor = ReadColor(colours, "ButtonFace", skinfile, GetSysColor(COLOR_BTNFACE) );
  180. m_btntextcolor = ReadColor(colours, "ButtonText", skinfile, GetSysColor(COLOR_BTNTEXT));
  181. m_btnhovercolor = ReadColor(colours, "ButtonHilight", skinfile, GetSysColor(COLOR_BTNFACE) );
  182. m_btnfocuscolor = ReadColor(colours, "ButtonFocus", skinfile, GetSysColor(COLOR_BTNFACE) );
  183. m_bInit = TRUE;
  184. return TRUE;
  185. }
  186. BOOL CSkinWin::DrawTitle(CDC *pDC, int x, int y, int w, int state)
  187. {
  188. int padding;
  189. int ox = x;
  190. padding = ( w - m_bmpTitle.Width() )/( m_titleoff2 - m_titleoff1 ) + 1 ;
  191. if ( padding < 0 ) padding = 0;
  192. RECT sr;
  193. if ( state == 0 )
  194. sr = CRect( 0, 0, m_titleoff1, m_TitleHeight );
  195. else
  196. sr = CRect( 0, m_TitleHeight, m_titleoff1, m_bmpTitle.Height() );
  197. m_bmpTitle.Draw( pDC, x, y, &sr );
  198. x += m_titleoff1;
  199. if ( state == 0 )
  200. sr = CRect( m_titleoff1, 0, m_titleoff2, m_TitleHeight );
  201. else
  202. sr = CRect( m_titleoff1, m_TitleHeight, m_titleoff2, m_bmpTitle.Height() );
  203. for ( int i = 0; i <= padding; i++, x += m_titleoff2 - m_titleoff1 )
  204. {
  205. int d = ( x + m_titleoff2 - m_titleoff1 - ox - w);
  206. if ( d > 0 )
  207. sr.right = sr.right - d;
  208. m_bmpTitle.Draw( pDC, x, y, &sr );
  209. }
  210. x = ox + w - ( m_bmpTitle.Width() - m_titleoff2 ) + 1 ;
  211. if ( state == 0 )
  212. sr = CRect( m_titleoff2, 0, m_bmpTitle.Width()-1, m_TitleHeight);
  213. else
  214. sr = CRect( m_titleoff2, m_TitleHeight, m_bmpTitle.Width()-1, m_bmpTitle.Height() );
  215. m_bmpTitle.Draw( pDC, x, y, &sr );
  216. return TRUE;
  217. }
  218. BOOL CSkinWin::DrawBottom(CDC *pDC, int x, int y, int w, int state)
  219. {
  220. int padding;
  221. int ox = x;
  222. padding = ( w - m_bmpBottom.Width() )/( m_bottomoff2 - m_bottomoff1 ) + 1 ;
  223. if ( padding < 0 ) padding = 0;
  224. RECT sr;
  225. if ( state == 0 )
  226. sr = CRect( 0, 0, m_bottomoff1, m_BorderBottomHeight);
  227. else
  228. sr = CRect( 0, m_BorderBottomHeight, m_bottomoff1, m_bmpBottom.Height() );
  229. m_bmpBottom.Draw( pDC, x, y, &sr );
  230. x += m_bottomoff1;
  231. if ( state == 0 )
  232. sr = CRect( m_bottomoff1, 0, m_bottomoff2, m_BorderBottomHeight );
  233. else
  234. sr = CRect( m_bottomoff1, m_BorderBottomHeight, m_bottomoff2, m_bmpBottom.Height() );
  235. for ( int i = 0; i <= padding; i++, x += m_bottomoff2 - m_bottomoff1 )
  236. {
  237. int d = ( x + m_bottomoff2 - m_bottomoff1 - ox - w);
  238. if ( d > 0 )
  239. sr.right = sr.right - d;
  240. m_bmpBottom.Draw( pDC, x, y, &sr );
  241. }
  242. x = ox + w - ( m_bmpBottom.Width() - m_bottomoff2 );
  243. if ( state == 0 )
  244. sr = CRect( m_bottomoff2, 0, m_bmpBottom.Width()-1, m_BorderBottomHeight );
  245. else
  246. sr = CRect( m_bottomoff2, m_BorderBottomHeight, m_bmpBottom.Width()-1, m_bmpBottom.Height() );
  247. m_bmpBottom.Draw( pDC, x, y, &sr );
  248. return TRUE;
  249. }
  250. BOOL CSkinWin::DrawLeft(CDC *pDC, int x, int y, int h, int state)
  251. {
  252. int padding;
  253. int oy = y;
  254. padding = ( h - m_bmpLeft.Height() )/( m_leftoff2 - m_leftoff1 ) + 1 ;
  255. if ( padding < 0 ) padding = 0;
  256. RECT sr;
  257. if ( state == 0 )
  258. sr = CRect( 0, 0, m_BorderLeftWidth, m_leftoff1 );
  259. else
  260. sr = CRect( m_BorderLeftWidth, 0, m_bmpLeft.Width(), m_leftoff1 );
  261. m_bmpLeft.Draw( pDC, x, y, &sr );
  262. y += m_leftoff1;
  263. if ( state == 0 )
  264. sr = CRect( 0, m_leftoff1, m_BorderLeftWidth, m_leftoff2 );
  265. else
  266. sr = CRect( m_BorderLeftWidth, m_leftoff1, m_bmpLeft.Width(), m_leftoff2 );
  267. for ( int i = 0; i <= padding; i++, y += m_leftoff2 - m_leftoff1 )
  268. {
  269. int d = ( y + m_leftoff2 - m_leftoff1 - oy - h);
  270. if ( d > 0 )
  271. sr.bottom = sr.bottom - d;
  272. m_bmpLeft.Draw( pDC, x, y, &sr );
  273. }
  274. y = oy + h - ( m_bmpLeft.Height() - m_leftoff2 ) ;
  275. if ( state == 0 )
  276. sr = CRect( 0, m_leftoff2, m_BorderLeftWidth, m_bmpLeft.Height());
  277. else
  278. sr = CRect( m_BorderLeftWidth, m_leftoff2, m_bmpLeft.Width(), m_bmpLeft.Height() );
  279. m_bmpLeft.Draw( pDC, x, y, &sr );
  280. return TRUE;
  281. }
  282. BOOL CSkinWin::DrawRight(CDC *pDC, int x, int y, int h, int state)
  283. {
  284. int padding;
  285. int oy = y;
  286. padding = ( h - m_bmpRight.Height() )/( m_rightoff2 - m_rightoff1 ) + 1 ;
  287. if ( padding < 0 ) padding = 0;
  288. RECT sr;
  289. if ( state == 0 )
  290. sr = CRect( 0, 0, m_BorderRightWidth, m_rightoff1 );
  291. else
  292. sr = CRect( m_BorderRightWidth, 0, m_bmpRight.Width(), m_rightoff1 );
  293. m_bmpRight.Draw( pDC, x, y, &sr );
  294. y += m_rightoff1;
  295. if ( state == 0 )
  296. sr = CRect( 0, m_rightoff1, m_BorderRightWidth, m_rightoff2 );
  297. else
  298. sr = CRect( m_BorderRightWidth, m_rightoff1, m_bmpRight.Width(), m_rightoff2 );
  299. for ( int i = 0; i <= padding; i++, y += m_rightoff2 - m_rightoff1 )
  300. {
  301. int d = ( y + m_rightoff2 - m_rightoff1 - oy - h);
  302. if ( d > 0 )
  303. sr.bottom = sr.bottom - d;
  304. m_bmpRight.Draw( pDC, x, y, &sr );
  305. }
  306. y = oy + h - ( m_bmpRight.Height() - m_rightoff2 ) ;
  307. if ( state == 0 )
  308. sr = CRect( 0, m_rightoff2, m_BorderRightWidth, m_bmpRight.Height());
  309. else
  310. sr = CRect( m_BorderRightWidth, m_rightoff2, m_bmpRight.Width(), m_bmpRight.Height() );
  311. m_bmpRight.Draw( pDC, x, y, &sr );
  312. return TRUE;
  313. }
  314. BOOL CSkinWin::DrawFrame(CDC *pDC, int x, int y, int w, int h, int state, int title )
  315. {
  316. if ( title )
  317. DrawTitle( pDC, x + m_BorderLeftWidth , y,
  318. w - m_BorderRightWidth - m_BorderLeftWidth + 1, state );
  319. DrawLeft( pDC, x, y, h, state );
  320. DrawRight( pDC, x + w - m_BorderRightWidth , y, h, state );
  321. DrawBottom( pDC, x + m_BorderLeftWidth,
  322. y + h - m_BorderBottomHeight, w - m_BorderRightWidth - m_BorderLeftWidth, state );
  323. return TRUE;
  324. }
  325. BOOL CSkinWin::InstallSkin(CWnd *wnd)
  326. {
  327. if ( !wnd || !m_bInit ) return FALSE;
  328. HookWindow( (HWND)NULL);
  329. int r = HookWindow( wnd );
  330. DWORD style = GetWindowLong( m_hWnd, GWL_STYLE );
  331. m_sizable = style & WS_SIZEBOX;
  332. m_minable = style & WS_MINIMIZEBOX;
  333. m_maxable = style & WS_MAXIMIZEBOX;
  334. //m_sysmenu = style & WS_MAXIMIZEBOX;
  335. style &= ~(WS_MINIMIZEBOX);
  336. style &= ~WS_MAXIMIZEBOX;
  337. style &= ~WS_SYSMENU;
  338. SetWindowLong( m_hWnd, GWL_STYLE, style );
  339. return r;
  340. }
  341. LRESULT CSkinWin::WindowProc(UINT msg, WPARAM wp, LPARAM lp)
  342. {
  343. if ( !IsWindow(m_hWnd) )
  344. return 0;
  345. if ( !m_bInit )
  346. return Default();
  347. switch ( msg )
  348. {
  349. case WM_SHOWWINDOW:
  350. //call setwindowpos to force OnNcCalcSize when hWnd is a dialog
  351. if ( wp )
  352. SetWindowPos( m_hWnd, 0, 0, 0, 400, 400, SWP_NOSIZE|SWP_NOMOVE|SWP_FRAMECHANGED );
  353. Default();
  354. return 0;
  355. break;
  356. //case WM_ERASEBKGND:
  357. case WM_INITMENUPOPUP:
  358. Default();
  359. return 0;
  360. // return OnEraseBkgnd(CDC::FromHandle((HDC)wp) );
  361. /*
  362. case WM_INITMENU:
  363. //a hack, when popup sysmenu, redraw title bar
  364. HMENU h;
  365. h = (HMENU)wp;
  366. int c;
  367. h = GetSubMenu(h, 0);
  368. c = GetMenuItemID( h, 0 );
  369. if ( c == SC_RESTORE )
  370. {
  371. CRect r;
  372. GetClientRect( m_hWnd, r );
  373. OnNcPaint(0);
  374. r.bottom = GetSystemMetrics(SM_CYCAPTION);
  375. InvalidateRect( m_hWnd, r, TRUE );
  376. UpdateWindow( m_hWnd );
  377. }
  378. Default();
  379. return 0;
  380. */
  381. case WM_SYSCOMMAND:
  382. OnSysCommand( wp, lp );
  383. //Default();
  384. return 0;
  385. case WM_SETTEXT:
  386. return OnSetText( wp, lp );
  387. case WM_NCPAINT:
  388. OnNcPaint( (HRGN)wp );
  389. return 0;
  390. case WM_NCCALCSIZE:
  391. OnNcCalcSize( (BOOL)wp, (NCCALCSIZE_PARAMS *)lp );
  392. return 0;
  393. case WM_SIZE:
  394. OnSize( wp, LOWORD(lp), HIWORD(lp) );
  395. return 0;
  396. case WM_NCACTIVATE:
  397. return OnNcActivate( (BOOL)wp );
  398. case WM_NCHITTEST:
  399. return OnNcHitTest(CPoint(LOWORD(lp), HIWORD(lp)));
  400. case WM_NCLBUTTONUP:
  401. OnNcLButtonUp(wp, CPoint(LOWORD(lp), HIWORD(lp)));
  402. return 0;
  403. case WM_NCLBUTTONDOWN:
  404. OnNcLButtonDown(wp, CPoint(LOWORD(lp), HIWORD(lp)));
  405. return 0;
  406. case WM_NCLBUTTONDBLCLK:
  407. OnNcLButtonDblClk(wp, CPoint(LOWORD(lp), HIWORD(lp)));
  408. return 0;
  409. case WM_NCRBUTTONUP:
  410. OnNcRButtonUp(wp, CPoint(LOWORD(lp), HIWORD(lp)));
  411. return 0;
  412. case WM_NCRBUTTONDOWN:
  413. OnNcRButtonDown(wp, CPoint(LOWORD(lp), HIWORD(lp)));
  414. return 0;
  415. case WM_NCMOUSEMOVE:
  416. OnNcMouseMove( wp,CPoint(LOWORD(lp), HIWORD(lp)));
  417. return 0;
  418. case WM_GETMINMAXINFO:
  419. OnGetMinMaxInfo( (MINMAXINFO *)lp );
  420. return 0;
  421. case WM_WINDOWPOSCHANGING:
  422. OnWindowPosChanging((WINDOWPOS *)lp);
  423. return 0;
  424. case WM_SIZING:
  425. OnSizing( wp, (LPRECT)lp );
  426. return 0;
  427. case WM_ACTIVATE:
  428. OnActivate( wp, CWnd::FromHandle((HWND)lp), 0 );
  429. return 0;
  430. case WM_COMMAND:
  431. if ( !HandleSysCommand( wp, lp ) )
  432. Default();
  433. return 0;
  434. default:
  435. return Default();
  436. }
  437. }
  438. void CSkinWin::OnNcPaint(HRGN rgn1)
  439. {
  440. CWnd *pWnd = CWnd::FromHandle(m_hWnd);
  441. CDC * pDC = pWnd->GetWindowDC();
  442. CRect wr;
  443. pWnd->GetWindowRect( wr );
  444. //f ( (DWORD)rgn)
  445. //pDC->SelectClipRgn( CRgn::FromHandle(rgn) );
  446. //m_bActive = GetActiveWindow() == m_hWnd;
  447. int state = 0;
  448. if ( m_bActive)
  449. state = 0;
  450. else state = 1;
  451. pDC->ExcludeClipRect(0, 0, wr.Width(), m_TitleHeight );
  452. DrawFrame( pDC, 0, 0, wr.Width(), wr.Height(), state, 0 );
  453. pDC->SelectClipRgn( NULL );
  454. CDC memDC, *pNewDC;
  455. CMyBitmap bmp;
  456. CBitmap *obmp;
  457. memDC.CreateCompatibleDC( pDC );
  458. bmp.CreateCompatibleBitmap( pDC, wr.Width(), m_TitleHeight );
  459. obmp = memDC.SelectObject(&bmp);
  460. pNewDC = &memDC;
  461. DrawTitle( pNewDC, m_BorderLeftWidth , 0,
  462. wr.Width() - m_BorderRightWidth - m_BorderLeftWidth + 1, state );
  463. DrawLeft( pNewDC, 0, 0, m_bmpLeft.Height(), state );
  464. DrawRight( pNewDC, wr.Width() - m_BorderRightWidth , 0, m_bmpRight.Height(), state );
  465. CRgn newrgn;
  466. newrgn.CreateRectRgn( 0, 0, wr.Width(), wr.Height() );
  467. if ( m_bTrans )
  468. {
  469. CRgn rgn;
  470. rgn.CreateRectRgn( 0, m_TitleHeight, wr.Width(), wr.Height() );
  471. HRGN hrgn = bmp.CreateRgnFromFile( m_colTrans );
  472. newrgn.CombineRgn( &rgn, CRgn::FromHandle(hrgn), RGN_XOR );
  473. pDC->SelectClipRgn( &newrgn );
  474. }
  475. else
  476. SetWindowRgn( m_hWnd, newrgn, FALSE );
  477. if ( m_downHitTest == HTCLOSE )
  478. DrawButton( pNewDC, 0, 1 );
  479. else if ( m_moveHitTest == HTCLOSE)
  480. DrawButton( pNewDC, 0, 2 );
  481. else
  482. DrawButton( pNewDC, 0, 0 );
  483. if ( m_downHitTest == HTMINBUTTON )
  484. DrawButton( pNewDC, 2, 1 );
  485. else if ( m_moveHitTest == HTMINBUTTON)
  486. DrawButton( pNewDC, 2, 2 );
  487. else
  488. DrawButton( pNewDC, 2, 0 );
  489. if ( m_downHitTest == HTMAXBUTTON )
  490. DrawButton( pNewDC, 1, 1 );
  491. else if ( m_moveHitTest == HTMAXBUTTON)
  492. DrawButton( pNewDC, 1, 2 );
  493. else
  494. DrawButton( pNewDC, 1, 0 );
  495. int cx = GetSystemMetrics(SM_CXSMICON);
  496. int cy = GetSystemMetrics(SM_CYSMICON);
  497. HICON hi = (HICON)SendMessage( m_hWnd, WM_GETICON, ICON_SMALL, 0);
  498. if ( !hi )
  499. {
  500. #ifdef IDR_MAINFRAME
  501. hi = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  502. #endif
  503. }
  504. //draw icon
  505. ::DrawIconEx( pNewDC->GetSafeHdc(), m_BorderLeftWidth, 5, (HICON)
  506. CopyImage( hi, IMAGE_ICON,
  507. cx, cy, 0), cx, cy, 0, 0, DI_NORMAL);
  508. //draw text
  509. if ( m_title.IsEmpty() )
  510. pWnd->GetWindowText(m_title);
  511. if (m_bActive)
  512. pNewDC->SetTextColor( m_colTitle1 );
  513. else
  514. pNewDC->SetTextColor( m_colTitle2 );
  515. CFont font, *ofont;
  516. font.CreatePointFont( GetSystemMetrics(SM_CYSMCAPTION), "System" );
  517. ofont = pNewDC->SelectObject(&font);
  518. pNewDC->SetBkMode(TRANSPARENT);
  519. pNewDC->DrawText( m_title, CRect( m_textShift, m_textShiftVer, wr.Width() - m_bmpTitle.Width() + m_titleoff2,
  520. m_TitleHeight ), DT_SINGLELINE | DT_LEFT | DT_VCENTER | DT_WORD_ELLIPSIS );
  521. pNewDC->SelectObject(&font);
  522. pDC->BitBlt( 0, 0, wr.Width(),
  523. m_TitleHeight, pNewDC, 0, 0, SRCCOPY );
  524. memDC.SelectObject(obmp);
  525. pDC->SelectClipRgn(NULL);
  526. }
  527. void CSkinWin::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS *lpncsp)
  528. {
  529. if ( bCalcValidRects )
  530. {
  531. lpncsp->rgrc[0].left = lpncsp->rgrc[0].left + m_BorderLeftWidth;
  532. lpncsp->rgrc[0].right = lpncsp->rgrc[0].right - m_BorderRightWidth;
  533. lpncsp->rgrc[0].top = lpncsp->rgrc[0].top + m_TitleHeight;
  534. lpncsp->rgrc[0].bottom = lpncsp->rgrc[0].bottom - m_BorderBottomHeight;
  535. lpncsp->rgrc[1] = lpncsp->rgrc[0];
  536. }
  537. else
  538. {
  539. Default();
  540. }
  541. }
  542. void CSkinWin::OnSizing(UINT nSide, LPRECT lpRect)
  543. {
  544. //Default();
  545. CWnd *pWnd = CWnd::FromHandle(m_hWnd);
  546. CRect wr(lpRect);
  547. /*
  548. if ( m_bTrans )
  549. SetWindowRgn( m_hWnd, GetRegion(wr.Width(), wr.Height() ), TRUE );
  550. else
  551. SetWindowRgn( m_hWnd, NULL, TRUE );
  552. */
  553. }
  554. void CSkinWin::OnSize(UINT nType, int cx, int cy)
  555. {
  556. //Default();
  557. CWnd *pWnd = CWnd::FromHandle(m_hWnd);
  558. CRect wr;
  559. Default();
  560. pWnd->GetWindowRect(wr);
  561. pWnd->Invalidate();
  562. OnNcPaint(0);
  563. if ( m_bTrans )
  564. SetWindowRgn( m_hWnd, GetRegion(wr.Width(), wr.Height() ), TRUE );
  565. else
  566. SetWindowRgn( m_hWnd, NULL, TRUE );
  567. }
  568. HRGN CSkinWin::GetRegion(int w, int h)
  569. {
  570. CWnd *pWnd = CWnd::FromHandle(m_hWnd);
  571. CRect wr;
  572. pWnd->GetWindowRect(wr);
  573. CRgn rgn;
  574. if ( m_bTrans )
  575. {
  576. CDC *pDC = pWnd->GetDC();
  577. CDC memDC;
  578. CMyBitmap bmp;
  579. CBitmap *obmp;
  580. memDC.CreateCompatibleDC(pDC);
  581. bmp.CreateCompatibleBitmap( pDC, w, m_TitleHeight );
  582. obmp = memDC.SelectObject(&bmp);
  583. /*
  584. memDC.FillSolidRect( 0, 0, w, h, 0 );
  585. DrawFrame( &memDC, 0, 0, w, h, 0 );
  586. */
  587. DrawTitle( &memDC, m_BorderLeftWidth , 0,
  588. wr.Width() - m_BorderRightWidth - m_BorderLeftWidth + 1, 0 );
  589. DrawLeft( &memDC, 0, 0, m_bmpLeft.Height(), 0 );
  590. DrawRight( &memDC, wr.Width() - m_BorderRightWidth , 0, m_bmpRight.Height(), 0 );
  591. memDC.SelectObject(obmp);
  592. pWnd->ReleaseDC( pDC );
  593. rgn.CreateRectRgn( 0, m_TitleHeight, wr.Width(), wr.Height() );
  594. HRGN hrgn = bmp.CreateRgnFromFile( m_colTrans );
  595. CRgn newrgn;
  596. newrgn.CreateRectRgn( 0, m_TitleHeight, wr.Width(), wr.Height() );
  597. newrgn.CombineRgn( &rgn, CRgn::FromHandle(hrgn), RGN_XOR );
  598. return (HRGN)newrgn.Detach();
  599. }
  600. else
  601. rgn.CreateRectRgn( 0, 0, wr.Width(), wr.Height() );
  602. return (HRGN)rgn.Detach();
  603. }
  604. BOOL CSkinWin::OnNcActivate(BOOL bActive)
  605. {
  606. m_bActive = bActive;
  607. OnNcPaint(0);
  608. if ( !bActive )
  609. {
  610. return 1;
  611. }
  612. else
  613. return 0;
  614. }
  615. UINT CSkinWin::OnNcHitTest(CPoint point)
  616. {
  617. CWnd *pWnd = CWnd::FromHandle(m_hWnd);
  618. CRect wr;
  619. pWnd->GetWindowRect(wr);
  620. point.x -= wr.left;
  621. point.y -= wr.top;
  622. if ( PtInRect( GetButtonRect(0), point ) )
  623. return HTCLOSE;
  624. if ( PtInRect( GetButtonRect(2), point ) && m_minable )
  625. return HTMINBUTTON;
  626. if ( PtInRect( GetButtonRect(1), point ) && m_maxable )
  627. return HTMAXBUTTON;
  628. CRect r;
  629. int cx = GetSystemMetrics(SM_CXSMICON);
  630. int cy = GetSystemMetrics(SM_CYSMICON);
  631. if ( PtInRect( CRect(m_BorderLeftWidth, 5, m_BorderLeftWidth + cx, cy + 5), point ) )
  632. return HTSYSMENU;
  633. r = CRect( 0, 0, m_BorderLeftWidth, m_TitleHeight );
  634. if ( PtInRect( r, point ) && m_sizable && m_winstate != 1 ) //!IsZoomed(m_hWnd) )
  635. return HTTOPLEFT;
  636. r = CRect( wr.Width() - m_BorderLeftWidth, 0, wr.Width(), m_TitleHeight );
  637. if ( PtInRect( r, point ) && m_sizable && m_winstate != 1 ) //!IsZoomed(m_hWnd) )
  638. return HTTOPRIGHT;
  639. r = CRect( 0, wr.Height() - m_BorderBottomHeight, m_BorderLeftWidth, wr.Height() );
  640. if ( PtInRect( r, point ) && m_sizable && m_winstate != 1 ) //!IsZoomed(m_hWnd) )
  641. return HTBOTTOMLEFT;
  642. r = CRect( wr.Width()-m_BorderRightWidth, wr.Height() - m_BorderBottomHeight, wr.Width(), wr.Height() );
  643. if ( PtInRect( r, point ) && m_sizable && m_winstate != 1 ) //!IsZoomed(m_hWnd) )
  644. return HTBOTTOMRIGHT;
  645. r = CRect( 0, m_TitleHeight, m_BorderLeftWidth, wr.Height() - m_BorderBottomHeight );
  646. if ( PtInRect( r, point ) && m_sizable && m_winstate != 1 ) //!IsZoomed(m_hWnd) )
  647. return HTLEFT;
  648. r = CRect( wr.Width()-m_BorderRightWidth, m_TitleHeight, wr.Width(), wr.Height() - m_BorderBottomHeight );
  649. if ( PtInRect( r, point ) && m_sizable && m_winstate != 1 ) //!IsZoomed(m_hWnd) )
  650. return HTRIGHT;
  651. r = CRect( m_BorderLeftWidth, wr.Height() - m_BorderBottomHeight, wr.Width()-m_BorderRightWidth, wr.Height() );
  652. if ( PtInRect( r, point ) && m_sizable && m_winstate != 1 ) //!IsZoomed(m_hWnd) )
  653. return HTBOTTOM;
  654. r = CRect( m_BorderLeftWidth, 0, wr.Width()-m_BorderRightWidth, m_BorderBottomHeight );
  655. if ( PtInRect( r, point ) && m_sizable && m_winstate != 1 ) //!IsZoomed(m_hWnd) )
  656. return HTTOP;
  657. //set to boder 5
  658. r = CRect( m_BorderLeftWidth, 5 , wr.Width()-m_BorderRightWidth, m_TitleHeight );
  659. if ( PtInRect( r, point ) )
  660. return HTCAPTION;
  661. return HTCLIENT;
  662. }
  663. void CSkinWin::OnNcLButtonDblClk(UINT nHitTest, CPoint point)
  664. {
  665. if ( nHitTest == HTCAPTION && m_sizable )
  666. {
  667. if ( m_winstate == 1 )
  668. Restore();
  669. else
  670. Maximize(); //ShowWindow(m_hWnd, SW_MAXIMIZE);
  671. m_downHitTest = 0;
  672. m_moveHitTest = 0;
  673. OnNcPaint(0);
  674. }
  675. }
  676. void CSkinWin::OnNcLButtonDown(UINT nHitTest, CPoint point)
  677. {
  678. m_downHitTest = nHitTest;
  679. m_moveHitTest = m_downHitTest;
  680. OnNcPaint(0);
  681. if ( nHitTest >= HTLEFT && nHitTest <= HTBOTTOMRIGHT ||
  682. nHitTest == HTCAPTION && m_winstate != 1 ) //!IsZoomed(m_hWnd) )
  683. Default();
  684. else if ( nHitTest == HTSYSMENU )
  685. {
  686. PopupSysMenu(point);
  687. /*
  688. CWnd * pWnd = CWnd::FromHandle(m_hWnd);
  689. //a tricky hack
  690. pWnd->ModifyStyle( 0, WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX );
  691. Default();
  692. pWnd->ModifyStyle( WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX, 0 );
  693. */
  694. }
  695. }
  696. void CSkinWin::OnNcLButtonUp(UINT nHitTest, CPoint point)
  697. {
  698. if ( nHitTest == HTCLOSE )
  699. {
  700. SendMessage(m_hWnd, WM_CLOSE, 0, 0);
  701. return;
  702. }
  703. else if ( nHitTest == HTMINBUTTON )
  704. Minimize();
  705. else if ( nHitTest == HTMAXBUTTON )
  706. {
  707. if ( m_winstate == 1 ) // IsZoomed(m_hWnd) )
  708. Restore(); //ShowWindow(m_hWnd, SW_RESTORE);
  709. else
  710. Maximize(); //ShowWindow(m_hWnd, SW_MAXIMIZE);
  711. }
  712. else
  713. return;
  714. m_downHitTest = 0;
  715. m_moveHitTest = 0;
  716. OnNcPaint(0);
  717. }
  718. void CSkinWin::OnNcMouseMove(UINT nHitTest, CPoint point)
  719. {
  720. if ( nHitTest >= HTLEFT && nHitTest <= HTBOTTOMRIGHT ||
  721. nHitTest == HTCAPTION && m_winstate != 1 ) //!IsZoomed(m_hWnd) )
  722. Default();
  723. m_moveHitTest = nHitTest;
  724. m_downHitTest = 0;
  725. if ( m_oldHitTest != nHitTest )
  726. {
  727. /*
  728. CRect r;
  729. r = GetButtonRect(0);
  730. r.UnionRect( r, GetButtonRect(1) );
  731. r.UnionRect( r, GetButtonRect(2) );
  732. CRgn rgn;
  733. rgn.CreateRectRgn( r.left, r.top, r.right, r.bottom );
  734. */
  735. OnNcPaint(0);
  736. m_oldHitTest = nHitTest;
  737. }
  738. }
  739. void CSkinWin::OnNcRButtonDown(UINT nHitTest, CPoint point)
  740. {
  741. if ( nHitTest == HTCAPTION )
  742. {
  743. /*
  744. CWnd * pWnd = CWnd::FromHandle(m_hWnd);
  745. pWnd->ModifyStyle( 0, WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX );
  746. Default();
  747. pWnd->ModifyStyle( WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX, 0 );
  748. */
  749. PopupSysMenu(point);
  750. }
  751. }
  752. void CSkinWin::OnNcRButtonUp(UINT nHitTest, CPoint point)
  753. {
  754. }
  755. CRect CSkinWin::GetButtonRect(int i)
  756. {
  757. CWnd *pWnd = CWnd::FromHandle(m_hWnd);
  758. CRect wr;
  759. pWnd->GetWindowRect(wr);
  760. CRect r;
  761. if ( i == 0 && m_bmpCloseBtn.GetSafeHandle() )
  762. {
  763. //close
  764. r = m_rectCloseBtn;
  765. r.left = wr.Width() - m_rectCloseBtn.right;
  766. r.right = wr.Width() - m_rectCloseBtn.left;
  767. }
  768. if ( i == 1 && m_bmpMaxBtn.GetSafeHandle())
  769. {
  770. //max
  771. if ( m_winstate != 1 || !m_bmpRestoreBtn.GetSafeHandle() )
  772. {
  773. r = m_rectMaxBtn;
  774. r.left = wr.Width() - m_rectMaxBtn.right;
  775. r.right = wr.Width() - m_rectMaxBtn.left;
  776. }
  777. else
  778. {
  779. r = m_rectRestoreBtn;
  780. r.left = wr.Width() - m_rectRestoreBtn.right;
  781. r.right = wr.Width() - m_rectRestoreBtn.left;
  782. }
  783. }
  784. if ( i == 2 && m_bmpMinBtn.GetSafeHandle())
  785. {
  786. //min
  787. r = m_rectMinBtn;
  788. r.left = wr.Width() - m_rectMinBtn.right;
  789. r.right = wr.Width() - m_rectMinBtn.left;
  790. }
  791. return r;
  792. }
  793. BOOL CSkinWin::DrawButton( CDC * pDC, int i, int state)
  794. {
  795. if ( i == 0 )
  796. {
  797. if ( m_bmpCloseBtn.GetSafeHandle() )
  798. {
  799. CRect r = GetButtonRect(0);
  800. m_bmpCloseBtn.Draw( pDC, r.left, r.top,
  801. CRect( state * r.Width(), 0, (state + 1 ) * r.Width(), m_bmpCloseBtn.Height() ), m_colTrans, m_bTrans );
  802. }
  803. }
  804. if ( i == 1 )
  805. {
  806. CRect r = GetButtonRect(1);
  807. if ( m_maxable && m_bmpMaxBtn.GetSafeHandle() )
  808. if ( m_winstate == 1&& m_bmpRestoreBtn.GetSafeHandle() )
  809. m_bmpRestoreBtn.Draw( pDC, r.left, r.top,
  810. CRect( state * r.Width(), 0, (state + 1 ) * r.Width(), m_bmpCloseBtn.Height() ), m_colTrans, m_bTrans );
  811. else
  812. m_bmpMaxBtn.Draw( pDC, r.left, r.top,
  813. CRect( state * r.Width(), 0, (state + 1 ) * r.Width(), m_bmpCloseBtn.Height() ) , m_colTrans, m_bTrans);
  814. }
  815. if ( i == 2 )
  816. {
  817. if ( m_minable && m_bmpMinBtn.GetSafeHandle() )
  818. {
  819. CRect r = GetButtonRect(2);
  820. m_bmpMinBtn.Draw( pDC, r.left, r.top,
  821. CRect( state * r.Width(), 0, (state + 1 ) * r.Width(), m_bmpCloseBtn.Height() ) , m_colTrans, m_bTrans);
  822. }
  823. }
  824. return TRUE;
  825. }
  826. void CSkinWin::OnGetMinMaxInfo(MINMAXINFO *lpMMI)
  827. {
  828. lpMMI->ptMinTrackSize = CPoint( m_bmpTitle.Width() + m_bmpLeft.Width() +
  829. m_bmpRight.Width(), m_bmpLeft.Height() + 20 );
  830. }
  831. void CSkinWin::OnWindowPosChanging(WINDOWPOS *lpwndpos)
  832. {
  833. }
  834. BOOL CSkinWin::OnEraseBkgnd(CDC *pDC)
  835. {
  836. if ( m_bmpDlg.GetSafeHandle() )
  837. {
  838. CRect r;
  839. GetClientRect( m_hWnd, r);
  840. for ( int i = 0; i < r.Width()/m_bmpDlg.Width() + 1; i++ )
  841. for ( int j = 0; j < r.Height()/m_bmpDlg.Height() + 1; j++ )
  842. {
  843. m_bmpDlg.Draw( pDC, CRect( i * m_bmpDlg.Width(), j * m_bmpDlg.Height(),
  844. i * m_bmpDlg.Width() + m_bmpDlg.Width(), j * m_bmpDlg.Height() + m_bmpDlg.Height() ) );
  845. }
  846. return TRUE;
  847. }
  848. else
  849. return FALSE;
  850. }
  851. CRect CSkinWin::GetMaximizeRect()
  852. {
  853. CRect r;
  854. SystemParametersInfo(SPI_GETWORKAREA, 0, r, 0);
  855. return r;
  856. }
  857. BOOL CSkinWin::Maximize()
  858. {
  859. CRect r = GetMaximizeRect();
  860. GetWindowRect( m_hWnd, m_rectRestoreWin );
  861. m_winstate = 1;
  862. ::MoveWindow( m_hWnd, r.left, r.top, r.Width(), r.Height(), TRUE );
  863. UpdateWindow( m_hWnd );
  864. return TRUE;
  865. }
  866. BOOL CSkinWin::Minimize()
  867. {
  868. m_oldwinstate = m_winstate;
  869. m_winstate = 2;
  870. ShowWindow(m_hWnd, SW_MINIMIZE);
  871. return TRUE;
  872. }
  873. BOOL CSkinWin::Restore()
  874. {
  875. if ( m_winstate == 1 )
  876. {
  877. ::MoveWindow( m_hWnd, m_rectRestoreWin.left, m_rectRestoreWin.top,
  878. m_rectRestoreWin.Width(), m_rectRestoreWin.Height(), TRUE );
  879. m_winstate = 0;
  880. UpdateWindow( m_hWnd );
  881. }
  882. return TRUE;
  883. }
  884. //void OnActivate(UINT nState,CWnd* pWndOther, BOOL bMinimized );
  885. void CSkinWin::OnActivate(UINT nState, CWnd *pWndOther, BOOL bMinimized)
  886. {
  887. //Default();
  888. m_bActive = ( nState == WA_ACTIVE || nState == WA_CLICKACTIVE );
  889. OnNcActivate(m_bActive);
  890. }
  891. LRESULT CSkinWin::OnSetText(WPARAM wp, LPARAM lp)
  892. {
  893. char * str = ( char *)lp;
  894. Default();
  895. m_title = str;
  896. OnNcPaint(0);
  897. return 0;
  898. }
  899. void CSkinWin::OnSysCommand(UINT nID, LPARAM lParam)
  900. {
  901. if ( nID == SC_MAXIMIZE )
  902. Maximize();
  903. else if ( nID == SC_RESTORE && m_winstate == 1 )
  904. Restore();
  905. else if ( nID == SC_RESTORE && m_winstate == 2 )
  906. {
  907. ShowWindow( m_hWnd, SW_RESTORE );
  908. m_winstate = m_oldwinstate;
  909. OnNcPaint(0);
  910. }
  911. else
  912. Default();
  913. }
  914. BOOL CSkinWin::PopupSysMenu(CPoint point)
  915. {
  916. CWnd * pWnd = CWnd::FromHandle(m_hWnd);
  917. CMenu SysMenu;
  918. SysMenu.Attach( GetSystemMenu(m_hWnd, FALSE) );
  919. /*
  920. when gray menuitem, a strange line appears!!
  921. if ( m_winstate == 0 )
  922. {
  923. SysMenu.EnableMenuItem( SC_MINIMIZE, MF_BYCOMMAND|MF_ENABLED );
  924. SysMenu.EnableMenuItem( SC_MAXIMIZE, MF_BYCOMMAND|MF_ENABLED );
  925. SysMenu.EnableMenuItem( SC_RESTORE, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED );
  926. }
  927. else if ( m_winstate == 1 )
  928. {
  929. SysMenu.EnableMenuItem( SC_MAXIMIZE, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED );
  930. SysMenu.EnableMenuItem( SC_RESTORE, MF_BYCOMMAND|MF_ENABLED );
  931. }
  932. else if ( m_winstate == 2 )
  933. {
  934. SysMenu.EnableMenuItem( SC_MINIMIZE, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED );
  935. SysMenu.EnableMenuItem( SC_RESTORE, MF_BYCOMMAND|MF_ENABLED );
  936. }
  937. */
  938. SysMenu.TrackPopupMenu( 0, point.x, point.y, pWnd );
  939. SysMenu.Detach();
  940. return TRUE;
  941. }
  942. BOOL CSkinWin::HandleSysCommand(WPARAM wp, LPARAM lp)
  943. {
  944. if ( lp == 0 )
  945. {
  946. int i = 0;
  947. CMenu SysMenu;
  948. SysMenu.Attach( GetSystemMenu(m_hWnd, FALSE) );
  949. int count = SysMenu.GetMenuItemCount();
  950. for( i = 0; i < count ; i++ )
  951. if ( SysMenu.GetMenuItemID(i) == wp )
  952. break;
  953. SysMenu.Detach();
  954. if ( i >= count )
  955. return FALSE;
  956. if ( wp == SC_MAXIMIZE )
  957. Maximize();
  958. else if ( wp == SC_MINIMIZE )
  959. Minimize();
  960. else if ( wp == SC_RESTORE && m_winstate == 1 )
  961. Restore();
  962. else if ( wp == SC_RESTORE && m_winstate == 2 )
  963. {
  964. ShowWindow( m_hWnd, SW_RESTORE );
  965. m_winstate = m_oldwinstate;
  966. OnNcPaint(0);
  967. }
  968. else
  969. SendMessage( m_hWnd, WM_SYSCOMMAND, wp, lp );
  970. return TRUE;
  971. }
  972. return FALSE;
  973. }