Example #1
0
static int processlogstateandvf(HWND hWnd)
{
	HLVITEM hItemSelected;
	LVSUBITEM subitem;
	char findbuff[5]={0};
	char statestr[20]={0};
	char vfstr[20]={0};
	char lastprintstr[80]={0};
	char bottomstr[50]={0};
	HDC mydc;
	int statecode;
	TSHORTKEY tstkey;

	memset(&subitem,0,sizeof(LVSUBITEM));
	memset(findbuff,0,5);
	memset(vfstr,0,20);
	memset(statestr,0,20);
	memset(lastprintstr,0,80);

	hItemSelected=SendMessage(hOneLogWnd,LVM_GETSELECTEDITEM,0,0);
	if (hItemSelected==0){
		return 0;
	}

	subitem.pszText=findbuff;
	subitem.subItem=3;
	SendMessage(hOneLogWnd,LVM_GETSUBITEMTEXT,hItemSelected,(LPARAM)&subitem);
	if ((!gOptions.UserExtendFormat) && subitem.pszText)
	{
		if (findbuff[0]=='F')
		{
#ifdef FACE
			if(gOptions.FaceFunOn && findbuff[1]=='a') //add by caona for face
			{
				sprintf(vfstr,"%c%c:%s",findbuff[0],findbuff[1],LoadStrByID(MID_FACE));
			}
#else
			sprintf(vfstr,"%c:%s",findbuff[0],LoadStrByID(MID_FINGER));
#endif
		}
		if (findbuff[0]=='P')
			sprintf(vfstr,"%c:%s",findbuff[0],LoadStrByID(MID_PWD));
		if (findbuff[0]=='I')
			sprintf(vfstr,"%c:%s",findbuff[0],LoadStrByID(MID_CARD_NUM));
		if (findbuff[0]=='C')
			sprintf(vfstr,"%c:%s",findbuff[0],LoadStrByID(MID_CARD));
		if (findbuff[0]=='G')
			sprintf(vfstr,"%c:%s",findbuff[0],LoadStrByID(MID_LOCK_GP));
		if (findbuff[0]=='O')
			sprintf(vfstr,"%c:%s",findbuff[0],LoadStrByID(MID_LOGHINTOTHER));

		sprintf(lastprintstr,"%s",vfstr);
	}
	else if(gOptions.UserExtendFormat)
	{
		int verifyStyle=atoi(findbuff);
		char *verify[15]={
			"FP/PW/RF",
			"FP",
			"PIN",
			"PW",
			"RF",
			"FP/PW",
			"FP/RF",
			"PW/RF",
			"PIN&FP",
			"FP&PW",
			"FP&RF",
			"PW&RF",
			"FP&PW&RF",
			"PIN&FP&PW",
			"FP&(RF/PIN)"
		};
		if(verifyStyle>14)
		{
			sprintf(lastprintstr,"%d:%s",verifyStyle, "Other");
			sprintf(vfstr,"%d:%s",verifyStyle, "Other");

		}
		else
		{
			sprintf(lastprintstr,"%d:%s",verifyStyle, verify[verifyStyle]);
			sprintf(vfstr,"%d:%s",verifyStyle, verify[verifyStyle]);
		}
	}
	if (gOptions.ShowState)
	{
		memset(&subitem,0,sizeof(LVSUBITEM));
		memset(findbuff,0,5);
		subitem.pszText=findbuff;
		subitem.subItem=4;
		SendMessage(hOneLogWnd,LVM_GETSUBITEMTEXT,hItemSelected,(LPARAM)&subitem);
		statecode = atoi(findbuff);
		memset(&tstkey,0,sizeof(TSHORTKEY));
		//		printf("statecode------------:%d\n",statecode);
		if(!gOptions.AntiPassbackFunOn) 
		{
			//Liaozz 20081014, change attlog display model
			if(FDB_GetShortKeyByState(statecode,&tstkey)!=NULL)
			{
				char mynamename[40];           //modify by jazzy 2008.12.04
				memset(mynamename,0,40);
				Str2UTF8(tftlocaleid,(unsigned char *)tstkey.stateName,(unsigned char *) mynamename);
				sprintf(statestr,"S:%s",mynamename);
			}
			//Liaozz 20081014, change attlog display model
		} 
		else 
		{
			if(gOptions.IMEFunOn==1)
			{
				if(FDB_GetShortKeyByState(statecode,&tstkey)!=NULL)
				{
					char mynamename[40]={0};           //modify by jazzy 2008.12.04
					memset(mynamename,0,40);
					Str2UTF8(tftlocaleid,(unsigned char *)tstkey.stateName,(unsigned char *) mynamename);
					sprintf(statestr,"S:%s",mynamename);
				}
			}
			else
			{
				if (statecode == 0)
					sprintf(statestr,"S:%s",LoadStrByID(HIT_SYSTEM5KEY1));
				if (statecode == 1)
					sprintf(statestr,"S:%s",LoadStrByID(HIT_SYSTEM5KEY2));
				if (statecode == 2)
					sprintf(statestr,"S:%s",LoadStrByID(HIT_SYSTEM5KEY5));
				if (statecode == 3)
					sprintf(statestr,"S:%s",LoadStrByID(HIT_SYSTEM5KEY6));
				if (statecode == 4)
					sprintf(statestr,"S:%s",LoadStrByID(HIT_SYSTEM5KEY3));
				if (statecode == 5)
					sprintf(statestr,"S:%s",LoadStrByID(HIT_SYSTEM5KEY4));
			}
		}
		//Liaozz end
		//printf("query state:%d\n",statecode);
		//printf("ddddddddddddddd 3 lastprintstr:%s, vfstr:%s, statestr=%s\n",lastprintstr, vfstr, statestr);
		sprintf(lastprintstr,"%s %s",lastprintstr, statestr);
		//printf("ddddddddddddddd lastprintstr:%s\n",lastprintstr);
	}

	//zsliu add
	log_State_rc.right = gOptions.LCDWidth;
	log_State_rc.bottom = gOptions.LCDHeight-5;
	
	InvalidateRect(hWnd,&log_State_rc,TRUE);

	mydc = GetClientDC(hWnd);
	SetBkColor(mydc,0x00FFA2BE);
	SelectFont(mydc,logqyfont1);
	SetTextColor(mydc,PIXEL_lightwhite);
	sprintf(bottomstr,"%s:%02d",LoadStrByID(MID_RECTOTAL),mylogcount);
	TextOut(mydc,50+gOptions.GridWidth,220,bottomstr);
	TextOut(mydc,190+gOptions.GridWidth,220,lastprintstr);
	ReleaseDC(mydc);

	return 0;
}
Example #2
0
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)

{

	static int  cxChar, cxCaps, cyChar, cyClient, iVscrollPos;

	HDC         hdc;

	int         i, y;

	PAINTSTRUCT ps;

	TCHAR       szBuffer[10];

	TEXTMETRIC  tm;

	switch (message)

	{

	case   WM_CREATE:

		hdc = GetDC(hwnd);


		GetTextMetrics(hdc, &tm);

		cxChar = tm.tmAveCharWidth;

		cxCaps = (tm.tmPitchAndFamily & 1 ? 3 : 2) * cxChar / 2;

		cyChar = tm.tmHeight + tm.tmExternalLeading;


		ReleaseDC(hwnd, hdc);


		SetScrollRange(hwnd, SB_VERT, 0, NUMLINES - 1, FALSE);

		SetScrollPos(hwnd, SB_VERT, iVscrollPos, TRUE);


		return 0;

	case WM_SIZE:

		cyClient = HIWORD(lParam);

		return 0;


	case WM_VSCROLL:

		switch (LOWORD(wParam))

		{

		case SB_LINEUP:

			iVscrollPos -= 1;

			break;



		case SB_LINEDOWN:

			iVscrollPos += 1;

			break;


		case SB_PAGEUP:

			iVscrollPos -= cyClient / cyChar;

			break;



		case SB_PAGEDOWN:

			iVscrollPos += cyClient / cyChar;

			break;



		case SB_THUMBPOSITION:

			iVscrollPos = HIWORD(wParam);

			break;



		default:

			break;

		}


		iVscrollPos = max(0, min(iVscrollPos, NUMLINES - 1));

		if (iVscrollPos != GetScrollPos(hwnd, SB_VERT))

		{

			SetScrollPos(hwnd, SB_VERT, iVscrollPos, TRUE);

			InvalidateRect(hwnd, NULL, TRUE);

		}

		return 0;



	case   WM_PAINT:

		hdc = BeginPaint(hwnd, &ps);

		for (i = 0; i < NUMLINES; i++)

		{

			y = cyChar * (i - iVscrollPos);

			TextOut(hdc, 0, y,

				sysmetrics[i].szLabel,

				lstrlen(sysmetrics[i].szLabel));



			TextOut(hdc, 22 * cxCaps, y,

				sysmetrics[i].szDesc,

				lstrlen(sysmetrics[i].szDesc));



			SetTextAlign(hdc, TA_RIGHT | TA_TOP);

			TextOut(hdc, 22 * cxCaps + 40 * cxChar, y, szBuffer,

				wsprintf(szBuffer, TEXT("%5d"),

				GetSystemMetrics(sysmetrics[i].Index)));

			SetTextAlign(hdc, TA_LEFT | TA_TOP);

		}

		EndPaint(hwnd, &ps);

		return 0;




	case   WM_DESTROY:

		PostQuitMessage(0);

		return 0;

	}

	return DefWindowProc(hwnd, message, wParam, lParam);

}
Example #3
0
File: wpause.c Project: zsx/gnuplot
LRESULT CALLBACK WINEXPORT
WndPauseProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	HDC hdc;
	PAINTSTRUCT ps;
	RECT rect;
	TEXTMETRIC tm;
	LPPW lppw;
	int cxChar, cyChar, middle;

	lppw = (LPPW)GetWindowLong(hwnd, 0);

	switch(message) {
		case WM_KEYDOWN:
			if (wParam == VK_RETURN) {
				if (lppw->bDefOK)
					SendMessage(hwnd, WM_COMMAND, IDOK, 0L);
				else
					SendMessage(hwnd, WM_COMMAND, IDCANCEL, 0L);
			}
			return(0);
		case WM_COMMAND:
			switch(LOWORD(wParam)) {
				case IDCANCEL:
				case IDOK:
				    if (!paused_for_mouse) { /* ignore OK and Cancel buttons during "pause mouse" */
					lppw->bPauseCancel = LOWORD(wParam);
					lppw->bPause = FALSE;
				    }
				    break;
			}
			return(0);
		case WM_SETFOCUS:
			SetFocus(lppw->bDefOK ? lppw->hOK : lppw->hCancel);
			return(0);
		case WM_PAINT:
			{
			hdc = BeginPaint(hwnd, &ps);
			SelectObject(hdc, GetStockObject(SYSTEM_FIXED_FONT));
			SetTextAlign(hdc, TA_CENTER);
			GetClientRect(hwnd, &rect);
			SetBkMode(hdc,TRANSPARENT);
			TextOut(hdc,(rect.right+rect.left)/2, (rect.bottom+rect.top)/6,
				lppw->Message,_fstrlen(lppw->Message));
			EndPaint(hwnd, &ps);
			return 0;
			}
		case WM_CREATE:
			{
		    	int ws_opts = WS_CHILD | BS_DEFPUSHBUTTON;
			if (!paused_for_mouse) /* don't show buttons during pausing for mouse or key */
			    ws_opts |= WS_VISIBLE;
			/* HBB 981202 HMENU sysmenu = GetSystemMenu(hwnd, FALSE); */
			lppw = ((CREATESTRUCT FAR *)lParam)->lpCreateParams;
			SetWindowLong(hwnd, 0, (LONG)lppw);
			lppw->hWndPause = hwnd;
			hdc = GetDC(hwnd);
			SelectObject(hdc, GetStockObject(SYSTEM_FIXED_FONT));
			GetTextMetrics(hdc, &tm);
			cxChar = tm.tmAveCharWidth;
			cyChar = tm.tmHeight + tm.tmExternalLeading;
			ReleaseDC(hwnd,hdc);
			middle = ((LPCREATESTRUCT) lParam)->cx / 2;
			lppw->hOK = CreateWindow((LPSTR)"button", (LPSTR)"OK",
				ws_opts,
					middle - 10*cxChar, 3*cyChar,
					8*cxChar, 7*cyChar/4,
					hwnd, (HMENU)IDOK,
					((LPCREATESTRUCT) lParam)->hInstance, NULL);
			lppw->bDefOK = TRUE;
			lppw->hCancel = CreateWindow((LPSTR)"button", (LPSTR)"Cancel",
				ws_opts,
					middle + 2*cxChar, 3*cyChar,
					8*cxChar, 7*cyChar/4,
					hwnd, (HMENU)IDCANCEL,
					((LPCREATESTRUCT) lParam)->hInstance, NULL);
			lppw->lpfnOK = (WNDPROC) GetWindowLong(lppw->hOK, GWL_WNDPROC);
#ifdef WIN32
			SetWindowLong(lppw->hOK, GWL_WNDPROC, (LONG)PauseButtonProc);
#else
			SetWindowLong(lppw->hOK, GWL_WNDPROC, (LONG)lppw->lpfnPauseButtonProc);
#endif
			lppw->lpfnCancel = (WNDPROC) GetWindowLong(lppw->hCancel, GWL_WNDPROC);
#ifdef WIN32
			SetWindowLong(lppw->hCancel, GWL_WNDPROC, (LONG)PauseButtonProc);
#else
			SetWindowLong(lppw->hCancel, GWL_WNDPROC, (LONG)lppw->lpfnPauseButtonProc);
#endif
			if (GetParent(hwnd))
				EnableWindow(GetParent(hwnd),FALSE);
#if 0 /* HBB 981203 */
			DeleteMenu(sysmenu,SC_RESTORE,MF_BYCOMMAND);
			DeleteMenu(sysmenu,SC_SIZE,MF_BYCOMMAND);
			DeleteMenu(sysmenu,SC_MINIMIZE,MF_BYCOMMAND);
			DeleteMenu(sysmenu,SC_MAXIMIZE,MF_BYCOMMAND);
			DeleteMenu(sysmenu,SC_TASKLIST,MF_BYCOMMAND);
			DeleteMenu(sysmenu,0,MF_BYCOMMAND); /* a separator */
			DeleteMenu(sysmenu,0,MF_BYCOMMAND); /* a separator */
#endif
			}
			return 0;
		case WM_DESTROY:
			GetWindowRect(hwnd, &rect);
			lppw->Origin.x = (rect.right+rect.left)/2;
			lppw->Origin.y = (rect.bottom+rect.top)/2;
			lppw->bPause = FALSE;
			if (GetParent(hwnd))
				EnableWindow(GetParent(hwnd),TRUE);
			break;
	}
	return DefWindowProc(hwnd, message, wParam, lParam);
}
void PaintBPPanel ( PAINTSTRUCT ps ) {
	TextOut( ps.hdc, 29,60,"Break when the Program Counter equals",37);
	TextOut( ps.hdc, 59,85,"0x",2);
}
Example #5
0
void Demo_LineCurve(HDC hDC, const RECT * rcPaint, int width, int height)
{
	// ROP2
	KLogFont logfont(- 10 * ONEINCH / 72, "Tahoma");
	KGDIObject font(hDC, logfont.CreateFont());

	for (int c=0; c<20; c++)
	{
		RECT rect = { c*200+400, 300, c*200+580, 4000 };

		HBRUSH hBrush = CreateSolidBrush(PALETTEINDEX(c));

		FillRect(hDC, & rect, hBrush);

		DeleteObject(hBrush);
	}
	
	{
		KGDIObject redbrush(hDC, CreateSolidBrush(RGB(0xFF, 0, 0)));
		SelectObject(hDC, GetStockObject(NULL_PEN));

		SetTextAlign(hDC, TA_TOP | TA_LEFT);

		for (int r=R2_BLACK; r<=R2_WHITE; r++)
		{
			SetROP2(hDC, r);
			TextOut(hDC, 4400, r*220+200, R2_Names[r-R2_BLACK], _tcslen(R2_Names[r-R2_BLACK]));

			Rectangle(hDC, 300, r*220+200, 4300, r*220+400);
		}
	
		SetROP2(hDC, R2_COPYPEN);
	}

	{
		KPen Red (PS_DOT,            0, RGB(0xFF, 0, 0));
		KPen Blue(PS_SOLID, ONEINCH/36, RGB(0, 0, 0xFF));

		for (int z=0; z<=2000; z+=400)
		{
			int x = 400, y = 6400;

			POINT p[4] = { x, y, x+ 400, y-z, x+800, y-z, x+1200, y }; x+= 1300;
			POINT q[4] = { x, y, x+ 400, y-z, x+800, y+z, x+1200, y }; x+= 1400;
		
			POINT r[4] = { x, y, x+1500, y-z, x- 200, y-z, x+1300, y }; x+= 1800;
			POINT s[4] = { x, y, x+1500, y-z, x- 200, y+z, x+1300, y }; x+= 1600;
		
			POINT t[4] = { x+600, y, x,  y-z, x+1300, y-z, x+600, y }; 

			Red.Select(hDC);
			Polyline(hDC, p, 4);
			Polyline(hDC, q, 4);
			Polyline(hDC, r, 4);
			Polyline(hDC, s, 4);
			Polyline(hDC, t, 4);
			Red.UnSelect();

			Blue.Select(hDC);
			PolyBezier(hDC, p, 4);
			PolyBezier(hDC, q, 4);
			PolyBezier(hDC, r, 4);
			PolyBezier(hDC, s, 4);
			PolyBezier(hDC, t, 4);
			Blue.UnSelect();
		}
	}

}
Example #6
0
LRESULT CALLBACK MainWndProc(HWND hWnd, UINT msg, WPARAM wParam,
   LPARAM lParam)
{
   switch (msg)
   {
      case WM_CREATE:
      {
         INITCOMMONCONTROLSEX icx;
         icx.dwSize = sizeof(INITCOMMONCONTROLSEX);
         icx.dwICC = ICC_BAR_CLASSES;

         InitCommonControlsEx(&icx);

         hTrackBar =
            CreateWindow(
               TRACKBAR_CLASS, "",
               TBS_HORZ | TBS_BOTH | TBS_AUTOTICKS |
               TBS_FIXEDLENGTH | TBS_ENABLESELRANGE |
               WS_CHILD | WS_VISIBLE,
               10, 260, 375, 40,
               hWnd, NULL, hInst, NULL
               );

         assert(hTrackBar != NULL);
         SNDMSG(hTrackBar, TBM_SETTHUMBLENGTH, 20, 0);
         SNDMSG(hTrackBar, TBM_SETRANGEMAX, TRUE, 100);

         // create the TrueType (scalable) font
         HDC hDC = GetDC(hWnd);
         try
         {
            // see Chapter 4 for the definition of MakeFont
            hTTFont = font::MakeFont(hDC, "Impact", 72);
            if (!hTTFont) throw;
         }
         catch (...)
         {
            ReleaseDC(hWnd, hDC);
         }
         ReleaseDC(hWnd, hDC);
         break;
      }
      case WM_HSCROLL:
      {
         if (reinterpret_cast<HWND>(lParam) == hTrackBar)
         {
            //
            // adjust the scaling factor according to
            // the position of the trackbar's slider
            //
            scale = static_cast<double>(
               (SNDMSG(hTrackBar, TBM_GETPOS, 0, 0) + 1) / 50.0
               );
            InvalidateRect(hWnd, NULL, true);
         }
         break;
      }
      case WM_ERASEBKGND:
      {
         LRESULT res = DefWindowProc(hWnd, msg, wParam, lParam);

         HDC hDC = reinterpret_cast<HDC>(wParam);
         HFONT hOldFont = static_cast<HFONT>(
            SelectObject(hDC, hTTFont)
            );
         try
         {
            SetBkMode(hDC, TRANSPARENT);

            // open a path bracket
            if (!BeginPath(hDC)) throw;

            // record the text to the path
            TextOut(hDC, 10, 10, pText, lstrlen(pText));

            // close the path bracket and
            // select the path into hDC
            EndPath(hDC);

            // determine the number of endpoints in the path
            const int num_points = GetPath(hDC, NULL, NULL, 0);
            if (num_points > 0)
            {
               // make room for the POINTs and vertex types
               POINT* pPEnds = new POINT[num_points];
               unsigned char* pTypes = new unsigned char[num_points];
               try
               {
                  // get the path's description
                  int num_got = GetPath(hDC, pPEnds, pTypes, num_points);
                  if (num_got > 0)
                  {
                     // start a new path bracket
                     if (!BeginPath(hDC)) throw;

                     // scale each point in the description
                     int iPoint;
                     for (iPoint = 0; iPoint < num_got; ++iPoint)
                     {
                        pPEnds[iPoint].x = static_cast<LONG>(
                           scale * pPEnds[iPoint].x + 0.5
                           );
                        pPEnds[iPoint].y = static_cast<LONG>(
                           scale * pPEnds[iPoint].y + 0.5
                           );
                     }

                     for (iPoint = 0; iPoint < num_points; ++iPoint)
                     {
                        // handle the MoveToEx case
                        if (pTypes[iPoint] == PT_MOVETO)
                        {
                           MoveToEx(
                             hDC, pPEnds[iPoint].x, pPEnds[iPoint].y, NULL
                             );
                        }
                        // handle the LineTo case
                        else if (
                           pTypes[iPoint] == PT_LINETO ||
                           pTypes[iPoint] == (PT_LINETO | PT_CLOSEFIGURE)
                           )
                        {
                           LineTo(hDC, pPEnds[iPoint].x, pPEnds[iPoint].y);
                        }
                        // handle the PolyBezierTo case
                        else if (
                           pTypes[iPoint] == PT_BEZIERTO ||
                           pTypes[iPoint] == (PT_BEZIERTO | PT_CLOSEFIGURE)
                           )
                        {
                           PolyBezierTo(hDC, pPEnds + iPoint, 3);
                           iPoint += 2;
                        }
                     }

                     // close the new path bracket
                     EndPath(hDC);

                     // stroke and fill the new path
                     StrokeAndFillPath(hDC);
                  }
               }
               catch (...)
               {
                  // clean up
                  delete [] pTypes;
                  delete [] pPEnds;
                  throw;
               }
               // clean up
               delete [] pTypes;
               delete [] pPEnds;
            }
            // ...
         }
         catch (...)
         {
            SelectObject(hDC, hOldFont);
         }
         SelectObject(hDC, hOldFont);
         return res;
      }
      case WM_SIZE:
      {
         MoveWindow(
            hTrackBar,
            0, HIWORD(lParam) - 40, LOWORD(lParam), 40,
            false
            );
         break;
      }
      case WM_DESTROY:
      {
         // clean up
         DeleteObject(hTTFont);
         PostQuitMessage(0);
         break;
      }
   }
   return DefWindowProc(hWnd, msg, wParam, lParam);
}
Example #7
0
LRESULT APIENTRY AboutWinProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
    //Font handles
    static HFONT TitleFont, VersionFont, ExplainFont, LinkFont;
    //static int HorPix; //Currently not used

    //Link edit box hook
    typedef LRESULT (APIENTRY *TypeWinProc)(HWND,UINT,WPARAM,LPARAM); //Windows message listener procedure type
    static TypeWinProc LinkBoxProc; //Original link control handler
    static HWND LinkHwnd=NULL; //Handle to link control
    if(hwnd==LinkHwnd) //Process link edit box messages
    {
        if(msg==WM_LBUTTONDBLCLK) //On double click, open link to project page
            ShellExecute(NULL, "open", ProjectLink, NULL, NULL, SW_SHOWDEFAULT);
        return LinkBoxProc(hwnd,msg,wParam,lParam);
    }

    //Normal about window messages
    switch(msg)
    {
    case WM_ACTIVATE:
    {
        //Get device caps for font height - Should find font sizes by Height*HorPix/72, but since this doesn't seem to work, so I used arbitrary numbers instead to match VB about form layout
        /*HDC MyDC=GetDC(hwnd);
        SetMapMode(MyDC, MM_TEXT);
        HorPix=GetDeviceCaps(MyDC, LOGPIXELSY);
        ReleaseDC(hwnd, MyDC);*/

        //Title Font
        LOGFONT TempFont= {37, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY, DEFAULT_PITCH | FF_DECORATIVE, "Arial"}; //Font Size=24
        TitleFont=CreateFontIndirect(&TempFont);
        //Version Font
        TempFont.lfWeight=FW_DONTCARE;
        TempFont.lfHeight=12; //Font Size=7
        VersionFont=CreateFontIndirect(&TempFont);
        //Explain Font
        TempFont.lfHeight=14; //Font Size=8
        strcpy(TempFont.lfFaceName, "Times New Roman");
        ExplainFont=CreateFontIndirect(&TempFont);
        //Link Box
        TempFont.lfHeight=12; //Font Size=8
        TempFont.lfUnderline=TRUE;
        strcpy(TempFont.lfFaceName, "MS Sans Serif");
        HFONT LinkFont=CreateFontIndirect(&TempFont);
        LinkHwnd=CreateWindow("Edit", ProjectLink, WS_CHILD|WS_VISIBLE|ES_READONLY, 0, MyHeight-16, MyWidth, 16, hwnd, NULL, (HINSTANCE)GetModuleHandle(NULL), 0);
        SendMessage(LinkHwnd, WM_SETFONT, (WPARAM)LinkFont, MAKELPARAM(TRUE, 0));
        LinkBoxProc=(TypeWinProc)SetWindowLong(LinkHwnd, GWL_WNDPROC, (LONG)AboutWinProc); //Listen for double clicks
        return 0;
    }
    case WM_PAINT:
    {
        //Prepare drawing
        PAINTSTRUCT DrawMe;
        HDC MyDC=BeginPaint(hwnd, &DrawMe);
        SetBkMode(MyDC, TRANSPARENT);
        SetTextColor(MyDC, 0x0);

        //Get Width of title string
        SIZE TitleStringSize;
        SelectObject(MyDC, TitleFont);
        GetTextExtentPoint32(MyDC, TitleString, sizeof(TitleString)-1, &TitleStringSize);

        //Output character strings
        TextOut(MyDC, (MyWidth-TitleStringSize.cx)/2,  0, TitleString, sizeof(TitleString));
        SelectObject(MyDC, VersionFont);
        TextOut(MyDC, (MyWidth+TitleStringSize.cx)/2,  20, VersionString, sizeof(VersionString));
        SelectObject(MyDC, ExplainFont);
        DrawText(MyDC, ExplainString, sizeof(ExplainString), (RECT*)&ExplainRect, DT_CENTER);

        //Draw signature and end drawing process
        DisplaySignature(MyDC, MyWidth-207, MyHeight-42-14);
        EndPaint(hwnd, &DrawMe);
        break;
    }
    case WM_CTLCOLORSTATIC: //Properly color the project link box
    {
        SetTextColor((HDC)wParam, GetSysColor(COLOR_HIGHLIGHT));
        SetBkColor((HDC)wParam, GetSysColor(COLOR_BTNFACE));
        return (LRESULT)GetSysColorBrush(COLOR_BTNFACE);
    }
    case WM_CLOSE: //Destroy all opened handles
        DeleteObject(TitleFont);
        DeleteObject(VersionFont);
        DeleteObject(ExplainFont);
        DeleteObject(LinkFont);
        DestroyWindow(hwnd);
        UnregisterClass("AboutWindow", (HINSTANCE)GetModuleHandle(NULL));
        DisplaySignature(NULL, 0, 0); //Delete the signature data
        AboutHwnd=NULL; //Clear the handle so we know about window is no longer open
        break;
    }
    return DefWindowProc(hwnd,msg,wParam,lParam);
}
Example #8
0
static LRESULT CALLBACK SizeTipWndProc(HWND hWnd, UINT nMsg,
                                       WPARAM wParam, LPARAM lParam)
{

    switch (nMsg) {
      case WM_ERASEBKGND:
        return TRUE;

      case WM_PAINT:
        {
            HBRUSH hbr;
            HGDIOBJ holdbr;
            RECT cr;
            int wtlen;
            LPTSTR wt;
            HDC hdc;

            PAINTSTRUCT ps;
            hdc = BeginPaint(hWnd, &ps);

            SelectObject(hdc, tip_font);
            SelectObject(hdc, GetStockObject(BLACK_PEN));

            hbr = CreateSolidBrush(tip_bg);
            holdbr = SelectObject(hdc, hbr);

            GetClientRect(hWnd, &cr);
            Rectangle(hdc, cr.left, cr.top, cr.right, cr.bottom);

            wtlen = GetWindowTextLength(hWnd);
            wt = (LPTSTR)smalloc((wtlen+1)*sizeof(TCHAR));
            GetWindowText(hWnd, wt, wtlen+1);

            SetTextColor(hdc, tip_text);
            SetBkColor(hdc, tip_bg);

            TextOut(hdc, cr.left+3, cr.top+3, wt, wtlen);

            sfree(wt);

            SelectObject(hdc, holdbr);
            DeleteObject(hbr);

            EndPaint(hWnd, &ps);
        }
        return 0;

      case WM_NCHITTEST:
        return HTTRANSPARENT;

      case WM_DESTROY:
        DeleteObject(tip_font);
        tip_font = NULL;
        break;

      case WM_SETTEXT:
        {
            LPCTSTR str = (LPCTSTR)lParam;
            SIZE sz;
            HDC hdc = CreateCompatibleDC(NULL);

            SelectObject(hdc, tip_font);
            GetTextExtentPoint32(hdc, str, _tcslen(str), &sz);

            SetWindowPos(hWnd, NULL, 0, 0, sz.cx+6, sz.cy+6, SWP_NOZORDER|SWP_NOMOVE|SWP_NOACTIVATE);
            InvalidateRect(hWnd, NULL, FALSE);

            DeleteDC(hdc);
        }
        break;
    }

    return DefWindowProc(hWnd, nMsg, wParam, lParam);
}
Example #9
0
/* Drawing on the DC */
static void print_file(const char *file_name, HDC hdc, int width, int height)
{
    #define MAX_BUF_SIZE 1024   /* An arbitrary maximum */
    #define X_OFFSET 5
    #define Y_OFFSET 5

    FILE* fh1;
    size_t results;
    int cnt=0, y_pos = Y_OFFSET, y_cnt = 0;
    char buf[MAX_BUF_SIZE];
    char ch;
    TEXTMETRIC tm;
    int max_chars_per_line, max_lines_per_page;

    SetMapMode(hdc, MM_LOMETRIC);
    GetTextMetrics(hdc, &tm);
    max_chars_per_line = MIN(width / (tm.tmMaxCharWidth + 1), MAX_BUF_SIZE);
    max_lines_per_page = height / (tm.tmHeight + 1);

    SetMapMode(hdc, MM_TEXT);
    GetTextMetrics(hdc, &tm);

    fh1 = ws_fopen(file_name, "r");
    if (!fh1) {
        MessageBox(NULL, "Open failed on input file",
                   "Error", MB_APPLMODAL | MB_OK);
        return;
    }

    while ((results = fread(&ch, 1, 1, fh1)) != 0) {
        /* end of page (form feed)? */
        if (ch == 0x0c) {
            /* send buffer */
            buf[cnt] = 0;
            TextOut(hdc, X_OFFSET,y_pos, buf, (int) strlen(buf));
            y_pos += tm.tmHeight;
            cnt = 0;

            /* reset page */
            EndPage(hdc);
            StartPage(hdc);
            y_pos = Y_OFFSET;
            y_cnt = 0;
            continue;
        }

        /* end of line (line feed)? */
        if (ch == 0x0a) {
            /* send buffer */
            buf[cnt] = 0;
            TextOut(hdc, X_OFFSET,y_pos, buf, (int) strlen(buf));
            y_pos += tm.tmHeight;
            cnt = 0;
            /* last line on page? -> reset page */
            if (++y_cnt == max_lines_per_page) {
                EndPage(hdc);
                StartPage(hdc);
                y_pos = Y_OFFSET;
                y_cnt = 0;
            }
            continue;
        }

        /* buffer full? */
        if (cnt == (max_chars_per_line - 1)) {
            /* send buffer */
            buf[cnt] = 0;
            TextOut(hdc, X_OFFSET, y_pos, buf, (int) strlen(buf));
            y_pos += tm.tmHeight;
            cnt = 0;
            /* last line on page? -> reset page */
            if (++y_cnt == max_lines_per_page) {
                EndPage(hdc);
                StartPage(hdc);
                y_pos = Y_OFFSET;
                y_cnt = 0;
            }
        }

        buf[cnt++] = ch;
    } /* while */

    /* Print the remaining text if needed */
    if (cnt > 0) {
        buf[cnt] = 0;
        TextOut(hdc, 0,y_pos, buf, (int) strlen(buf));
    }

    fclose(fh1);
}
Example #10
0
// The window procedure					
LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{	
	// Static variables are variables that aren't erased after the function quits.  
	// WndProc gets called millions of times.  We want these variables vales to persist
	// for each call to WndProc, thus we make 'em static.
	static RECT clientRect = {0}; // This will hold the client dimensions of window
	
	TEXTMETRIC textInfo; // This a struct that contains the basic physical properties of a font							
	PAINTSTRUCT paintStruct; // A PAINTSTRUCT structure is something we need to paint (draw) when handling the WM_PAINT message.
	HDC hdc=NULL; // An HDC is a handle to a device context.  We use this handle as a way to communicate to the graphics card so we can draw things to the window.  
	int x, y; // These will be used to position our text.
	char szHello[]="Hello World!"; // The string to print, pretty original huh? :)

	// This checks what the message is.  Below we handle the messages that we care of about.
	// Remember there are HUNDREDS of messages we could handle, but we'll only deal with the 
	// following four.
    switch(iMsg)											
    {														
		// This message is sent when the window is created.
		case WM_CREATE:										
			// Upon creation we need to get the rectangular dimensions of the client area
			// of our window. The client area is the area of the window minus the title bar and border
			// surrounding the window.
			GetClientRect(hwnd, &clientRect);
			break;											

		// This message is sent to the WndProc after the windows size has changed
		case WM_SIZE:
			
			// Since the window has been resized, we need to get our client area again.										
			GetClientRect(hwnd, &clientRect);
			break;				

		// This message is sent to the WndProc when the window needs to be repainted.  This might be if
		// we moved the window, resized it, or maximized it, or if another window was covering ours.
		case WM_PAINT:
			// This is how we get an HDC to paint with.  BeginPaint() passes back an hdc and fills 
			// in the paintStruct structure.  The paintStruct holds optional information on how to paint
			// but all we really care about is getting the HDC of the window so we can draw
			// to the window.									
			hdc = BeginPaint(hwnd, &paintStruct);			
			
			// Here we pass in the hdc of our window and our textInfo into GetTextMetrics().  
			// This fills in textInfo with all the font info for the window such as height, 
			// width, spacing, etc, etc.  At any one time, an HDC can have one font 
			// associated with it.  By default Windows assigns a font to a window upon creation.
			// This call to GetTextMetrics will obtain the information for the default font
			// associated with our window that we created.
			GetTextMetrics(hdc, &textInfo);				
			
			// Now we want to change the color of our default font
			// We can do this by the SetTextColor function.  Notice the macro RGB.  If you
			// are not familiar with color formats, be sure and check out the 
			// quick lesson on RGB at the bottom of this file.												
			SetTextColor(hdc, RGB(255, 0, 0));				
															
															
			// Alright, here's where some math comes in :)  It's just simple algebra so don't panic.
			// We want "Hello World!" to be centered in the screen.  So first we want to find the 
			// width and height of the window.  Remember we stored the client rect of the window
			// in our WM_CREATE message.  In general a RECT is a struct with four members, left
			// right, top, and bottom.  With (left,top) defining the upper left corner of the 
			// RECT and (right,bottom) defining the lower right corner of the RECT.  By definition,
			// a client rect's upper-left corner is (0,0).  This means we know the width and height
			// of the window is clientRect.right and clientRect.bottom respectively.
			
			// Our goal is to have our text to be centered in the screen. 
			// So, first we calculate an (x,y) that are dead center in our window.
			x = clientRect.right / 2;
			y = clientRect.bottom / 2;
															
			// Now we need to subtract half of the length of the string from
			// our x position so that the string of text can be centered in the 
			// window.  To do that, we calculate the number of characters in the string
			// by strlen(szHello).  Next we multiply by the average character width
			// for our font.  This will give us the total length in pixels of our text.
			// Dividing that by two and subtracting it from our x will give us the starting x
			// position to draw our text.											
			x = x - ((strlen(szHello) * textInfo.tmAveCharWidth) / 2);											
			
			// Okay x is ready to go, now we need to do a bit more math to y.  We want the 
			// text centered in the screen, so we'll subtract off half of the text's height
			// so it's centered nicely in the window.
			y = y - (textInfo.tmHeight / 2);											
						
			// Now we need to print the text, which TextOut will do nicely 
			// for us.  The first parameter, hdc, is the device context for 
			// drawing to.  The next two parameters, (x,y) is the starting upper-left
			// corner to begin drawing the text to.  The next parameter, szHello, is the
			// the text string to print.  The last parameter, is the number of 
			// characters to print.  As mentioned above, strlen() returns the number of 
			// characters in a string.    
			TextOut(hdc, x, y, szHello, strlen(szHello));			
			
			// And that about wraps up our our end paint.  This should be 
			// the last function you call after BeginPaint.  As the name suggests,
			// this tells Windows we're done drawing %)
			EndPaint(hwnd, &paintStruct);					
		    break;											

		// This message is sent when it's time to destroy the window
		case WM_DESTROY:									
			PostQuitMessage(0); // Quit the tutorial																	
			break;											
	}													

	// The DefWindowProc function calls the default window procedure to provide default processing
	// for any window messages that an application does not process.  This function ensures that every
	// message is processed. DefWindowProc is called with the same parameters received by the WndProc. 
	return DefWindowProc (hwnd, iMsg, wParam, lParam);		

} // End of the WndProc
BOOL CTextLayout::Render(HDC hdc, const WCHAR *psz,  UINT nCnt, UINT nSelStart, UINT nSelEnd,
                         const COMPOSITIONRENDERINFO *pCompositionRenderInfo, UINT nCompositionRenderInfo)
{
    POINT ptCurrent;
    ptCurrent.x = 0;
    ptCurrent.y = 0;

    SetBkMode(hdc, OPAQUE);
    SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
    SetBkColor(hdc, GetSysColor(COLOR_WINDOW));

    // Render lines
    for (UINT i = 0; i < _nLineCnt; i++)
    {
        if (_prgLines[i].nCnt)
        {
            TextOut(hdc, 
                    ptCurrent.x, 
                    ptCurrent.y, 
                    psz + _prgLines[i].nPos, 
                    _prgLines[i].nCnt);
        }
        ptCurrent.x = 0;
        ptCurrent.y += _nLineHeight;
    }
   
    _fCaret = FALSE;

    // Render selection/caret
    RECT rcSel;
    if (_nLineCnt)
    {
        for (UINT i = 0; i < _nLineCnt; i++)
        {
            if ((nSelEnd >= _prgLines[i].nPos) &&
                (nSelStart <= _prgLines[i].nPos + _prgLines[i].nCnt))
            {
                UINT nSelStartInLine = 0;
                UINT nSelEndInLine = _prgLines[i].nCnt;

                if (nSelStart > _prgLines[i].nPos)
                    nSelStartInLine = nSelStart - _prgLines[i].nPos;

                if (nSelEnd < _prgLines[i].nPos + _prgLines[i].nCnt)
                    nSelEndInLine = nSelEnd - _prgLines[i].nPos;
    
                if (nSelStartInLine != nSelEndInLine)
                {
                    for (UINT j = nSelStartInLine; j < nSelEndInLine; j++)
                    {
                        InvertRect(hdc, &_prgLines[i].prgCharInfo[j].rc);
                    }
                }
                else
                {
                    if (nSelStartInLine == _prgLines[i].nCnt)
                    {
                        rcSel = _prgLines[i].prgCharInfo[nSelStartInLine - 1].rc;
                        rcSel.left = rcSel.right;
                        rcSel.right++;
                    }
                    else
                    {
                        rcSel = _prgLines[i].prgCharInfo[nSelStartInLine].rc;
                        rcSel.right = rcSel.left + 1;
                    }
                    InvertRect(hdc, &rcSel);
                    _fCaret = TRUE;
                    _rcCaret = rcSel;
                }
            }

            for (UINT j = 0; j < nCompositionRenderInfo; j++)
            {
    
                if ((pCompositionRenderInfo[j].nEnd >= _prgLines[i].nPos) &&
                   (pCompositionRenderInfo[j].nStart <= _prgLines[i].nPos + _prgLines[i].nCnt))
                {
                    UINT nCompStartInLine = 0;
                    UINT nCompEndInLine = _prgLines[i].nCnt;
                    int  nBaseLineWidth = (_nLineHeight / 18) + 1;
    
                    if (pCompositionRenderInfo[j].nStart > _prgLines[i].nPos)
                        nCompStartInLine = pCompositionRenderInfo[j].nStart - _prgLines[i].nPos;
    
                    if (pCompositionRenderInfo[j].nEnd < _prgLines[i].nPos + _prgLines[i].nCnt)
                        nCompEndInLine = pCompositionRenderInfo[j].nEnd - _prgLines[i].nPos;
    
                    for (UINT k = nCompStartInLine; k < nCompEndInLine; k++)
                    {
                        UINT uCurrentCompPos = _prgLines[i].nPos + k - pCompositionRenderInfo[j].nStart;
                        BOOL bClause = FALSE;
     
                        if (k + 1 == nCompEndInLine)
                        {
                            bClause = TRUE;
                        }

                        if ((pCompositionRenderInfo[j].da.crText.type != TF_CT_NONE) &&
                            (pCompositionRenderInfo[j].da.crBk.type != TF_CT_NONE))
                        {
                            SetBkMode(hdc, OPAQUE);
                            SetTextColor(hdc, GetAttributeColor(&pCompositionRenderInfo[j].da.crText));
                            SetBkColor(hdc, GetAttributeColor(&pCompositionRenderInfo[j].da.crBk));
 
                            RECT rc = _prgLines[i].prgCharInfo[k].rc;
                            ExtTextOut(hdc, rc.left, rc.top, ETO_OPAQUE, &rc, 
                                       psz + _prgLines[i].nPos + k, 1, NULL);
                        }
     
                        if (pCompositionRenderInfo[j].da.lsStyle != TF_LS_NONE)
                        {
                            HPEN hpen = CreateUnderlinePen(&pCompositionRenderInfo[j].da, nBaseLineWidth);
                            if (hpen)
                            {
                                HPEN hpenOrg;
                                hpenOrg = (HPEN)SelectObject(hdc, hpen);
                                RECT rc = _prgLines[i].prgCharInfo[k].rc;
     
                                POINT pts[2];
                                pts[0].x = rc.left;
                                pts[0].y = rc.bottom;
                                pts[1].x = rc.right - (bClause ? nBaseLineWidth : 0);
                                pts[1].y = rc.bottom;
                                Polyline(hdc, pts, 2);
     
                                SelectObject(hdc, hpenOrg);
                            }
                        }
                    }
                }
            }
        }

    }
    else
    {
        rcSel.left = 0;
        rcSel.top = 0;
        rcSel.right = 1;
        rcSel.bottom = _nLineHeight;
        InvertRect(hdc, &rcSel);
        _fCaret = TRUE;
        _rcCaret = rcSel;
    }

    return TRUE;
}
Example #12
0
// Window layer procedure
LRESULT CALLBACK LayerWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	HDC hdc;
	RECT clipRect	= {0, 0, 500, 500};
	HBRUSH hBrush;
	HPEN hPen;
	HFONT hFont;


	switch (message)
	{
	case WM_ERASEBKGND:
		 GetClientRect(hWnd, &clipRect);
		
		hdc = GetDC(hWnd);
        hBrush = CreateSolidBrush(RGB(100,100,100));
        SelectObject(hdc, hBrush);
		hPen = CreatePen(PS_DASH,1,RGB(255,255,255));
		SelectObject(hdc, hPen);
		Rectangle(hdc,0,0,clipRect.right,clipRect.bottom);

		//矩形のサイズを出力
		int fHeight;
		fHeight = -MulDiv(8, GetDeviceCaps(hdc, LOGPIXELSY), 72);
		hFont = CreateFont(fHeight,    //フォント高さ
			0,                    //文字幅
			0,                    //テキストの角度
			0,                    //ベースラインとx軸との角度
			FW_REGULAR,            //フォントの重さ(太さ)
			FALSE,                //イタリック体
			FALSE,                //アンダーライン
			FALSE,                //打ち消し線
			ANSI_CHARSET,    //文字セット
			OUT_DEFAULT_PRECIS,    //出力精度
			CLIP_DEFAULT_PRECIS,//クリッピング精度
			PROOF_QUALITY,        //出力品質
			FIXED_PITCH | FF_MODERN,//ピッチとファミリー
			L"Tahoma");    //書体名

		SelectObject(hdc, hFont);
		// show size
		int iWidth, iHeight;
		iWidth  = clipRect.right  - clipRect.left;
		iHeight = clipRect.bottom - clipRect.top;

		wchar_t sWidth[200], sHeight[200];
		swprintf_s(sWidth, L"%d", iWidth);
		swprintf_s(sHeight, L"%d", iHeight);

		int w,h,h2;
		w = -fHeight * 2.5 + 8;
		h = -fHeight * 2 + 8;
		h2 = h + fHeight;

		SetBkMode(hdc,TRANSPARENT);
		SetTextColor(hdc,RGB(0,0,0));
		TextOut(hdc, clipRect.right-w+1,clipRect.bottom-h+1,(LPCWSTR)sWidth,wcslen(sWidth));
		TextOut(hdc, clipRect.right-w+1,clipRect.bottom-h2+1,(LPCWSTR)sHeight,wcslen(sHeight));
		SetTextColor(hdc,RGB(255,255,255));
		TextOut(hdc, clipRect.right-w,clipRect.bottom-h,(LPCWSTR)sWidth,wcslen(sWidth));
		TextOut(hdc, clipRect.right-w,clipRect.bottom-h2,(LPCWSTR)sHeight,wcslen(sHeight));

		DeleteObject(hPen);
		DeleteObject(hBrush);
		DeleteObject(hFont);
		ReleaseDC(hWnd, hdc);

		return TRUE;

        break;
	default:
		return DefWindowProc(hWnd, message, wParam, lParam);
	}
	return 0;

}
Example #13
0
int CALLBACK DlgProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
	HDC hdc,khdc;
	HBITMAP oldbmp,newbmp;
	PAINTSTRUCT paint;
	RECT rect;
	char s[32];
	LPDRAWITEMSTRUCT dw;
	int i=0;
	HBRUSH hb;

	switch(msg)
	{
	case WM_INITDIALOG:

		ShowWindow(hWnd,SW_SHOW);
		OldListProc = (WNDPROC)SetWindowLong(GetDlgItem(hWnd,IDC_LIST1),GWL_WNDPROC,(long)NewWindowProc);
//		for(i=0;i<50;i++)
//			SendMessage(GetDlgItem(hWnd,IDC_LIST1),LB_ADDSTRING,0,(LPARAM)s);
//		GetWindowRect(GetDlgItem(hWnd,IDC_LIST1),&rect);
//		InvalidateRect(GetDlgItem(hWnd,IDC_LIST1),&rect,TRUE);
		GetCallAddress(GetDlgItem(hWnd,IDC_LIST1));
		if(SendMessage(GetDlgItem(hWnd,IDC_LIST1),LB_GETCOUNT,wParam,lParam)>0)
			SendMessage(GetDlgItem(hWnd,IDC_LIST1),LB_SETCURSEL,0,0);

		
		break;

	case WM_CLOSE:
		
		EndDialog(hWnd,0);
		break;
	case WM_PAINT:
		hdc=BeginPaint(hWnd,&paint);
		newbmp = LoadBitmap(hin,MAKEINTRESOURCE(IDB_BITMAP1));		
		GetClientRect(hWnd,&rect);
		khdc = CreateCompatibleDC( hdc );
		oldbmp = (HBITMAP)SelectObject(khdc,(HGDIOBJ)newbmp);
		BitBlt(hdc,0,0,rect.right-rect.left,rect.bottom-rect.top,khdc,0,0,SRCCOPY);
		SelectObject(khdc,(HGDIOBJ)oldbmp);
		DeleteObject(khdc);
		DeleteObject((HGDIOBJ)newbmp);
		EndPaint(hWnd,&paint);
		
		break;
	case WM_DRAWITEM:
		if(wParam == IDC_LIST1)
		{
			dw = (LPDRAWITEMSTRUCT) lParam;
			SendMessage(dw->hwndItem,LB_GETITEMRECT,dw->itemID,(WPARAM)&rect);
			if(dw->itemState & ODS_SELECTED||dw->itemState)
			{
				hb = CreateSolidBrush(RGB(0xff,0xff,0xff));
				FillRect(dw->hDC,&rect,hb);
				DeleteObject(hb);
			}

//			SendMessage(hWnd,LB_GETITEMDATA,dw->itemID,(LPARAM)s);
			wsprintf(s,"0x%08x",(dw->itemData)&0x7fffffff);
			if((dw->itemData&0x80000000)==0)
				SetTextColor(dw->hDC,RGB(0,0,0));
			else
				SetTextColor(dw->hDC,RGB(0xff,0,0));
			TextOut(dw->hDC,rect.left+2,rect.top+2,s,lstrlen(s));

		}

		else		return DefWindowProc(hWnd,msg,wParam,lParam);
		break;
	case WM_CTLCOLORLISTBOX:
		hdc=(HDC)wParam;
		::SetBkMode(hdc,TRANSPARENT);
		SetTextColor(hdc,RGB(64,32,0));
		return (int)GetStockObject(HOLLOW_BRUSH);
		break;
	}
	return 0;
}
Example #14
0
File: osd.c Project: hownam/fennec
void draw_scrolls(HDC dc, HDC sdc, int x, int y, int w, double v, struct osd_item *oi)
{
	int lw = 1, rw = 1, mw = 10, i, xp = 0, lp = 0, ow = w;

	BitBlt(dc, x, y, lw, oi->h, sdc, oi->sx, oi->sy, SRCCOPY);
	lp = x + lw;

	for(i=0; i<=(w - rw - lw - mw); i+=mw)
	{
		BitBlt(dc, x + lw + i, y, mw, oi->h, sdc, oi->sx + lw, oi->sy, SRCCOPY);
		lp = x + lw + i + mw;
	}

	BitBlt(dc, lp, y, (x + w) - lp - rw, oi->h, sdc, oi->sx + lw, oi->sy, SRCCOPY);
	BitBlt(dc, x + w - rw, y, rw, oi->h, sdc, oi->sx + oi->w - rw, oi->sy, SRCCOPY);

	xp = lp = 0;

	w = (int)(w * v);

	if(w > 0)
	{
		BitBlt(dc, x, y, lw, oi->h, sdc, oi->sx_h, oi->sy_h, SRCCOPY);
		lp = x + lw;

		for(i=0; i<=(w - rw - lw - mw); i+=mw)
		{
			BitBlt(dc, x + lw + i, y, mw, oi->h, sdc, oi->sx_h + lw, oi->sy_h, SRCCOPY);
			lp = x + lw + i + mw;
		}

		BitBlt(dc, lp, y, (x + w) - lp - rw, oi->h, sdc, oi->sx_h + lw, oi->sy_h, SRCCOPY);
		BitBlt(dc, x + w - rw, y, rw, oi->h, sdc, oi->sx_h + oi->w - rw, oi->sy_h, SRCCOPY);
	}

	if(ow > 40)
	{
		if(oi->id == osd_id_seek)
		{
			HFONT nfont, ofont;
			SIZE  pz;
			string ttext;
			nfont = CreateFont(-MulDiv(10, GetDeviceCaps(dc, LOGPIXELSY), 72),
												0, 0, 0, FW_NORMAL, 0, 0, 0, DEFAULT_CHARSET,
												OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, 5,
												DEFAULT_PITCH, uni("Tahoma"));

			ofont = (HFONT) SelectObject(dc, nfont);

			SetBkMode(dc, TRANSPARENT);
			

			ttext = get_time_text((int)(vdata.shared->audio.output.getduration_ms() / 1000));
			GetTextExtentPoint32(dc, ttext, (int)str_len(ttext), &pz);
			SetTextColor(dc, 0x000000);
			TextOut(dc, x + ow - pz.cx + 1, y + oi->h + 5 + 1, ttext, (int)str_len(ttext));
			SetTextColor(dc, 0xffffff);
			TextOut(dc, x + ow - pz.cx, y + oi->h + 5, ttext, (int)str_len(ttext));

			ttext = get_time_text((int)(vdata.shared->audio.output.getposition_ms() / 1000));
			GetTextExtentPoint32(dc, ttext, (int)str_len(ttext), &pz);
			SetTextColor(dc, 0x000000);
			TextOut(dc, x + 1, y + oi->h + 5 + 1, ttext, (int)str_len(ttext));
			SetTextColor(dc, 0xffffff);
			TextOut(dc, x, y + oi->h + 5, ttext, (int)str_len(ttext));

			if(show_seek_position_tip)
			{
				double posfrac = (double)show_seek_position_tip / (double)ow;
				int duration = (int)(vdata.shared->audio.output.getduration_ms() / 1000);
				ttext = get_time_text((int)((double)duration * posfrac));
				GetTextExtentPoint32(dc, ttext, (int)str_len(ttext), &pz);
				SetTextColor(dc, 0x000000);
				TextOut(dc, x + show_seek_position_tip + 1 - (pz.cx / 2), y - pz.cy - 5 + 1, ttext, (int)str_len(ttext));
				SetTextColor(dc, 0xffffff);
				TextOut(dc, x + show_seek_position_tip - (pz.cx / 2), y - pz.cy - 5 , ttext, (int)str_len(ttext));
			}


			SelectObject(dc, ofont);
			DeleteObject(nfont);
		}
	}
}
Example #15
0
Text::Text(int FSIZE, const char *text, string printtext,int Startx, int Starty, int Startz, int W, int H, bool Console)
{

	ObjString = text;
	textout = printtext.c_str();
	Width = W;
	Height = H;
	DeathCounter = 50;//frames before deleting
	ConsoleDisplay = Console;
	fontsize = FSIZE;
	
	CollBox.top = Starty;
	CollBox.bottom = (Starty + H);
	CollBox.left = Startx;
	CollBox.right = (Startx +(W));

	DDSURFACEDESC2 ddsd;
	INITIALIZE_DDRAW(ddsd);
	ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CKSRCBLT;
	ddsd.dwWidth = W;
	ddsd.dwHeight = H;
	ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY;
	ddsd.ddckCKSrcBlt.dwColorSpaceLowValue = _RGB16BIT565(255, 0, 255);
	ddsd.ddckCKSrcBlt.dwColorSpaceHighValue = _RGB16BIT565(255, 0, 255);

	if(FAILED(lpdd->CreateSurface(&ddsd, &TheBitmap, NULL)))
	{
		// Failed making surface
	}

	x = Startx;
	y = Starty;
	z = Startz;
//text render code

	 if (lpddsback->GetDC(&hdc) == DD_OK)  
	 {  
		 
		  SetBkMode(hdc, TRANSPARENT); 
		  SetTextColor(hdc, RGB(255,255,255));
		  if(textout.length() < (int)(Width/8))
		  {
			  LOGFONT logfont = {fontsize,0,0,0,FW_SEMIBOLD,false,false,false,DEFAULT_CHARSET ,OUT_CHARACTER_PRECIS,CLIP_DEFAULT_PRECIS, PROOF_QUALITY,FF_MODERN,"Lucida Console"};
			  tempfont = CreateFontIndirect(&logfont);
			SelectObject(hdc,tempfont);
			TextOut(hdc, x, y, textout.c_str(), textout.length()); 
		  }
		  else
		  {
			for(int i = 0;(i*(int)(Width/8))<(int)textout.length();i++)
			{
			  LOGFONT logfont = {fontsize,0,0,0,FW_SEMIBOLD,false,false,false,DEFAULT_CHARSET ,OUT_CHARACTER_PRECIS,CLIP_DEFAULT_PRECIS, PROOF_QUALITY,FF_MODERN,"Lucida Console"};
			  tempfont = CreateFontIndirect(&logfont);
			SelectObject(hdc,tempfont);
				TextOut(hdc, x, (y+(i*20)), (textout.substr((i*(int)(Width/8)),(int)(Width/8))).c_str(), (textout.substr((i*(int)(Width/8)),(int)(Width/8))).length()); 
			}
		  }

		  lpddsback->ReleaseDC(hdc);  


	 }


	

	SourceRect.top = 0;
	SourceRect.left = 0;
	SourceRect.right = W;
	SourceRect.bottom = H;

	RenderThis = true;
}
Example #16
0
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam,LPARAM lParam)
        
{
        
    static DWORD          dwCharSet = DEFAULT_CHARSET ;
        
    static int            cxChar, cyChar, cxClient, cyClient, cxBuffer, cyBuffer,
        
                                  xCaret, yCaret ;
        
    static TCHAR *pBuffer = NULL ;
        
    HDC                           hdc ;
        
    int                           x, y, i ;
        
    PAINTSTRUCT           ps ;
        
    TEXTMETRIC            tm ;
        
   
        
    switch (message)
        
    {
        
    case   WM_INPUTLANGCHANGE:
        
            dwCharSet = wParam ;
        
               // fall through
        
    case   WM_CREATE:
        
            hdc = GetDC (hwnd) ;
        
            SelectObject (hdc, CreateFont (0, 0, 0, 0, 0, 0, 0, 0,
        
                                                                dwCharSet, 0, 0, 0, FIXED_PITCH, NULL)) ;
        
        
        
            GetTextMetrics (hdc, &tm) ;
        
            cxChar = tm.tmAveCharWidth ;
        
            cyChar = tm.tmHeight ;
        
        
        
            DeleteObject (SelectObject (hdc, GetStockObject (SYSTEM_FONT))) ;
        
            ReleaseDC (hwnd, hdc) ;
        
            // fall through              
        
    case   WM_SIZE:
        
                   // obtain window size in pixels
        

            if (message == WM_SIZE)
        
            {
        
                           cxClient = LOWORD (lParam) ;
        
                           cyClient = HIWORD (lParam) ;
        
            }
        
                   // calculate window size in characters
        
        
        
            cxBuffer = max (1, cxClient / cxChar) ;
        
            cyBuffer = max (1, cyClient / cyChar) ;
        
        
        
                   // allocate memory for buffer and clear it
        
        
        
            if (pBuffer != NULL)
        
                           free (pBuffer) ;
        

            pBuffer = (TCHAR *) malloc (cxBuffer * cyBuffer * sizeof (TCHAR)) ;
        
        
        
            for (y = 0 ; y < cyBuffer ; y++)
        
                           for (x = 0 ; x < cxBuffer ; x++)
        
                                          BUFFER(x,y) = ' ' ;
        

                   // set caret to upper left corner
        

            xCaret = 0 ;
        
            yCaret = 0 ;
        
                  
        
            if (hwnd == GetFocus ())
        
                           SetCaretPos (xCaret * cxChar, yCaret * cyChar) ;
        

            InvalidateRect (hwnd, NULL, TRUE) ;
        
            return 0 ;
        
                  
        
    case   WM_SETFOCUS:
        
                           // create and show the caret
        
            CreateCaret (hwnd, NULL, cxChar, cyChar) ;
        
            SetCaretPos (xCaret * cxChar, yCaret * cyChar) ;
        
           ShowCaret (hwnd) ;
        
            return 0 ;
        
        
        
    case WM_KILLFOCUS:
        
                           // hide and destroy the caret
        
            HideCaret (hwnd) ;
        
            DestroyCaret () ;
        
            return 0 ;
        
        
        
    case   WM_KEYDOWN:
        
            switch (wParam)
        
            {
        
            case VK_HOME:
        
                           xCaret = 0 ;
        
                           break ;
        
             
        
                           case   VK_END:
        
                                          xCaret = cxBuffer - 1 ;
        
                                          break ;
        
             
        
                           case   VK_PRIOR:
        
                                          yCaret = 0 ;
        
                                          break ;
        
             
        
                           case   VK_NEXT:
        
                                          yCaret = cyBuffer - 1 ;
        
                                          break ;
        
             
        
                           case   VK_LEFT:
        
                                          xCaret = max (xCaret - 1, 0) ;
        
                                          break ;
        
             
        
                   case   VK_RIGHT:
        
                           xCaret = min (xCaret + 1, cxBuffer - 1) ;
        
                           break ;
        
             
        
                   case   VK_UP:
        
                          yCaret = max (yCaret - 1, 0) ;
        
                           break ;
        
             
        
                   case   VK_DOWN:
        
                           yCaret = min (yCaret + 1, cyBuffer - 1) ;
        
                           break ;
        
             
        
                   case   VK_DELETE:
        
                           for (x = xCaret ; x < cxBuffer - 1 ; x++)
        
                                          BUFFER (x, yCaret) = BUFFER (x + 1, yCaret) ;
        
             
        
                           BUFFER (cxBuffer - 1, yCaret) = ' ' ;
        
             
        
                           HideCaret (hwnd) ;
        
                           hdc = GetDC (hwnd) ;
        
        
        
                           SelectObject (hdc, CreateFont (0, 0, 0, 0, 0, 0, 0, 0,
        
                                                                 dwCharSet, 0, 0, 0,FIXED_PITCH, NULL)) ;
        
                          TextOut (hdc, xCaret * cxChar, yCaret * cyChar,
        
                                                          & BUFFER (xCaret, yCaret),
        
                                                          cxBuffer - xCaret) ;
        

                           DeleteObject (SelectObject (hdc, GetStockObject (SYSTEM_FONT))) ;
        
                           ReleaseDC (hwnd, hdc) ;
        
                          ShowCaret (hwnd) ;
        
                          break ;
        
            }
        
            SetCaretPos (xCaret * cxChar, yCaret * cyChar) ;
        
            return 0 ;
        
        
        
    case   WM_CHAR:
        
            for (i = 0 ; i < (int) LOWORD (lParam) ; i++)
        
            {
        
                   switch (wParam)
        
                           {
        
                   case '\b':                                           // backspace
        
                                  if (xCaret > 0)
        
                                          {
        
                                                  xCaret-- ;
        
                                                SendMessage (hwnd, WM_KEYDOWN, VK_DELETE, 1) ;
        
                                          }
        
                                   break ;
        
                  
        
           case '\t':                                                  // tab
        
                           do
        
                                   {
        
                                          SendMessage (hwnd, WM_CHAR, ' ', 1) ;
        
                                   }
        
                           while (xCaret % 8 != 0) ;
        
                           break ;
        
            case '\n':                                                  // line feed
        
                           if (++yCaret == cyBuffer)
        
                                          yCaret = 0 ;
        
                           break ;
        
                  
        
            case '\r':                                                  // carriage return
        
                           xCaret = 0 ;
        
                  
        
                           if (++yCaret == cyBuffer)
        
                                          yCaret = 0 ;
        
                           break ;
        
                  
        
            case '\x1B':                                       // escape
        
                           for (y = 0 ; y < cyBuffer ; y++)
        
                           for (x = 0 ; x < cxBuffer ; x++)
        
                                          BUFFER (x, y) = ' ' ;
        
                       
        
                           xCaret = 0 ;
        
                           yCaret = 0 ;
        
                       
        
                           InvalidateRect (hwnd, NULL, FALSE) ;
        
                           break ;
        
                       
        
            default:                                                    // character codes
        
                   BUFFER (xCaret, yCaret) = (TCHAR) wParam ;
        
                  
        
                   HideCaret (hwnd) ;
        
                   hdc = GetDC (hwnd) ;
        
        
        
                   SelectObject (hdc, CreateFont (0, 0, 0, 0, 0, 0, 0, 0,
        
                                                          dwCharSet, 0, 0, 0, FIXED_PITCH, NULL)) ;
        
                   TextOut (hdc, xCaret * cxChar, yCaret * cyChar,
        
                                          & BUFFER (xCaret, yCaret), 1) ;
        
                   DeleteObject (
        
                           SelectObject (hdc, GetStockObject (SYSTEM_FONT))) ;
        
                   ReleaseDC (hwnd, hdc) ;
        
                   ShowCaret (hwnd) ;
        

                  if (++xCaret == cxBuffer)
        
                           {
        
                                   xCaret = 0 ;
        
                                   if (++yCaret == cyBuffer)
        
                                                  yCaret = 0 ;
        
                           }
        
                   break ;
        
            }
        
    }
        
        
        
            SetCaretPos (xCaret * cxChar, yCaret * cyChar) ;
        
            return 0 ;
        
        
        
    case   WM_PAINT:
        
            hdc = BeginPaint (hwnd, &ps) ;
        
        
        
            SelectObject (hdc, CreateFont (0, 0, 0, 0, 0, 0, 0, 0,
        
                                                 dwCharSet, 0, 0, 0, FIXED_PITCH, NULL)) ;
        
            for (y = 0 ; y < cyBuffer ; y++)
        
                   TextOut (hdc, 0, y * cyChar, & BUFFER(0,y), cxBuffer) ;
        
            DeleteObject (SelectObject (hdc, GetStockObject (SYSTEM_FONT))) ;
        
            EndPaint (hwnd, &ps) ;
        
            return 0 ;
        
        
        
    case   WM_DESTROY:
        
            PostQuitMessage (0) ;
        
            return 0 ;
        
    }
        
    return DefWindowProc (hwnd, message, wParam, lParam) ;
        
}
Example #17
0
//Yeah this truly turned into a mess with the latest additions.. but it sure looks nice ;)
void CtrlMemView::onPaint(WPARAM wParam, LPARAM lParam)
{
	GetClientRect(wnd, &rect);
	PAINTSTRUCT ps;
	HDC hdc;
	hdc = BeginPaint(wnd, &ps);
	int width = rect.right;
	int numRows=(rect.bottom/rowHeight)/2+1;
	SetBkMode(hdc, TRANSPARENT);
	HPEN nullPen=CreatePen(0,0,0xFFFFFF);
	HPEN currentPen=CreatePen(0,0,0);
	HPEN selPen=CreatePen(0,0,0x808080);
	LOGBRUSH lbr;
	lbr.lbHatch=0; lbr.lbStyle=0; 
	lbr.lbColor=0xFFFFFF;
	HBRUSH nullBrush=CreateBrushIndirect(&lbr);
	lbr.lbColor=0xFFEfE8;
	HBRUSH currentBrush=CreateBrushIndirect(&lbr);
	lbr.lbColor=0x70FF70;
	HBRUSH pcBrush=CreateBrushIndirect(&lbr);
	HPEN oldPen=(HPEN)SelectObject(hdc,nullPen);
	HBRUSH oldBrush=(HBRUSH)SelectObject(hdc,nullBrush);
   	HFONT oldFont = (HFONT)SelectObject(hdc,(HGDIOBJ)font);

	int i;
	for (i=-numRows; i<=numRows; i++)
	{
		unsigned int address=curAddress + i*align;

		int rowY1 = rect.bottom/2 + rowHeight*i - rowHeight/2;
		int rowY2 = rect.bottom/2 + rowHeight*i + rowHeight/2;

		wchar temp[256];
		swprintf(temp,L"%08x",address);

		//SelectObject(hdc,currentBrush);
		Rectangle(hdc,0,rowY1,16,rowY2);

		if(selecting && address == (u32)selection)
			SelectObject(hdc,selPen);
		else
			SelectObject(hdc,i==0 ? currentPen : nullPen);

		Rectangle(hdc,16,rowY1,width,rowY2);
		SelectObject(hdc,nullBrush);
		SetTextColor(hdc,0x600000);
		TextOut(hdc,17,rowY1,temp,(int)wcslen(temp));
		SetTextColor(hdc,0x000000);
		
		switch(mode)
		{
		case MV_NORMAL:
			swprintf(temp, L"%08X  %08X  %08X  %08X",
				ReadMem32((address+0)), ReadMem32((address+4)), ReadMem32((address+8)), ReadMem32((address+12)));
			TextOut(hdc,90,rowY1,temp,(int)wcslen(temp));

			SetTextColor(hdc,0x0033BB22);
			((u32*)temp)[0] = ReadMem32(address);
			((u32*)temp)[1] = ReadMem32(address+4);
			((u32*)temp)[2] = ReadMem32(address+8);
			((u32*)temp)[3] = ReadMem32(address+12);
			((u32*)temp)[4] = 0x00000000;
			TextOut(hdc,420,rowY1,temp,(int)wcslen(temp));
		break;

		case MV_SYMBOLS:
			SetTextColor(hdc,0x0000FF);
			//int fn = address&3;//Debugger_GetSymbolNum(address);
			swprintf(temp,L"MV_SYMBOLS !!!");
	//		sprintf(temp, "%s (0x%x b)", Debugger_GetSymbolName(fn),Debugger_GetSymbolSize(fn));
			TextOut(hdc,200,rowY1,temp,(int)wcslen(temp));

			SetTextColor(hdc,0x0000000);
			UINT value = 0xBADC0D3;//ReadMem(address,4);//CMemory::ReadUnchecked_U32(address);
			swprintf(temp, L"%08x", value );
		//	sprintf(temp, "%08x [%s]", value, Debugger_GetSymbolName(Debugger_GetSymbolNum(value)));
			TextOut(hdc,70,rowY1,temp,(int)wcslen(temp));
		break;
		}
	}

	SelectObject(hdc,oldFont);
	SelectObject(hdc,oldPen);
	SelectObject(hdc,oldBrush);
	
	DeleteObject(nullPen);
	DeleteObject(currentPen);
	DeleteObject(selPen);

	DeleteObject(nullBrush);
	DeleteObject(pcBrush);
	DeleteObject(currentBrush);
	
	EndPaint(wnd, &ps);
}
Example #18
0
LRESULT CALLBACK LConProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	HWND view;
	HDC hdc;
	HBRUSH hbr;
	HGDIOBJ oldfont;
	RECT rect;
	int titlelen;
	SIZE size;
	LOGFONT lf;
	TEXTMETRIC tm;
	HINSTANCE inst = (HINSTANCE)(LONG_PTR)GetWindowLongPtr(hWnd, GWLP_HINSTANCE);
	DRAWITEMSTRUCT *drawitem;
	CHARFORMAT2W format;

	switch (msg)
	{
	case WM_CREATE:
		// Create game title static control
		memset (&lf, 0, sizeof(lf));
		hdc = GetDC (hWnd);
		lf.lfHeight = -MulDiv(12, GetDeviceCaps(hdc, LOGPIXELSY), 72);
		lf.lfCharSet = ANSI_CHARSET;
		lf.lfWeight = FW_BOLD;
		lf.lfPitchAndFamily = VARIABLE_PITCH | FF_ROMAN;
		strcpy (lf.lfFaceName, "Trebuchet MS");
		GameTitleFont = CreateFontIndirect (&lf);

		oldfont = SelectObject (hdc, GetStockObject (DEFAULT_GUI_FONT));
		GetTextMetrics (hdc, &tm);
		DefaultGUIFontHeight = tm.tmHeight;
		if (GameTitleFont == NULL)
		{
			GameTitleFontHeight = DefaultGUIFontHeight;
		}
		else
		{
			SelectObject (hdc, GameTitleFont);
			GetTextMetrics (hdc, &tm);
			GameTitleFontHeight = tm.tmHeight;
		}
		SelectObject (hdc, oldfont);

		// Create log read-only edit control
		view = CreateWindowEx (WS_EX_NOPARENTNOTIFY, "RichEdit20W", NULL,
			WS_CHILD | WS_VISIBLE | WS_VSCROLL |
			ES_LEFT | ES_MULTILINE | WS_CLIPSIBLINGS,
			0, 0, 0, 0,
			hWnd, NULL, inst, NULL);
		HRESULT hr;
		hr = GetLastError();
		if (view == NULL)
		{
			ReleaseDC (hWnd, hdc);
			return -1;
		}
		SendMessage (view, EM_SETREADONLY, TRUE, 0);
		SendMessage (view, EM_EXLIMITTEXT, 0, 0x7FFFFFFE);
		SendMessage (view, EM_SETBKGNDCOLOR, 0, RGB(70,70,70));
		// Setup default font for the log.
		//SendMessage (view, WM_SETFONT, (WPARAM)GetStockObject (DEFAULT_GUI_FONT), FALSE);
		format.cbSize = sizeof(format);
		format.dwMask = CFM_BOLD | CFM_COLOR | CFM_FACE | CFM_SIZE | CFM_CHARSET;
		format.dwEffects = 0;
		format.yHeight = 200;
		format.crTextColor = RGB(223,223,223);
		format.bCharSet = ANSI_CHARSET;
		format.bPitchAndFamily = FF_SWISS | VARIABLE_PITCH;
		wcscpy(format.szFaceName, L"DejaVu Sans");	// At least I have it. :p
		SendMessageW(view, EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&format);

		ConWindow = view;
		ReleaseDC (hWnd, hdc);

		view = CreateWindowEx (WS_EX_NOPARENTNOTIFY, "STATIC", NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | SS_OWNERDRAW, 0, 0, 0, 0, hWnd, NULL, inst, NULL);
		if (view == NULL)
		{
			return -1;
		}
		SetWindowLong (view, GWL_ID, IDC_STATIC_TITLE);
		GameTitleWindow = view;

		return 0;

	case WM_SIZE:
		if (wParam != SIZE_MAXHIDE && wParam != SIZE_MAXSHOW)
		{
			LayoutMainWindow (hWnd, ErrorPane);
		}
		return 0;

	case WM_DRAWITEM:
		// Draw title banner.
		if (wParam == IDC_STATIC_TITLE && DoomStartupInfo.Name.IsNotEmpty())
		{
			const PalEntry *c;

			// Draw the game title strip at the top of the window.
			drawitem = (LPDRAWITEMSTRUCT)lParam;

			// Draw the background.
			rect = drawitem->rcItem;
			rect.bottom -= 1;
			c = (const PalEntry *)&DoomStartupInfo.BkColor;
			hbr = CreateSolidBrush (RGB(c->r,c->g,c->b));
			FillRect (drawitem->hDC, &drawitem->rcItem, hbr);
			DeleteObject (hbr);

			// Calculate width of the title string.
			SetTextAlign (drawitem->hDC, TA_TOP);
			oldfont = SelectObject (drawitem->hDC, GameTitleFont != NULL ? GameTitleFont : (HFONT)GetStockObject (DEFAULT_GUI_FONT));
			titlelen = (int)DoomStartupInfo.Name.Len();
			GetTextExtentPoint32 (drawitem->hDC, DoomStartupInfo.Name, titlelen, &size);

			// Draw the title.
			c = (const PalEntry *)&DoomStartupInfo.FgColor;
			SetTextColor (drawitem->hDC, RGB(c->r,c->g,c->b));
			SetBkMode (drawitem->hDC, TRANSPARENT);
			TextOut (drawitem->hDC, rect.left + (rect.right - rect.left - size.cx) / 2, 2, DoomStartupInfo.Name, titlelen);
			SelectObject (drawitem->hDC, oldfont);
			return TRUE;
		}
		// Draw startup screen
		else if (wParam == IDC_STATIC_STARTUP)
		{
			if (StartupScreen != NULL)
			{
				drawitem = (LPDRAWITEMSTRUCT)lParam;

				rect = drawitem->rcItem;
				// Windows expects DIBs to be bottom-up but ours is top-down,
				// so flip it vertically while drawing it.
				StretchDIBits (drawitem->hDC, rect.left, rect.bottom - 1, rect.right - rect.left, rect.top - rect.bottom,
					0, 0, StartupBitmap->bmiHeader.biWidth, StartupBitmap->bmiHeader.biHeight,
					ST_Util_BitsForBitmap(StartupBitmap), StartupBitmap, DIB_RGB_COLORS, SRCCOPY);

				// If the title banner is gone, then this is an ENDOOM screen, so draw a short prompt
				// where the command prompt would have been in DOS.
				if (GameTitleWindow == NULL)
				{
					static const char QuitText[] = "Press any key or click anywhere in the window to quit.";

					SetTextColor (drawitem->hDC, RGB(240,240,240));
					SetBkMode (drawitem->hDC, TRANSPARENT);
					oldfont = SelectObject (drawitem->hDC, (HFONT)GetStockObject (DEFAULT_GUI_FONT));
					TextOut (drawitem->hDC, 3, drawitem->rcItem.bottom - DefaultGUIFontHeight - 3, QuitText, countof(QuitText)-1);
					SelectObject (drawitem->hDC, oldfont);
				}
				return TRUE;
			}
		}
		// Draw stop icon.
		else if (wParam == IDC_ICONPIC)
		{
			HICON icon;
			POINTL char_pos;
			drawitem = (LPDRAWITEMSTRUCT)lParam;

			// This background color should match the edit control's.
			hbr = CreateSolidBrush (RGB(70,70,70));
			FillRect (drawitem->hDC, &drawitem->rcItem, hbr);
			DeleteObject (hbr);

			// Draw the icon aligned with the first line of error text.
			SendMessage (ConWindow, EM_POSFROMCHAR, (WPARAM)&char_pos, ErrorIconChar);
			icon = (HICON)LoadImage (0, IDI_ERROR, IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_SHARED);
			DrawIcon (drawitem->hDC, 6, char_pos.y, icon);
			return TRUE;
		}
		return FALSE;

	case WM_COMMAND:
		if (ErrorIcon != NULL && (HWND)lParam == ConWindow && HIWORD(wParam) == EN_UPDATE)
		{
			// Be sure to redraw the error icon if the edit control changes.
			InvalidateRect (ErrorIcon, NULL, TRUE);
			return 0;
		}
		break;

	case WM_CLOSE:
		PostQuitMessage (0);
		break;

	case WM_DESTROY:
		if (GameTitleFont != NULL)
		{
			DeleteObject (GameTitleFont);
		}
		break;
	}
	return DefWindowProc (hWnd, msg, wParam, lParam);
}
Example #19
0
long CALLBACK EXPORT ConsoleFunc(HWND hwnd,unsigned message,WPARAM wParam,
                                 LPARAM lParam)
{
  CONSOLE *con;
  PAINTSTRUCT ps;
  RECT rect;

  switch (message) {
  case WM_CHAR:
    if ((con=Hwnd2Console(hwnd))!=NULL) {
      /* store in a key queue */
      if ((con->keyq_end+1)%KEYQUEUE_SIZE==con->keyq_start) {
        MessageBeep(MB_OK);
        break;
      } /* if */
      con->keyqueue[con->keyq_end]=(short)wParam;
      con->keyq_end=(con->keyq_end+1)%KEYQUEUE_SIZE;
    } /* if */
    break;

  case WM_CREATE:
    /* The "hwnd" member of the CONSOLE structure has not yet been set, which
     * means that Hwnd2Console() cannot work on the real "hwnd". There should
     * at every instant be only one CONSOLE structure with a NULL handle,
     * however.
     */
    if ((con=Hwnd2Console(NULL))!=NULL) {
      con->hwnd=hwnd;
      SetConsoleFont(con,con->cheight);
      GetWindowRect(hwnd, &rect);
      SetRect(&rect,rect.left,rect.top,
              rect.left+con->cwidth*con->columns,
              rect.top+con->cheight*con->winlines);
      AdjustWindowRect(&rect,GetWindowLong(hwnd,GWL_STYLE),FALSE);
      if (con->winlines<con->lines)
        rect.right+=GetSystemMetrics(SM_CXVSCROLL);
      ClampToScreen(&rect);
      SetWindowPos(hwnd,NULL,rect.left,rect.top,rect.right-rect.left,rect.bottom-rect.top,
                   SWP_NOZORDER);
    } /* if */
    break;

  case WM_DESTROY:
    if ((con=Hwnd2Console(hwnd))!=NULL)
      DoDeleteConsole(con);
    break;

  case WM_GETMINMAXINFO:
    if ((con=Hwnd2Console(hwnd))!=NULL) {
      MINMAXINFO FAR *lpmmi=(MINMAXINFO FAR*)lParam;
      int rx,ry,hsize,vsize;
      GetClientRect(hwnd,&rect);
      rx= (rect.right < con->columns*con->cwidth) ? con->columns*con->cwidth-rect.right : 0;
      ry= (rect.bottom < con->lines*con->cheight) ? con->lines*con->cheight-rect.bottom : 0;
      hsize= (ry>0) ? GetSystemMetrics(SM_CXVSCROLL) : 0;
      vsize= (rx>0) ? GetSystemMetrics(SM_CYHSCROLL) : 0;
      SetRect(&rect,0,0,con->cwidth*con->columns+hsize,con->cheight*con->lines+vsize);
      AdjustWindowRect(&rect,GetWindowLong(hwnd,GWL_STYLE),FALSE);
      lpmmi->ptMaxTrackSize.x=rect.right-rect.left;
      lpmmi->ptMaxTrackSize.y=rect.bottom-rect.top;
      lpmmi->ptMaxSize=lpmmi->ptMaxTrackSize;
    } /* if */
    break;

  case WM_SYSKEYDOWN:
  case WM_KEYDOWN:
    if ((con=Hwnd2Console(hwnd))!=NULL) {
      TCHAR str[20];
      int i;
      str[0]=__T('\0');
      switch (LOWORD(wParam)) {
      case VK_F1:
      case VK_F2:
      case VK_F3:
      case VK_F4:
      case VK_F5:
      case VK_F6:
      case VK_F7:
      case VK_F8:
      case VK_F9:
      case VK_F10:
      case VK_F11:
      case VK_F12:
        if (LOWORD(wParam)<=VK_F5)
          _stprintf(str,__T("\033[%d~\n"),LOWORD(wParam)-VK_F1+11);
        else if (LOWORD(wParam)==VK_F10)
          _stprintf(str,__T("\033[%d~\n"),LOWORD(wParam)-VK_F6+17);
        else
          _stprintf(str,__T("\033[%d~\n"),LOWORD(wParam)-VK_F11+23);
        break;
      case VK_ADD:
      case VK_SUBTRACT:
        /* check Ctrl key */
        if ((GetKeyState(VK_CONTROL) & 0x8000)!=0) {
          POINT pt;
          int newheight=con->cheight;
          int oldheight=newheight;
          int incr= (LOWORD(wParam)==VK_SUBTRACT) ? -1 : 1;
          do {
            newheight+=incr;
            /* make a new font, re-create a caret and redraw everything */
            SetConsoleFont(con,newheight);
          } while (newheight>5 && (oldheight==con->cheight || con->hfont==NULL));
          if (con->hfont==NULL) /* reset to original on failure */
            SetConsoleFont(con,oldheight);
          GetClientRect(hwnd,&rect);
          DestroyCaret();
          CreateCaret(hwnd,NULL,con->cwidth,2);
          RefreshCaretPos(con);
          /* redraw the window */
          InvalidateRect(hwnd,NULL,TRUE);
          /* resize the window */
          SetRect(&rect,0,0,con->cwidth*con->columns,con->cheight*con->winlines);
          AdjustWindowRect(&rect,GetWindowLong(hwnd,GWL_STYLE),FALSE);
          pt.x=pt.y=0;
          ClientToScreen(hwnd,&pt);
          OffsetRect(&rect,pt.x,pt.y);
          ClampToScreen(&rect);
          SetWindowPos(hwnd,NULL,rect.left,rect.top,rect.right-rect.left,rect.bottom-rect.top,
                       SWP_NOZORDER);
        } /* if */
        break;
      case VK_UP:
        _tcscpy(str,__T("\033[A"));
        break;
      case VK_DOWN:
        _tcscpy(str,__T("\033[B"));
        break;
      case VK_RIGHT:
        _tcscpy(str,__T("\033[C"));
        break;
      case VK_LEFT:
        _tcscpy(str,__T("\033[D"));
        break;
      case VK_HOME:
        _tcscpy(str,__T("\033[1~"));
        break;
      case VK_END:
        _tcscpy(str,__T("\033[4~"));
        break;
      case VK_INSERT:
        _tcscpy(str,__T("\033[2~"));
        break;
      case VK_DELETE:
        _tcscpy(str,__T("\033[3~"));
        break;
      case VK_PRIOR:  /* PageUp */
        _tcscpy(str,__T("\033[5~"));
        break;
      case VK_NEXT:   /* PageDown */
        _tcscpy(str,__T("\033[6~"));
        break;
      default:
        return DefWindowProc(hwnd,message,wParam,lParam);
      } /* switch */
      for (i=0; str[i]!=__T('\0'); i++) {
        if ((con->keyq_end+1)%KEYQUEUE_SIZE!=con->keyq_start) {
          con->keyqueue[con->keyq_end]=(short)str[i];
          con->keyq_end=(con->keyq_end+1)%KEYQUEUE_SIZE;
        } /* if */
      } /* for */
    } /* if */
    break;

  case WM_KILLFOCUS:
    HideCaret(hwnd);
    DestroyCaret();
    break;
  case WM_SETFOCUS:
    if ((con=Hwnd2Console(hwnd))!=NULL) {
      CreateCaret(hwnd,NULL,con->cwidth,2);
      RefreshCaretPos(con);
      ShowCaret(hwnd);
    } /* if */
    break;

  case WM_LBUTTONDOWN:
    SetFocus(hwnd);
    break;

  case WM_PAINT:
    HideCaret(hwnd);
    BeginPaint(hwnd, &ps);
    if ((con=Hwnd2Console(hwnd))!=NULL && con->buffer!=NULL) {
      TCHAR *string;
      string=malloc(con->columns*sizeof(TCHAR));
      if (string!=NULL) {
        int l,c,bpos,start;
        TCHAR attr;
        HFONT hfontOrg;
        int scrollx=GetScrollPos(hwnd,SB_HORZ);
        int scrolly=GetScrollPos(hwnd,SB_VERT);
        GetClientRect(hwnd,&rect);
        hfontOrg=SelectObject(ps.hdc,con->hfont);
        SetBkMode(ps.hdc,OPAQUE);
        for (l=0; l<con->lines; l++) {
          bpos=l*con->columns*2;
          c=0;
          while (c<con->columns) {
            /* find stretches with the same attribute */
            attr=con->buffer[bpos+1];
            start=c;
            while (c<con->columns && con->buffer[bpos+1]==attr) {
              assert(c-start>=0);
              assert(c-start<con->columns);
              string[c-start]=con->buffer[bpos];
              c++;
              bpos+=2;
            } /* if */
            SetTextAttribute(ps.hdc,attr);
            TextOut(ps.hdc,start*con->cwidth-scrollx,l*con->cheight-scrolly,string,c-start);
          } /* while */
        } /* for */
        SelectObject(ps.hdc,hfontOrg);
        free(string);
      } /* if */
    } /* if */
    EndPaint(hwnd, &ps);
    ShowCaret(hwnd);
    break;

  case WM_SIZE:
    if ((con=Hwnd2Console(hwnd))!=NULL) {
      int rx,ry;
      /* add/remove/recalculate scroll bars */
      GetClientRect(hwnd,&rect);
      rx= (rect.right < con->columns*con->cwidth) ? con->columns*con->cwidth-rect.right : 0;
      ry= (rect.bottom < con->lines*con->cheight) ? con->lines*con->cheight-rect.bottom : 0;
      /* adjust scrolling position, if necessary */
      if (GetScrollPos(hwnd,SB_HORZ)>=rx) {
        SetScrollPos(hwnd,SB_HORZ,rx,FALSE);
        InvalidateRect(hwnd,NULL,FALSE);
      } /* if */
      if (GetScrollPos(hwnd,SB_VERT)>=ry) {
        SetScrollPos(hwnd,SB_VERT,ry,FALSE);
        InvalidateRect(hwnd,NULL,FALSE);
      } /* if */
      SetScrollRange(hwnd,SB_HORZ,0,rx,TRUE);
      SetScrollRange(hwnd,SB_VERT,0,ry,TRUE);
    } /* if */
    break;

  case WM_HSCROLL:
    if ((con=Hwnd2Console(hwnd))!=NULL) {
      int scrollx=GetScrollPos(hwnd,SB_HORZ);
      int oldpos=scrollx;
      int min,max;
      GetScrollRange(hwnd,SB_HORZ,&min,&max);
      switch (LOWORD(wParam)) {
      case SB_TOP:
        scrollx=min;
        break;
      case SB_BOTTOM:
        scrollx=max;
        break;
      case SB_LINELEFT:
        scrollx=(scrollx>min) ? scrollx-1 : min;
        break;
      case SB_LINERIGHT:
        scrollx=(scrollx<max) ? scrollx+1 : max;
        break;
      case SB_PAGELEFT:
        scrollx=(scrollx>min) ? scrollx-50 : min;
        break;
      case SB_PAGERIGHT:
        scrollx=(scrollx<max) ? scrollx+50 : max;
        break;
      case SB_THUMBTRACK:
        scrollx=(int)HIWORD(wParam);
        break;
      } /* switch */
      if (oldpos!=scrollx) {
        SetScrollPos(hwnd,SB_HORZ,scrollx,TRUE);
        InvalidateRect(hwnd,NULL,FALSE);
        RefreshCaretPos(con);
      } /* if */
    } /* if */
    break;
  case WM_VSCROLL:
    if ((con=Hwnd2Console(hwnd))!=NULL) {
      int scrolly=GetScrollPos(hwnd,SB_VERT);
      int oldpos=scrolly;
      int min,max;
      GetScrollRange(hwnd,SB_VERT,&min,&max);
      switch (LOWORD(wParam)) {
      case SB_TOP:
        scrolly=min;
        break;
      case SB_BOTTOM:
        scrolly=max;
        break;
      case SB_LINELEFT:
        scrolly=(scrolly>min) ? scrolly-1 : min;
        break;
      case SB_LINERIGHT:
        scrolly=(scrolly<max) ? scrolly+1 : max;
        break;
      case SB_PAGELEFT:
        scrolly=(scrolly>min) ? scrolly-50 : min;
        break;
      case SB_PAGERIGHT:
        scrolly=(scrolly<max) ? scrolly+50 : max;
        break;
      case SB_THUMBTRACK:
        scrolly=(int)HIWORD(wParam);
        break;
      } /* switch */
      if (oldpos!=scrolly) {
        SetScrollPos(hwnd,SB_VERT,scrolly,TRUE);
        InvalidateRect(hwnd,NULL,FALSE);
        RefreshCaretPos(con);
      } /* if */
    } /* if */
    break;

  default:
    return DefWindowProc(hwnd,message,wParam,lParam);
  } /* switch */
  return 0L;
}
Example #20
0
int ProcessImage(char	*filename,		/* input filename */
				int	OrientationFlag,	/* input:  0 => up, 1 => left, 2 => right */
				double	lefteye_circles[4],	/* output: for coord system aligning */
				double	righteye_circles[4],	/* output: for coord system aligning */
				int	*strabismus,		/* output:  flag has 0-3 for value */
				int	*red_reflex_lumin,	/* output:  flag has 0-2 for value */
				int	*left_arr_class,	/* output:  flag has 0-2 for value */
				int	*right_arr_class,	/* output:  flag has 0-2 for value */
				int	*left_arr_col,		/* output:  X-centroid of left-eye ARR */
				int	*left_arr_row,		/* output:  Y-centroid of left-eye ARR */
				int	*right_arr_col,		/* output:  X-centroid of right-eye ARR */
				int	*right_arr_row,		/* output:  Y-centroid of right-eye ARR */
				int	FullImagesFlag,		/* input:  write out full-size images? */
				int	RawEyesFlag)		/* input:  write out raw zoomed eyes? */

{
char		text[300],savepath[300],savefile[300];
HANDLE		hFind;
WIN32_FIND_DATA	fd;
HDC			hDC;
HBRUSH		DrawBrush;
RECT		outline;
unsigned char	*Raw,*threshimage,*dispimage;
int			i,ROWS,COLS,temp;
int			*points,total_points,one,two,total_circles;
double		**red_circles,*red_spacings;
double		*red_gradients,*red_residuals;
double		**white_circles,*white_spacings;
double		*white_gradients,*white_residuals;
double		*white_red_radii;
int			corneal_reflex_indices1[400],total_cr1;
int			corneal_reflex_indices2[400],total_cr2;
int			abnormal_red_reflex_indices1[4000],total_arr1;
int			abnormal_red_reflex_indices2[4000],total_arr2;
double		pupil_to_pupil_dist,pupils_horizon_angle,temp_d;
int			lefteye_cr_point,righteye_cr_point,diff;
int			red_reflex_avg1[3],red_reflex_avg2[3];

		/*********************************************************
		** All reports start out not available
		*********************************************************/

(*strabismus)=NOT_AVAILABLE;
(*red_reflex_lumin)=NOT_AVAILABLE;
(*left_arr_class)=NOT_AVAILABLE;
(*right_arr_class)=NOT_AVAILABLE;

		/*********************************************************
		** Get memory dynamically -- it's a bunch
		*********************************************************/

if ((points=(int *)calloc(MAX_BRIGHTS,sizeof(int))) == NULL  ||
    (red_circles=(double **)calloc(MAX_BRIGHTS,sizeof(double *))) == NULL  ||
    (red_spacings=(double *)calloc(MAX_BRIGHTS,sizeof(double))) == NULL  ||
    (red_gradients=(double *)calloc(MAX_BRIGHTS,sizeof(double))) == NULL  ||
    (red_residuals=(double *)calloc(MAX_BRIGHTS,sizeof(double))) == NULL  ||
    (white_circles=(double **)calloc(MAX_BRIGHTS,sizeof(double *))) == NULL  ||
    (white_spacings=(double *)calloc(MAX_BRIGHTS,sizeof(double))) == NULL  ||
    (white_gradients=(double *)calloc(MAX_BRIGHTS,sizeof(double))) == NULL  ||
    (white_residuals=(double *)calloc(MAX_BRIGHTS,sizeof(double))) == NULL  ||
    (white_red_radii=(double *)calloc(MAX_BRIGHTS,sizeof(double))) == NULL)
  {
  MessageBox(MainWnd,"Unable to allocate memory","ProcessImage()",MB_OK | MB_APPLMODAL);
  exit(0);
  }
for (i=0; i<MAX_BRIGHTS; i++)
  {
  red_circles[i]=(double *)calloc(3,sizeof(double));
  white_circles[i]=(double *)calloc(3,sizeof(double));
  }

		/*********************************************************
		** Get image ready to process -- load used to happen here,
		** but with GUI interface, just copy for display
		*********************************************************/

StripFilename(filename,text);
if (OrientationFlag == 0)
  {
  Raw=up_image;
  ROWS=UP_ROWS;
  COLS=UP_COLS;
  }
else
  {
  Raw=side_image;
  ROWS=SIDE_ROWS;
  COLS=SIDE_COLS;
  }
threshimage=(unsigned char *)calloc(ROWS*COLS,1);
if (DisplayGraphics == 1)
  dispimage=(unsigned char *)calloc(ROWS*COLS*3,1);
else
  dispimage=NULL;
if (threshimage == NULL  ||  (DisplayGraphics == 1  &&  dispimage == NULL))
  {
  MessageBox(MainWnd,"Unable to allocate memory 2","ProcessImage()",MB_OK | MB_APPLMODAL);
  exit(0);
  }
if (DisplayGraphics == 1)
  {
  for (i=0; i<ROWS*COLS*3; i++)
    dispimage[i]=Raw[i]/2;
  MakeDisplayImage(dispimage,ROWS,COLS,0);
  PaintImage();
  }
sprintf(savepath,"Analyzing image %s ...",text);
hDC=GetDC(MainWnd);
outline.top=0; outline.bottom=25;
outline.left=0; outline.right=385;
DrawBrush=CreateSolidBrush(RGB(255,255,255));
FillRect(hDC,&outline,DrawBrush);
DeleteObject(DrawBrush);
TextOut(hDC,0,0,savepath,strlen(savepath));
ReleaseDC(MainWnd,hDC);

		/*********************************************************
		** Find eye models -- corneal reflexes (CRs) modeled by
		** blobs, followed by pupil and iris boundaries modeled
		** by concentric circles.
		*********************************************************/

i=FindBrightSpots(Raw,ROWS,COLS,threshimage,&total_points,points);
if (i == 0)
  {
  MessageBox(MainWnd,"Please try another photograph.","Image too dark or too bright",MB_OK | MB_APPLMODAL);
  return(0);	/* too many bright spots */
  }
FindCircles(Raw,ROWS,COLS,dispimage,points,total_points,
        red_circles,red_gradients,red_spacings,red_residuals,white_circles,
        white_red_radii,white_gradients,white_spacings,white_residuals);
total_circles=BestTwoCircles(points,COLS,total_points,red_circles,red_gradients,
        red_spacings,red_residuals,white_circles,white_red_radii,
        white_gradients,white_spacings,white_residuals,&one,&two);
if (total_circles < 2)
  {
  /* if (AutoReport == 0) */
    MessageBox(MainWnd,"Please try another photograph.","Photo inconclusive",MB_OK | MB_APPLMODAL);
  return(0);	/* no eyes, no report */
  }

if (DisplayGraphics == 1)
  {
  for (i=0; i<ROWS*COLS*3; i++)
    dispimage[i]=Raw[i]/2;
  MakeDisplayImage(dispimage,ROWS,COLS,0);
  PaintImage();
  FlashCircles(dispimage,ROWS,COLS,
	  red_circles[one][2] >= 0.0 ? red_circles[one] : white_circles[one],
	  red_circles[two][2] >= 0.0 ? red_circles[two] : white_circles[two]);
  for (i=0; i<ROWS*COLS*3; i++)
    dispimage[i]=Raw[i];
  }

		/*********************************************************
		** Test resulting eye model pair.  Red circles must be
		** minimum strength, minimum spacing (of points in circle).
		** Eyes must not be overlapping, and must have tolerable
		** angle of inclination with user-given orientation.
		*********************************************************/

/* printf("red circle tests %lf,%lf %lf,%lf ",
	red_residuals[one],red_spacings[one],
	red_residuals[two],red_spacings[two]); */
//if (red_residuals[one] >= MAX_EYE_RESID  ||  red_spacings[one] > MAX_EYE_SPACE  ||
//	red_residuals[two] >= MAX_EYE_RESID  ||  red_spacings[two] > MAX_EYE_SPACE )
//  {
//  if (AutoReport == 0)
//    MessageBox(MainWnd,"Please try another photograph.","Photo inconclusive",MB_OK | MB_APPLMODAL);
//  return(0);	/* not good circle fits */
//  }
if (red_residuals[one] > 0.0)
  {
  lefteye_circles[0]=red_circles[one][0];
  lefteye_circles[1]=red_circles[one][1];
  lefteye_circles[2]=red_circles[one][2];
  lefteye_circles[3]=white_red_radii[one];
  }
else
  {
  lefteye_circles[0]=white_circles[one][0];
  lefteye_circles[1]=white_circles[one][1];
  lefteye_circles[2]=-1.0;
  lefteye_circles[3]=white_circles[one][2];
  }
lefteye_cr_point=points[one];
if (red_residuals[two] > 0.0)
  {
  righteye_circles[0]=red_circles[two][0];
  righteye_circles[1]=red_circles[two][1];
  righteye_circles[2]=red_circles[two][2];
  righteye_circles[3]=white_red_radii[two];
  }
else
  {
  righteye_circles[0]=white_circles[two][0];
  righteye_circles[1]=white_circles[two][1];
  righteye_circles[2]=-1.0;
  righteye_circles[3]=white_circles[two][2];
  }
righteye_cr_point=points[two];
pupil_to_pupil_dist=sqrt(SQR(lefteye_circles[0]-righteye_circles[0])+
	SQR(lefteye_circles[1]-righteye_circles[1]));
if (OrientationFlag == 0)	/* up-image */
  pupils_horizon_angle=atan2(fabs(lefteye_circles[1]-righteye_circles[1]),
	fabs(lefteye_circles[0]-righteye_circles[0]));
else				/* side image, right or left */
  pupils_horizon_angle=atan2(fabs(lefteye_circles[0]-righteye_circles[0]),
	fabs(lefteye_circles[1]-righteye_circles[1]));
/* printf("\neye model tests %lf-%lf-%lf  %lf  ", 
	pupil_to_pupil_dist,lefteye_circles[3],righteye_circles[3],
	pupils_horizon_angle*180/M_PI); */
if (pupil_to_pupil_dist < lefteye_circles[3]  ||
	pupil_to_pupil_dist < righteye_circles[3]  ||
	pupils_horizon_angle > 30.0*M_PI/180.0)
  {
  if (DisplayGraphics == 1)
    MessageBox(MainWnd,"Please try another photograph.","Eye orientation not consistent",MB_OK | MB_APPLMODAL);
  return(0);			/* reliable eye models not found */
  }
if (lefteye_circles[2] <= 7.5  ||  righteye_circles[2] <= 7.5)
  {
  if (DisplayGraphics == 1)
    MessageBox(MainWnd,"Please try another photograph.","Pupils need to be more dilated.",MB_OK | MB_APPLMODAL);
  return(0);			/* reliable eye models not found */
  }

		/*********************************************************
		** Switch left and right eye models if not in proper place
		*********************************************************/

if ((OrientationFlag == 0  &&  lefteye_circles[0] < righteye_circles[0])  ||
      (OrientationFlag == 1  &&  lefteye_circles[1] > righteye_circles[1])  ||
      (OrientationFlag == 2  &&  lefteye_circles[1] < righteye_circles[1]))
  {	/* switch left and right eye to proper places */
  for (i=0; i<4; i++)
    {
    temp_d=lefteye_circles[i];
    lefteye_circles[i]=righteye_circles[i];
    righteye_circles[i]=temp_d;
    }
  temp=lefteye_cr_point;
  lefteye_cr_point=righteye_cr_point;
  righteye_cr_point=temp;
  }

		/*********************************************************
		** Classify pupil interior.  This finds any abnormal areas
		** in the red reflexes, and classifies them.  It also
		** classifies any possible strabismus, and decides if
		** the red reflexes have equal luminensce.
		*********************************************************/

ClassifyPupilInterior(Raw,threshimage,dispimage,ROWS,COLS,lefteye_circles,
	lefteye_cr_point,corneal_reflex_indices1,&total_cr1,
	abnormal_red_reflex_indices1,&total_arr1,red_reflex_avg1,
	left_arr_class,left_arr_col,left_arr_row);
ClassifyPupilInterior(Raw,threshimage,dispimage,ROWS,COLS,righteye_circles,
	righteye_cr_point,corneal_reflex_indices2,&total_cr2,
	abnormal_red_reflex_indices2,&total_arr2,red_reflex_avg2,
	right_arr_class,right_arr_col,right_arr_row);
ClassifyPupilAlignment(lefteye_circles,corneal_reflex_indices1,total_cr1,
	righteye_circles,corneal_reflex_indices2,total_cr2,
	COLS,OrientationFlag,strabismus);
hDC=GetDC(MainWnd);
if (lefteye_circles[2] > 0.0  &&  righteye_circles[2] > 0.0)
  {
  diff=(abs(red_reflex_avg1[0]-red_reflex_avg2[0])+
	  abs(red_reflex_avg1[1]-red_reflex_avg2[1])+
	  abs(red_reflex_avg1[2]-red_reflex_avg2[2]))/3;
  if (diff <= MAX_LUMIN_DIFF)
	{
//	TextOut(hDC,0,0,"RR NORMAL",strlen("RR NORMAL"));
    *red_reflex_lumin=NORMAL;
	}
  else
	{
//	TextOut(hDC,0,0,"RR UNEQUAL",strlen("RR UNEQUAL"));
    *red_reflex_lumin=UNEQUAL_LUMIN;
	}
  }
else
  {
//  TextOut(hDC,0,0,"RR NOT DETECTED",strlen("RR NOT DETECTED"));
  *red_reflex_lumin=NOT_DETECTED;
  }
ReleaseDC(MainWnd,hDC);

		/*********************************************************
		** Write out images for report
		*********************************************************/

sprintf(savepath,"%s%sSimages",DataPath,
		(DataPath[strlen(DataPath)-1] == '\\' ? "" : "\\"));
if ((hFind=FindFirstFile(savepath,&fd)) == INVALID_HANDLE_VALUE)
  {
  if (!CreateDirectory(savepath,NULL))
    {
	MessageBox(NULL,"Saving results","Unable to create Simages folder; saving in runtime folder",
		  MB_APPLMODAL | MB_OK);
	strcpy(savepath,".\\");
	}
  }
FindClose(hFind);
sprintf(savefile,"%s\\S%s",savepath,&(filename[1]));
SaveImage(savefile,Raw,ROWS,COLS,4);

sprintf(savepath,"%s%seyes",DataPath,
		(DataPath[strlen(DataPath)-1] == '\\' ? "" : "\\"));
if ((hFind=FindFirstFile(savepath,&fd)) == INVALID_HANDLE_VALUE)
  {
  if (!CreateDirectory(savepath,NULL))
    {
	MessageBox(NULL,"Saving results","Unable to create eyes folder; saving in runtime folder",
		  MB_APPLMODAL | MB_OK);
	strcpy(savepath,".\\");
	}
  }
FindClose(hFind);
strcat(savepath,"\\"); strcat(savepath,text);
WriteImage(savepath,Raw,ROWS,COLS,
	lefteye_circles,corneal_reflex_indices1,total_cr1,
	abnormal_red_reflex_indices1,total_arr1,*left_arr_class,
	righteye_circles,corneal_reflex_indices2,total_cr2,
	abnormal_red_reflex_indices2,total_arr2,*right_arr_class,
	OrientationFlag,FullImagesFlag,RawEyesFlag,1);

		/*********************************************************
		** Free up dynamic memory
		*********************************************************/

for (i=0; i<MAX_BRIGHTS; i++)
  {
  free(red_circles[i]);
  free(white_circles[i]);
  }
free(points);
free(red_circles);
free(red_spacings);
free(red_gradients);
free(red_residuals);
free(white_circles);
free(white_spacings);
free(white_gradients);
free(white_residuals);
free(white_red_radii);

free(threshimage);
if (DisplayGraphics == 1)
  free(dispimage);
return(1);
}
Example #21
0
void CTextButton::draw(HDC hdc, int ox, int oy)
{
	CFButton::draw(hdc, ox, oy) ;
   TextOut(hdc, x+ox+2, y+oy+2, str.c_str(), str.size()) ;
}
Example #22
0
// ----------------------------------------------------------------------------------------
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
 HRSRC   hResource;
 HGLOBAL resPoints;
 DWORD   resSize;
 LPVOID  rgnPoints;
 HRGN    hWindowRegion;
 static  CFont fntTitle;
 static  CFont fntDescr;
 static  HWND  hCloseButton = NULL;
 HDC     hdc;
 PAINTSTRUCT pt;
	
 switch (message) 
 {
  case WM_CREATE:		 
   hResource = FindResource(d_about.hInstance,d_about.d_lprgnname,ABOUT_STC_RGN_RESOURCE_TYPE);
   if (NULL==hResource) 
    AfxMessageBox(_T("Can't find resource!"),MB_OK|MB_ICONSTOP);

   resPoints = LoadResource(d_about.hInstance,hResource);
   if (NULL==resPoints)
    AfxMessageBox(_T("Can't load resource!"),MB_OK|MB_ICONSTOP);

   resSize = SizeofResource(d_about.hInstance,hResource);
   if (0==resSize)
    AfxMessageBox(_T("Size of resource = 0 !"),MB_OK|MB_ICONSTOP);

   rgnPoints = LockResource(resPoints);
   hWindowRegion = ExtCreateRegion(NULL,resSize,(RGNDATA*)rgnPoints);
   SetWindowRgn(hWnd,hWindowRegion,TRUE);

   hCloseButton = CreateWindowEx(NULL,_T("button"),_T("close"),
                WS_CHILD | (d_about.showCloseButton ? WS_VISIBLE : 0),
                280,186,45,16,hWnd,(HMENU)IDC_BUTTON_CLOSE,
				d_about.hInstance,NULL);

   if (d_about.modal)
    ::SetFocus(hCloseButton);

   fntDescr.CreateFont(
   12,                        // nHeight
   0,                         // nWidth
   0,                         // nEscapement
   0,                         // nOrientation
   FW_NORMAL,                 // nWeight
   FALSE,                     // bItalic
   FALSE,                     // bUnderline
   0,                         // cStrikeOut
   ANSI_CHARSET,              // nCharSet
   OUT_DEFAULT_PRECIS,        // nOutPrecision
   CLIP_DEFAULT_PRECIS,       // nClipPrecision
   DEFAULT_QUALITY,           // nQuality
   DEFAULT_PITCH | FF_SWISS,  // nPitchAndFamily
   _T("Arial"));

   fntTitle.CreateFont(
   14,                        // nHeight
   0,                         // nWidth
   0,                         // nEscapement
   0,                         // nOrientation
   FW_NORMAL,                 // nWeight
   FALSE,                     // bItalic
   FALSE,                     // bUnderline
   0,                         // cStrikeOut
   ANSI_CHARSET,              // nCharSet
   OUT_DEFAULT_PRECIS,        // nOutPrecision
   CLIP_DEFAULT_PRECIS,       // nClipPrecision
   DEFAULT_QUALITY,           // nQuality
   DEFAULT_PITCH | FF_SWISS,  // nPitchAndFamily
   _T("Arial"));

   SendMessage(hCloseButton,WM_SETFONT,(LPARAM)fntDescr.m_hObject,TRUE);

   if (d_about.autoClose > 0)
     SetTimer(hWnd, AUTOCLOSE_TIMER_ID, d_about.autoClose, NULL);
   break;
  case WM_LBUTTONDOWN:
   SendMessage(hWnd,WM_NCLBUTTONDOWN,HTCAPTION,lParam); 		
   break;
  case WM_COMMAND:
   if (LOWORD(wParam)==IDC_BUTTON_CLOSE)
    DestroyWindow(hWnd);
   break;
  case WM_DESTROY:
   fntTitle.DeleteObject();
   fntDescr.DeleteObject();
   //we again ready for create a new instance!
   is_instance = false;
   break;
  case WM_KILLFOCUS:
   if (d_about.modal) 
    if ((HWND)wParam!=hCloseButton)
     SetFocus(hWnd);
   break;
  case WM_PAINT:
   hdc = BeginPaint(hWnd,&pt);
   SetBkColor(hdc,RGB(0,0,0));
   //draw title
   SetTextColor(hdc,RGB(40,250,50));
   SelectObject(hdc,fntTitle.m_hObject);
   TextOut(hdc,195,16,d_about.about_product,_tcslen(d_about.about_product));
   //draw description
   SelectObject(hdc,fntDescr.m_hObject);
   SetTextColor(hdc,RGB(250,240,250));
   SetBkMode(hdc, TRANSPARENT);
   DrawText(hdc,d_about.about_description,-1,CRect(203,45,433,170),DT_EDITCONTROL |DT_WORD_ELLIPSIS);

   EndPaint(hWnd,&pt); 
   break;
  case WM_TIMER:
   ASSERT(KillTimer(hWnd, AUTOCLOSE_TIMER_ID));
   DestroyWindow(hWnd);
   break;
  default:
   return DefWindowProc(hWnd, message, wParam, lParam);
 }
 return 0;
}
Example #23
0
/** 在指定位置输出字符串 */
void GLFont::PrintText(char *string, float x, float y)
{
	HBITMAP hBitmap,hOldBmp; /**< 定义两个位图句柄 */
	BITMAP bm;               /**< 位图结构变量 */
	SIZE size;               /**< 位图尺寸 */
	GLboolean lp,tp;
	HDC hDC = ::CreateCompatibleDC(0); /**< 暂存设备场景 */
	glGetBooleanv(GL_LIGHTING,&lp);  /**< 查看场景中是否有光照 */
	glGetBooleanv(GL_TEXTURE_2D,&tp);/**< 查看场景中是否启用纹理 */
	/** 保存和设置一些属性 */
	glLoadIdentity();
	glPushMatrix();
	glTranslatef(0,0,-10.0f);
	glDisable(GL_LIGHTING);    /**< 关闭光照 */
	glDisable(GL_TEXTURE_2D);  /**< 关闭纹理 */
	glDisable(GL_DEPTH_TEST);  /**< 关闭深度测试 */
	SelectObject(hDC, m_hFont); /**< 选择字体 */
	::GetTextExtentPoint32(hDC, string, strlen(string), &size);/**< 获取字符位图大小 */
	hBitmap = CreateBitmap(size.cx, size.cy,1, 1, NULL); /**< 创建与hDC相关单色位图 */
	hOldBmp = (HBITMAP)SelectObject(hDC,hBitmap); /**< 选择位图 */
  
	SetBkColor(hDC, RGB(0, 0, 0));              /**< 背景色为黑色 */
	SetTextColor(hDC, RGB(255, 255, 255));      /**< 字体颜色白色 */
	SetBkMode(hDC, OPAQUE);                     /**< 用当前的背景颜色填充背景 */
	TextOut(hDC, 0, 0, string, strlen(string)); /**< 输出文字到暂存hDC */
	/** 获得相关位图数据结构 */
	GetObject(hBitmap, sizeof(bm), &bm);
	size.cx = (bm.bmWidth + 31) & (~31); /**< 边缘对齐 */
	size.cy = bm.bmHeight;
	int bufsize = size.cx * size.cy/8;  /**< 图形数据长度 */
    /** 定义单色位图结构 */  
	struct {
	BITMAPINFOHEADER bih;
	RGBQUAD col[2];
	}bic;
    /** 获取单色位图结构信息 */
	BITMAPINFO *binf = (BITMAPINFO *)&bic;
	binf->bmiHeader.biSize = sizeof(binf->bmiHeader); /**< 修改结构信息 */
	binf->bmiHeader.biWidth = bm.bmWidth;
	binf->bmiHeader.biHeight = bm.bmHeight;
	binf->bmiHeader.biPlanes = 1;
	binf->bmiHeader.biBitCount = 1;       /**< 单色 */
	binf->bmiHeader.biCompression = BI_RGB;  /**< 颜色方式 */
	binf->bmiHeader.biSizeImage = bufsize;
	binf->bmiHeader.biXPelsPerMeter = 1;
	binf->bmiHeader.biYPelsPerMeter = 1;
	binf->bmiHeader.biClrUsed = 0;
	binf->bmiHeader.biClrImportant = 0;
	/** 定义图形数据块 */ 
	UCHAR* pBmpBits = new UCHAR[bufsize];	
	memset(pBmpBits, 0, sizeof(UCHAR)*bufsize);
	/** 将设备无关数据保存在pBmpBits指向的数据块中 */
	::GetDIBits(hDC, hBitmap, 0, bm.bmHeight, pBmpBits, binf,DIB_RGB_COLORS);
	 
	/** 显示字符串 */
	glPixelStorei(GL_UNPACK_ALIGNMENT, 1); /**< 指定像素存储模式 */
	glRasterPos2f(x,y);                  /**< 定位 */
	glBitmap(size.cx, size.cy, 0.0, 0.0, 0.0, 0.0, pBmpBits); /**< 位图显示 */
	delete pBmpBits;                       /**< 删除指针 */
	SelectObject(hDC, hOldBmp);           /**< 恢复原来位图信息 */
	DeleteObject(hBitmap);
	::DeleteDC(hDC);
	/** 恢复一些属性 */
	if(lp)
         glEnable(GL_LIGHTING);       /**< 启用光照 */
	if(tp)
		glEnable(GL_TEXTURE_2D);      /**< 启用纹理 */
	glEnable(GL_DEPTH_TEST);          /**< 启用深度测试 */
	glPopMatrix();
}
Example #24
0
VOID DIALOG_FilePrint(VOID)
{
    DOCINFO di;
    TEXTMETRIC tm;
    PRINTDLG printer;
    SIZE szMetric;
    int border;
    int xLeft, yTop, pagecount, dopage, copycount;
    unsigned int i;
    LOGFONT hdrFont;
    HFONT font, old_font=0;
    DWORD size;
    LPTSTR pTemp;
    static const TCHAR times_new_roman[] = _T("Times New Roman");
    RECT rcPrintRect;

    /* Get a small font and print some header info on each page */
    ZeroMemory(&hdrFont, sizeof(hdrFont));
    hdrFont.lfHeight = 100;
    hdrFont.lfWeight = FW_BOLD;
    hdrFont.lfCharSet = ANSI_CHARSET;
    hdrFont.lfOutPrecision = OUT_DEFAULT_PRECIS;
    hdrFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
    hdrFont.lfQuality = PROOF_QUALITY;
    hdrFont.lfPitchAndFamily = VARIABLE_PITCH | FF_ROMAN;
    _tcscpy(hdrFont.lfFaceName, times_new_roman);

    font = CreateFontIndirect(&hdrFont);

    /* Get Current Settings */
    ZeroMemory(&printer, sizeof(printer));
    printer.lStructSize = sizeof(printer);
    printer.hwndOwner = Globals.hMainWnd;
    printer.hInstance = Globals.hInstance;

    /* Set some default flags */
    printer.Flags = PD_RETURNDC | PD_SELECTION;

    /* Disable the selection radio button if there is no text selected */
    if (!GetSelectionTextLength(Globals.hEdit))
    {
        printer.Flags = printer.Flags | PD_NOSELECTION;
    }

    printer.nFromPage = 0;
    printer.nMinPage = 1;
    /* we really need to calculate number of pages to set nMaxPage and nToPage */
    printer.nToPage = (WORD)-1;
    printer.nMaxPage = (WORD)-1;

    /* Let commdlg manage copy settings */
    printer.nCopies = (WORD)PD_USEDEVMODECOPIES;

    printer.hDevMode = Globals.hDevMode;
    printer.hDevNames = Globals.hDevNames;

    if (!PrintDlg(&printer))
    {
        DeleteObject(font);
        return;
    }

    Globals.hDevMode = printer.hDevMode;
    Globals.hDevNames = printer.hDevNames;

    assert(printer.hDC != 0);

    /* initialize DOCINFO */
    di.cbSize = sizeof(DOCINFO);
    di.lpszDocName = Globals.szFileTitle;
    di.lpszOutput = NULL;
    di.lpszDatatype = NULL;
    di.fwType = 0;

    if (StartDoc(printer.hDC, &di) <= 0)
    {
        DeleteObject(font);
        return;
    }


    /* Get the file text */
    if (printer.Flags & PD_SELECTION)
    {
        size = GetSelectionTextLength(Globals.hEdit) + 1;
    }
    else
    {
        size = GetWindowTextLength(Globals.hEdit) + 1;
    }

    pTemp = HeapAlloc(GetProcessHeap(), 0, size * sizeof(TCHAR));
    if (!pTemp)
    {
        EndDoc(printer.hDC);
        DeleteObject(font);
        ShowLastError();
        return;
    }

    if (printer.Flags & PD_SELECTION)
    {
        size = GetSelectionText(Globals.hEdit, pTemp, size);
    }
    else
    {
        size = GetWindowText(Globals.hEdit, pTemp, size);
    }

    /* Get the current printing area */
    rcPrintRect = GetPrintingRect(printer.hDC, Globals.lMargins);

    /* Ensure that each logical unit maps to one pixel */
    SetMapMode(printer.hDC, MM_TEXT);

    /* Needed to get the correct height of a text line */
    GetTextMetrics(printer.hDC, &tm);

    border = 15;
    for (copycount=1; copycount <= printer.nCopies; copycount++) {
        i = 0;
        pagecount = 1;
        do {
            /* Don't start a page if none of the conditions below are true */
            dopage = 0;

            /* The user wants to print the current selection */
            if (printer.Flags & PD_SELECTION)
            {
                dopage = 1;
            }

            /* The user wants to print the entire document */
            if (!(printer.Flags & PD_PAGENUMS) && !(printer.Flags & PD_SELECTION))
            {
                dopage = 1;
            }

            /* The user wants to print a specified range of pages */
            if ((pagecount >= printer.nFromPage && pagecount <= printer.nToPage))
            {
                dopage = 1;
            }

            old_font = SelectObject(printer.hDC, font);

            if (dopage) {
                if (StartPage(printer.hDC) <= 0) {
                    SelectObject(printer.hDC, old_font);
                    EndDoc(printer.hDC);
                    DeleteDC(printer.hDC);
                    HeapFree(GetProcessHeap(), 0, pTemp);
                    DeleteObject(font);
                    AlertPrintError();
                    return;
                }

                SetViewportOrgEx(printer.hDC, rcPrintRect.left, rcPrintRect.top, NULL);

                /* Write a rectangle and header at the top of each page */
                Rectangle(printer.hDC, border, border, rcPrintRect.right - border, border + tm.tmHeight * 2);
                /* I don't know what's up with this TextOut command. This comes out
                kind of mangled.
                */
                TextOut(printer.hDC,
                        border * 2,
                        border + tm.tmHeight / 2,
                        Globals.szFileTitle,
                        lstrlen(Globals.szFileTitle));
            }

            /* The starting point for the main text */
            xLeft = 0;
            yTop = border + tm.tmHeight * 4;

            SelectObject(printer.hDC, old_font);

            /* Since outputting strings is giving me problems, output the main
             * text one character at a time. */
            do {
                if (pTemp[i] == '\n') {
                    xLeft = 0;
                    yTop += tm.tmHeight;
                }
                else if (pTemp[i] != '\r') {
                    if (dopage)
                        TextOut(printer.hDC, xLeft, yTop, &pTemp[i], 1);

                    /* We need to get the width for each individual char, since a proportional font may be used */
                    GetTextExtentPoint32(printer.hDC, &pTemp[i], 1, &szMetric);
                    xLeft += szMetric.cx;

                    /* Insert a line break if the current line does not fit into the printing area */
                    if (xLeft > rcPrintRect.right)
                    {
                        xLeft = 0;
                        yTop = yTop + tm.tmHeight;
                    }
                }
            } while (i++ < size && yTop < rcPrintRect.bottom);

            if (dopage)
                EndPage(printer.hDC);
            pagecount++;
        } while (i < size);
    }

    if (old_font != 0)
        SelectObject(printer.hDC, old_font);
    EndDoc(printer.hDC);
    DeleteDC(printer.hDC);
    HeapFree(GetProcessHeap(), 0, pTemp);
    DeleteObject(font);
}
Example #25
0
void Demo_AreaFill(HDC hDC, const RECT * rcPaint, int width, int height)
{
	const COLORREF c0 = RGB(0x20, 0x20, 0x20);
	const COLORREF c1 = RGB(0xF0, 0xF0, 0x20);

	for (int i=0; i<4; i++)
		GradientRectangle(hDC, 1000+1100*i, 500, 2000+1100*i, 1500, c0, c1, i*450);

	for (i=0; i<4; i++)
		SymGradientRectangle(hDC, 1000+1100*i, 1600, 2000+1100*i, 2600, c0, c1, i*450);

	for (i=0; i<4; i++)
		CornerGradientRectangle(hDC, 1000+1100*i, 2700, 2000+1100*i, 3700, c0, c1, i);

	CenterGradientRectangle(hDC, 5600, 1500, 6600, 2500, c0, c1);
	CenterGradientRectangle(hDC, 5600, 2600, 6600, 3600, c1, c0);

	//  Buttons
	RoundRectButton(hDC, 0,    4000,  800, 4800,   0, 100, RGB(0x20, 0x20, 0x20), RGB(0xF0, 0xF0, 0x20));
	RoundRectButton(hDC, 1000, 4000, 1800, 4800, 400, 100, RGB(0xF0, 0x20, 0x20), RGB(0x20, 0xF0, 0x20));
	RoundRectButton(hDC, 2000, 4000, 2800, 4800, 800, 100, RGB(0xFF, 0xFF, 0x20), RGB(0x20, 0x20, 0xF0));
	
	   GradientRectangle(hDC, 0, 5000, 2000, 6000, RGB(0xFF, 0x0, 0), RGB(0, 0, 0xFF), 0);
	HLSGradientRectangle(hDC, 0, 6200, 2000, 7200, RGB(0xFF, 0x0, 0), RGB(0, 0, 0xFF), 200);

	RadialGradientFill(hDC, 3200, 6300, 3200    , 6300   ,  1000, RGB(0xFF, 0xFF, 0xFF), RGB(0, 0, 0xFF), 8);
	RadialGradientFill(hDC, 5300, 6300, 5300-300, 6300-600, 1000, RGB(0xFF, 0xFF, 0xFF), RGB(0, 0, 0xFF), 16);
	RadialGradientFill(hDC, 7400, 6300, 7400-300, 6300+300, 1000, RGB(0xFF, 0xFF, 0xFF), RGB(0, 0, 0xFF), 256);

	{
		RECT r = { 7000, 500, 8500, 500+1500 };

		KGDIObject blue(hDC, CreatePen(PS_SOLID, 1 * ONEINCH/72, RGB(0, 0, 0xFF)));
		KGDIObject yellow(hDC, CreateSolidBrush(RGB(0xFF, 0xFF, 0)));
	
		Rectangle(hDC, 7000, 500, 8500, 500+1500);
		
		BrickPatternFill(hDC, 7000,  500, 8500,	 500+1500, 150, 150);
		BrickPatternFill(hDC, 7000, 2100, 8500, 2100+1500, 100, 100);
	}

	KLogFont logfont(- 8 * ONEINCH / 72, "Tahoma");
	KGDIObject font(hDC, logfont.CreateFont());

	{
		SelectObject(hDC, GetStockObject(NULL_PEN));
	
		typedef enum { GAP = 1200 };

		for (int hs= HS_HORIZONTAL; hs<=HS_DIAGCROSS; hs++)
		{
			HBRUSH hBrush = CreateHatchBrush(hs, RGB(0, 0, 0xFF));
			HGDIOBJ hOld  = SelectObject(hDC, hBrush);

			SetBkColor(hDC, RGB(0xFF, 0xFF, 0));
			Rectangle(hDC, hs*GAP, 8000, hs*GAP+890, 8890);

			SetBkColor(hDC, RGB(0xFF, 0xFF, 0xFF));
		
			SetTextAlign(hDC, TA_CENTER);
			TextOut(hDC, hs*GAP+880/2, 8980, HS_Names[hs-HS_HORIZONTAL], _tcslen(HS_Names[hs-HS_HORIZONTAL]));

			SelectObject(hDC, hOld);
			DeleteObject(hBrush);
		}
	}

	{
		HINSTANCE hCards = LoadLibrary("cards.dll");

		for (int i=0; i<3; i++)
	{
		HBRUSH hBrush;
		int    width, height;

		switch ( i )
		{
			case 0:
				{
					HBITMAP hBitmap = LoadBitmap(hCards, MAKEINTRESOURCE(52));
					BITMAP  bmp;

					GetObject(hBitmap, sizeof(bmp), & bmp);
					width = bmp.bmWidth; height = bmp.bmHeight;

					hBrush = CreatePatternBrush(hBitmap);
					DeleteObject(hBitmap);
				}
				break;

			case 1:
				{
					HRSRC hResource = FindResource(hCards, MAKEINTRESOURCE(52-14), RT_BITMAP);
					HGLOBAL hGlobal = LoadResource(hCards, hResource);
	
					hBrush  = CreateDIBPatternBrushPt(LockResource(hGlobal), DIB_RGB_COLORS);
					width   = ((BITMAPCOREHEADER *) hGlobal)->bcWidth; // old DIB format
					height  = ((BITMAPCOREHEADER *) hGlobal)->bcHeight;// old DIB format
				}
				break;

			case 2:
				{
					HRSRC hResource = FindResource(hCards, MAKEINTRESOURCE(52-28), RT_BITMAP);
					HGLOBAL hGlobal = LoadResource(hCards, hResource);

					hBrush  = CreateDIBPatternBrush(hGlobal, DIB_RGB_COLORS);
					width   = ((BITMAPCOREHEADER *) hGlobal)->bcWidth;  // old DIB format
					height  = ((BITMAPCOREHEADER *) hGlobal)->bcHeight; // old DIB format
				}
		}
		
		HGDIOBJ hOld  = SelectObject(hDC, hBrush);

		POINT P = { i*1400+200 + width*10*i/4, 10000 + height*10*i/4 };
		LPtoDP(hDC, &P, 1);
		SetBrushOrgEx(hDC, P.x, P.y, NULL); // make sure cards aligned with rectangle
	
		Rectangle(hDC, i*1400+200, 10000, i*1400+200+width*30/2+1, 10000+height*30/2+1);
	
		SelectObject(hDC, hOld);
		DeleteObject(hBrush);

	}
	}

}
Example #26
0
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
     static CHOOSEFONT cf ;
     static int        iPage ;
     static LOGFONT    lf ;
     HDC               hdc ;
     int               cxChar, cyChar, x, y, i, cxLabels ;
     PAINTSTRUCT       ps ;
     SIZE              size ;
     TCHAR             szBuffer [8] ;
     TEXTMETRIC        tm ;
     WCHAR             ch ;

     switch (message)
     {
     case WM_CREATE:
          hdc = GetDC (hwnd) ;
          lf.lfHeight = - GetDeviceCaps (hdc, LOGPIXELSY) / 6 ;  // 12 points
          lstrcpy (lf.lfFaceName, TEXT ("Lucida Sans Unicode")) ;
          ReleaseDC (hwnd, hdc) ;

          cf.lStructSize = sizeof (CHOOSEFONT) ;
          cf.hwndOwner   = hwnd ;
          cf.lpLogFont   = &lf ;
          cf.Flags       = CF_INITTOLOGFONTSTRUCT | CF_SCREENFONTS ;

          SetScrollRange (hwnd, SB_VERT, 0, 255, FALSE) ;
          SetScrollPos   (hwnd, SB_VERT, iPage,  TRUE ) ;
          return 0 ;

     case WM_COMMAND:
          switch (LOWORD (wParam))
          {
          case IDM_FONT:
               if (ChooseFont (&cf))
                    InvalidateRect (hwnd, NULL, TRUE) ;
               return 0 ;
          }
          return 0 ;

     case WM_VSCROLL:
          switch (LOWORD (wParam))
               {
               case SB_LINEUP:         iPage -=  1 ;  break ;
               case SB_LINEDOWN:       iPage +=  1 ;  break ;
               case SB_PAGEUP:         iPage -= 16 ;  break ;
               case SB_PAGEDOWN:       iPage += 16 ;  break ;
               case SB_THUMBPOSITION:  iPage = HIWORD (wParam) ;  break ;

               default:
                    return 0 ;
               }

          iPage = max (0, min (iPage, 255)) ;

          SetScrollPos (hwnd, SB_VERT, iPage, TRUE) ;
          InvalidateRect (hwnd, NULL, TRUE) ;
          return 0 ;

     case WM_PAINT:
          hdc = BeginPaint (hwnd, &ps) ;

          SelectObject (hdc, CreateFontIndirect (&lf)) ;

          GetTextMetrics (hdc, &tm) ;
          cxChar = tm.tmMaxCharWidth ;
          cyChar = tm.tmHeight + tm.tmExternalLeading ;

          cxLabels = 0 ;

          for (i = 0 ; i < 16 ; i++)
          {
               wsprintf (szBuffer, TEXT (" 000%1X: "), i) ;
               GetTextExtentPoint (hdc, szBuffer, 7, &size) ;

               cxLabels = max (cxLabels, size.cx) ;
          }

          for (y = 0 ; y < 16 ; y++)
          {
               wsprintf (szBuffer, TEXT (" %03X_: "), 16 * iPage + y) ;
               TextOut (hdc, 0, y * cyChar, szBuffer, 7) ;

               for (x = 0 ; x < 16 ; x++)
               {
                    ch = (WCHAR) (256 * iPage + 16 * y + x) ;
                    TextOutW (hdc, x * cxChar + cxLabels,
                                   y * cyChar, &ch, 1);
               }
          }

          DeleteObject (SelectObject (hdc, GetStockObject (SYSTEM_FONT)));
          EndPaint (hwnd, &ps) ;
          return 0 ;

     case WM_DESTROY:
          PostQuitMessage (0) ;
          return 0 ;
     }
     return DefWindowProc (hwnd, message, wParam, lParam) ;
}
Example #27
0
void MYFONT::ShowText(int x,int y,char *p)
{
	TextOut(hdc,x,y,p,strlen(p));
}
Example #28
0
bool
StarServer::OnPaint()
{
    PAINTSTRUCT paintstruct;
    HDC hdc = BeginPaint(hwnd, &paintstruct);

    Text txt_title = title_text;
    Text txt_mode;
    Text txt_users = Game::GetText("server.no-users");
    char buf[256];

    txt_title += " ";
    txt_title += versionInfo;

    switch (game_mode) {
    case LOAD_MODE:
    case MENU_MODE:  
        txt_mode = Game::GetText("server.mode.lobby");

        if (lobby_server) {
            sprintf_s(buf, Game::GetText("server.users").data(), lobby_server->NumUsers());
            txt_users = buf;
        }
        break;

    case PLAY_MODE:  
        txt_mode = Game::GetText("server.mode.active");
        if (lobby_server) {
            sprintf_s(buf, Game::GetText("server.users-and-players").data(), lobby_server->NumUsers(), NetGame::NumPlayers());
        }
        else {
            sprintf_s(buf, Game::GetText("server.players").data(), NetGame::NumPlayers());
        }
        txt_users = buf;
        break;

    default:
        txt_mode = Game::GetText("server.mode.other");
        break;
    }

    if (lobby_server && lobby_server->GetStatus() == NetServerInfo::PERSISTENT)
    txt_mode += " " + Game::GetText("server.alt.persistent");

    if (paused)
    txt_mode += " " + Game::GetText("server.alt.paused");

    TextOut(hdc, 4,  4, txt_title, txt_title.length());
    TextOut(hdc, 4, 22, txt_mode,  txt_mode.length());
    TextOut(hdc, 4, 40, txt_users, txt_users.length());

    Sim* sim = Sim::GetSim();
    if (sim && sim->GetMission()) {
        Mission* mission = sim->GetMission();
        Text txt_msn = Game::GetText("server.mission");
        txt_msn += mission->Name();
        TextOut(hdc, 4, 58, txt_msn, txt_msn.length());
    }

    EndPaint(hwnd, &paintstruct);
    return true;
}
Example #29
0
static BOOL PrintIt(
  int iTotalPages,
  int iLinesPerPage,
  int iTotalLines,
  int iCharsPerLine,
  int yChar,
  LPCTSTR pstrBuffer,
  HWND hwnd)
  {
   WORD iColCopy, iNoiColCopy;
   int iPage, iLine, iLineNum;
   HWND hwndEdit;
   struct statusWindowData *theStatusData;
   struct displayWindowData *theDisplayData;
   ATOM theAtom = (unsigned short) GetClassLongPtr(hwnd,GCW_ATOM);
   void *valuePtr;
   int count;
   int dummy, displayStart;

   if (theAtom == EditAtomClass)
     {    
      hwndEdit = GetDlgItem(hwnd,ID_EDIT_CONTROL);
     }
   else if (theAtom == StatusAtomClass)
     {   
      theStatusData = (struct statusWindowData *) GetWindowLongPtr(hwnd,GWLP_USERDATA);
   
      if (theStatusData == NULL) 
        { return TRUE; }
     }
   else if (theAtom == DisplayAtomClass)
     {
      theDisplayData = (struct displayWindowData *) GetWindowLongPtr(hwnd,GWLP_USERDATA);
   
      if (theDisplayData == NULL) 
        { return TRUE; }

      DisplayLineCountAndStart(hwnd,&dummy,&displayStart);
     }
   else
     { return TRUE; }

   /*========================================================*/
   /* If we're collating and there are multiple copies, then */
   /* print in the order (1,2,3,1,2,3...), otherwise print   */
   /* in the order (1,1,...2,2,...,3,3,...).                 */
   /*========================================================*/
   
   for (iColCopy = 0;
        iColCopy < ((WORD) PrintDialog.Flags & PD_COLLATE ? PrintDialog.nCopies : 1);
        iColCopy++)
     {
      for (iPage = 0 ; iPage < iTotalPages ; iPage++)
        {
         if (PrintDialog.Flags & PD_PAGENUMS)
           {
            if (((iPage + 1) < PrintDialog.nFromPage) ||
                ((iPage + 1) > PrintDialog.nToPage))
              { continue; }
           }

         for (iNoiColCopy = 0;
              iNoiColCopy < (PrintDialog.Flags & PD_COLLATE ? 1 : PrintDialog.nCopies);
              iNoiColCopy++)
           {
            if (StartPage(PrintDialog.hDC) < 0)
              { return(FALSE); }
            
            if (((ATOM) GetClassLongPtr(hwnd,GCW_ATOM)) == EditAtomClass)
              {
               for (iLine = 0 ; iLine < iLinesPerPage ; iLine++)
                 {
                  iLineNum = iLinesPerPage * iPage + iLine ;

                  if (iLineNum > iTotalLines)
                    { break; }

                  *(int *) pstrBuffer = iCharsPerLine;

                  TextOut(PrintDialog.hDC,0,yChar * iLine,pstrBuffer,
                             (int) SendMessage(hwndEdit,EM_GETLINE,(WPARAM) iLineNum, 
                                              (LPARAM) pstrBuffer)) ;
                 }
              }
			else if (((ATOM) GetClassLongPtr(hwnd,GCW_ATOM)) == StatusAtomClass)
              {                  
               iLineNum = iLinesPerPage * iPage;
               iLine = 0;
               for (valuePtr = (*theStatusData->getNextValue)(GetCurrentEnvironment(),NULL), count = 0;
                    valuePtr != NULL;
                    valuePtr = (*theStatusData->getNextValue)(GetCurrentEnvironment(),valuePtr), count++)
                 {
                  if (count < iLineNum) continue;
                  if (count > (iLineNum + iLinesPerPage)) break;
                  if (count > iTotalLines) break;
                  
                  (*theStatusData->getPPForm)(GetCurrentEnvironment(),(char *) pstrBuffer,(unsigned) iCharsPerLine,valuePtr);

                  TextOut(PrintDialog.hDC,0,yChar * iLine,pstrBuffer,(int) strlen(pstrBuffer));
                  
                  iLine++;
                 }  
              }
			else if (((ATOM) GetClassLongPtr(hwnd,GCW_ATOM)) == DisplayAtomClass)
              {                  
               iLineNum = (iLinesPerPage * iPage) + displayStart;
               if (iLineNum > DIALOG_SIZE)
                 { iLineNum -= DIALOG_SIZE; }

               for (iLine = 0 ; iLine < iLinesPerPage ; iLine++)
                 {
                  if (theDisplayData->terminal[iLineNum] == NULL)
                    { break; }
                    
                  TextOut(PrintDialog.hDC,0,yChar * iLine,
                          theDisplayData->terminal[iLineNum],
                          (int) strlen(theDisplayData->terminal[iLineNum]));
                  iLineNum++;
                  if (iLineNum > DIALOG_SIZE)
                    { iLineNum = 0; }
                    
                  if (iLineNum == displayStart)
                    { break; }
                 }
              }

            if (EndPage(PrintDialog.hDC) < 0)
              { return(FALSE); }

            if (bUserAbort)
              { return(TRUE); }
           }

         if (bUserAbort)
            { return(TRUE); }
        }

      if (bUserAbort)
        { return(TRUE); }
     }
     
   return(TRUE);
  }
Example #30
0
LRESULT CALLBACK ColumnTreeWndProc(HWND hwnd, UINT iMessage, WPARAM
    wParam, LPARAM lParam)
{
    HTREEITEM titem;
    HD_LAYOUT hdl;
    WINDOWPOS wp;
    COLUMNINFO *ptr;
    RECT r,  *rp;
    HD_ITEM hie;
    TCHeader *h;
    HD_NOTIFY *n;
    TV_DISPINFO *t;
    LPTV_INSERTSTRUCT is;
    int i;
    TV_ITEM item;
    TCData *td;
    TV_HITTESTINFO tvh;
    TREEINFO *treeinfo;
    PAINTSTRUCT ps;
    HDC dc;
    NM_TREEVIEW *ntv;
    if (iMessage >= TV_FIRST && iMessage < TV_FIRST + 100)
    {
        ptr = (COLUMNINFO*)GetWindowLong(hwnd, 0);
        switch (iMessage)
        {
            case TVM_HITTEST:
                tvh.pt = ((TV_HITTESTINFO*)lParam)->pt;
                ptr = (COLUMNINFO*)GetWindowLong(hwnd, 0);
                GetRelativeRect(hwnd, ptr->hwndTree, &r);
                tvh.pt.x -= r.left;
                tvh.pt.y -= r.top;
                if ((titem = TreeView_HitTest(ptr->hwndTree, &tvh)))
                {
                    ((TV_HITTESTINFO*)lParam)->flags = tvh.flags;
                    ((TV_HITTESTINFO*)lParam)->hItem = tvh.hItem;
                }
                return (LRESULT)titem;
            case TVM_INSERTITEM:
                is = (LPTV_INSERTSTRUCT)lParam;
                is->UNNAMED_UNION item.mask |= TVIF_TEXT | TVIF_PARAM;
                is->UNNAMED_UNION item.pszText = LPSTR_TEXTCALLBACK;
                titem = (HTREEITEM)SendMessage(ptr->hwndTree, iMessage, wParam,
                    lParam);
                return (LRESULT)titem;
            default:
                return SendMessage(ptr->hwndTree, iMessage, wParam, lParam);
        }
    }
    else if (iMessage >= HDM_FIRST && iMessage < HDM_FIRST + 100)
    {
        ptr = (COLUMNINFO*)GetWindowLong(hwnd, 0);
        return SendMessage(ptr->hwndHeader, iMessage, wParam, lParam);
    }
    switch (iMessage)
    {
        case WM_ERASEBKGND:
            return 1;
        case WM_NOTIFY:
            n = (HD_NOTIFY*)lParam;
            ptr = (COLUMNINFO*)GetWindowLong(hwnd, 0);
            switch (n->hdr.code)
            {
            case NM_RCLICK:
                #ifdef XXXXX
                    ptr = (COLUMNINFO*)GetWindowLong(hwnd, 0);
                    GetCursorPos(&pos);
                    ScreenToClient(ptr->hwndTree, &pos);
                    titem = TreeView_HitTest(ptr->hwndTree, &pos);
                    for (i = 0; i < ptr->displaycount; i++)
                    if (titem == ptr->displaylist[i])
                    {
                        ptr->sel = i;
                        InvalidateRect(ptr->hwndTree, 0, 0);
                        break;
                    }
                #endif 
                return SendMessage(GetParent(hwnd), iMessage, wParam, lParam);
            case TVN_SELCHANGING:
                return TRUE;
            case HDN_ENDTRACK:
                SendMessage(ptr->hwndTree, TCF_SETDIVIDER, 0, n->pitem->cxy);
                InvalidateRect(ptr->hwndTree, 0, 1);
                return 0;
            case TVN_GETDISPINFO:
                t = (LPNMTVDISPINFO)n;
                if (TreeView_GetItemRect(ptr->hwndTree, t->item.hItem, &r, TRUE)
                    )
                {
                    if (ptr->displaycount < DISPLAY_MAX)
                        ptr->displaylist[ptr->displaycount++] = t->item.hItem;
                    strcpy(t->item.pszText, "");
//                    t->item.cchTextMax = 0;
                }
                return 0;
            case TVN_DELETEITEM:
                ntv = (NM_TREEVIEW*)lParam;
                if (ptr->displaycount)
                    for (i = 0; i < ptr->displaycount; i++)
                if (ptr->displaylist[i] == ntv->itemOld.hItem)
                {
                    ptr->sel =  - 1;
                    memcpy(&ptr->displaylist[i], &ptr->displaylist[i + 1], (ptr
                        ->displaycount - i - 1) *sizeof(HTREEITEM));
                    ptr->displaycount--;
                    return 0;
                }
                return 0;
            }
            // fall through 
        case WM_COMMAND:
            return SendMessage(GetParent(hwnd), iMessage, wParam, lParam);
        case WM_CREATE:
            ptr = (COLUMNINFO*)calloc(1, sizeof(COLUMNINFO)
                );
            ptr->displaycount = 0;
            ptr->sel =  - 1;
            SetWindowLong(hwnd, 0, (int)ptr);
            GetClientRect(hwnd, &r);
            ptr->hwndHeader = CreateWindow(WC_HEADER, 0, WS_CLIPSIBLINGS |
                WS_CHILD | HDS_HORZ | WS_BORDER, r.left, r.top, r.right -
                r.left, r.bottom - r.top, hwnd, 0, (HINSTANCE)GetWindowLong
                (GetParent(hwnd), GWL_HINSTANCE), 0);
            hdl.prc = &r;
            hdl.pwpos = &wp;
            SendMessage(ptr->hwndHeader, HDM_LAYOUT, 0, (LPARAM) &hdl);
            //         wp.x += 2*GetSystemMetrics(SM_CXDLGFRAME );
            //         wp.cx -= 4 * GetSystemMetrics(SM_CXDLGFRAME) ;
            //         wp.y += 2*GetSystemMetrics(SM_CYDLGFRAME );
            //         wp.cy -= 4 * GetSystemMetrics(SM_CYDLGFRAME) ;
            ptr->watchFont = CreateFontIndirect(&systemDialogFont);
            SendMessage(ptr->hwndHeader, WM_SETFONT, (WPARAM)ptr->watchFont, 0);
            SetWindowPos(ptr->hwndHeader, wp.hwndInsertAfter, wp.x, wp.y, wp.cx,
                wp.cy, wp.flags | SWP_SHOWWINDOW);
            r.left = wp.x;
            r.right = wp.x + wp.cx;
            r.top = wp.y + wp.cy;
            ptr->hwndTree = CreateWindowEx(0, szextTreeWindClassName, 0,
                WS_CLIPSIBLINGS | WS_VISIBLE | WS_CHILD | WS_BORDER |
                TVS_HASLINES | TVS_LINESATROOT | TVS_HASBUTTONS, r.left, r.top,
                r.right - r.left, r.bottom - r.top, hwnd, (HMENU)1000, 
                (HINSTANCE)GetWindowLong(GetParent(hwnd), GWL_HINSTANCE), 0);
            SendMessage(ptr->hwndTree, WM_SETFONT, (WPARAM)ptr->watchFont, 0);
            hie.mask = HDI_WIDTH;
            SendMessage(ptr->hwndHeader, HDM_GETITEM, 0, (LPARAM) &hie);
            SendMessage(ptr->hwndTree, TCF_SETDIVIDER, 0, hie.cxy);
            break;

        case WM_DESTROY:
            ptr = (COLUMNINFO*)GetWindowLong(hwnd, 0);
            DestroyWindow(ptr->hwndHeader);
            DeleteObject(ptr->watchFont);
            free((void*)ptr);
            break;
        case WM_LBUTTONDOWN:
        case WM_RBUTTONDOWN:
            break;
        case WM_SIZE:
            ptr = (COLUMNINFO*)GetWindowLong(hwnd, 0);
            r.left = r.top = 0;
            r.right = LOWORD(lParam);
            r.bottom = HIWORD(lParam);
            hdl.prc = &r;
            hdl.pwpos = &wp;
            SendMessage(ptr->hwndHeader, HDM_LAYOUT, 0, (LPARAM) &hdl);
            //         wp.x += 2*GetSystemMetrics(SM_CXDLGFRAME );
            //         wp.cx -= 4 * GetSystemMetrics(SM_CXDLGFRAME) ;
            //         wp.y += 2*GetSystemMetrics(SM_CYDLGFRAME );
            //         wp.cy -= 4 * GetSystemMetrics(SM_CYDLGFRAME) ;
            SetWindowPos(ptr->hwndHeader, wp.hwndInsertAfter, wp.x, wp.y, wp.cx,
                wp.cy, wp.flags);
            r.left = wp.x;
            r.right = wp.x + wp.cx;
            r.top = wp.y + wp.cy;
            MoveWindow(ptr->hwndTree, r.left, r.top, r.right - r.left, r.bottom
                - r.top, 0);
            GetClientRect(ptr->hwndHeader, &r);
            hie.mask = HDI_WIDTH;
            hie.cxy = (r.right - r.left) / 2;
            SendMessage(ptr->hwndHeader, HDM_SETITEM, 0, (LPARAM) &hie);
            SendMessage(ptr->hwndHeader, HDM_SETITEM, 1, (LPARAM) &hie);
            SendMessage(ptr->hwndTree, TCF_SETDIVIDER, 0, hie.cxy);
            InvalidateRect(ptr->hwndHeader, 0, 1);
            InvalidateRect(ptr->hwndTree, 0, 1);
            break;
        case TCF_SETHEADER:
            ptr = (COLUMNINFO*)GetWindowLong(hwnd, 0);
            h = (TCHeader*)lParam;
            GetWindowRect(ptr->hwndHeader, &r);
            hie.mask = HDI_TEXT | HDI_FORMAT | HDI_WIDTH;
            if (h->colBmp1)
                    hie.mask |= HDI_BITMAP;
            hie.pszText = h->colText1;
            hie.hbm = h->colBmp1;
            hie.cxy = (r.right - r.left) / 2;
            hie.cchTextMax = strlen(h->colText1);
            hie.fmt = HDF_LEFT | HDF_STRING;
            SendMessage(ptr->hwndHeader, HDM_INSERTITEM, 100, (LPARAM) &hie);
            hie.mask = HDI_TEXT | HDI_FORMAT | HDI_WIDTH;
            if (h->colBmp2)
                hie.mask |= HDI_BITMAP;
            hie.pszText = h->colText2;
            hie.hbm = h->colBmp2;
            hie.cxy = (r.right - r.left) / 2;
            hie.cchTextMax = strlen(h->colText2);
            hie.fmt = HDF_LEFT | HDF_STRING;
            SendMessage(ptr->hwndHeader, HDM_INSERTITEM, 100, (LPARAM) &hie);
            SendMessage(ptr->hwndTree, TCF_SETDIVIDER, 0, hie.cxy);
            return 0;
        case WM_PAINT:
            dc = BeginPaint(hwnd, &ps);
            EndPaint(hwnd, &ps);
            break;
        case WM_ACTIVATEME:
            SendMessage(GetParent(hwnd), WM_ACTIVATEME, 0, 0);
            break;
        case WM_SETFONT:
        case WM_GETFONT:
            ptr = (COLUMNINFO*)GetWindowLong(hwnd, 0);
            return SendMessage(ptr->hwndTree, iMessage, wParam, lParam);
        case TCN_PAINT:
            rp = (RECT*)lParam;
            ptr = (COLUMNINFO*)GetWindowLong(hwnd, 0);
            {
                hie.mask = HDI_WIDTH;
                SendMessage(ptr->hwndHeader, HDM_GETITEM, 0, (LPARAM) &hie);
                hie.cxy -= GetSystemMetrics(SM_CXBORDER);
                rp->left = hie.cxy;
                if (rp->left < rp->right)
                {
                    LOGBRUSH lbrush;
                    HBRUSH graybrush;
                    HDC dc = (HDC)wParam;
                    int lined = FALSE;
                    HFONT font = (HFONT)SendMessage(ptr->hwndTree, WM_GETFONT,
                        0, 0);
                    lbrush.lbStyle = BS_SOLID;
                    lbrush.lbColor = 0xff0000;
                    graybrush = CreateBrushIndirect(&lbrush);
//                    dc = GetDC(ptr->hwndTree);
                    font = SelectObject(dc, font);
                    if (GetWindowLong(hwnd, GWL_STYLE) &TCS_LINE)
                    {
                        HPEN pen;
                        pen = CreatePen(PS_SOLID, 1, 0);

                        lined = TRUE;
                        pen = SelectObject(dc, pen);
                        MoveToEx(dc, rp->left, rp->top, 0);
                        LineTo(dc, rp->left, rp->bottom + 1);
                        pen = SelectObject(dc, pen);
                        DeleteObject(pen);
                    }
                    for (i = 0; i < ptr->displaycount; i++)
                    {
                        COLORREF color, bgcolor;
                        item.hItem = ptr->displaylist[i];
                        item.mask = TVIF_PARAM;
                        TreeView_GetItem(ptr->hwndTree, &item);
                        td = (TCData*)item.lParam;
                        TreeView_GetItemRect(ptr->hwndTree, ptr->displaylist[i],
                            &r, TRUE);
                        if (td->col1Text)
                        {
                            HRGN rgn;
                            rgn = CreateRectRgn(r.left, r.top, rp->left - 2,
                                r.bottom);
                            SelectClipRgn(dc, rgn);
                            if (ptr->sel == i)
                            {
                                color = SetTextColor(dc, RetrieveSysColor(COLOR_WINDOW));
                                bgcolor = SetBkColor(dc, td->col1Color);
                            }
                            else
                                color = SetTextColor(dc, td->col1Color);
                            TextOut(dc, r.left, r.top, td->col1Text, strlen(td
                                ->col1Text));
                            SetTextColor(dc, color);
                            if (ptr->sel == i)
                                SetBkColor(dc, bgcolor);
                            SelectClipRgn(dc, NULL);
                            DeleteObject(rgn);
                        }
                        if (td->col2Text)
                        {
                            if (ptr->sel == i)
                            {
                                color = SetTextColor(dc, RetrieveSysColor(COLOR_WINDOW));
                                bgcolor = SetBkColor(dc, td->col2Color);
                            }
                            else
                                color = SetTextColor(dc, td->col2Color);
                            TextOut(dc, rp->left + (lined ? 3 : 0), r.top, td
                                ->col2Text, strlen(td->col2Text));
                            SetTextColor(dc, color);
                            if (ptr->sel == i)
                                SetBkColor(dc, bgcolor);
                        }
                    }
                    SelectObject(dc, font);
//                    ReleaseDC(ptr->hwndTree, dc);
                    DeleteObject(graybrush);

                }
                ptr->displaycount = 0;
            }
            break;
    }
    return DefWindowProc(hwnd, iMessage, wParam, lParam);
}