Example #1
0
void  ex_trace_scrn(int x, int y, char* _msg)
{
#ifdef _WIN32
		HDC hDC = GetDC(NULL);
		RECT  rtScreen;
		SetRectEmpty(&rtScreen);
		
		SetTextColor(hDC, 0x00ff0000);
		SetBkColor(hDC, 0x00FF00FF);

	
	#if defined(UNICODE) || defined(_UNICODE)
		wchar_t uni_msg[128];
		memset(uni_msg, 0, sizeof(uni_msg));
		ex_char2uni(_msg, uni_msg, Ex_MIDOF(uni_msg) );

		DrawTextW(hDC, uni_msg, wcslen(uni_msg) , &rtScreen, DT_CALCRECT );
		OffsetRect(&rtScreen, x, y );
		DrawTextW(hDC, uni_msg, wcslen(uni_msg) , &rtScreen, DT_LEFT|DT_TOP );	

	#else
		DrawTextA(hDC, _msg, strlen(_msg) , &rtScreen, DT_CALCRECT );
		OffsetRect(&rtScreen, x, y );
		DrawTextA(hDC, _msg, strlen(_msg) , &rtScreen, DT_LEFT|DT_TOP );	
	#endif

	ReleaseDC(NULL, hDC);
#endif
}
Example #2
0
static LRESULT WINAPI wmp_wnd_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch(msg) {
    case WM_PAINT: {
        PAINTSTRUCT ps;
        HFONT font;
        RECT rect;
        HDC hdc;

        TRACE("WM_PAINT\n");

        GetClientRect(hwnd, &rect);
        hdc = BeginPaint(hwnd, &ps);

        SelectObject(hdc, GetStockObject(DC_BRUSH));
        SetDCBrushColor(hdc, RGB(255,0,0));
        SetBkColor(hdc, RGB(255,0,0));

        font = CreateFontA(25,0,0,0,400,0,0,0,ANSI_CHARSET,0,0,DEFAULT_QUALITY,DEFAULT_PITCH,NULL);
        SelectObject(hdc, font);

        Rectangle(hdc, rect.left, rect.top, rect.right, rect.bottom);
        DrawTextA(hdc, "FIXME: WMP", -1, &rect, DT_CENTER | DT_SINGLELINE | DT_VCENTER);

        DeleteObject(font);
        EndPaint(hwnd, &ps);
        break;
    }
    }

    return DefWindowProcW(hwnd, msg, wParam, lParam);

}
Example #3
0
static LRESULT CALLBACK PluginWinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch (msg) {
    case WM_PAINT:
        {
            // draw a frame and display the string
            PAINTSTRUCT ps;
            HDC hdc = BeginPaint(hWnd, &ps);
            RECT rc;
            GetClientRect(hWnd, &rc);

            HBRUSH hbr = CreateSolidBrush(RGB(rand()%255, rand()%255, rand()%255));
            FillRect(hdc, &rc, hbr);
            FrameRect(hdc, &rc, GetStockBrush(DKGRAY_BRUSH));

            CPlugin * p = (CPlugin *)GetWindowLong(hWnd, GWL_USERDATA);
            if(p) {
                if (p->m_String[0] == 0) {
                    strcpy("NPPublishCardX", p->m_String);
                }

                DrawTextA(hdc, p->m_String, strlen(p->m_String), &rc, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
            }

            DeleteObject(hbr);
            EndPaint(hWnd, &ps);
        }
        break;
    default:
        break;
    }

    return DefWindowProc(hWnd, msg, wParam, lParam);
}
    SIZE sizeWithText(const char * pszText, int nLen, DWORD dwFmt, LONG nWidthLimit)
    {
        SIZE tRet = {0};
        do 
        {
            CC_BREAK_IF(! pszText || nLen <= 0);

            RECT rc = {0, 0, 0, 0};
            DWORD dwCalcFmt = DT_CALCRECT;

            if (nWidthLimit > 0)
            {
                rc.right = nWidthLimit;
                dwCalcFmt |= DT_WORDBREAK
                    | (dwFmt & DT_CENTER)
                    | (dwFmt & DT_RIGHT);
            }
            // use current font to measure text extent
            HGDIOBJ hOld = SelectObject(m_hDC, m_hFont);

            // measure text size
            DrawTextA(m_hDC, pszText, nLen, &rc, dwCalcFmt);
            SelectObject(m_hDC, hOld);

            tRet.cx = rc.right;
            tRet.cy = rc.bottom;
        } while (0);

        return tRet;
    }
 virtual void DrawWhiteText
 (HDC dc, RECT& rect, const char* text, int flags)
 {
     HGDIOBJ oldFont = SelectObject(dc, GetDefaultFont());
     SetTextColor(dc, RGB(0xff, 0xff, 0xff));
     SetBkMode(dc, TRANSPARENT);
     DrawTextA(dc, text, -1, &rect, flags);
     SelectObject(dc, oldFont);
 }
Example #6
0
void __fastcall TMainForm::BookComboBoxDrawItem(TWinControl *Control, int Index,
      TRect &Rect, TOwnerDrawState State)
{
	TComboBox *c = (TComboBox*)Control;
	TRect rect, r;
	AnsiString s;
	HDC dc;
	HFONT font1, font2;
	HGDIOBJ old;
	TBook *b;

	b = (TBook*)(c->Items->Objects[Index]);
	r = rect = Rect;
//	dc = GetDC(Control->Handle);
	c->Canvas->FillRect(rect);

	dc = c->Canvas->Handle;
	font1 = CreateFontA(Font->Height, 0, 0, 0, 0, 0u, 0u, 0u, RUSSIAN_CHARSET, 0u, 0u, 0u, 0u, TEXT("Tahoma"));
	font2 = CreateFontA(Font->Height, 0, 0, 0, 0, 1u, 0u, 0u, RUSSIAN_CHARSET, 0u, 0u, 0u, 0u, TEXT("Tahoma"));
//
	old = SelectObject(dc, font1);
	SetTextColor(dc, 0x00000000);

	rect = r;
	rect.Bottom -= 14;
	rect.left += 2;
//	SetBkMode(dc, TRANSPARENT);
	s = b->BookName;
	DrawTextA(dc, s.c_str(), s.Length(), &rect, DT_LEFT);

	rect = r;
	rect.Top += 14;
	rect.left += 10;
//    rect.bottom -= 2;
	SelectObject(dc, font2);
//	SetTextColor(dc, 0x0000ff00);
	s = b->BookAuthor;
	DrawTextA(dc, s.c_str(), s.Length(), &rect, DT_LEFT);

	SelectObject(dc, old);
//	ReleaseDC(c->Canvas, dc);
	DeleteObject(font1);
	DeleteObject(font2);
}
Example #7
0
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)
    {
    case WM_PAINT:
        {
            PAINTSTRUCT ps;
            RECT area;            

            HDC hDC = BeginPaint(hWnd, &ps);
            GetClientRect(hWnd, &area);
            SetBkMode(hDC, TRANSPARENT);

            // draw caption with the fuzzed font
            HFONT hFont = MyCreateFont(); 
            HFONT hOldFont = (HFONT)SelectObject(hDC, hFont);
            if (hOldFont) 
            { 
                DrawTextA(hDC, m_szTable, -1, &area, DT_CENTER | DT_VCENTER);
                SelectObject(hDC, hOldFont); 
            } 
            
            EndPaint(hWnd, &ps);

            break;
        }

    case WM_COMMAND:
        {
            switch (wParam)
            {
            case ID_CLOSE:

#ifdef TEST_MSG
                MessageBoxA(0, __FUNCTION__, "ID_CLOSE", MB_ICONINFORMATION);
#endif
                // window can be closed now
                SetEvent(m_hWndEvent);
                break;
            }

            break;
        }

    case WM_DESTROY:

        PostQuitMessage(0);
        break;

    default:

        return DefWindowProc(hWnd, message, wParam, lParam);
    }

    return 0;
}
Example #8
0
File: draw.c Project: RPG-7/reactos
/**********************************************************************
 *          PAINTING_DrawStateJam
 *
 * Jams in the requested type in the dc
 */
static BOOL PAINTING_DrawStateJam(HDC hdc, UINT opcode,
                                  DRAWSTATEPROC func, LPARAM lp, WPARAM wp,
                                  LPRECT rc, UINT dtflags, BOOL unicode )
{
    HDC memdc;
    HBITMAP hbmsave;
    BOOL retval;
    INT cx = rc->right - rc->left;
    INT cy = rc->bottom - rc->top;

    switch(opcode)
    {
        case DST_TEXT:
        case DST_PREFIXTEXT:
            if(unicode)
                return DrawTextW(hdc, (LPWSTR)lp, (INT)wp, rc, dtflags);
            else
                return DrawTextA(hdc, (LPSTR)lp, (INT)wp, rc, dtflags);

        case DST_ICON:
            return DrawIconEx(hdc, rc->left, rc->top, (HICON)lp, cx, cy, 0, NULL, DI_NORMAL);

        case DST_BITMAP:
            memdc = CreateCompatibleDC(hdc);
            if(!memdc)
                return FALSE;
            hbmsave = (HBITMAP)SelectObject(memdc, (HBITMAP)lp);
            if(!hbmsave)
            {
                DeleteDC(memdc);
                return FALSE;
            }
            retval = BitBlt(hdc, rc->left, rc->top, cx, cy, memdc, 0, 0, SRCCOPY);
            SelectObject(memdc, hbmsave);
            DeleteDC(memdc);
            return retval;

        case DST_COMPLEX:
            if(func)
            {
                BOOL bRet;
                /* DRAWSTATEPROC assumes that it draws at the center of coordinates  */

                OffsetViewportOrgEx(hdc, rc->left, rc->top, NULL);
                bRet = func(hdc, lp, wp, cx, cy);
                /* Restore origin */
                OffsetViewportOrgEx(hdc, -rc->left, -rc->top, NULL);
                return bRet;
            }
            else
            {
                return FALSE;
            }
    }
    return FALSE;
}
Example #9
0
void Drawer::Draw(int width, int height, const ParsedParts& parts, const ParsedCuts& cuts, const Part& sheet)
{
	double scalex = width / (double)sheet.rect.Size[0];
    double scaley = height / (double)sheet.rect.Size[1];
    double scale;
    if (scalex < scaley)
    	scale = scalex;
    else
      	scale = scaley;
	HGDIOBJ hres = SelectObject(m_hdc, m_hblackpen);
	assert(hres);

	// drawing sheet
	hres = SelectObject(m_hdc, m_hhatchbrush);
	assert(hres != NULL);
	BOOL bres = Rectangle(m_hdc, 0, 0, int(sheet.rect.Size[0] * scale),
		int(sheet.rect.Size[1] * scale));
    assert(bres != FALSE);

	// drawing parts
	hres = SelectObject(m_hdc, m_hwhitebrush);
	assert(hres != NULL);
    {for (ParsedParts::const_iterator i = parts.begin(); i != parts.end(); i++)
    {
    	RECT Rect;
        Rect.left = LONG(i->pos[0] * scale);
        Rect.top = LONG(i->pos[1] * scale);
        Rect.right = LONG((i->pos[0] + i->rect.Size[0]) * scale);
        Rect.bottom = LONG((i->pos[1] + i->rect.Size[1]) * scale);
		bres = Rectangle(m_hdc, Rect.left, Rect.top, Rect.right, Rect.bottom);
    	assert(bres != FALSE);
		ostringstream ss;
		ss << i->rect.Size[0] << "x" << i->rect.Size[1];
		int ires = DrawTextA(m_hdc, ss.str().c_str(), ss.str().length(), &Rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
		assert(ires != 0);
    }}

	// drawing cuts
	hres = SelectObject(m_hdc, m_hredpen);
	assert(hres != NULL);
    {for (ParsedCuts::const_iterator i = cuts.begin(); i != cuts.end(); i++)
    {
		bres = MoveToEx(m_hdc, int(i->pos[0] * scale), int(i->pos[1] * scale), NULL);
		assert(bres);
    	if (i->s)
		{
			bres = LineTo(m_hdc, int((i->pos[0]) * scale), int((i->pos[1] + i->length) * scale));
        	assert(bres);
		}
        else
		{
			bres = LineTo(m_hdc, int((i->pos[0] + i->length) * scale), int(i->pos[1] * scale));
        	assert(bres);
		}
    }}
}
void EmoticonsSelectionLayout::DrawEmoticonText(HDC hdc, char *txt, RECT rc)
{
	HFONT hFont = GetFont(hdc);
	HFONT oldFont = (HFONT) SelectObject(hdc, hFont);

	DrawTextA(hdc, txt, strlen(txt), &rc, DT_NOPREFIX);

	SelectObject(hdc, oldFont);
	ReleaseFont(hFont);
}
Example #11
0
INT_PTR CALLBACK CLyricsDlg::DialogProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	switch (uMsg)
	{
	case WM_DESTROY: KillTimer(hDlg, ID_TIMER); break;
	case WM_CLOSE: EndDialog(hDlg, IDCANCEL); break;
	case WM_COMMAND:
		{
			switch (LOWORD(wParam))
			{
			case IDOK: OnOk(hDlg); break;
			case IDCANCEL: EndDialog(hDlg, IDCANCEL); break;
			case IDC_SET: OnSet(hDlg); break;
			}
		}
		break;//case WM_COMMAND
	case WM_INITDIALOG: OnInitDialog(hDlg, lParam);break;

	case WM_DRAWITEM:
		{
			DRAWITEMSTRUCT* pDraw = (DRAWITEMSTRUCT*)lParam;
			HDC hMemDC = CreateCompatibleDC(pDraw->hDC);
			HBITMAP hOldBmp;
	
			if (pDraw->itemAction & ODA_SELECT || pDraw->itemAction & ODA_DRAWENTIRE)
			{
				if (pDraw->itemState & ODS_SELECTED)
					hOldBmp = (HBITMAP)SelectObject(hMemDC, m_hbSet2);
				else
					hOldBmp = (HBITMAP)SelectObject(hMemDC, m_hbSet);
			}
			else
				hOldBmp = (HBITMAP)SelectObject(hMemDC, m_hbSet);

			BitBlt(pDraw->hDC, 0, 0, 22, 19, hMemDC, 0, 0, SRCCOPY);
			SelectObject(hMemDC, hOldBmp);

			HFONT hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
			RECT rect;// = {0, 0, 21, 18};
			GetClientRect(pDraw->hwndItem, &rect);
			SetBkMode(pDraw->hDC, TRANSPARENT);
			DrawTextA(pDraw->hDC, "Setează", -1, &rect, DT_CENTER | DT_VCENTER | DT_EXTERNALLEADING | DT_SINGLELINE); 

			DeleteDC(hMemDC);
		}
		break;

	case WM_LBUTTONUP: OnLButtonUp(hDlg, wParam, lParam); break;
	case WM_MOUSEMOVE: OnMouseMove(hDlg, wParam, lParam); break;
	}

	return 0;
}
Example #12
0
//
//  함수: WndProc(HWND, UINT, WPARAM, LPARAM)
//
//  목적: 주 창의 메시지를 처리합니다.
//
//  WM_COMMAND	- 응용 프로그램 메뉴를 처리합니다.
//  WM_PAINT	- 주 창을 그립니다.
//  WM_DESTROY	- 종료 메시지를 게시하고 반환합니다.
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	int wmId, wmEvent;
	PAINTSTRUCT ps; // 페인트 구조체
	HDC hdc; // Device Context 핸들

	// WM_~  WindowMessage 의 약자.
	switch (message)
	{
	case WM_COMMAND:		// 메뉴를 선택하면 발생되는 이벤트
		wmId    = LOWORD(wParam);
		wmEvent = HIWORD(wParam);
		// 메뉴 선택을 구문 분석합니다.
		switch (wmId)
		{
		case IDM_ABOUT:
			DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
			break;
		case IDM_EXIT:
			DestroyWindow(hWnd);
			break;
		default:
			return DefWindowProc(hWnd, message, wParam, lParam);
		}
		break;

	// 화면 갱신 메세지
	case WM_PAINT:
		{
			hdc = BeginPaint(hWnd, &ps);	// Device Context 핸들 얻음.
			
			TextOutA( hdc, 10, 10, "hello World", 11);
			RECT r;
			SetRect(&r, 100, 100, 200, 200);
			DrawTextA( hdc, "hello World", 11, &r, DT_CENTER);

			EndPaint(hWnd, &ps);		// 화면 갱신 종료
		}
		break;

	// 윈도우 종료 메세지
	case WM_DESTROY:
		PostQuitMessage(0);
		break;

	// 그 밖에 나머지 메세지는 DefWindowProc() 함수에서 처리한다.
	default:
		return DefWindowProc(hWnd, message, wParam, lParam);
	}
	return 0;
}
Example #13
0
LRESULT CALLBACK TipMsgWindow::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	PAINTSTRUCT ps;
	HDC hdc;
	TipMsgWindow *pThis = NULL;

	switch (message)
	{
	case WM_TIMER:
		BringWindowToTop(hWnd);
		break;
	case WM_GETMINMAXINFO:
		MINMAXINFO* mmi;
		mmi = (MINMAXINFO*)lParam;
		mmi->ptMinTrackSize.x = 1;
		mmi->ptMinTrackSize.y = 1;
		mmi->ptMaxTrackSize.x = 200;
		mmi->ptMaxTrackSize.y = 200;
		break;
	case WM_CREATE:
		SetTimer(hWnd,0, 1000, NULL);
		break;
	case WM_PAINT:
		RECT rc;
		pThis = (TipMsgWindow*)GetWindowLong(hWnd, GWL_USERDATA);
		if (pThis == NULL)
		{
			DOLOG("have not right TipMsgWindow instance£¡");
			break;
		}
		
		hdc = BeginPaint(hWnd, &ps);
		//hbr = CreateSolidBrush(RGB(0, 0, 0));
		rc.top = 0;
		rc.left = 0;
		rc.right = pThis->m_size.x;
		rc.bottom = pThis->m_size.y;
		//assert(FillRect(hdc, &rc, hbr));
		SetTextColor(hdc, RGB(255, 0, 0));
		SetBkColor(hdc, RGB(0, 0, 0));
		DrawTextA(hdc, pThis->m_Msg, strlen(pThis->m_Msg), &rc, DT_CENTER | DT_VCENTER);
		EndPaint(hWnd, &ps);
		break;
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	default:
		return DefWindowProc(hWnd, message, wParam, lParam);
	}
	return 0;
}
void NCLDebug::DrawTextF(const Vector3& pos, const float font_size, const TextAlignment alignment, const Vector4 colour, const string text, ...)
{
	va_list args;
	va_start(args, text);

	char buf[1024];
	int needed = vsnprintf_s(buf, 1023, _TRUNCATE, text.c_str(), args);
	va_end(args);

	int length = (needed < 0) ? 1024 : needed;

	std::string formatted_text = std::string(buf, (size_t)length);
	DrawTextA(pos, font_size, formatted_text, alignment, colour);
}
RECT EmoticonsSelectionLayout::CalcRect(char *txt)
{
	HDC hdc = GetDC(hwnd);
	HFONT hFont = GetFont(hdc);
	HFONT oldFont = (HFONT) SelectObject(hdc, hFont);

	RECT rc = { 0, 0, 0xFFFF, 0xFFFF };
	DrawTextA(hdc, txt, strlen(txt), &rc, DT_CALCRECT | DT_NOPREFIX);

	SelectObject(hdc, oldFont);
	ReleaseFont(hFont);

	ReleaseDC(hwnd, hdc);
	return rc;
}
Example #16
0
int DrawTextUTF8(HDC hdc, LPCTSTR str, int nc, LPRECT lpRect, UINT format)
{
  if (WDL_HasUTF8(str) AND_IS_NOT_WIN9X)
  {
    if (nc<0) nc=(int)strlen(str);

    {
      MBTOWIDE(wstr, str);
      if (wstr_ok)
      {
        int rv=DrawTextW(hdc,wstr,-1,lpRect,format);;
        MBTOWIDE_FREE(wstr);
        return rv;
      }
      MBTOWIDE_FREE(wstr);
    }

  }
  return DrawTextA(hdc,str,nc,lpRect,format);
}
Example #17
0
int DrawTextUTF8(HDC hdc, LPCTSTR str, int nc, LPRECT lpRect, UINT format)
{
  if (WDL_HasUTF8(str) && GetVersion()<0x80000000)
  {
    if (nc<0) nc=strlen(str);

    {
      MBTOWIDE(wstr, str);
      if (wstr_ok)
      {
        int rv=DrawTextW(hdc,wstr,-1,lpRect,format);;
        MBTOWIDE_FREE(wstr);
        return rv;
      }
      MBTOWIDE_FREE(wstr);
    }

  }
  return DrawTextA(hdc,str,nc,lpRect,format);
}
Example #18
0
start_edit(TableUI *tui, int edit_existing) {
    RECT rt = get_cell_rect(tui, tui->cur_row, tui->cur_col), rt_cont = rt;    
    
    if (is_editing(tui)) end_edit(tui);
    
    if (edit_existing) {
        Cell cell = try_cell(tui->table, tui->cur_row, tui->cur_col);
        SetWindowTextA(tui->edit, cell.str);
        
        /* Resize Edit to fit content; at least as big as the cell */
        DrawTextA(tui->bitmap, cell.str, cell.len, &rt_cont,
            DT_NOPREFIX | DT_RIGHT | DT_CALCRECT | DT_EDITCONTROL);
        UnionRect(&rt, &rt, &rt_cont);
    } else
        SetWindowText(tui->edit, L"");
    
    MoveWindow(tui->edit, rt.left, rt.top,
        rt.right - rt.left, rt.bottom - rt.top, 0);
    ShowWindow(tui->edit, SW_NORMAL);
    SetFocus(tui->edit);
}
Example #19
0
//
// This is meant to be called only by CONS_Printf() while game startup
//
void I_LoadingScreen(LPCSTR msg)
{
    RECT rect;

    // paranoia
    if (!hDCMain || !bmiMain || !vid.buffer)
        return;

    GetClientRect(vid.WndParent, &rect);

    SetDIBitsToDevice(hDCMain, 0, 0, vid.width, vid.height, 0, 0, 0, vid.height, vid.buffer, bmiMain, DIB_RGB_COLORS);

    if (msg)
    {
        if (rect.bottom - rect.top > 32)
            rect.top = rect.bottom - 32; // put msg on bottom of window
        SetBkMode(hDCMain, TRANSPARENT);
        SetTextColor(hDCMain, RGB(0x00, 0x00, 0x00));
        DrawTextA(hDCMain, msg, -1, &rect, DT_WORDBREAK|DT_CENTER);
    }
}
Example #20
0
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
     static BOOL     bValidFile ;
     static BYTE     buffer[MAXREAD] ;
     static HWND     hwndList, hwndText ;
     static RECT     rect ;
     static TCHAR    szFile[MAX_PATH + 1] ;
     HANDLE          hFile ;
     HDC             hdc ;
     int             i, cxChar, cyChar ;
     PAINTSTRUCT     ps ;
     TCHAR           szBuffer[MAX_PATH + 1] ;

     switch (message)
     {
     case WM_CREATE :
          cxChar = LOWORD (GetDialogBaseUnits ()) ;
          cyChar = HIWORD (GetDialogBaseUnits ()) ;
          
          rect.left = 20 * cxChar ;
          rect.top  =  3 * cyChar ;
          
          // See Page 382 in Windows Programming book for this example.
          hwndList = CreateWindow (TEXT ("listbox"), NULL,
                              WS_CHILDWINDOW | WS_VISIBLE | LBS_STANDARD,
                              cxChar, cyChar * 3,
                              cxChar * 13 + GetSystemMetrics (SM_CXVSCROLL),
                              cyChar * 10,
                              hwnd, (HMENU) ID_LIST,
                              (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE),
                              NULL) ;
          
          // Get current directory
          GetCurrentDirectory (MAX_PATH + 1, szBuffer) ;
          
          hwndText = CreateWindow (TEXT ("static"), szBuffer,
                              WS_CHILDWINDOW | WS_VISIBLE | SS_LEFT,
                              cxChar, cyChar, cxChar * MAX_PATH, cyChar,
                              hwnd, (HMENU) ID_TEXT,
                              (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE),
                              NULL) ;
          
          OldList = (WNDPROC) SetWindowLong (hwndList, GWL_WNDPROC,
                                               (LPARAM) ListProc) ;
          
          // indicate that this listbox is a file list box.
          SendMessage (hwndList, LB_DIR, DIRATTR, (LPARAM) TEXT ("*.*")) ; 
          return 0 ;
          
     case WM_SIZE :
          rect.right  = LOWORD (lParam) ;
          rect.bottom = HIWORD (lParam) ;
          return 0 ;
          
     case WM_SETFOCUS :
          SetFocus (hwndList) ;
          return 0 ;
          
     case WM_COMMAND :
          if (LOWORD (wParam) == ID_LIST && HIWORD (wParam) == LBN_DBLCLK)
          {

               if (LB_ERR == (i = SendMessage (hwndList, LB_GETCURSEL, 0, 0)))
                    break ;
               
               SendMessage (hwndList, LB_GETTEXT, i, (LPARAM) szBuffer) ;
               
               if (INVALID_HANDLE_VALUE != (hFile = CreateFile (szBuffer, 
                         GENERIC_READ, FILE_SHARE_READ, NULL, 
                         OPEN_EXISTING, 0, NULL)))

               {
            	   // this branch means we are handling a file.
            	   
                    CloseHandle (hFile) ;
                    bValidFile = TRUE ;
                    lstrcpy (szFile, szBuffer) ;
                    GetCurrentDirectory (MAX_PATH + 1, szBuffer) ;

                    if (szBuffer [lstrlen (szBuffer) - 1] != '\\')
                         lstrcat (szBuffer, TEXT ("\\")) ;
                    SetWindowText (hwndText, lstrcat (szBuffer, szFile)) ;
               }
               else
               {
            	   // this branch means we are handling a sub folder
            	   
                    bValidFile = FALSE ;
                    szBuffer [lstrlen (szBuffer) - 1] = '\0' ;

                         // If setting the directory doesn't work, maybe it's
                         // a drive change, so try that.

                    if (!SetCurrentDirectory (szBuffer + 1)) // what szBuffer + 1 mean?
                    {
                         szBuffer [3] = ':' ;
                         szBuffer [4] = '\0' ;
                         SetCurrentDirectory (szBuffer + 2) ; // what szBuffer + 2 mean?
                    }

                         // Get the new directory name and fill the list box.

                    GetCurrentDirectory (MAX_PATH + 1, szBuffer) ;
                    SetWindowText (hwndText, szBuffer) ;
                    SendMessage (hwndList, LB_RESETCONTENT, 0, 0) ;
                    SendMessage (hwndList, LB_DIR, DIRATTR, 
                                           (LPARAM) TEXT ("*.*")) ;
               }
               InvalidateRect (hwnd, NULL, TRUE) ;
          }
          return 0 ;

     case WM_PAINT :
          if (!bValidFile)
               break ;

          if (INVALID_HANDLE_VALUE == (hFile = CreateFile (szFile, 
                  GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL)))
          {
               bValidFile = FALSE ;
               break ;
          }
          
          // Read a file to variable.
          ReadFile (hFile, buffer, MAXREAD, &i, NULL) ;
          CloseHandle (hFile) ;

               // i now equals the number of bytes in buffer.
               // Commence getting a device context for displaying text.

          hdc = BeginPaint (hwnd, &ps) ;
          SelectObject (hdc, GetStockObject (SYSTEM_FIXED_FONT)) ;
          SetTextColor (hdc, GetSysColor (COLOR_BTNTEXT)) ;
          SetBkColor   (hdc, GetSysColor (COLOR_BTNFACE)) ;

               // Assume the file is ASCII
          
          // draw the contents in buffer by using GDI function.
          DrawTextA (hdc, buffer, i, &rect, DTFLAGS) ;

          EndPaint (hwnd, &ps) ;
          return 0 ;
          
     case WM_DESTROY :
          PostQuitMessage (0) ;
          return 0 ;
     }
     return DefWindowProc (hwnd, message, wParam, lParam) ;
}
Example #21
0
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    static int          nLineCount,lineNo;
    static int          cyClient, cxChar, cyChar;
    static int          xScroll;
    static HGLOBAL      hResource;
    static HWND         hwndScroll;
    static HWND         hScroll;

    CHAR        *szText;
    HINSTANCE   hInstance;
    HDC         hdc;
    PAINTSTRUCT ps;
    RECT        clientRect;
    int         i;

    switch(msg)
    {
    case WM_CREATE:
        hInstance = ((LPCREATESTRUCT)lParam)->hInstance;
        lineNo = 0;
        //Load Text resource
        hResource = LoadResource(hInstance, FindResource(hInstance, TEXT("ANNABELLEE"), TEXT("TEXT")));
        szText = (CHAR *)LockResource(hResource);

        //Create Scrollbar
        hScroll = CreateWindow(TEXT("scrollbar"), NULL, SB_VERT | WS_CHILD | WS_VISIBLE, 
                    0, 0, 0, 0,
                    hwnd, (HMENU)1, hInstance, NULL);
        //calculate line count
        while(*szText != '\0' && *szText != '\\')
        {
            if (*szText == '\n')
                ++nLineCount;
            szText = AnsiNext(szText);
        }
        *szText == '\0';

        //Get char size
        cxChar = LOWORD(GetDialogBaseUnits());
        cyChar = HIWORD(GetDialogBaseUnits());
        xScroll = GetSystemMetrics(SM_CXVSCROLL);

        //Setup scroll 
        SetScrollRange(hScroll, SB_CTL, 0, nLineCount, TRUE);
        SetScrollPos(hScroll, SB_CTL, 0, TRUE);
        break;
    case WM_SIZE:
        {
            MoveWindow(hScroll, LOWORD(lParam) - xScroll, 0, xScroll, HIWORD(lParam), TRUE); 
            cyClient = HIWORD(lParam);
            SetFocus(hScroll);
            break;
        }
    case WM_SETFOCUS:
        {
            SetFocus(hScroll);
            break;
        }
    case WM_VSCROLL:
        {
            switch(wParam)
            {
                case SB_TOP:
                    lineNo = 0;
                    break;
                case SB_BOTTOM:
                    lineNo = nLineCount;
                    break;
                case SB_LINEDOWN:
                    lineNo++;
                    break;
                case SB_LINEUP:
                    lineNo--;
                    break;
                case SB_PAGEDOWN:
                    lineNo += cyClient / cyChar;
                    break;
                case SB_PAGEUP:
                    lineNo -= cyClient / cyChar;
                    break;
                default:
                    break;
            }
            lineNo = max(0, lineNo);
            lineNo = min(lineNo, nLineCount);
            SetScrollPos(hScroll, SB_CTL, lineNo, TRUE);
            InvalidateRect(hwnd, NULL, TRUE);
            break;
        }
    case WM_PAINT:
        {
            hdc = BeginPaint(hwnd, &ps);
            GetClientRect(hwnd, &clientRect);
            clientRect.left += cxChar;
            clientRect.top += cyChar*(1 - lineNo);
            szText = (CHAR *)LockResource(hResource);
            DrawTextA(hdc, szText, -1, &clientRect, DT_TOP); 
            EndPaint(hwnd, &ps);
            break;
        }
    case WM_DESTROY:
        {
            FreeResource(hResource);
            PostQuitMessage(0);
            break;
        }
    }
    return DefWindowProc(hwnd, msg, wParam, lParam);
}
Example #22
0
static LRESULT CALLBACK ACCWndProc(HWND hwnd, UINT msg,  WPARAM wParam, LPARAM lParam) {
	ACCData* data =  (ACCData *) GetWindowLong(hwnd, 0);
	switch(msg) 
	{
		case WM_NCCREATE:
		{
			SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) | BS_OWNERDRAW);
			SetWindowLong(hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_TRANSPARENT);

			data = (ACCData*) mir_alloc(sizeof(ACCData));
			if (data == NULL) 
				return FALSE;
			SetWindowLong(hwnd, 0, (LONG)data);

			ZeroMemory(data, sizeof(ACCData));
            data->hHook = HookEventMessage(ME_AV_AVATARCHANGED, hwnd, DM_AVATARCHANGED);
            data->hHookMy = HookEventMessage(ME_AV_MYAVATARCHANGED, hwnd, DM_MYAVATARCHANGED);
			data->hFont = (HFONT) GetStockObject(DEFAULT_GUI_FONT);
			data->borderColor = -1;
			data->bkgColor = -1;
			data->avatarBorderColor = -1;
			data->respectHidden = TRUE;
			data->showingFlash = FALSE;
			data->resizeIfSmaller = TRUE;

			return TRUE;
		}
        case WM_NCDESTROY:
        {
			DestroyFlash(hwnd, data);
			if (data) 
			{
                UnhookEvent(data->hHook);
                UnhookEvent(data->hHookMy);
				mir_free(data);
			}
			SetWindowLong(hwnd, 0, (LONG)NULL);
			break;
		}
		case WM_SETFONT:
		{
			data->hFont = (HFONT)wParam;
			Invalidate(hwnd);
			break;
		}
		case AVATAR_SETCONTACT:
		{
			if (data->showingFlash)
			{
				DestroyFlash(hwnd, data);
				data->showingFlash = FALSE;
			}

			data->hContact = (HANDLE) lParam;
			lstrcpynA(data->proto, (char*) CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)data->hContact, 0), sizeof(data->proto));

			if (DBGetContactSettingWord(data->hContact, "ContactPhoto", "Format", 0) == PA_FORMAT_XML)
			{
				data->showingFlash = StartFlash(hwnd, data);
			}

			NotifyAvatarChange(hwnd);
			Invalidate(hwnd);
			return TRUE;
		}
		case AVATAR_SETPROTOCOL:
		{
			if (data->showingFlash)
			{
				DestroyFlash(hwnd, data);
				data->showingFlash = FALSE;
			}

			data->hContact = NULL;
			if (lParam == NULL)
				data->proto[0] = '\0';
			else
				lstrcpynA(data->proto, (char *) lParam, sizeof(data->proto));

			NotifyAvatarChange(hwnd);
			Invalidate(hwnd);
			return TRUE;
		}
		case AVATAR_SETBKGCOLOR:
		{
			data->bkgColor = (COLORREF) lParam;
			if (data->showingFlash)
				SetBkgFlash(hwnd, data);
			NotifyAvatarChange(hwnd);
			Invalidate(hwnd);
			return TRUE;
		}
		case AVATAR_SETBORDERCOLOR:
		{
			data->borderColor = (COLORREF) lParam;
			if (data->showingFlash)
				ResizeFlash(hwnd, data);
			NotifyAvatarChange(hwnd);
			Invalidate(hwnd);
			return TRUE;
		}
		case AVATAR_SETAVATARBORDERCOLOR:
		{
			data->avatarBorderColor = (COLORREF) lParam;
			NotifyAvatarChange(hwnd);
			Invalidate(hwnd);
			return TRUE;
		}
		case AVATAR_SETAVATARROUNDCORNERRADIUS:
		{
			data->avatarRoundCornerRadius = (int) lParam;
			NotifyAvatarChange(hwnd);
			Invalidate(hwnd);
			return TRUE;
		}
		case AVATAR_SETNOAVATARTEXT:
		{
			lstrcpynA(data->noAvatarText, Translate((char*) lParam), sizeof(data->noAvatarText));
			Invalidate(hwnd);
			return TRUE;
		}
		case AVATAR_RESPECTHIDDEN:
		{
			data->respectHidden = (BOOL) lParam;
			NotifyAvatarChange(hwnd);
			Invalidate(hwnd);
			return TRUE;
		}
		case AVATAR_SETRESIZEIFSMALLER:
		{
			data->resizeIfSmaller = (BOOL) lParam;
			NotifyAvatarChange(hwnd);
			Invalidate(hwnd);
			return TRUE;
		}
		case AVATAR_GETUSEDSPACE:
		{
			int *width = (int *)wParam;
			int *height = (int *)lParam;

			if (data->hContact == NULL && data->proto[0] == '\0')
			{
				*width = 0;
				*height = 0;
				return TRUE;
			}

			RECT rc;
			GetClientRect(hwnd, &rc);

			// Get avatar
			if (data->showingFlash && ServiceExists(MS_FAVATAR_GETINFO))
			{
				FLASHAVATAR fa = {0}; 
                fa.hContact = data->hContact;
				fa.cProto = data->proto;
				fa.hParentWindow = hwnd;
                fa.id = 1675;
				CallService(MS_FAVATAR_GETINFO, (WPARAM)&fa, 0);
				if (fa.hWindow != NULL)
				{
					*width = rc.right - rc.left;
					*height = rc.bottom - rc.top;
					return TRUE;
				}
			}

			avatarCacheEntry *ace;
			if (data->hContact == NULL)
				ace = (avatarCacheEntry *) CallService(MS_AV_GETMYAVATAR, 0, (LPARAM) data->proto);
			else
				ace = (avatarCacheEntry *) CallService(MS_AV_GETAVATARBITMAP, 0, (LPARAM) data->hContact);

			if (ace == NULL || ace->bmHeight == 0 || ace->bmWidth == 0 
				|| (data->respectHidden && (ace->dwFlags & AVS_HIDEONCLIST)))
			{
				*width = 0;
				*height = 0;
				return TRUE;
			}

			// Get its size
			int targetWidth = rc.right - rc.left;
			int targetHeight = rc.bottom - rc.top;

			if (!data->resizeIfSmaller && ace->bmHeight <= targetHeight && ace->bmWidth <= targetWidth)
			{
				*height = ace->bmHeight;
				*width = ace->bmWidth;
			} 
			else if (ace->bmHeight > ace->bmWidth)
			{
				float dScale = targetHeight / (float)ace->bmHeight;
				*height = targetHeight;
				*width = (int) (ace->bmWidth * dScale);
			}
			else 
			{
				float dScale = targetWidth / (float)ace->bmWidth;
				*height = (int) (ace->bmHeight * dScale);
				*width = targetWidth;
			}

			return TRUE;
		}
        case DM_AVATARCHANGED:
		{
			if (data->hContact == (HANDLE) wParam)
			{
				if (data->showingFlash)
				{
					DestroyFlash(hwnd, data);
					data->showingFlash = FALSE;
				}

				if (DBGetContactSettingWord(data->hContact, "ContactPhoto", "Format", 0) == PA_FORMAT_XML)
					data->showingFlash = StartFlash(hwnd, data);

				NotifyAvatarChange(hwnd);
				Invalidate(hwnd);
			}
            break;
		}
        case DM_MYAVATARCHANGED:
		{
			if (data->hContact == NULL && strcmp(data->proto, (char*) wParam) == 0)
			{
				if (data->showingFlash)
				{
					DestroyFlash(hwnd, data);
					data->showingFlash = FALSE;
				}

				NotifyAvatarChange(hwnd);
				Invalidate(hwnd);
			}
            break;
		}
		case WM_NCPAINT:
		case WM_PAINT:
		{
			if (data->hContact == NULL && data->proto[0] == '\0')
				break;

			PAINTSTRUCT ps;
			HDC hdc = BeginPaint(hwnd, &ps);
			if (hdc == NULL) 
				break;

			int oldBkMode = SetBkMode(hdc, TRANSPARENT);
			SetStretchBltMode(hdc, HALFTONE);

			RECT rc;
			GetClientRect(hwnd, &rc);

			// Draw background
			if (data->bkgColor != -1)
			{
				HBRUSH hbrush = CreateSolidBrush(data->bkgColor);
				FillRect(hdc, &rc, hbrush);
				DeleteObject(hbrush);
			}

			// If has a flash avatar, don't draw it
			if (data->showingFlash && ServiceExists(MS_FAVATAR_GETINFO))
			{
				FLASHAVATAR fa = {0}; 
                fa.hContact = data->hContact;
				fa.cProto = data->proto;
				fa.hParentWindow = hwnd;
                fa.id = 1675;
				CallService(MS_FAVATAR_GETINFO, (WPARAM)&fa, 0);
				if (fa.hWindow != NULL)
				{
					// Draw control border
					if (data->borderColor != -1)
					{
						HBRUSH hbrush = CreateSolidBrush(data->borderColor);
						FrameRect(hdc, &rc, hbrush);
						DeleteObject(hbrush);
					}
					return TRUE;
				}
			}

			// Draw avatar
            AVATARDRAWREQUEST avdrq = {0};
            avdrq.cbSize = sizeof(avdrq);
			avdrq.rcDraw = rc;
            avdrq.hContact = data->hContact;
			avdrq.szProto = data->proto;
            avdrq.hTargetDC = hdc;
            avdrq.dwFlags = AVDRQ_HIDEBORDERONTRANSPARENCY
				| (data->respectHidden ? AVDRQ_RESPECTHIDDEN : 0) 
				| (data->hContact != NULL ? 0 : AVDRQ_OWNPIC)
				| (data->avatarBorderColor == -1 ? 0 : AVDRQ_DRAWBORDER)
				| (data->avatarRoundCornerRadius <= 0 ? 0 : AVDRQ_ROUNDEDCORNER)
				| (data->resizeIfSmaller ? 0 : AVDRQ_DONTRESIZEIFSMALLER);
            avdrq.clrBorder = data->avatarBorderColor;
            avdrq.radius = data->avatarRoundCornerRadius;
			if (!CallService(MS_AV_DRAWAVATAR, 0, (LPARAM)&avdrq)) 
			{
				HGDIOBJ oldFont = SelectObject(hdc, data->hFont);

				// Get text rectangle
				RECT tr = avdrq.rcDraw;
				tr.top += 10;
				tr.bottom -= 10;
				tr.left += 10;
				tr.right -= 10;

				// Calc text size
				RECT tr_ret = tr;
				DrawTextA(hdc, data->noAvatarText, -1, &tr_ret, 
						DT_WORDBREAK | DT_NOPREFIX | DT_CENTER | DT_CALCRECT);
				
				// Calc needed size
				tr.top += ((tr.bottom - tr.top) - (tr_ret.bottom - tr_ret.top)) / 2;
				tr.bottom = tr.top + (tr_ret.bottom - tr_ret.top);
				DrawTextA(hdc, data->noAvatarText, -1, &tr, 
						DT_WORDBREAK | DT_NOPREFIX | DT_CENTER);

				SelectObject(hdc, oldFont);
			}

			// Draw control border
			if (data->borderColor != -1)
			{
				HBRUSH hbrush = CreateSolidBrush(data->borderColor);
				FrameRect(hdc, &rc, hbrush);
				DeleteObject(hbrush);
			}

			SetBkMode(hdc, oldBkMode);

			EndPaint(hwnd, &ps);
			return TRUE;
		}
		case WM_ERASEBKGND:
		{
			HDC hdc = (HDC) wParam;
			RECT rc;
			GetClientRect(hwnd, &rc);

			// Draw background
			if (data->bkgColor != -1)
			{
				HBRUSH hbrush = CreateSolidBrush(data->bkgColor);
				FillRect(hdc, &rc, hbrush);
				DeleteObject(hbrush);
			}

			// Draw control border
			if (data->borderColor != -1)
			{
				HBRUSH hbrush = CreateSolidBrush(data->borderColor);
				FrameRect(hdc, &rc, hbrush);
				DeleteObject(hbrush);
			}

			return TRUE;
		}
		case WM_SIZE:
		{
			if (data->showingFlash)
				ResizeFlash(hwnd, data);
			InvalidateRect(hwnd, NULL, TRUE);
			break;
		}
	}
	return DefWindowProc(hwnd, msg, wParam, lParam);
}
Example #23
0
 	CCXBitmapDC::CCXBitmapDC(const char *text, CGSize dimensions, UITextAlignment alignment, const char *fontName, float fontSize)
 	{
		HWND hWnd  = CCDirector::sharedDirector()->getOpenGLView()->getHWnd();
		HDC hWndDC = GetDC(hWnd);
		m_hMemDC = CreateCompatibleDC(hWndDC);
		ReleaseDC(hWnd, hWndDC);

		// create font
		HFONT hFont = NULL;
		HFONT hNewFont = NULL;
		LOGFONT lFont = {0};
		lFont.lfHeight = -(LONG)fontSize;
		MultiByteToWideChar(CP_ACP, 0, fontName, -1, lFont.lfFaceName, LF_FACESIZE);
		hFont = CreateFontIndirect(&lFont);
		if (hFont)
		{
			hNewFont = hFont;
		}
		else
		{
			hNewFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
		}
		HGDIOBJ hOldFont = SelectObject(m_hMemDC, hNewFont);

		// calculate text size
        int len = strlen(text);
		SIZE extent;
		if (CGSize::CGSizeEqualToSize(dimensions, CGSizeZero))
		{
			GetTextExtentPointA(m_hMemDC, text, len, &extent);
		}
		else
		{
			extent.cx = (int)dimensions.width;
			extent.cy = (int)dimensions.height;
		}

		// create hbitmap
		m_hBmp = CreateBitmap(extent.cx, extent.cy, 1, 32, NULL);
		m_hOld = SelectObject(m_hMemDC, m_hBmp);

		// set style
        DWORD dwStyle = DT_SINGLELINE | DT_VCENTER;

		switch (alignment)
		{
		case UITextAlignmentLeft:
			dwStyle |= DT_LEFT;
			break;
		case UITextAlignmentCenter:
			dwStyle |= DT_CENTER;
			break;
		case UITextAlignmentRight:
			dwStyle |= DT_RIGHT;
			break;
		default:
			dwStyle |= DT_CENTER;
			break;
		}

		// draw text
		RECT rc = {0, 0, extent.cx, extent.cy};
		SetBkMode(m_hMemDC, TRANSPARENT);
		SetTextColor(m_hMemDC, RGB(255, 255, 255)); // white color
		DrawTextA(m_hMemDC, text, len, &rc, dwStyle);

		// free resource
		SelectObject(m_hMemDC, hOldFont);
		if (hFont)
		{
			DeleteObject(hFont);
		}
 	}
Example #24
0
//---------------------------------------------------------------------------
void __fastcall TMatrForm::dgDrawCell(TObject *Sender, int ACol, int ARow,
	  TRect &Rect, TGridDrawState State)
{
	AnsiString s, n1, n2, n3;
	int ball, PartCode;
	TDrawGrid* dg = (TDrawGrid*)Sender;
	TColor clr;
	TRect rect;
	TTaskTypeList *Tasks;
	TMatrArr *Grid;
	TColor clError = (TColor)0x00CCCCFF;
	
//	TTextFormat tf;

	try {

	if (!MatrixList->Count)
		return;

	Tasks = CurMatrix->Tasks;
	Grid = CurMatrix->Grid;

	//Нумерация
	if (ACol == 0) {
		s = ARow;
		DrawTextA(dg->Canvas->Handle, s.c_str(), s.Length(), &Rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
	}

	//Номера заданий
	if (ARow == 0 && ACol >= TASK_COL && ACol < Tasks->Count + TASK_COL) {
//		if (Tasks->Number1[ACol - TASK_COL])
//			n1 = String((char)(Tasks->Number1[ACol - TASK_COL] - 1 + 'A'));
//		else
//			n1 = "";
//
//		if (Tasks->Number2[ACol - TASK_COL])
//			n2 = IntToStr(Tasks->Number2[ACol - TASK_COL]);
//		else
//			n2 = "";
//
//		if (Tasks->Number3[ACol - TASK_COL])
//			n3 = "." + IntToStr(Tasks->Number3[ACol - TASK_COL]);
//		else
//			n3 = "";
//
//		s = n1 + n2 + n3;
		s = Tasks->Caption[ACol - TASK_COL];
		DrawTextA(dg->Canvas->Handle, s.c_str(), s.Length(), &Rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
	}

	//Код ученика
	if (ARow == 0 && ACol == 1) {
		rect = Rect;
		dg->Canvas->FillRect(Rect);
		rect.left += 2;
		s = "Код ученика";
		DrawTextA(dg->Canvas->Handle, s.c_str(), s.Length(), &rect, DT_WORDBREAK | DT_VCENTER);
	}

	//Заливка
	/*if (ARow > 0 && ACol >= TASK_COL) {
		if (Tasks->Number1[ACol - TASK_COL] == 0) {
			dg->Canvas->Brush->Color = (TColor)0xefffff;
			dg->Canvas->FillRect(Rect);
		}
		if (Tasks->Number1[ACol - TASK_COL] == 1) {
			dg->Canvas->Brush->Color = (TColor)0xffefff;
			dg->Canvas->FillRect(Rect);
		}
		if (Tasks->Number1[ACol - TASK_COL] == 2) {
			dg->Canvas->Brush->Color = (TColor)0xffffef;
			dg->Canvas->FillRect(Rect);
		}
	}*/

	if (ACol == 1 && ARow == 1) {
		s = s;
	}

	//Заполнение кодов учеников
	if (ACol == PARTICIPANT_COL && ARow >= START_ARR_ROW && (ACol - START_ARR_COL) < Grid->ColCount)	{
		PartCode = Grid->Cells[ARow - START_ARR_ROW][ACol - PARTICIPANT_COL].ToIntDef(0);
		if (Grid->Cells[ARow - START_ARR_ROW][ACol - PARTICIPANT_COL] != "" &&
			(PartCode <= 0 || MatrixList->ParticipantMatch(PartCode, ACol - PARTICIPANT_COL))) {
			dg->Canvas->Brush->Color = clError;
			dg->Canvas->FillRect(Rect);
//			ImageList1->Draw(dg->Canvas, 200, 200, 0, true);
		}
		s = Grid->Cells[ARow - START_ARR_ROW][ACol - START_ARR_COL];
		DrawTextA(dg->Canvas->Handle, s.c_str(), s.Length(), &Rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
	}
	
	//Заполнение из массива
	if (ACol > START_ARR_COL && (ACol - START_ARR_COL) < Grid->ColCount &&
		ARow >= START_ARR_ROW && ARow <= Grid->RowCount)
	{
		s = Grid->Cells[ARow - START_ARR_ROW][ACol - START_ARR_COL];
		if (s != "" && ACol != PARTICIPANT_COL) {
			ball = s.ToIntDef(-1);
			if ((ball < 0 || ball > Tasks->BallMax[ACol - TASK_COL]) && ACol >= TASK_COL) {
				dg->Canvas->Brush->Color = clError;
				dg->Canvas->FillRect(Rect);
			}
		}
		DrawTextA(dg->Canvas->Handle, s.c_str(), s.Length(), &Rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
	}

	} catch (...) {
//		ShowMessage("Произошёл сбой программы. Программа будет закрыта.");
//		dg->OnDrawCell = dgDrawCell;
	}
}
Example #25
0
/* ----------------------------------------------------------------
    Win\Gui\Window C API
------------------------------------------------------------------*/
int wingui_control_static_autosize(HWND handle, int style, int extrastyle, int x, int y TSRMLS_DC)
{
	HDC dc;
	RECT rect;
	BOOL worked;
	UINT flags = DT_CALCRECT;

	dc = GetDC(handle);
	if (dc == 0) {
		goto error;
	}

	worked = GetClientRect(handle, &rect);

	if (worked == 0) {
		goto error;
	}

	/* get our flags right for drawtext */
	if ((SS_CENTER & style) == SS_CENTER) {
		flags |= DT_CENTER;
	} else if ((SS_RIGHT & style) == SS_RIGHT) {
		flags |= DT_RIGHT;
	} else if ((SS_LEFT & style) == SS_LEFT) {
		flags |= DT_LEFT;
	}
	
	if ( ((WS_EX_RTLREADING & extrastyle) == WS_EX_RTLREADING)
		|| ((WS_EX_LAYOUTRTL & extrastyle) == WS_EX_LAYOUTRTL) ) {
			flags |= DT_RTLREADING;
	}

	if ((SS_WORDELLIPSIS & style) == SS_WORDELLIPSIS) {
		flags |= DT_WORD_ELLIPSIS | DT_SINGLELINE;
	} else if ((SS_PATHELLIPSIS & style) == SS_PATHELLIPSIS) {
		flags |= DT_PATH_ELLIPSIS | DT_SINGLELINE;
	} else if ((SS_ENDELLIPSIS & style) == SS_ENDELLIPSIS) {
		flags |= DT_END_ELLIPSIS | DT_SINGLELINE;
	} 

	if ((SS_NOPREFIX & style) == SS_NOPREFIX) {
		flags |= DT_NOPREFIX;
	} 

	if ((SS_LEFTNOWORDWRAP & style) == SS_LEFTNOWORDWRAP) {
		flags |= DT_SINGLELINE;
	} else if ((SS_SIMPLE & style) == SS_SIMPLE) {
		flags |= DT_SINGLELINE;
	} else {
		flags |= DT_WORDBREAK;
	}

	if ((SS_EDITCONTROL & style) == SS_EDITCONTROL) {
		flags |= DT_EDITCONTROL;
	}

	if (IsWindowUnicode(handle)) {
		int length, worked_len;
		wchar_t * text;

		length = GetWindowTextLengthW(handle);
		text = safe_emalloc(length, sizeof(wchar_t), 1);

		worked_len = GetWindowTextW(handle, text, length + 1);
		if (worked_len == 0) {
			goto error;
		}

		worked = DrawTextW(dc, text, -1, &rect, flags); 

		if (worked == 0) {
			goto error;
		}
	} else {
		int length, worked_len;
		char * text;

		length = GetWindowTextLengthA(handle);
		text = safe_emalloc(length, sizeof(char), 1);

		worked_len = GetWindowTextA(handle, text, length + 1);
		if (worked_len == 0) {
			goto error;
		}

		worked = DrawTextA(dc, text, -1, &rect, flags); 

		if (worked == 0) {
			goto error;
		}
	}

    MoveWindow(handle, x, y, (rect.right - rect.left), (rect.bottom - rect.top), FALSE);
	ReleaseDC(handle, dc);
	return SUCCESS;

error:
	ReleaseDC(handle, dc);
	winsystem_create_error(GetLastError(), ce_winsystem_runtimeexception TSRMLS_CC);
	return FAILURE;
}
Example #26
0
void _bta_sys_draw(HWND hwnd, NPP instance) {
	bta_info *bta = (bta_info*)instance->pdata;
	PAINTSTRUCT ps;
	RECT winsize;
	HBRUSH clr;
	HFONT hFont;
	int width=0, height=0;
	int x = 0, y = 0;
	char str[128];

	GetWindowRect(hwnd, &winsize);
	width=(winsize.right-winsize.left);
	height=(winsize.bottom-winsize.top);

	COLORREF bg=RGB(0xFF,0xFF,0xFF);
	COLORREF black=RGB(0,0,0);

	if( !_bta_hovering ) {
		// set normal cursor
		SetCursor( LoadCursor(NULL, IDC_ARROW) );
	
		if( bta->type==1 ) 
			sprintf(str, "subscribe");
		else
			sprintf(str, "pay now");
	} else {
		// set hand cursor
		SetCursor( LoadCursor(NULL, IDC_HAND) );

		bg=RGB(0xEE,0xEE,0xFF);
		
		sprintf(str, "$%0.2f%s", bta->price, bta->type==1?"/mo":"");
	}

	HDC dc=GetDC(hwnd);
	HBITMAP bta_icon = XPMLoadBitmap(dc, icon_xpm);
	ReleaseDC(hwnd, dc);

	BeginPaint(hwnd, &ps);

	hFont = (HFONT)GetStockObject(ANSI_VAR_FONT); 
	SelectObject(ps.hdc, hFont);

	SetTextColor(ps.hdc, black);
	SetBkColor(ps.hdc, bg);
	clr = CreateSolidBrush(black);
	SelectObject(ps.hdc, clr);
	Rectangle(ps.hdc, 0,0, width, height);

	/// paint icon
	HDC hdcIcon = CreateCompatibleDC(ps.hdc);
	SelectObject(hdcIcon, bta_icon);
	BitBlt(ps.hdc,4,4,16,16, hdcIcon,0,0,SRCCOPY);

	DeleteObject( clr );
	clr = CreateSolidBrush(bg);
	SelectObject(ps.hdc, clr);
	Rectangle(ps.hdc, 23, 1, width-1, height-1);

	SetRect(&winsize, 24, 2, width-2, height-2);
	DrawTextA(ps.hdc, str, -1, &winsize, DT_CENTER|DT_VCENTER|DT_SINGLELINE);

	EndPaint(hwnd, &ps);

	// free icon, font, brushes?
	DeleteObject( bta_icon );
	DeleteObject( hFont );
	DeleteObject( hdcIcon );
	DeleteObject( clr );
}
    int drawText(const char * pszText, SIZE& tSize, CCImage::ETextAlign eAlign)
    {
        int nRet = 0;
        do 
        {
            CC_BREAK_IF(! pszText);

            DWORD dwFmt = DT_WORDBREAK;
            DWORD dwHoriFlag = eAlign & 0x0f;
            DWORD dwVertFlag = (eAlign & 0xf0) >> 4;

            switch (dwHoriFlag)
            {
            case 1: // left
                dwFmt |= DT_LEFT;
                break;
            case 2: // right
                dwFmt |= DT_RIGHT;
                break;
            case 3: // center
                dwFmt |= DT_CENTER;
                break;
            }

            int nLen = strlen(pszText);
            SIZE newSize = sizeWithText(pszText, nLen, dwFmt, tSize.cx);

            RECT rcText = {0};
            // if content width is 0, use text size as content size
            if (tSize.cx <= 0)
            {
                tSize = newSize;
                rcText.right  = newSize.cx;
                rcText.bottom = newSize.cy;
            }
            else
            {

                LONG offsetX = 0;
                LONG offsetY = 0;
                rcText.right = newSize.cx; // store the text width to rectangle

                // calculate text horizontal offset
                if (1 != dwHoriFlag          // and text isn't align to left
                    && newSize.cx < tSize.cx)   // and text's width less then content width,
                {                               // then need adjust offset of X.
                    offsetX = (2 == dwHoriFlag) ? tSize.cx - newSize.cx     // align to right
                        : (tSize.cx - newSize.cx) / 2;                      // align to center
                }

                // if content height is 0, use text height as content height
                // else if content height less than text height, use content height to draw text
                if (tSize.cy <= 0)
                {
                    tSize.cy = newSize.cy;
                    dwFmt   |= DT_NOCLIP;
                    rcText.bottom = newSize.cy; // store the text height to rectangle
                }
                else if (tSize.cy < newSize.cy)
                {
                    // content height larger than text height need, clip text to rect
                    rcText.bottom = tSize.cy;
                }
                else
                {
                    rcText.bottom = newSize.cy; // store the text height to rectangle

                    // content larger than text, need adjust vertical position
                    dwFmt |= DT_NOCLIP;

                    // calculate text vertical offset
                    offsetY = (2 == dwVertFlag) ? tSize.cy - newSize.cy     // align to bottom
                        : (3 == dwVertFlag) ? (tSize.cy - newSize.cy) / 2   // align to middle
                        : 0;                                                // align to top
                }

                if (offsetX || offsetY)
                {
                    OffsetRect(&rcText, offsetX, offsetY);
                }
            }

            CC_BREAK_IF(! prepareBitmap(tSize.cx, tSize.cy));

            // draw text
            HGDIOBJ hOldFont = SelectObject(m_hDC, m_hFont);
            HGDIOBJ hOldBmp  = SelectObject(m_hDC, m_hBmp);

            RECT rc = {0, 0, tSize.cx, tSize.cy};
            SetBkMode(m_hDC, TRANSPARENT);
            SetTextColor(m_hDC, RGB(255, 255, 255)); // white color
            nRet = DrawTextA(m_hDC, pszText, nLen, &rcText, dwFmt);

            SelectObject(m_hDC, hOldBmp);
            SelectObject(m_hDC, hOldFont);
        } while (0);
        return nRet;
    }
Example #28
0
HRESULT TShellExt::HandleMenuMsg2(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *plResult)
{
	LRESULT Dummy;
	if (plResult == NULL)
		plResult = &Dummy;

	SIZE tS;
	HBRUSH hBr;

	*plResult = true;
	if (uMsg == WM_DRAWITEM && wParam == 0) {
		// either a main sub menu, a group menu or a contact
		DRAWITEMSTRUCT *dwi = (DRAWITEMSTRUCT*)lParam;
		TMenuDrawInfo *psd = (TMenuDrawInfo*)dwi->itemData;
		// don't fill
		SetBkMode(dwi->hDC, TRANSPARENT);
		// where to draw the icon?
		RECT icorc;
		icorc.left = 0;
		icorc.top = dwi->rcItem.top + ((dwi->rcItem.bottom - dwi->rcItem.top) / 2) - (16 / 2);
		icorc.right = icorc.left + 16;
		icorc.bottom = icorc.top + 16;
		// draw for groups
		if (psd->fTypes & (dtGroup | dtEntry)) {
			hBr = GetSysColorBrush(COLOR_MENU);
			FillRect(dwi->hDC, &dwi->rcItem, hBr);
			DeleteObject(hBr);

			if (dwi->itemState & ODS_SELECTED) {
				// only do this for entry menu types otherwise a black mask
				// is drawn under groups
				hBr = GetSysColorBrush(COLOR_HIGHLIGHT);
				FillRect(dwi->hDC, &dwi->rcItem, hBr);
				DeleteObject(hBr);
				SetTextColor(dwi->hDC, GetSysColor(COLOR_HIGHLIGHTTEXT));
			}
			// draw icon
			if (dwi->itemState & ODS_SELECTED)
				hBr = GetSysColorBrush(COLOR_HIGHLIGHT);
			else
				hBr = GetSysColorBrush(COLOR_MENU);

			DrawIconEx(dwi->hDC, icorc.left + 1, icorc.top, psd->hStatusIcon, 16, 16, 0, hBr, DI_NORMAL);
			DeleteObject(hBr);

			// draw the text
			dwi->rcItem.left += dwi->rcItem.bottom - dwi->rcItem.top - 2;
			DrawTextA(dwi->hDC, psd->szText, psd->cch, &dwi->rcItem, DT_NOCLIP | DT_NOPREFIX | DT_SINGLELINE | DT_VCENTER);
			// draw the name of the database text if it's there
			if (psd->szProfile != NULL) {
				GetTextExtentPoint32A(dwi->hDC, psd->szText, psd->cch, &tS);
				dwi->rcItem.left += tS.cx + 8;
				SetTextColor(dwi->hDC, GetSysColor(COLOR_GRAYTEXT));
				DrawTextA(dwi->hDC, psd->szProfile, lstrlenA(psd->szProfile), &dwi->rcItem, DT_NOCLIP | DT_NOPREFIX | DT_SINGLELINE | DT_VCENTER);
			}
		}
		else {
			// it's a contact!
			hBr = GetSysColorBrush(COLOR_MENU);
			FillRect(dwi->hDC, &dwi->rcItem, hBr);
			DeleteObject(hBr);
			if (dwi->itemState & ODS_SELECTED) {
				hBr = GetSysColorBrush(COLOR_HIGHLIGHT);
				FillRect(dwi->hDC, &dwi->rcItem, hBr);
				DeleteObject(hBr);
				SetTextColor(dwi->hDC, GetSysColor(COLOR_HIGHLIGHTTEXT));
			}
			// draw icon
			if (dwi->itemState & ODS_SELECTED)
				hBr = GetSysColorBrush(COLOR_HIGHLIGHT);
			else
				hBr = GetSysColorBrush(COLOR_MENU);

			DrawIconEx(dwi->hDC, icorc.left + 2, icorc.top, psd->hStatusIcon, 16, 16, 0, hBr, DI_NORMAL);
			DeleteObject(hBr);

			// draw the text
			dwi->rcItem.left += dwi->rcItem.bottom - dwi->rcItem.top + 1;
			DrawTextA(dwi->hDC, psd->szText, psd->cch, &dwi->rcItem, DT_NOCLIP | DT_NOPREFIX | DT_SINGLELINE | DT_VCENTER);
		}
	}
	else if (uMsg == WM_MEASUREITEM) {
		// don't check if it's really a menu
		MEASUREITEMSTRUCT *msi = (MEASUREITEMSTRUCT*)lParam;
		TMenuDrawInfo *psd = (TMenuDrawInfo*)msi->itemData;
		NONCLIENTMETRICS ncm;
		ncm.cbSize = (bIsVistaPlus) ? sizeof(ncm) : offsetof(NONCLIENTMETRICS, iPaddedBorderWidth);
		SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &ncm, 0);
		// create the font used in menus, this font should be cached somewhere really
		HFONT hFont = CreateFontIndirect(&ncm.lfMenuFont);
		// select in the font
		HFONT hOldFont = (HFONT)SelectObject(hMemDC, hFont);
		// default to an icon
		int dx = 16;
		// get the size 'n' account for the icon
		GetTextExtentPoint32A(hMemDC, psd->szText, psd->cch, &tS);
		dx += tS.cx;
		// main menu item?
		if (psd->szProfile != NULL) {
			GetTextExtentPoint32A(hMemDC, psd->szProfile, lstrlenA(psd->szProfile), &tS);
			dx += tS.cx;
		}
		// store it
		msi->itemWidth = dx + ncm.iMenuWidth;
		msi->itemHeight = ncm.iMenuHeight + 2;
		if (tS.cy > (int)msi->itemHeight) 
			msi->itemHeight += tS.cy - msi->itemHeight;
		// clean up
		SelectObject(hMemDC, hOldFont);
		DeleteObject(hFont);
	}
	return S_OK;
}
Example #29
0
LRESULT CALLBACK _bta_sys_prompt_callback( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
	struct _bta_prompt_info *p = _bta_sys_info; //TODO: get from starting thread ...
	POINTS m;
	int x=0,y=0,z=0, lastover=OVER_OTHER;
	HDC dc;
	static int pinlen=0;
	static int done=0, redraw=1;
	static int over=OVER_OTHER;
	static HBRUSH clr[5];
	static HFONT hFont;

	switch( uMsg ) {
		case WM_CREATE:
			pinlen=0;
			done=0;
			redraw=0;
			over=OVER_OTHER;
			p->pin[0]=0;

			clr[0] = CreateSolidBrush(RGB(0,0,0x55));
			clr[1] = CreateSolidBrush(RGB(0x55,0x55,0x99));
			clr[2] = CreateSolidBrush(RGB(0xdd,0xdd,0xff));
			clr[3] = CreateSolidBrush(RGB(0xff,0xff,0xff));
			clr[4] = CreateSolidBrush(RGB(0xff,0xcc,0xcc));
			hFont = (HFONT)GetStockObject(ANSI_VAR_FONT); 

			// load banner image
			dc = GetDC(hwnd);
			p->banner = XPMLoadBitmap(dc, dialog_xpm);
			ReleaseDC(hwnd, dc);

			return DefWindowProc(hwnd, uMsg, wParam, lParam);
			break;

		case WM_MOVE:
			InvalidateRect(hwnd, NULL, FALSE);
			UpdateWindow(hwnd);
			break;

		case WM_PAINT: 
			redraw=1;
			break;

		case WM_CLOSE:
			done=-1;
			break;

		case WM_DESTROY:
			PostQuitMessage(0);
			return 0;

		case WM_MOUSEMOVE:
			m = MAKEPOINTS(lParam);
			lastover=over;
			x=m.x; y=m.y;

			if( x>=pinbox.left && x<=pinbox.right && y>=pinbox.top && y<=pinbox.bottom ) {
				if( over!=OVER_PINBOX ) {
					over=OVER_PINBOX;
					SetCursor(p->cursor[1]);
				}
			} else {
				if( over==OVER_PINBOX )
					SetCursor(p->cursor[0]);
				over=OVER_OTHER;
			}

			if( y>=buttons[0].top && y<=buttons[0].bottom ) {
				if( x>=buttons[0].left && x<=buttons[0].right ) {
					over=OVER_CANCEL;
				} else if( x>=buttons[1].left && x<=buttons[1].right ) {
					over=OVER_OK;
				}
			}
			if( over!=lastover ) { InvalidateRect(hwnd, NULL, FALSE); UpdateWindow(hwnd); }
			break;

		case WM_SETCURSOR:
			if( over==OVER_PINBOX )
				SetCursor(p->cursor[1]);
			return 0;

		case WM_LBUTTONUP: 
			switch( over) {
				case OVER_OK: done=1; break;
				case OVER_CANCEL: done=-1; break;
			}
			break;

		case WM_CHAR: 
			switch( wParam ) {
				case 27: done=-1; break;
				case '\b': if( pinlen>0 ) p->pin[ --pinlen ]=0; break;
				case '\r': done=1; break;
				case '0':
				case '1':
				case '2':
				case '3':
				case '4':
				case '5':
				case '6':
				case '7':
				case '8':
				case '9':  if(pinlen==13) break; 
										 p->pin[pinlen++]=(char)wParam;
									 p->pin[pinlen]=0;
									 break;
			}

			InvalidateRect(hwnd, NULL, FALSE);
			UpdateWindow(hwnd);
			break;
		default:
			return DefWindowProc(hwnd, uMsg, wParam, lParam);

	}
	// can't be done if no pin
	if( done==1 && p->pin[0]==0 ) done=0;

	if( redraw ) {
		redraw=0;

		PAINTSTRUCT ps;
		BeginPaint(hwnd, &ps);

		// draw banner
		HDC hdcBanner = CreateCompatibleDC(ps.hdc);
		SelectObject(hdcBanner, p->banner);
		BitBlt(ps.hdc,0,0,DIALOG_WIDTH, DIALOG_BANNER_HEIGHT, hdcBanner,0,0,SRCCOPY);

		// draw pinbox
		if( over==OVER_PINBOX ) 
			FillRect(ps.hdc, &pinbox, clr[2]);
		else
			FillRect(ps.hdc, &pinbox, clr[3]);

		RECT dot = {262,74, 268,80};
		for(z=0; z<=pinlen; z++) {
			dot.left=262+z*10;
			dot.right=dot.left+6;
			if( z!=pinlen )
				FillRect(ps.hdc, &dot, clr[0]);
			else {// cursor
				MoveToEx(ps.hdc, dot.left, 71, NULL);
				LineTo(ps.hdc, dot.left, 83);
			}
		}

		// draw description text
		RECT descRect;	
		SetTextColor(ps.hdc, RGB(0,0,0));
		SetBkColor(ps.hdc, RGB(0xFF,0xFF,0xFF));
		SetRect(&descRect, 5,110, DIALOG_WIDTH-5, DIALOG_HEIGHT-40);
		DrawTextA(ps.hdc, ((bta_info *)p->instance->pdata)->desc, -1, &descRect, DT_LEFT|DT_TOP|DT_WORDBREAK);

		// draw error message
		if( p->error[0]!=0 ) {
			RECT err;
			SetRect(&err, 10, DIALOG_HEIGHT-70, DIALOG_WIDTH-10, DIALOG_HEIGHT-45);
			FillRect(ps.hdc, &err, clr[4]);
			SetBkColor(ps.hdc, RGB(0xFF,0xCC,0xCC));
			DrawTextA(ps.hdc, p->error, -1, &err, DT_CENTER|DT_VCENTER|DT_SINGLELINE);
		}

		// draw buttons
		SelectObject(ps.hdc, hFont);
		SetTextColor(ps.hdc, RGB(0xFF,0xFF,0xFF));
		if( over==OVER_CANCEL ) SetBkColor(ps.hdc, RGB(0x55,0x55,0x99));
		else SetBkColor(ps.hdc, RGB(0,0,0x55));
		FillRect(ps.hdc, &buttons[0], over==OVER_CANCEL?clr[1]:clr[0]);
		DrawText(ps.hdc, L"Cancel", -1, &buttons[0], DT_CENTER|DT_VCENTER|DT_SINGLELINE);
		if( over==OVER_OK ) SetBkColor(ps.hdc, RGB(0x55,0x55,0x99));
		else SetBkColor(ps.hdc, RGB(0,0,0x55));
		FillRect(ps.hdc, &buttons[1], over==OVER_OK?clr[1]:clr[0]);
		DrawText(ps.hdc, L"OK", -1, &buttons[1], DT_CENTER|DT_VCENTER|DT_SINGLELINE);

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

	if( done!=0 ) {
		// tell main window we have a PIN
		if( done>0 )
			SendMessage(p->parent, WM_USER, 42, 42);

		DeleteObject( clr[0] );
		DeleteObject( clr[1] );
		DeleteObject( clr[2] );
		DeleteObject( clr[3] );
		DeleteObject( clr[4] );

		DeleteObject( p->banner );

		DestroyWindow(hwnd);
		return 1;
	}

	return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
    int wmId, wmEvent;
    PAINTSTRUCT ps;
    HDC hdc;
    CHAR * strTemp;
    HDROP hDropInfo;

    switch (message) {
    case WM_COMMAND:
        wmId = LOWORD(wParam);
        wmEvent = HIWORD(wParam);
        // Parse the menu selections:
        switch (wmId)
        {
        case IDM_ABOUT:
            DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
            break;
        case IDM_EXIT:
            DestroyWindow(hWnd);
            break;
        default:
            return DefWindowProc(hWnd, message, wParam, lParam);
        }
        break;
    case WM_PAINT:
        hdc = BeginPaint(hWnd, &ps);
        SetBkColor(hdc, RGB(0, 0, 0));
        FillRect(hdc, &rectScreen, GetStockBrush(BLACK_BRUSH));
        SetTextColor(hdc, RGB(255, 255, 255));
        DrawTextA(hdc, strFileName, strlen(strFileName), &rectTopLeft, DT_RIGHT | DT_SINGLELINE);
        if (strFilePath)
            DrawTextA(hdc, strFilePath, strlen(strFilePath), &rectTopRight, DT_LEFT | DT_EDITCONTROL | DT_WORDBREAK | DT_PATH_ELLIPSIS);
        switch (conStep) {
            case CONVERT_STEP_READY_COMPLETE:
                strTemp = strReadyCompleted;
                break;
            case CONVERT_STEP_READY:
                strTemp = strReady;
                break;
            //Step 1 processing
            case CONVERT_STEP_1:
                strTemp = strProcessing1;
                break;
            case CONVERT_STEP_INVALID_FILE:
                strTemp = strErrorInvalidFile;
                break;
            case CONVERT_STEP_MANIFEST_INCLUDED:
                strTemp = strErrorManifestIncluded;
                break;
            case CONVERT_STEP_NOPERM:
                strTemp = strErrorNoPerm;
                break;
            //Step 2 processing
            case CONVERT_STEP_2:
                strTemp = strProcessing2;
                break;
            case CONVERT_STEP_APP_RESOURCE_FAIL:
                strTemp = strErrorAppResourceMissing;
                break;
            //Step 3 processing
            case CONVERT_STEP_3:
                strTemp = strProcessing3;
                break;
            case CONVERT_STEP_UNABLE_MOVE_FILE:
                strTemp = strErrorUnableMoveFile;
                break;
            case CONVERT_STEP_UNABLE_COPY_FILE:
                strTemp = strErrorUnableCopyFile;
                break;
            //Step 4 processing
            case CONVERT_STEP_4:
                strTemp = strProcessing4;
                break;
            case CONVERT_STEP_UNABLE_WRITE_FILE:
                strTemp = strErrorUnableWriteFile;
                break;
            case CONVERT_STEP_UNABLE_ADD_RES:
                strTemp = strErrorUnableAddRes;
                break;
            case CONVERT_STEP_UNABLE_SAVE_RES:
                strTemp = strErrorUnableSaveRes;
                break;
            default:
                strTemp = strDefault;
                break;
        }
        DrawTextA(hdc, strTemp, strlen(strTemp), &rectBottom, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
        EndPaint(hWnd, &ps);
        break;
    case WM_DESTROY:
        if (strFilePath) free(strFilePath);
        PostQuitMessage(0);
        break;
    case WM_DROPFILES:
        hDropInfo = (HDROP)wParam;
        if (hThreadHandle) {
            DWORD dwWaitResult = WaitForSingleObject(hThreadHandle, 0);

            switch (dwWaitResult) {
                case STATUS_WAIT_0:
                case STATUS_ABANDONED_WAIT_0:
                    CloseHandle(hThreadHandle);
                    hThreadHandle = 0;
                    break;
                default:
                userTryMultiFiles:
                    MessageBoxA(hWnd, mbMsg, mbCaption, MB_OK | MB_ICONWARNING);
                    goto doNotProcessNewFile;
            }
        }
        UINT numFiles = DragQueryFileA(hDropInfo, -1, NULL, 0);
        if (numFiles > 1) {
            goto userTryMultiFiles;
        }
        EnterCriticalSection(&m_cs);
        UINT buffsize = MAX_SIZE;
        CHAR * buf = malloc(MAX_SIZE);
        workerInfo* worker = malloc(sizeof(workerInfo));
        if (strFilePath) {
            free(strFilePath);
            strFilePath = NULL;
        }
        DragQueryFileA(hDropInfo, 0, buf, buffsize);
        worker->fileStr = buf;
        worker->hWnd = hWnd;
        hThreadHandle = CreateThread(NULL, 0, WorkerThread, worker, 0, (LPDWORD)&hThread);
        LeaveCriticalSection(&m_cs);
    doNotProcessNewFile:
        //This is required to be at bottom for less coding.
        DragFinish(hDropInfo);
        break;
    default:
        return DefWindowProc(hWnd, message, wParam, lParam);
    }
    return 0;
}