Beispiel #1
0
LRESULT CPerfBar::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
    UNREFERENCED_PARAMETER(uMsg);
    UNREFERENCED_PARAMETER(wParam);
    UNREFERENCED_PARAMETER(lParam);
    bHandled = FALSE;

    HDC hDC = GetDC();

    m_font =
        CreateFontW(
            -MulDiv(8, GetDeviceCaps(hDC, LOGPIXELSY), 72),
            0,
            0,
            0,
            FW_BOLD,
            FALSE,
            FALSE,
            FALSE,
            ANSI_CHARSET,
            0,
            0,
            0,
            0,
            L"Arial"
        );

    ReleaseDC(hDC);

    SetTimer(1000, 1000, nullptr);

    return 0;
}
		void Recreate(int res, bool bold, bool italic, bool underline, const core::stringw& fontName)
		{
			if (font)
				DeleteFont(font);
			font = CreateFontW(
				res,
				0, 0, 0,
				bold ? FW_BOLD : 0,
				italic,
				underline,
				0,
				ANSI_CHARSET | ARABIC_CHARSET,
				OUT_DEFAULT_PRECIS,
				CLIP_DEFAULT_PRECIS,
				DEFAULT_QUALITY,
				DEFAULT_PITCH | FF_SWISS,
				fontName.c_str());
			fontDirty = false;
		}
Beispiel #3
0
void NFOView::ChangeFont(void)
{
	HFONT font = CreateFontW(_fontSize,
				       0,
					   0,
					   0,
					   FW_DONTCARE,
			           FALSE, FALSE, FALSE,
					   DEFAULT_CHARSET,
					   OUT_DEFAULT_PRECIS,
					   CLIP_DEFAULT_PRECIS,
				       DEFAULT_QUALITY,
				       DEFAULT_PITCH,
                       _fontName.c_str());

    SendMessage(_handle, WM_SETFONT, (WPARAM)font, MAKELPARAM(TRUE, 0));

    AfterChangeFont();
}
Beispiel #4
0
void Font::create(wchar_t *fontname, int size)
{
	Hfont = CreateFontW(
		size,					//フォント高さ
		0,						//文字幅
		0,						//テキストの角度
		0,						//ベースラインとx軸との角度
		FW_REGULAR,				//フォントの太さ
		FALSE,					//イタリック体
		FALSE,					//アンダーライン
		FALSE,					//打ち消し線
		SHIFTJIS_CHARSET,		//文字セット
		OUT_DEFAULT_PRECIS,		//出力精度
		CLIP_DEFAULT_PRECIS,	//クリッピング精度
		ANTIALIASED_QUALITY,	//出力品質
		FIXED_PITCH | FF_MODERN,//ピッチとファミリー
		fontname);				//書体名

	Hdc = wglGetCurrentDC();
	SelectObject(Hdc, Hfont);
}
Beispiel #5
0
void
font_create(int font_size, struct font_context *ctx) {
	TEXTMETRIC tm;
	HFONT f = CreateFontW(
		font_size,0,
		0, 0, 
		FW_SEMIBOLD,
		FALSE, FALSE, FALSE, 
		DEFAULT_CHARSET, 
		OUT_DEFAULT_PRECIS, 
		CLIP_DEFAULT_PRECIS,
		ANTIALIASED_QUALITY,
		DEFAULT_PITCH, 
		NULL
	);

	HDC dc = CreateCompatibleDC(NULL);
	SelectObject(dc, f);
	ctx->font = (void *)f;
	ctx->dc = (void *)dc;
	GetTextMetrics(dc,&tm);
	ctx->h=tm.tmHeight + 1;
	ctx->ascent=tm.tmAscent;
}
Beispiel #6
0
VOID
LoadDialogControls(
    IN PMIXER_WINDOW MixerWindow,
    LPRECT DialogOffset,
    LPVOID DlgResource,
    DWORD DialogIdMultiplier)
{
    LPDLGTEMPLATE DialogHeader;
    PDLGITEMTEMPLATE DialogItem;
    LPWORD Offset;
    WORD FontSize;
    WCHAR FontName[100];
    WORD Length, Index;
    HFONT Font;

    /* get dialog header */
    DialogHeader = (LPDLGTEMPLATE)DlgResource;

    /* sanity check */
    assert(DialogHeader->cdit);

    if (MixerWindow->Window)
        MixerWindow->Window = (HWND*)HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, MixerWindow->Window, (MixerWindow->WindowCount + DialogHeader->cdit) * sizeof(HWND));
    else
        MixerWindow->Window = (HWND*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, DialogHeader->cdit * sizeof(HWND));
    if (!MixerWindow->Window)
    {
        /* no memory */
        return;
    }

    /* now walk past the dialog header */
    Offset = (LPWORD)(DialogHeader + 1);

    /* FIXME: support menu */
    assert(*Offset == 0);
    Offset++;

    /* FIXME: support classes */
    assert(*Offset == 0);
    Offset++;

    /* FIXME: support titles */
    assert(*Offset == 0);
    Offset++;

    /* get font size */
    FontSize = *Offset;
    Offset++;

    /* calculate font length */
    Length = wcslen((LPWSTR)Offset) + 1;
    assert(Length < (sizeof(FontName) / sizeof(WCHAR)));

    /* copy font */
    wcscpy(FontName, (LPWSTR)Offset);

    Font = CreateFontW(FontSize+8, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_DONTCARE, FontName);
    assert(Font);

    /* move offset after font name */
    Offset += Length;

    /* offset is now at first dialog item control */
    DialogItem = (PDLGITEMTEMPLATE)Offset;

    /* enumerate now all controls */
    for(Index = 0; Index < DialogHeader->cdit; Index++)
    {
        /* add controls */
        Offset = AddDialogControl(MixerWindow->hWnd, &MixerWindow->Window[MixerWindow->WindowCount], DialogOffset, DialogItem, DialogIdMultiplier, Font);

        /* sanity check */
        assert(Offset);

        /* move dialog item to new offset */
        DialogItem =(PDLGITEMTEMPLATE)Offset;

        /* increment window count */
        MixerWindow->WindowCount++;
    }
}
void MusPlayer_WinAPI::initUI(HWND hWnd)
{
    HGDIOBJ hFont   = GetStockObject(DEFAULT_GUI_FONT);
    HFONT hFontBold = CreateFontW(-11, 0, 0, 0, FW_BOLD, FALSE, FALSE,
                                0, ANSI_CHARSET, OUT_DEFAULT_PRECIS,
                               CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
                               DEFAULT_PITCH | FF_SWISS, L"Tahoma");
    int left = 5;
    int top = 10;

    HWND hText = CreateWindowExW(0, L"STATIC", L"Press \"Open\" or drag&&drop music file into this window",
                                WS_CHILD | WS_VISIBLE | SS_LEFT,
                                left, top, 400, 15,
                                hWnd, NULL, m_hInstance, NULL);
    top += 25;

    m_labelTitle = CreateWindowExW(0, L"STATIC", L"", WS_CHILD | WS_VISIBLE | SS_LEFT,
                                left, top, 400, 15,
                                hWnd, NULL, m_hInstance, NULL);
    top += 15;
    m_labelArtist = CreateWindowExW(0, L"STATIC", L"", WS_CHILD | WS_VISIBLE | SS_LEFT,
                                left, top, 400, 15,
                                hWnd, NULL, m_hInstance, NULL);
    top += 15;
    m_labelAlboom = CreateWindowExW(0, L"STATIC", L"", WS_CHILD | WS_VISIBLE | SS_LEFT,
                                left, top, 400, 15,
                                hWnd, NULL, m_hInstance, NULL);
    top += 15;
    m_labelCopyright = CreateWindowExW(0, L"STATIC", L"", WS_CHILD | WS_VISIBLE | SS_LEFT,
                                left, top, 400, 15,
                                hWnd, NULL, m_hInstance, NULL);
    top += 15;


    m_buttonOpen = CreateWindowExW(0, L"BUTTON", L"Open", WS_TABSTOP|WS_VISIBLE|WS_CHILD,
                                left, top, 60, 21, hWnd,
                                (HMENU)CMD_Open, // Here is the ID of your button ( You may use your own ID )
                                m_hInstance, NULL);
    left += 60;

    m_buttonPlay = CreateWindowExW(0, L"BUTTON", L"Play/Pause", WS_TABSTOP|WS_VISIBLE|WS_CHILD,
                                left, top, 60, 21, hWnd,
                                (HMENU)CMD_Play, // Here is the ID of your button ( You may use your own ID )
                                m_hInstance, NULL);
    left += 60;

    m_buttonStop = CreateWindowExW(0, L"BUTTON", L"Stop", WS_TABSTOP|WS_VISIBLE|WS_CHILD,
                                left, top, 60, 21, hWnd,
                                (HMENU)CMD_Stop, // Here is the ID of your button ( You may use your own ID )
                                m_hInstance, NULL);

    left += 60;
    m_volume    = CreateWindowExW(0, TRACKBAR_CLASS, L"Volume", WS_TABSTOP|WS_VISIBLE|WS_CHILD,
                                  left, top-2, 80, 25, hWnd,
                                  (HMENU)CMD_Volume, // Here is the ID of your button ( You may use your own ID )
                                  m_hInstance, NULL);
    SendMessageW(m_volume, TBM_SETRANGE,
                (WPARAM)TRUE,               //redraw flag
                (LPARAM)MAKELONG(0, 128));  //min. & max. positions
    SendMessageW(m_volume, TBM_SETPOS,
                (WPARAM)TRUE,               //redraw flag
                (LPARAM)128);
    SendMessageW(m_volume, WM_SETFONT, (WPARAM)hFont, 0);
    left += 80;

    m_formatInfo = CreateWindowExW(0, L"STATIC", L"", WS_CHILD | WS_VISIBLE | SS_LEFT,
                                   left, top, 200, 15,
                                   hWnd, NULL, m_hInstance, NULL);
    SendMessageW(m_formatInfo, WM_SETFONT, (WPARAM)hFont, 0);

    left = 5;
    top += 21;

    m_recordWave = CreateWindowExW(0, L"BUTTON", L"Record wave", WS_TABSTOP|WS_VISIBLE|WS_CHILD|SS_LEFT|BS_CHECKBOX,
                                                             left, top, 200, 15,
                                                             hWnd, (HMENU)CMD_RecordWave, m_hInstance, NULL);
    SendMessageW(m_recordWave, WM_SETFONT, (WPARAM)hFont, 0);
    CheckDlgButton(m_groupADLMIDI, CMD_RecordWave, BST_UNCHECKED);

    top += 18;

    WNDPROC OldBtnProc;

    m_groupGME = CreateWindowExW(0, L"BUTTON", L"Game Music Emulators setup", WS_VISIBLE | WS_CHILD | BS_GROUPBOX,
                                left, top, 330, 50, hWnd, (HMENU)GRP_GME, m_hInstance, NULL);
    SendMessageW(m_groupGME, WM_SETFONT, (WPARAM)hFont, 0);
    OldBtnProc = reinterpret_cast<WNDPROC>(static_cast<LONG_PTR>(
                 SetWindowLongPtr(m_groupGME, GWLP_WNDPROC,
                 reinterpret_cast<LONG_PTR>(MusPlayer_WinAPI::SubCtrlProc))) );
    SetWindowLongPtr(m_groupGME, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(OldBtnProc));

    m_gme.m_labelTrack = CreateWindowExW(0, L"STATIC", L"Track number:", WS_CHILD | WS_VISIBLE | SS_LEFT,
                                10, 20, 70, 15,
                                 m_groupGME, NULL, m_hInstance, NULL);
    SendMessageW(m_gme.m_labelTrack, WM_SETFONT, (WPARAM)hFont, 0);

    m_gme.m_trackNum = CreateWindowExW(0, L"EDIT", L"ED_RED",
                                    WS_TABSTOP|WS_CHILD|WS_VISIBLE|ES_LEFT|WS_BORDER,
                                    80, 20, 240, 20,
                                    m_groupGME, (HMENU)(CMD_TrackID),
                                    m_hInstance, NULL);

    SendMessageW(m_gme.m_trackNum, WM_SETFONT, (WPARAM)hFont, 0);
    // with a spin control to its right side
    m_gme.m_trackNumUpDown = CreateWindowExW(0, UPDOWN_CLASS, L"SP_RED",
                                            WS_TABSTOP|WS_CHILD | WS_VISIBLE
                                            | UDS_ARROWKEYS | UDS_ALIGNRIGHT
                                            | UDS_SETBUDDYINT | WS_BORDER,
                                            80, 20, 240, 20,
                                            m_groupGME, (HMENU)(CMD_TrackIDspin), m_hInstance, NULL);
    SendMessageW(m_gme.m_trackNumUpDown, WM_SETFONT, (WPARAM)hFont, 0);

    // Set the buddy control.
    SendMessage(m_gme.m_trackNumUpDown, UDM_SETBUDDY, (LONG)m_gme.m_trackNum, 0L);
    // Set the range.
    SendMessage(m_gme.m_trackNumUpDown, UDM_SETRANGE, 0L, MAKELONG(32000, 0) );
    // Set the initial value
    SendMessage(m_gme.m_trackNumUpDown, UDM_SETPOS, 0L, MAKELONG((int)(0), 0));

    //SendMessage(m_gme.m_trackNumUpDown, UDS_WRAP, 0L, FALSE);




    m_groupMIDI = CreateWindowExW(0, L"BUTTON", L"MIDI Setup", WS_VISIBLE|WS_CHILD|BS_GROUPBOX|WS_GROUP,
                                left, top, 330, 50,
                                hWnd, (HMENU)GRP_MIDI, m_hInstance, NULL);
    SendMessageW(m_groupMIDI, WM_SETFONT, (WPARAM)hFont, 0);

    OldBtnProc = reinterpret_cast<WNDPROC>(static_cast<LONG_PTR>(
                 SetWindowLongPtr(m_groupMIDI, GWLP_WNDPROC,
                 reinterpret_cast<LONG_PTR>(MusPlayer_WinAPI::SubCtrlProc))) );
    SetWindowLongPtr(m_groupMIDI, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(OldBtnProc));

    top += 50;

    m_midi.m_labelDevice = CreateWindowExW(0, L"STATIC", L"MIDI Device:", WS_CHILD | WS_VISIBLE | SS_LEFT,
                                10, 20, 70, 15,
                                m_groupMIDI, NULL, m_hInstance, NULL);
    SendMessageW(m_midi.m_labelDevice, WM_SETFONT, (WPARAM)hFont, 0);

    const wchar_t* midiDevices[] = {
        L"ADL Midi (OPL Synth emulation)",
        L"Timidity (GUS-like wavetable MIDI Synth)",
        L"Native midi (Built-in MIDI of your OS)"
    };
    m_midi.m_midiDevice = CreateWindowExW(0, L"COMBOBOX", L"MidiDevice", WS_TABSTOP|WS_VISIBLE|WS_CHILD|CBS_DROPDOWNLIST|WS_TABSTOP,
                                              80, 17, 240, 210, m_groupMIDI, (HMENU)CMD_MidiDevice, m_hInstance, NULL);
    SendMessageW(m_midi.m_midiDevice, WM_SETFONT, (WPARAM)hFont, 0);
    SendMessageW(m_midi.m_midiDevice, CB_ADDSTRING, 0, (LPARAM)midiDevices[0]);
    SendMessageW(m_midi.m_midiDevice, CB_ADDSTRING, 0, (LPARAM)midiDevices[1]);
    SendMessageW(m_midi.m_midiDevice, CB_ADDSTRING, 0, (LPARAM)midiDevices[2]);
    SendMessageW(m_midi.m_midiDevice, CB_SETCURSEL, 0, 0);

    m_groupADLMIDI = CreateWindowExW(0, L"BUTTON", L"ADLMIDI Extra Setup", WS_VISIBLE|WS_CHILD|BS_GROUPBOX|WS_GROUP,
                                left, top, 330, 125,
                                hWnd, (HMENU)GRP_ADLMIDI, m_hInstance, NULL);
    SendMessageW(m_groupADLMIDI, WM_SETFONT, (WPARAM)hFont, 0);
    //top += 50;

    OldBtnProc=reinterpret_cast<WNDPROC>(static_cast<LONG_PTR>(
                 SetWindowLongPtr(m_groupADLMIDI, GWLP_WNDPROC,
                 reinterpret_cast<LONG_PTR>(MusPlayer_WinAPI::SubCtrlProc))) );
    SetWindowLongPtr(m_groupADLMIDI, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(OldBtnProc));


    m_adlmidi.m_labelBank = CreateWindowExW(0, L"STATIC", L"ADL Midi bank ID:", WS_CHILD|WS_VISIBLE | SS_LEFT,
                                10, 20, 70, 15,
                                m_groupADLMIDI, NULL, m_hInstance, NULL);
    SendMessageW(m_adlmidi.m_labelBank, WM_SETFONT, (WPARAM)hFont, 0);

    m_adlmidi.m_bankID = CreateWindowExW(0, L"COMBOBOX", L"BankId", WS_TABSTOP|WS_VISIBLE|WS_CHILD|CBS_DROPDOWNLIST|CBS_DISABLENOSCROLL|WS_VSCROLL|CBS_NOINTEGRALHEIGHT|WS_TABSTOP,
                                              80, 17, 240, 210, m_groupADLMIDI, (HMENU)CMD_Bank, m_hInstance, NULL);
    SendMessageW(m_adlmidi.m_bankID, WM_SETFONT, (WPARAM)hFont, 0);
    int insCount            = MIX_ADLMIDI_getTotalBanks();
    const char*const* names = MIX_ADLMIDI_getBankNames();
    for(int i=0; i<insCount; i++)
    {
        SendMessageA(m_adlmidi.m_bankID, CB_ADDSTRING, 0, (LPARAM)names[i]);
    }
    SendMessageW(m_adlmidi.m_bankID, CB_SETCURSEL, 58, 0);


    m_adlmidi.m_tremolo = CreateWindowExW(0, L"BUTTON", L"Deep tremolo", WS_TABSTOP|WS_VISIBLE|WS_CHILD|SS_LEFT|BS_CHECKBOX,
                                          10, 40, 200, 15,
                                          m_groupADLMIDI, (HMENU)CMD_Tremolo, m_hInstance, NULL);
    SendMessageW(m_adlmidi.m_tremolo, WM_SETFONT, (WPARAM)hFont, 0);
    CheckDlgButton(m_groupADLMIDI, CMD_Tremolo, BST_CHECKED);

    m_adlmidi.m_vibrato = CreateWindowExW(0, L"BUTTON", L"Deep vibrato", WS_TABSTOP|WS_VISIBLE|WS_CHILD|SS_LEFT|BS_CHECKBOX,
                                          10, 60, 200, 15,
                                          m_groupADLMIDI, (HMENU)CMD_Vibrato, m_hInstance, NULL);
    SendMessageW(m_adlmidi.m_vibrato, WM_SETFONT, (WPARAM)hFont, 0);
    CheckDlgButton(m_groupADLMIDI, CMD_Vibrato, BST_CHECKED);

    m_adlmidi.m_scalableMod = CreateWindowExW(0, L"BUTTON", L"Scalable modulation", WS_TABSTOP|WS_VISIBLE|WS_CHILD|SS_LEFT|BS_CHECKBOX,
                                          10, 80, 200, 15,
                                          m_groupADLMIDI, (HMENU)CMD_ScalableMod, m_hInstance, NULL);
    SendMessageW(m_adlmidi.m_scalableMod, WM_SETFONT, (WPARAM)hFont, 0);
    CheckDlgButton(m_groupADLMIDI, CMD_ScalableMod, BST_UNCHECKED);

    m_adlmidi.m_adlibDrums = CreateWindowExW(0, L"BUTTON", L"AdLib drums mode", WS_TABSTOP|WS_VISIBLE|WS_CHILD|SS_LEFT|BS_CHECKBOX,
                                          10, 100, 200, 15,
                                          m_groupADLMIDI, (HMENU)CMD_AdLibDrums, m_hInstance, NULL);
    SendMessageW(m_adlmidi.m_adlibDrums, WM_SETFONT, (WPARAM)hFont, 0);
    CheckDlgButton(m_groupADLMIDI, CMD_AdLibDrums, BST_UNCHECKED);


    ShowWindow(m_groupGME, SW_HIDE);
    ShowWindow(m_groupMIDI, SW_HIDE);
    ShowWindow(m_groupADLMIDI, SW_HIDE);


    SendMessageW(hWnd, WM_SETFONT, (WPARAM)hFont, 0);

    SendMessageW(m_buttonOpen, WM_SETFONT, (WPARAM)hFont, 0);
    SendMessageW(m_buttonPlay, WM_SETFONT, (WPARAM)hFont, 0);
    SendMessageW(m_buttonStop, WM_SETFONT, (WPARAM)hFont, 0);

    SendMessageW(hText, WM_SETFONT, (WPARAM)hFontBold, 0);

    SendMessageW(m_labelTitle, WM_SETFONT, (WPARAM)hFont, 0);
    SendMessageW(m_labelArtist, WM_SETFONT, (WPARAM)hFont, 0);
    SendMessageW(m_labelAlboom, WM_SETFONT, (WPARAM)hFont, 0);
    SendMessageW(m_labelCopyright, WM_SETFONT, (WPARAM)hFont, 0);

    SetWindowTextW(hWnd, L"Simple SDL2 Mixer X Music player [WinAPI-based]");

    HMENU hSubMenu;
    m_contextMenu = CreatePopupMenu();
    AppendMenuW(m_contextMenu, MF_STRING, CMD_Open, L"Open");
    AppendMenuW(m_contextMenu, MF_STRING, CMD_Play, L"Play/Pause");
    AppendMenuW(m_contextMenu, MF_STRING, CMD_Stop, L"Stop");
    AppendMenuW(m_contextMenu, MF_SEPARATOR, 0, 0);
    AppendMenuW(m_contextMenu, MF_STRING, CMD_Reverb, L"Reverb");
    AppendMenuW(m_contextMenu, MF_STRING, CMD_AssocFiles, L"Associate files");
    EnableMenuItem(m_contextMenu, CMD_AssocFiles, MF_GRAYED);
    AppendMenuW(m_contextMenu, MF_SEPARATOR, 0, 0);

    hSubMenu = CreatePopupMenu();
    AppendMenuA(hSubMenu, MF_STRING, CMD_Version, "SDL Mixer X Music Player [WinAPI], v." _FILE_VERSION);
    EnableMenuItem(hSubMenu, CMD_Version, MF_GRAYED);
    AppendMenuW(hSubMenu, MF_STRING, CMD_ShowLicense, L"Licensed under GNU GPLv3 license");
    AppendMenuW(hSubMenu, MF_SEPARATOR, 0, 0);
    AppendMenuW(hSubMenu, MF_STRING, CMD_ShowSource, L"Get source code");

    AppendMenuW(m_contextMenu,  MF_STRING | MF_POPUP, (UINT)hSubMenu, L"About");

}
Beispiel #8
0
//Basic Init, create the font, backbuffer, etc
WINDOW *curses_init(void)
{
   // _windows = new WINDOW[20];         //initialize all of our variables
    lastchar=-1;
    inputdelay=-1;

    int fontsize = 16;
    std::string typeface;
    int map_fontwidth = 8;
    int map_fontheight = 16;
    int map_fontsize = 16;
    std::string map_typeface;
    int overmap_fontwidth = 8;
    int overmap_fontheight = 16;
    int overmap_fontsize = 16;
    std::string overmap_typeface;
    bool fontblending;

    std::ifstream jsonstream(FILENAMES["fontdata"].c_str(), std::ifstream::binary);
    if (jsonstream.good()) {
        JsonIn json(jsonstream);
        JsonObject config = json.get_object();
        // fontsize, fontblending, map_* are ignored in wincurse.
        fontwidth = config.get_int("fontwidth", fontwidth);
        fontheight = config.get_int("fontheight", fontheight);
        typeface = config.get_string("typeface", typeface);
        jsonstream.close();
    } else { // User fontdata is missed. Try to load legacy fontdata.
        // Get and save all values. With unused.
        std::ifstream InStream(FILENAMES["legacy_fontdata"].c_str(), std::ifstream::binary);
        if(InStream.good()) {
            JsonIn jIn(InStream);
            JsonObject config = jIn.get_object();
            fontwidth = config.get_int("fontwidth", fontwidth);
            fontheight = config.get_int("fontheight", fontheight);
            fontsize = config.get_int("fontsize", fontsize);
            typeface = config.get_string("typeface", typeface);
            map_fontwidth = config.get_int("map_fontwidth", fontwidth);
            map_fontheight = config.get_int("map_fontheight", fontheight);
            map_fontsize = config.get_int("map_fontsize", fontsize);
            map_typeface = config.get_string("map_typeface", typeface);
            overmap_fontwidth = config.get_int("overmap_fontwidth", fontwidth);
            overmap_fontheight = config.get_int("overmap_fontheight", fontheight);
            overmap_fontsize = config.get_int("overmap_fontsize", fontsize);
            overmap_typeface = config.get_string("overmap_typeface", typeface);
            InStream.close();
            // Save legacy as user fontdata.
            assure_dir_exist(FILENAMES["config_dir"]);
            std::ofstream OutStream(FILENAMES["fontdata"].c_str(), std::ofstream::binary);
            if(!OutStream.good()) {
                DebugLog( D_ERROR, DC_ALL ) << "Can't save user fontdata file.\n"
                << "Check permissions for: " << FILENAMES["fontdata"].c_str();
                return NULL;
            }
            JsonOut jOut(OutStream, true); // pretty-print
            jOut.start_object();
            jOut.member("fontblending", fontblending);
            jOut.member("fontwidth", fontwidth);
            jOut.member("fontheight", fontheight);
            jOut.member("fontsize", fontsize);
            jOut.member("typeface", typeface);
            jOut.member("map_fontwidth", map_fontwidth);
            jOut.member("map_fontheight", map_fontheight);
            jOut.member("map_fontsize", map_fontsize);
            jOut.member("map_typeface", map_typeface);
            jOut.member("overmap_fontwidth", overmap_fontwidth);
            jOut.member("overmap_fontheight", overmap_fontheight);
            jOut.member("overmap_fontsize", overmap_fontsize);
            jOut.member("overmap_typeface", overmap_typeface);
            jOut.end_object();
            OutStream << "\n";
            OutStream.close();
        } else {
            DebugLog( D_ERROR, DC_ALL ) << "Can't load fontdata files.\n"
            << "Check permissions for:\n" << FILENAMES["legacy_fontdata"].c_str() << "\n"
            << FILENAMES["fontdata"].c_str() << "\n";
            return NULL;
        }
    }

    halfwidth=fontwidth / 2;
    halfheight=fontheight / 2;
    WindowWidth= OPTIONS["TERMINAL_X"] * fontwidth;
    WindowHeight = OPTIONS["TERMINAL_Y"] * fontheight;

    WinCreate();    //Create the actual window, register it, etc
    timeBeginPeriod(1); // Set Sleep resolution to 1ms
    CheckMessages();    //Let the message queue handle setting up the window

    WindowDC   = GetDC(WindowHandle);
    backbuffer = CreateCompatibleDC(WindowDC);

    BITMAPINFO bmi = BITMAPINFO();
    bmi.bmiHeader.biSize         = sizeof(BITMAPINFOHEADER);
    bmi.bmiHeader.biWidth        = WindowWidth;
    bmi.bmiHeader.biHeight       = -WindowHeight;
    bmi.bmiHeader.biPlanes       = 1;
    bmi.bmiHeader.biBitCount     = 8;
    bmi.bmiHeader.biCompression  = BI_RGB; // Raw RGB
    bmi.bmiHeader.biSizeImage    = WindowWidth * WindowHeight * 1;
    bmi.bmiHeader.biClrUsed      = 16; // Colors in the palette
    bmi.bmiHeader.biClrImportant = 16; // Colors in the palette
    backbit = CreateDIBSection(0, &bmi, DIB_RGB_COLORS, (void**)&dcbits, NULL, 0);
    DeleteObject(SelectObject(backbuffer, backbit));//load the buffer into DC

    // Load private fonts
    if (SetCurrentDirectoryW(L"data\\font")){
        WIN32_FIND_DATA findData;
        for (HANDLE findFont = FindFirstFileW(L".\\*", &findData); findFont != INVALID_HANDLE_VALUE; )
        {
            if (!(findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)){ // Skip folders
                AddFontResourceExW(findData.cFileName, FR_PRIVATE,NULL);
            }
            if (!FindNextFile(findFont, &findData)){
                FindClose(findFont);
                break;
            }
        }
        SetCurrentDirectoryW(L"..\\..");
    }

    // Use desired font, if possible
    font = CreateFontW(fontheight, fontwidth, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
                      DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,
                      PROOF_QUALITY, FF_MODERN, widen(typeface).c_str());

    SetBkMode(backbuffer, TRANSPARENT);//Transparent font backgrounds
    SelectObject(backbuffer, font);//Load our font into the DC
//    WindowCount=0;

    init_colors();

    mainwin = newwin(OPTIONS["TERMINAL_Y"],OPTIONS["TERMINAL_X"],0,0);
    return mainwin;   //create the 'stdscr' window and return its ref
}
Beispiel #9
0
BOOL CMainWindow::OnCreate(__in HINSTANCE hInstance)
{
	// window caption
	SetWindowTextW(m_hDialog, pStrings->Get(IDS_XPI).c_str());

	// XPIGUI
	m_pXPIGUI = new XPIGUI;

	ZeroMemory(m_pXPIGUI, sizeof(XPIGUI));

	// XPIGUI - instance
	m_pXPIGUI->hInstance = hInstance;

	// XPIGUI - application icon
	m_pXPIGUI->hIcon = LoadIconW(hInstance, MAKEINTRESOURCEW(IDI_XPI));
	if (m_pXPIGUI->hIcon != NULL)
		SendMessageW(m_hDialog, WM_SETICON, ICON_BIG, (LPARAM)m_pXPIGUI->hIcon);
#ifdef _DEBUG
	else
		pLog->Write(LOG_WF_ERROR | LOG_WF_ECHODEBUG, L"Couldn't load XPI icon, continuing anyway. [LE=0x%08X]", GetLastError());
#endif

	// XPIGUI - small application icon
	m_pXPIGUI->hIconSmall = LoadIconW(hInstance, MAKEINTRESOURCEW(IDI_XPI_SMALL));
	if (m_pXPIGUI->hIconSmall != NULL)
		SendMessageW(m_hDialog, WM_SETICON, ICON_SMALL, (LPARAM)m_pXPIGUI->hIconSmall);
#ifdef _DEBUG
	else
		pLog->Write(LOG_WF_ERROR | LOG_WF_ECHODEBUG, L"Couldn't load small XPI icon, continuing anyway. [LE=0x%08X]", GetLastError());
#endif

	// XPIGUI - load Consolas from resource
	m_pXPIGUI->hMemFont = AddFontFromResource(GetModuleHandle(NULL), MAKEINTRESOURCEW(IDR_CONSOLAS));
	if (m_pXPIGUI->hMemFont == NULL)
	{
	}

	// XPIGUI - Consolas font handle
	m_pXPIGUI->hFont = CreateFontW(14, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_CHARACTER_PRECIS, CLEARTYPE_QUALITY, FF_DONTCARE, L"Consolas");
	if (m_pXPIGUI->hFont == NULL)
	{
#ifdef _DEBUG
		pLog->Write(LOG_WF_ERROR, L"Couldn't create log font, aborting. [LE=0x%08X]", GetLastError());
#endif
		NotifyErrorUI();
		return FALSE;
	}

	// XPIGUI - direction image list
	do
	{
		m_pXPIGUI->hImageList = ImageList_Create(16, 16, ILC_COLOR24 | ILC_MASK, 4, 0);
		ImageList_SetBkColor(m_pXPIGUI->hImageList, CLR_NONE);
		if (m_pXPIGUI->hImageList != NULL)
		{
			HBITMAP hBitmap = LoadBitmapW(m_pXPIGUI->hInstance, MAKEINTRESOURCEW(IDB_DIRECTIONS));
			if (hBitmap != NULL)
			{
				if (ImageList_AddMasked(m_pXPIGUI->hImageList, hBitmap, RGB(255, 0, 255)) != -1)
					break;
				DeleteObject((HGDIOBJ)hBitmap);
			}
		}

#ifdef _DEBUG
		pLog->Write(LOG_WF_ERROR, L"Couldn't create packet direction icons image-list, aborting.");
#endif
		NotifyErrorUI();
		return FALSE;
	} while (0);

	// XPIGUI - injection icons
	m_pXPIGUI->hInjectOut = (HICON)LoadImageW(m_pXPIGUI->hInstance, MAKEINTRESOURCEW(IDI_INJECT_OUT), IMAGE_ICON, 16, 16, 0);
	if (m_pXPIGUI->hInjectOut == NULL)
	{
#ifdef _DEBUG
		pLog->Write(LOG_WF_ERROR, L"Couldn't load inject OUT icon, aborting. [LE=0x%08X]", GetLastError());
#endif
		NotifyErrorUI();
		return FALSE;
	}
	m_pXPIGUI->hInjectIn = (HICON)LoadImageW(m_pXPIGUI->hInstance, MAKEINTRESOURCEW(IDI_INJECT_IN), IMAGE_ICON, 16, 16, 0);
	if (m_pXPIGUI->hInjectIn == NULL)
	{
#ifdef _DEBUG
		pLog->Write(LOG_WF_ERROR, L"Couldn't load inject IN icon, aborting. [LE=0x%08X]", GetLastError());
#endif
		NotifyErrorUI();
		return FALSE;
	}

	// XPIGUI - pause/resume icons
	m_pXPIGUI->hPauseIcon = (HICON)LoadImageW(m_pXPIGUI->hInstance, MAKEINTRESOURCEW(IDI_PAUSE), IMAGE_ICON, 16, 16, 0);
	if (m_pXPIGUI->hPauseIcon == NULL)
	{
#ifdef _DEBUG
		pLog->Write(LOG_WF_ERROR, L"Couldn't load pause icon, aborting. [LE=0x%08X]", GetLastError());
#endif
		NotifyErrorUI();
		return FALSE;
	}
	Static_SetIcon(GetDlgItem(m_hDialog, IDC_PAUSELOGGING), m_pXPIGUI->hPauseIcon);
	m_pXPIGUI->hResumeIcon = (HICON)LoadImageW(m_pXPIGUI->hInstance, MAKEINTRESOURCEW(IDI_RESUME), IMAGE_ICON, 16, 16, 0);
	if (m_pXPIGUI->hResumeIcon == NULL)
	{
#ifdef _DEBUG
		pLog->Write(LOG_WF_ERROR, L"Couldn't load resume icon, aborting. [LE=0x%08X]", GetLastError());
#endif
		NotifyErrorUI();
		return FALSE;
	}

	RECT rcClient;
	GetClientRect(m_hDialog, &rcClient);
	SetWindowPos(GetDlgItem(m_hDialog, IDC_PAUSELOGGING), NULL, rcClient.right - rcClient.left - UI_PAUSE_WIDTH - UI_PAUSE_PADDING, UI_PAUSE_PADDING, UI_PAUSE_WIDTH, UI_PAUSE_HEIGHT, 0);

	// XPIGUI - clear packets icon
	m_pXPIGUI->hClearIcon = (HICON)LoadImageW(m_pXPIGUI->hInstance, MAKEINTRESOURCEW(IDI_CLEAR), IMAGE_ICON, 16, 16, 0);
	if (m_pXPIGUI->hClearIcon == NULL)
	{
#ifdef _DEBUG
		pLog->Write(LOG_WF_ERROR, L"Couldn't load clear icon, aborting. [LE=0x%08X]", GetLastError());
#endif
		NotifyErrorUI();
		return FALSE;
	}
	Static_SetIcon(GetDlgItem(m_hDialog, IDC_CLEAR), m_pXPIGUI->hClearIcon);
	SetWindowPos(GetDlgItem(m_hDialog, IDC_CLEAR), NULL, rcClient.right - rcClient.left - UI_CLEAR_WIDTH - (UI_CLEAR_PADDING * 2) - UI_PAUSE_WIDTH, UI_CLEAR_PADDING, UI_CLEAR_WIDTH, UI_CLEAR_HEIGHT, 0);

	// XPIGUI - settings image list
	do
	{
		m_pXPIGUI->hSettingsImageList = ImageList_Create(16, 16, ILC_COLOR24 | ILC_MASK, 4, 0);
		ImageList_SetBkColor(m_pXPIGUI->hSettingsImageList, CLR_NONE);
		if (m_pXPIGUI->hSettingsImageList != NULL)
		{
			HBITMAP hBitmap = LoadBitmapW(m_pXPIGUI->hInstance, MAKEINTRESOURCEW(IDB_PACKET_STATES));
			if (hBitmap != NULL)
			{
				if (ImageList_AddMasked(m_pXPIGUI->hSettingsImageList, hBitmap, RGB(255, 0, 255)) != -1)
					break;
				DeleteObject((HGDIOBJ)hBitmap);
			}
		}

#ifdef _DEBUG
		pLog->Write(LOG_WF_ERROR, L"Couldn't create settings image-list, aborting.");
#endif
		NotifyErrorUI();
		return FALSE;
	} while (0);

	// XPIGUI - color icons
	for (INT i = 0; i < _countof(m_pXPIGUI->hColorIcon); i++)
	{
		HICON hTempIcon = LoadIcon(m_pXPIGUI->hInstance, MAKEINTRESOURCEW(g_XPIColors[i].wIcon));
		m_pXPIGUI->hColorIcon[i] = MenuBitmapFromIcon(m_hDialog, hTempIcon, 16, 16);
		if (m_pXPIGUI->hColorIcon[i] == NULL)
		{
#ifdef _DEBUG
			pLog->Write(LOG_WF_ERROR, L"Couldn't load color icon #%d, aborting. [LE=0x%08X]", i, GetLastError());
#endif
			NotifyErrorUI();
			return FALSE;
		}
		DestroyIcon(hTempIcon);
	}

	// XPIGUI - formatted image list
	do
	{
		m_pXPIGUI->hFormattedImageList = ImageList_Create(16, 16, ILC_COLOR24 | ILC_MASK, 4, 0);
		if (m_pXPIGUI->hFormattedImageList != NULL)
		{
			ImageList_SetBkColor(m_pXPIGUI->hFormattedImageList, CLR_NONE);

			HBITMAP hBitmap = LoadBitmapW(m_pXPIGUI->hInstance, MAKEINTRESOURCEW(IDB_FORMATTED_LIST));
			if (hBitmap != NULL)
			{
				if (ImageList_AddMasked(m_pXPIGUI->hFormattedImageList, hBitmap, RGB(255, 0, 255)) != -1)
					break;
				DeleteObject((HGDIOBJ)hBitmap);
			}
		}

#ifdef _DEBUG
		pLog->Write(LOG_WF_ERROR, L"Couldn't create formatted image-list, aborting.");
#endif
		NotifyErrorUI();
		return FALSE;
	} while (0);

	// XPIGUI - stop icon
	m_pXPIGUI->hStop = (HICON)LoadImageW(m_pXPIGUI->hInstance, MAKEINTRESOURCEW(IDI_STOP), IMAGE_ICON, 16, 16, 0);
	if (m_pXPIGUI->hStop == NULL)
	{
#ifdef _DEBUG
		pLog->Write(LOG_WF_ERROR, L"Couldn't load stop icon, aborting. [LE=0x%08X]", GetLastError());
#endif
		NotifyErrorUI();
		return FALSE;
	}

	// shell notify icon
	ZeroMemory(&m_NotifyIconData, sizeof(m_NotifyIconData));
	m_NotifyIconData.cbSize = sizeof(m_NotifyIconData);
	m_NotifyIconData.hWnd = m_hDialog;
	m_NotifyIconData.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
	m_NotifyIconData.hIcon = m_pXPIGUI->hIconSmall;
	m_NotifyIconData.uCallbackMessage = WM_SHELLNOTIFY;
	if (FAILED(StringCchCopyW(m_NotifyIconData.szTip, _countof(m_NotifyIconData.szTip), pStrings->Get(IDS_XPI).c_str())))
		m_NotifyIconData.uFlags &= ~NIF_TIP;
	Shell_NotifyIconW(NIM_ADD, &m_NotifyIconData);

	// tooltips window (for icons)
	m_hIconTips = CreateWindowEx(0, TOOLTIPS_CLASS, L"", TTS_NOPREFIX | TTS_ALWAYSTIP, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, m_hDialog, 0, m_pXPIGUI->hInstance, NULL);
	SetWindowPos(m_hIconTips, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);

	TOOLINFO ti;
	ti.cbSize = sizeof(ti);
	ti.uFlags = TTF_SUBCLASS | TTF_IDISHWND;
	ti.hwnd = m_hDialog;

	std::wstring wstrTemp;

	wstrTemp = pStrings->Get(IDS_CLEAR_ALL_PACKETS);
	ti.uId = (UINT_PTR)GetDlgItem(m_hDialog, IDC_CLEAR);
	ti.lpszText = (LPWSTR)wstrTemp.c_str();
	SendMessage(m_hIconTips, TTM_ADDTOOL, 0, (LPARAM)&ti);

	wstrTemp = pStrings->Get(IDS_PAUSE_LOGGING);
	ti.uId = (UINT_PTR)GetDlgItem(m_hDialog, IDC_PAUSELOGGING);
	ti.lpszText = (LPWSTR)wstrTemp.c_str();
	SendMessage(m_hIconTips, TTM_ADDTOOL, 0, (LPARAM)&ti);

	// tabs creation
	TAB_INFO  Tabs[] =
	{
		{ pStrings->Get(IDS_TAB_PLAIN), MAKEINTRESOURCEW(IDD_PLAINVIEW), CPlainView::DialogProc },
		{ pStrings->Get(IDS_TAB_FORMATTED), MAKEINTRESOURCEW(IDD_FORMATTEDVIEW), CFormattedView::DialogProc },
		{ pStrings->Get(IDS_TAB_SETTINGS), MAKEINTRESOURCEW(IDD_SETTINGS), CMainSettings::DialogProc }
	};

	INT iCount = 0;

	foreach(const TAB_INFO& i, Tabs)
	{
		HWND hWnd = CreateDialogParamW(m_pXPIGUI->hInstance, i.lpwszTemplate, m_hDialog, i.DlgProc, (LPARAM)m_pXPIGUI);
		if (hWnd != NULL)
		{
			TCITEMW tci;
			tci.mask = TCIF_TEXT | TCIF_PARAM;
			tci.pszText = (LPWSTR)i.wstrCaption.c_str();
			tci.lParam = (LPARAM)m_pXPIGUI;

			if (TabCtrl_InsertItem(GetDlgItem(m_hDialog, IDC_TAB), iCount++, &tci) != -1)
			{
				ShowWindow(hWnd, m_vhTabs.empty() ? SW_SHOW : SW_HIDE);
				m_vhTabs.push_back(hWnd);
				continue;
			}
		}

#ifdef _DEBUG
		pLog->Write(LOG_WF_ERROR, L"Couldn't create tab ID %s, aborting.", i.wstrCaption);
#endif
		NotifyErrorUI();
		return FALSE;
	}
Beispiel #10
0
void CPerfBar::PaintData(HDC hdc, POINT offset)
{
    Configuration::pages_t& pages = m_config.GetPages();
    //Configuration::counters_t & counters = m_config.GetCounters();

    if (pages.empty()) {
        return;
    }

    if (pages.size() <= m_currentPage) {
        m_currentPage = pages.size() - 1;
    }

    Configuration::Page& page = pages[m_currentPage];

    if (page.Lines.empty()) {
        return;
    }

    auto values = m_perfMonitor.GetValues();

    TEXTMETRIC textMetric;
    GetTextMetrics(hdc, &textMetric);

    wchar_t buf[1024] = { 0 };
    wchar_t display[1024] = { 0 };

    for (size_t i = 0; i < page.Lines.size(); ++i) {
        buf[0] = 0;

        Configuration::Line& line = page.Lines[i];

        for (auto iit = line.Display.begin(); iit != line.Display.end(); ++iit) {
            auto value_it = values.find(iit->Counter);

            wchar_t formattedValue[256] = { 0 };
            if (value_it == values.end()) {
                wcscpy_s(formattedValue, _countof(formattedValue), L"[N/A]");
            } else {
                double val = value_it->second;
                if (iit->Divide > 0) {
                    val /= iit->Divide;
                }

                wchar_t formattingString[256] = { 0 };
                swprintf_s(
                    formattingString,
                    _countof(formattingString),
                    L"%s%d%s",
                    L"%.",
                    iit->Decimals > 0 ? iit->Decimals : 0,
                    L"f"
                );

                swprintf_s(
                    formattedValue,
                    _countof(formattedValue),
                    formattingString,
                    val
                );
            }

            swprintf_s(
                display,
                _countof(display),
                L"%s%s%s",
                iit->Prefix.c_str(),
                formattedValue,
                iit->Suffix.c_str()
            );

            wcscat_s(buf, _countof(buf), display);
        }

        RECT rc;
        GetClientRect(&rc);

        int offsetY = page.OffsetY + ((int)i * (textMetric.tmHeight - textMetric.tmExternalLeading));

        rc.top += offsetY + offset.y;
        rc.bottom += offset.y;
        rc.left += offset.x;
        rc.right += offset.x;

        HFONT font =
            CreateFontW(
                -MulDiv((int)line.Font.Size, GetDeviceCaps(hdc, LOGPIXELSY), 72),
                0,
                0,
                0,
                line.Font.Bold ? FW_BOLD : 0,
                line.Font.Italic,
                FALSE,
                FALSE,
                ANSI_CHARSET,
                0,
                0,
                0,
                0,
                line.Font.Family.c_str()
            );

        SetTextColor(hdc, line.Font.Color);
        HFONT oldFont = (HFONT)SelectObject(hdc, font);
        DrawTextW(hdc, buf, (int)wcslen(buf), &rc, DT_LEFT | DT_TOP);
        SelectObject(hdc, oldFont);
        DeleteObject(font);
    }
}
LRESULT CApplication::OnPaint(HWND hwnd)
{
    RECT rcClient; 
    PAINTSTRUCT ps;
    HDC hdc = BeginPaint(hwnd, &ps);
    FillRect(hdc, &ps.rcPaint, _hbrush);

    // get the dimensions of the main window.   
    GetClientRect(_hwnd, &rcClient);

    // Logo
    HFONT hlogo = CreateFontW(_fontHeightLogo, 0, 0, 0, 0, FALSE, 0, 0, 0, 0, 0, 0, 0, _fontTypeface);    // Logo Font and Size
    if (hlogo != NULL)
    {
        HFONT hOldFont = static_cast<HFONT>(SelectObject(hdc, hlogo));

        SetBkMode(hdc, TRANSPARENT);

        rcClient.top = 10;
        rcClient.left = 30;

        DrawTextW(hdc, L"Windows samples", -1, &rcClient, DT_WORDBREAK);

        SelectObject(hdc, hOldFont);

        DeleteObject(hlogo);
    }

    // Title
    HFONT htitle = CreateFontW(_fontHeightTitle, 0, 0, 0, 0, FALSE, 0, 0, 0, 0, 0, 0, 0, _fontTypeface);    // Title Font and Size
    if (htitle != NULL)
    {
        HFONT hOldFont = static_cast<HFONT>(SelectObject(hdc, htitle));

        SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
        
        rcClient.top = 25;
        rcClient.left = 30;
        
        DrawTextW(hdc, L"WAM Sample", -1, &rcClient, DT_WORDBREAK);

        SelectObject(hdc, hOldFont);

        DeleteObject(htitle);
    }

    // Description
    HFONT hdescription = CreateFontW(_fontHeightDescription, 0, 0, 0, 0, FALSE, 0, 0, 0, 0, 0, 0, 0, _fontTypeface);    // Description Font and Size
    if (hdescription != NULL)
    {
        HFONT hOldFont = static_cast<HFONT>(SelectObject(hdc, hdescription));

        rcClient.top = 90;
        rcClient.left = 30;
        
        DrawTextW(hdc, L"This sample shows how DirectComposition and Windows Animation Manager (WAM) can be used together as an independent animation platform.", -1, &rcClient, DT_WORDBREAK);

        rcClient.top = 400;
        rcClient.left = 220;
        
        DrawTextW(hdc, L"Left/Right click to control the animation.", -1, &rcClient, DT_WORDBREAK);
        
        SelectObject(hdc, hOldFont);

        DeleteObject(hdescription);
    }

    EndPaint(hwnd, &ps); 

    return 0;
}
// Handles the WM_PAINT message
LRESULT CApplication::OnPaint()
{
    RECT rcClient;
    PAINTSTRUCT ps;
    HDC hdc = BeginPaint(_hwnd, &ps);

    // get the dimensions of the main window.
    GetClientRect(_hwnd, &rcClient);

    // Logo
    HFONT hlogo = CreateFontW(_fontHeightLogo, 0, 0, 0, 0, FALSE, 0, 0, 0, 0, 0, 0, 0, _fontTypeface);    // Logo Font and Size
    if (hlogo != NULL)
    {
        HFONT hOldFont = static_cast<HFONT>(SelectObject(hdc, hlogo));

        SetBkMode(hdc, TRANSPARENT);

        rcClient.top = 10;
        rcClient.left = 50;

        DrawTextW(hdc, L"Windows samples", -1, &rcClient, DT_WORDBREAK);

        SelectObject(hdc, hOldFont);

        DeleteObject(hlogo);
    }

    // Title
    HFONT htitle = CreateFontW(_fontHeightTitle, 0, 0, 0, 0, FALSE, 0, 0, 0, 0, 0, 0, 0, _fontTypeface);    // Title Font and Size
    if (htitle != NULL)
    {
        HFONT hOldFont = static_cast<HFONT>(SelectObject(hdc, htitle));

        SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));

        rcClient.top = 25;
        rcClient.left = 50;

        DrawTextW(hdc, L"DirectComposition Effects Sample", -1, &rcClient, DT_WORDBREAK);

        SelectObject(hdc, hOldFont);

        DeleteObject(htitle);
    }

    // Description
    HFONT hdescription = CreateFontW(_fontHeightDescription, 0, 0, 0, 0, FALSE, 0, 0, 0, 0, 0, 0, 0, _fontTypeface);    // Description Font and Size
    if (hdescription != NULL)
    {
        HFONT hOldFont = static_cast<HFONT>(SelectObject(hdc, hdescription));

        rcClient.top = 90;
        rcClient.left = 50;

        DrawTextW(hdc, L"This sample explains how to use DirectComposition effects: rotation, scaling, perspective, translation and opacity.", -1, &rcClient, DT_WORDBREAK);

        rcClient.top = 500;
        rcClient.left = 450;

        DrawTextW(hdc, L"A) Left-click to toggle between single and multiple-panels view.\nB) Use keys 1-4 to switch the color of the right-panel.", -1, &rcClient, DT_WORDBREAK);

        SelectObject(hdc, hOldFont);

        DeleteObject(hdescription);
    }

    EndPaint(_hwnd, &ps);

    return 0;
}
Beispiel #13
0
void drawText(const string* text, float x, float y, const string* font_name, int font_size) {
    text = (string*)wstrdup(text);

    HDC hdc = CreateCompatibleDC(0);

    string* font_face = wstrdup(font_name);
    int font_height = -MulDiv(font_size, GetDeviceCaps(hdc, LOGPIXELSY), 72);
    HFONT hfont = CreateFontW(font_height, 0, 0, 0, FW_NORMAL, FALSE, FALSE,
                              FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS,
                              CLIP_DEFAULT_PRECIS, PROOF_QUALITY,
                              DEFAULT_PITCH, font_face);

    free(font_face);

    SelectObject(hdc, hfont);

    SetBkMode(hdc, TRANSPARENT);
    SetTextColor(hdc, RGB(255, 0, 0));

    RECT rect = { 0 };
    DrawTextW(hdc, text, -1, &rect, DT_CALCRECT | DT_NOCLIP);

    int width  = rect.right  - rect.left + 2,
        height = rect.bottom - rect.top  + 2;
    rect.left++;
    rect.top++;

    void* bitmap_data = calloc(width*height, sizeof(uint32_t));
    for (int i = 3; i < width*height*4; i+= 4)
        *((uint8_t*)bitmap_data+i) = 0xff;

    HBITMAP hbitmap = CreateBitmap(width, height, 1, 32, bitmap_data);
    SelectObject(hdc, hbitmap);

    DrawTextW(hdc, text, -1, &rect, DT_TOP | DT_LEFT);
    DeleteObject(hfont);
    free(text);

    GetBitmapBits(hbitmap, width*height*4, bitmap_data);

    DeleteObject(hbitmap);
    DeleteDC(hdc);

    for (int i = 0; i < width*height*4; i += 4) {
        *((uint8_t*)bitmap_data+i+3) = *((uint8_t*)bitmap_data+i+2);
        *((uint8_t*)bitmap_data+i  ) = 0x10;
        *((uint8_t*)bitmap_data+i+1) = 0x10;
        *((uint8_t*)bitmap_data+i+2) = 0x10;
    }

    textureT* tex = createTexture();
    textureT* old_tex = useTexture(tex, 0);

    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_BGRA,
                 GL_UNSIGNED_BYTE, bitmap_data);

    free(bitmap_data);

    triMeshT* text_quad = createQuad(2.0f, 2.0f);

    if (!text_shader)
        initTextShader();

    shaderT* old_shader = useShader(text_shader);

    setShaderParam("ScreenSize", &(vec2) { (float)screenWidth(), (float)screenHeight() });
    setShaderParam("TextRect"  , &(vec4) { (float)x, (float)y, (float)width, (float)height });

    GLint depth_mask;
    glGetIntegerv(GL_DEPTH_WRITEMASK, &depth_mask);

    GLboolean cull_face, depth_test;
    glGetBooleanv(GL_CULL_FACE, &cull_face);
    glGetBooleanv(GL_DEPTH_TEST, &depth_test);

    glDepthMask(GL_FALSE);
    glDisable  (GL_CULL_FACE);
    glDisable  (GL_DEPTH_TEST);

    drawMesh(text_quad);

    glDepthMask(depth_mask);

    if (cull_face)  glEnable(GL_CULL_FACE);
    if (depth_test) glEnable(GL_DEPTH_TEST);

    useTexture (old_tex, 0);
    useShader  (old_shader);
    freeTexture(tex);
    freeMesh   (text_quad);
}
int main(void)
{
	int argc;
	LPWSTR *argv;
	WCHAR *fontname, *string;
	int len;
	HDC dc;
	HFONT font, prevfont;
	IDWriteFontCollection *sysfc;
	UINT32 index;
	BOOL exists;
	IDWriteFontFamily *dwfamily;
	IDWriteFont *dwfont;
	IDWriteFontFace *dwface;
	featurePreparer *features;
	HRESULT hr;

	// TODO would using wmain() be adequate?
	argv = CommandLineToArgvW(GetCommandLineW(), &argc);
	if (argv == NULL)
		dieLE("error getting command-line arguments");
	if (argc != 3) {
		fprintf(stderr, "usage: %ws font string\n", argv[0]);
		return 1;
	}
	fontname = argv[1];
	string = argv[2];
	len = wcslen(string);

	// DirectWrite requires COM
	hr = CoInitialize(NULL);
	if (hr != S_OK)
		die("error initializing COM", hr);
	// Uniscribe requires a device context with the font to use
	dc = GetDC(NULL);
	if (dc == NULL)
		dieLE("error getting screen HDC for Uniscribe");
	// TODO DEFAULT_CHARSET might affect the results we get
	font = CreateFontW(0, 0, 0, 0, 0, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, fontname);
	if (font == NULL)
		dieLE("error creating font for Uniscribe");
	prevfont = (HFONT) SelectObject(dc, font);
	if (prevfont == NULL)
		dieLE("error selecting font into HDC for Uniscribe");
	// and initialize DirectWrite
	hr = DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED,
		__uuidof (IDWriteFactory),
		(IUnknown **) (&dwfactory));
	if (hr != S_OK)
		die("error initializing DirectWrite", hr);
	// and load the font *there*
	hr = dwfactory->GetSystemFontCollection(&sysfc, TRUE);
	if (hr != S_OK)
		die("error loading DirectWrite system font collection", hr);
	hr = sysfc->FindFamilyName(fontname, &index, &exists);
	if (hr != S_OK)
		die("error finding DirectWrite font family", hr);
	if (!exists)
		die("font not found in DirectWrite system font collection", E_FAIL);
	hr = sysfc->GetFontFamily(index, &dwfamily);
	if (hr != S_OK)
		die("error loading DirectWrite font family", hr);
	hr = dwfamily->GetFirstMatchingFont(DWRITE_FONT_WEIGHT_NORMAL,
		DWRITE_FONT_STRETCH_NORMAL,
		DWRITE_FONT_STYLE_NORMAL,
		&dwfont);
	if (hr != S_OK)
		die("error loading DirectWrite font object", hr);
	hr = dwfont->CreateFontFace(&dwface);
	if (hr != S_OK)
		die("error creating DirectWrite font face", hr);

	// first, uniscribe only; no features are used
//	uniscribeTest(dc, string, len, NULL,
//		doScriptItemize, doScriptShape, "Uniscribe");

	// next, unprepared features (NULL values)
	features = new featurePreparer;
//features->add('z','e','r','o',1);
//features->add('f','r','a','c',1);features->prepare(len);
//	uniscribeTest(dc, string, len, features,
//		doScriptItemizeOpenType, doScriptShapeOpenType, "Uniscribe OpenType");
	directwriteAnalyzerTest(dwface, string, len, features);
	delete features;

	dwface->Release();
	dwfont->Release();
	dwfamily->Release();
	sysfc->Release();
	dwfactory->Release();
	SelectObject(dc, prevfont);
	DeleteObject(font);
	ReleaseDC(NULL, dc);
	CoUninitialize();
	return 0;
}
Beispiel #15
0
extern "C" int main(int argc, wchar_t* argv[])
{
    TRACED_HOOK_HANDLE      hHook = new HOOK_TRACE_INFO();
    NTSTATUS                NtStatus;
    ULONG                   ACLEntries[1] = {0};
    UNICODE_STRING*         NameBuffer = NULL;

    ORIG_CreateFontIndirectW = CreateFontIndirectW;

    FORCE(LhInstallHook(
            ORIG_CreateFontIndirectW,
            IMPL_CreateFontIndirectW,
            (PVOID)0,
            hHook));
    FORCE(LhSetInclusiveACL(ACLEntries, 1, hHook));

    CreateFontIndirectW(0);
    CreateFontW(10, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, L"system");
    LOGFONTA lf = {};
    CreateFontIndirectA(&lf);
    CreateFontA(12, 0, 0, 0, 400, 0, 0, 0, 2, 0, 0, 0, 0, "MARLETT");

#if 0
    ORIG_GetTextExtentPoint32A = GetTextExtentPoint32A;
    FORCE(LhInstallHook(
            ORIG_GetTextExtentPoint32A,
            IMPL_GetTextExtentPoint32A,
            (PVOID)0,
            hHook));
    HDC hdc = GetDC(NULL);
    SIZE size;
    FORCE(LhSetInclusiveACL(ACLEntries, 1, hHook));
    GetTextExtentPoint32W(hdc, L"abc", 3, &size);
    GetTextExtentPointW(hdc, L"abc", 3, &size);
    GetTextExtentPoint32A(hdc, "abc", 3, &size);
    GetTextExtentPointA(hdc, "abc", 3, &size);
#endif

#if 0
    ORIG_MessageBeepHook = MessageBeep;
    /*
        The following shows how to install and remove local hooks...
    */
    FORCE(LhInstallHook(
            ORIG_MessageBeepHook,
            MessageBeepHook,
            (PVOID)0,
            hHook));

    printf(".\n");
    // won't invoke the hook handler because hooks are inactive after installation
    MessageBeep(123);
    getch();

    BOOL flags = 1;
    FORCE(LhIsThreadIntercepted(hHook, 0, &flags));
    printf("Intercepted %d\n", flags);
    // activate the hook for the current thread
    FORCE(LhSetInclusiveACL(ACLEntries, 1, hHook));
    FORCE(LhIsThreadIntercepted(hHook, 0, &flags));
    printf("Intercepted %d\n", flags);

    printf(".\n");
    // will be redirected into the handler...
    MessageBeep(123);
    getch();

    FORCE(LhSetGlobalExclusiveACL(ACLEntries, 1));
    printf(".\n");
    // will be redirected into the handler...
    MessageBeep(123);
    getch();

    FORCE(LhSetGlobalInclusiveACL(ACLEntries, 1));
    printf(".\n");
    // will be redirected into the handler...
    MessageBeep(123);
    getch();

    printf(".\n");
    // won't invoke the hook handler because hooks are inactive after installation
    ORIG_MessageBeepHook(123);
    getch();
#endif
    // this will also invalidate "hHook", because it is a traced handle...
    LhUninstallAllHooks();
    // this will do nothing because the hook is already removed...
    LhUninstallHook(hHook);

    printf(".\n");
    // will be redirected into the handler...
    MessageBeep(123);
    getch();

    // now we can safely release the traced handle
    delete hHook;

    hHook = NULL;

    // even if the hook is removed, we need to wait for memory release
    LhWaitForPendingRemovals();

    return 0;

ERROR_ABORT:

    if(hHook != NULL)
        delete hHook;

    if(NameBuffer != NULL)
        free(NameBuffer );

    printf("\n[Error(0x%p)]: \"%S\" (code: %d {0x%p})\n", (PVOID)NtStatus, RtlGetLastErrorString(), RtlGetLastError(), (PVOID)RtlGetLastError());

    _getch();

    return NtStatus;
}
// CreateFontManageData のWindows環境依存処理を行う関数
static int CreateFontManageData_Win( FONTMANAGE *ManageData, int DefaultCharSet )
{
	int CreateFontSize ;
	int SampleScale ;
	int EnableAddHeight	= FALSE ;
	int	AddHeight		= 0 ;
	int	OrigHeight		= 0 ;

	switch( ManageData->ImageBitDepth )
	{
	default:
	case DX_FONTIMAGE_BIT_1:
		SampleScale = 1 ;
		break ;

	case DX_FONTIMAGE_BIT_4:
		SampleScale = 4 ;
		break ;

	case DX_FONTIMAGE_BIT_8:
		SampleScale = 16 ;
		break ;
	}
	CreateFontSize = ManageData->BaseInfo.FontSize * SampleScale ;

CREATEFONTLABEL:

	// 既にフォントが作成されていたら削除
	if( ManageData->FontObj != NULL )
	{
		DeleteObject( ManageData->FontObj ) ;
	}

	if( ManageData->FontName[0] != L'\0' )
	{
		// 特に文字セットの指定が無い場合で、且つ指定のフォント名の指定の文字セットが無い場合は文字セットを DEFAULT_CHARSET にする
		if( DefaultCharSet == TRUE )
		{
			wchar_t	TempNameBuffer[ 16 ][ 64 ] ;
			wchar_t	*TempNameBufferP ;
			int		TempNameNum ;
			int		TempNameBufferAlloc ;
			int		i ;

			TempNameNum = EnumFontName( TempNameBuffer[ 0 ], 16, ManageData->BaseInfo.CharSet, ManageData->FontName ) ;
			if( TempNameNum >= 16 )
			{
				TempNameNum			= EnumFontName( NULL,            0,           ManageData->BaseInfo.CharSet, ManageData->FontName ) ;
				TempNameBufferP		= ( wchar_t * )malloc( TempNameNum * 64 * sizeof( wchar_t ) ) ;
				TempNameNum			= EnumFontName( TempNameBufferP, TempNameNum, ManageData->BaseInfo.CharSet, ManageData->FontName ) ;
				TempNameBufferAlloc = TRUE ;
			}
			else
			{
				TempNameBufferAlloc = FALSE ;
				TempNameBufferP		= TempNameBuffer[ 0 ] ;
			}

			for( i = 0 ; i < TempNameNum && CL_strcmp( CODEPAGE_UTF16LE, ( char * )( TempNameBufferP + i * 64 ), ( char * )ManageData->FontName ) != 0 ; i ++ ){}
			if( i == TempNameNum )
			{
				ManageData->BaseInfo.CharSet = DX_CHARSET_DEFAULT ;
			}

			if( TempNameBufferAlloc )
			{
				free( TempNameBufferP ) ;
				TempNameBufferP = NULL ;
			}
		}

		ManageData->FontObj = CreateFontW(
			CreateFontSize + AddHeight, 0, 0, 0,
			ManageData->BaseInfo.FontThickness * 100,
			ManageData->BaseInfo.Italic, FALSE, FALSE,
			CharSetTable[ ManageData->BaseInfo.CharSet ],
			OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
			NONANTIALIASED_QUALITY, FIXED_PITCH,
			ManageData->FontName
		) ;

		if( ManageData->FontObj == NULL )
		{
			ManageData->FontObj = CreateFontW(
				CreateFontSize + AddHeight, 0, 0, 0,
				ManageData->BaseInfo.FontThickness * 100,
				ManageData->BaseInfo.Italic, FALSE, FALSE,
				DEFAULT_CHARSET,
				OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
				NONANTIALIASED_QUALITY, FIXED_PITCH,
				ManageData->FontName
			) ;

			if( ManageData->FontObj == NULL )
			{
				ManageData->FontObj = CreateFontW(
					CreateFontSize + AddHeight, 0, 0, 0,
					ManageData->BaseInfo.FontThickness * 100,
					ManageData->BaseInfo.Italic, FALSE, FALSE,
					SHIFTJIS_CHARSET,
					OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
					NONANTIALIASED_QUALITY, FIXED_PITCH,
					ManageData->FontName
				) ;

				if( ManageData->FontObj == NULL )
				{
					wprintf( L"指定のフォントの作成に失敗しました\n" ) ;
					goto ERR ;
				}
			}
		}
	}
	else
	{
		ManageData->FontObj = CreateFontW(
			CreateFontSize + AddHeight, 0, 0, 0,
			ManageData->BaseInfo.FontThickness * 100,
			ManageData->BaseInfo.Italic, FALSE, FALSE,
			CharSetTable[ ManageData->BaseInfo.CharSet ],
			OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
			NONANTIALIASED_QUALITY, FIXED_PITCH,
			L"MS ゴシック"
		) ;
		ManageData->FontName[0] = L'\0' ;
	}

	if( ManageData->FontObj == NULL )
	{
		ManageData->FontObj = CreateFontW(
			CreateFontSize + AddHeight, 0, 0, 0,
			ManageData->BaseInfo.FontThickness * 100,
			FALSE, FALSE, FALSE,
			DEFAULT_CHARSET,
			OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
			NONANTIALIASED_QUALITY, FIXED_PITCH,
			L"MS ゴシック"
		) ;

		if( ManageData->FontObj == NULL )
		{
			ManageData->FontObj = CreateFontW(
				CreateFontSize + AddHeight, 0, 0, 0,
				ManageData->BaseInfo.FontThickness * 100,
				FALSE, FALSE, FALSE,
				DEFAULT_CHARSET,
				OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
				NONANTIALIASED_QUALITY, FIXED_PITCH,
				NULL
			) ;
		}
		ManageData->FontName[0] = L'\0' ;

		if( ManageData->FontObj == NULL )
		{
			wprintf( L"フォントの作成に失敗しました\n" ) ;
			goto ERR ;
		}
	}

	// 文字のサイズを取得する
	{
		HDC			DC ;
		HFONT		OldFont ;
		TEXTMETRIC	TextInfo ;

		// デバイスコンテキストを取得
		DC = CreateCompatibleDC( NULL ) ;
		if( DC == NULL )
		{
			wprintf( L"デバイスコンテキストの取得に失敗しました\n" ) ;
			goto ERR ;
		}

		// フォントのセット
		OldFont = ( HFONT )SelectObject( DC, ManageData->FontObj ) ;

		// フォントのステータスを取得
		GetTextMetrics( DC, &TextInfo ) ;

		// もし TextInfo.tmInternalLeading + TextInfo.tmExternalLeading が 0 ではなかったらその高さを追加してフォントを作成しなおす
		if( EnableAddHeight == FALSE )
		{
			if( TextInfo.tmInternalLeading + TextInfo.tmExternalLeading > 0 )
			{
				OrigHeight		= TextInfo.tmHeight ;
				AddHeight		= ( int )( CreateFontSize / ( 1.0f - ( float )( TextInfo.tmInternalLeading + TextInfo.tmExternalLeading ) / TextInfo.tmHeight ) ) - CreateFontSize ;
				EnableAddHeight	= TRUE ;

				SelectObject( DC, OldFont ) ;
				DeleteDC( DC ) ;

				DeleteObject( ManageData->FontObj ) ;
				ManageData->FontObj = NULL ;

				goto CREATEFONTLABEL ;
			}
			
			ManageData->BaseInfo.FontAddHeight = 0 ;
		}
		else
		{
			ManageData->BaseInfo.FontAddHeight = ( WORD )( ( TextInfo.tmHeight - OrigHeight ) / SampleScale ) ;
		}

		// フォントの最大サイズを取得
		if( ManageData->BaseInfo.Italic )
		{
			// イタリック体の場合は最大幅が 1.35倍になる
			ManageData->BaseInfo.MaxWidth = ( WORD )( ( TextInfo.tmMaxCharWidth * 135 / SampleScale + 4 * 135 ) / 100 ) ;
		}
		else
		{
			ManageData->BaseInfo.MaxWidth = ( WORD )( TextInfo.tmMaxCharWidth / SampleScale + 4 ) ;
		}

		// フォントの高さを保存
		ManageData->BaseInfo.FontHeight = ( WORD )( TextInfo.tmHeight / SampleScale + 1 ) ;

		// GetGlyphOutline が使用できるかどうかを調べる
		{
			GLYPHMETRICS	gm ;
			MAT2			mt = { { 0, 1 }, { 0, 0 }, { 0, 0 }, { 0, 1 } } ;
			unsigned int	Code ;
			DWORD			DataSize ;

			memset( &gm, 0, sizeof( GLYPHMETRICS ) ) ;
			Code		= ' ' ;
			DataSize	= GetGlyphOutline( DC, Code, GGO_BITMAP, &gm, 0, NULL, &mt ) ;

			// 失敗した場合は TextOut 方式を使用する
			if( DataSize == GDI_ERROR )
			{
				ManageData->UseTextOut = TRUE ;
			}
		}

		// TextOut 方式を使用する場合は DIB を作成しておく
		ManageData->CacheBitmap			= NULL ;
		ManageData->CacheBitmapMem		= NULL ;
		ManageData->CacheBitmapMemPitch	= 0 ;
		if( ManageData->UseTextOut )
		{
			BITMAPINFO	*BmpInfoPlus ;
			BITMAP		BmpData ;

			// イメージビット深度も DX_FONTIMAGE_BIT_1 のみ
			ManageData->ImageBitDepth = DX_FONTIMAGE_BIT_1 ;

			// キャッシュ領域のステータスの初期化
			BmpInfoPlus = ( BITMAPINFO * )malloc( sizeof( BITMAPINFO ) + sizeof( RGBQUAD ) * 256 ) ;
			if( BmpInfoPlus == NULL )
			{
				wprintf( L"メモリの確保に失敗しました" ) ;
				return -1 ;
			}
			BmpInfoPlus->bmiHeader.biSize			= sizeof( BITMAPINFOHEADER ) ;
			BmpInfoPlus->bmiHeader.biWidth			=  ManageData->BaseInfo.MaxWidth ;
			BmpInfoPlus->bmiHeader.biHeight			= -ManageData->BaseInfo.MaxWidth ;
			BmpInfoPlus->bmiHeader.biPlanes			= 1 ;
			BmpInfoPlus->bmiHeader.biBitCount		= 8 ;
			BmpInfoPlus->bmiHeader.biCompression	= BI_RGB ;
			BmpInfoPlus->bmiHeader.biSizeImage		= ( DWORD )( ManageData->BaseInfo.MaxWidth * ManageData->BaseInfo.MaxWidth ) ;

			// カラーパレットのセット
			{
				RGBQUAD *Color ;
				int		i ;

				Color = &BmpInfoPlus->bmiColors[0] ;
				for( i = 0 ; i < 256 ; i ++ )
				{
					Color->rgbBlue     = ( BYTE )i ;
					Color->rgbRed      = ( BYTE )i ;
					Color->rgbBlue     = ( BYTE )i ;
					Color->rgbReserved = 0 ;

					Color ++ ;
				}
			}

			// DIBデータを作成する
			ManageData->CacheBitmapMem	= NULL ; 
			ManageData->CacheBitmap		= CreateDIBSection( DC, BmpInfoPlus, DIB_PAL_COLORS, ( void ** )&ManageData->CacheBitmapMem, NULL, 0 ) ;

			// ピッチを得る
			GetObject( ManageData->CacheBitmap, sizeof( BITMAP ), &BmpData ) ;
			ManageData->CacheBitmapMemPitch = BmpData.bmWidthBytes ;

			// メモリの解放
			free( BmpInfoPlus ) ;
		}

		// フォントを元に戻す
		SelectObject( DC, OldFont ) ;

		// デバイスコンテキストを削除する
		DeleteDC( DC ) ;
	}

	// 正常終了
	return 0 ;

	// エラー処理
ERR :

	return -1 ;
}
Beispiel #17
0
/***********************************************************************
 *           D3DXCreateFontIndirectW    (D3DX9_36.@)
 */
HRESULT WINAPI D3DXCreateFontIndirectW(IDirect3DDevice9 *device, const D3DXFONT_DESCW *desc, ID3DXFont **font)
{
    D3DDEVICE_CREATION_PARAMETERS cpars;
    D3DDISPLAYMODE mode;
    struct d3dx_font *object;
    IDirect3D9 *d3d;
    HRESULT hr;

    TRACE("(%p, %p, %p)\n", device, desc, font);

    if (!device || !desc || !font) return D3DERR_INVALIDCALL;

    TRACE("desc: %d %d %d %d %d %d %d %d %d %s\n", desc->Height, desc->Width, desc->Weight, desc->MipLevels, desc->Italic,
            desc->CharSet, desc->OutputPrecision, desc->Quality, desc->PitchAndFamily, debugstr_w(desc->FaceName));

    /* The device MUST support D3DFMT_A8R8G8B8 */
    IDirect3DDevice9_GetDirect3D(device, &d3d);
    IDirect3DDevice9_GetCreationParameters(device, &cpars);
    IDirect3DDevice9_GetDisplayMode(device, 0, &mode);
    hr = IDirect3D9_CheckDeviceFormat(d3d, cpars.AdapterOrdinal, cpars.DeviceType, mode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_A8R8G8B8);
    if (FAILED(hr))
    {
        IDirect3D9_Release(d3d);
        return D3DXERR_INVALIDDATA;
    }
    IDirect3D9_Release(d3d);

    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct d3dx_font));
    if (!object)
    {
        *font = NULL;
        return E_OUTOFMEMORY;
    }
    object->ID3DXFont_iface.lpVtbl = &D3DXFont_Vtbl;
    object->ref = 1;
    object->device = device;
    object->desc = *desc;

    object->hdc = CreateCompatibleDC(NULL);
    if (!object->hdc)
    {
        HeapFree(GetProcessHeap(), 0, object);
        return D3DXERR_INVALIDDATA;
    }

    object->hfont = CreateFontW(desc->Height, desc->Width, 0, 0, desc->Weight, desc->Italic, FALSE, FALSE, desc->CharSet,
                                desc->OutputPrecision, CLIP_DEFAULT_PRECIS, desc->Quality, desc->PitchAndFamily, desc->FaceName);
    if (!object->hfont)
    {
        DeleteDC(object->hdc);
        HeapFree(GetProcessHeap(), 0, object);
        return D3DXERR_INVALIDDATA;
    }
    SelectObject(object->hdc, object->hfont);
    SetTextColor(object->hdc, 0x00ffffff);
    SetBkColor(object->hdc, 0x00000000);

    IDirect3DDevice9_AddRef(device);
    *font = &object->ID3DXFont_iface;

    return D3D_OK;
}
extern void
CResizerInit(CResizer *cs, HINSTANCE hInst, HWND dlg, int iIDD)
{
	BOOL bDialogEx = 0;

	/* set variables */
	cs->inst = hInst;
	cs->IDD  = iIDD;
	cs->hwnd = dlg;

	/* Get current point size information */
	HDC hdcScreen = GetDC(NULL);

	if (!hdcScreen) {
		cs->dpi = 96;
	}
	else {
		cs->dpi = GetDeviceCaps(hdcScreen, LOGPIXELSX);
		ReleaseDC(NULL, hdcScreen);
	}

	helper::DLGTEMPLATEEX *lpDialogTemplate;

	if (!hInst)
		{ } // hInst = AfxFindResourceHandle(IMAKEINTRESOURCE(IDD), RT_DIALOG);

	HRSRC hResource = ::FindResource(hInst, MAKEINTRESOURCE(cs->IDD), RT_DIALOG);
	HANDLE hDialogTemplate = LoadResource(hInst, hResource);
	lpDialogTemplate = (helper::DLGTEMPLATEEX *)LockResource(hDialogTemplate);

	bDialogEx = helper::IsDialogEx((const DLGTEMPLATE*) lpDialogTemplate);

	querydialogdata((LPCSTR)lpDialogTemplate, &cs->sDialogData);
/*	cs->sDialogData.style	= lpDialogTemplate->style;
	cs->sDialogData.exStyle	= lpDialogTemplate->exStyle;
 */
	if ((cs->sDialogData.pt<0)||(cs->sDialogData.pt>32767))
	{
		// I don't know what to do if it happens this way
		// this is a compromise solution:
		cs->sDialogData.pt = -cs->sDialogData.pt;
		cs->sDialogData.pt &= 0xFFFF;
	}

	cs->font=CreateFontW(
		-(int)(cs->sDialogData.pt*96.0/72.0 + 0.5), // negative makes it use "char size"
	0,              // logical average character width
	0,              // angle of escapement
	0,              // base-line orientation angle
	cs->sDialogData.weight,  // weight
	cs->sDialogData.italic,  // italic
	FALSE,          // underline attribute flag
	FALSE,          // strikeout attribute flag
	DEFAULT_CHARSET,    // character set identifier
	OUT_DEFAULT_PRECIS, // output precision
	CLIP_DEFAULT_PRECIS,// clipping precision
	DEFAULT_QUALITY,    // output quality
	DEFAULT_PITCH,  // pitch and family
	cs->sDialogData.faceName  // pointer to typeface name string
	);

	cs->oldfont=(HFONT)::SendMessage(cs->hwnd, WM_GETFONT, 0, 0);
	SendMessage(cs->hwnd, WM_SETFONT, (LPARAM)cs->font, TRUE);

	/* Pick up all of the item ID's */
	/* go through the Item ID's to resize them */
	helper::DLGITEMTEMPLATEEX *itemE =
		(helper::DLGITEMTEMPLATEEX *)helper::FindFirstDlgItem((DLGTEMPLATE *)lpDialogTemplate);
	DLGITEMTEMPLATE *item = (DLGITEMTEMPLATE *) itemE;

	cs->jNtItems = 0;
	int jMax = helper::DlgTemplateItemCount((DLGTEMPLATE *)lpDialogTemplate);
	while (cs->jNtItems < jMax) {
		if (bDialogEx) {
			cs->asDI[cs->jNtItems].x = itemE->x;
			cs->asDI[cs->jNtItems].y = itemE->y;
			cs->asDI[cs->jNtItems].cx= itemE->cx;
			cs->asDI[cs->jNtItems].cy= itemE->cy;
			cs->asDI[cs->jNtItems].id= itemE->id;
			itemE=(helper::DLGITEMTEMPLATEEX *)helper::FindNextDlgItem((DLGITEMTEMPLATE *)itemE,TRUE);
		}
		else {
			cs->asDI[cs->jNtItems].x = item->x;
			cs->asDI[cs->jNtItems].y = item->y;
			cs->asDI[cs->jNtItems].cx= item->cx;
			cs->asDI[cs->jNtItems].cy= item->cy;
			cs->asDI[cs->jNtItems].id= item->id;
			cs->asDI[cs->jNtItems].uiFlags = 0;
			item = helper::FindNextDlgItem(item,FALSE);
		}
		cs->asDI[cs->jNtItems].uiFlags = 0;
		cs->jNtItems++;
	}

	UnlockResource(hDialogTemplate);
	FreeResource(hDialogTemplate);

	cs->x_factor = (double) 2;
	cs->y_factor = (double) 2;

}	/* CResizerInit */
Beispiel #19
0
//-------------------------------------------------------------------------------------------------
static LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    //Skype begin
    static UINT iIdSkypeControlApiAttach;
    static constexpr const LPARAM iSkypeControlApiAttachSuccess = 0;
    static COLORREF colRef = RGB(255, 127, 0);
    static bool bNeedSkype = true;
    //Skype end
    static HFONT hFont;
    static bool bTimerActive = false;
    static const wchar_t *wSoundCardName;

    switch (uMsg)
    {
    case WM_CREATE:
    {
        if ((hFont = CreateFontW(48, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, DEFAULT_PITCH, L"Tahoma")) &&
                SetLayeredWindowAttributes(hWnd, 0, 0, LWA_COLORKEY) &&
                //Skype begin
                ((iIdSkypeControlApiAttach = RegisterWindowMessageW(L"SkypeControlAPIAttach"))))
            if (const UINT iCount = RegisterWindowMessageW(L"SkypeControlAPIDiscover"))
                if (PostMessageW(HWND_BROADCAST, iCount, reinterpret_cast<WPARAM>(hWnd), 0) &&
                        //Skype end
                        SetTimer(hWnd, 1, 1500, nullptr))
                {
                    bTimerActive = true;
                    wSoundCardName = static_cast<wchar_t*>(reinterpret_cast<const CREATESTRUCT*>(lParam)->lpCreateParams);
                    return 0;
                }
        return -1;
    }
    case WM_PAINT:
    {
        PAINTSTRUCT ps;
        if (const HDC hDc = BeginPaint(hWnd, &ps))
        {
            RECT rect;
            if (GetClientRect(hWnd, &rect))
            {
                rect.top = 40;
                SelectObject(hDc, hFont);
                SetBkColor(hDc, RGB(1, 1, 1));
                SetTextColor(hDc, colRef);        //Skype
                DrawTextW(hDc, wSoundCardName, -1, &rect, DT_CENTER);
            }
            EndPaint(hWnd, &ps);
        }
        return 0;
    }
    //Skype begin
    case WM_COPYDATA:
        if (bNeedSkype)
        {
            const COPYDATASTRUCT *const copyData = reinterpret_cast<const COPYDATASTRUCT*>(lParam);
            if (copyData->dwData == 0 && copyData->cbData > 10 && strncmp(static_cast<const char*>(copyData->lpData), "AUDIO_OUT ", 10) == 0)
            {
                colRef = RGB(255, 255, 0);
                InvalidateRect(hWnd, nullptr, FALSE);
                bNeedSkype = false;
            }
        }
        return TRUE;
    //Skype end
    case WM_TIMER:
    {
        KillTimer(hWnd, 1);
        bTimerActive = false;
        PostMessageW(hWnd, WM_CLOSE, 0, 0);
        return 0;
    }
    case WM_DESTROY:
    {
        if (bTimerActive)
            KillTimer(hWnd, 1);
        if (hFont)
            DeleteObject(hFont);
        PostQuitMessage(0);
        return 0;
    }
    }

    //Skype begin
    if (uMsg == iIdSkypeControlApiAttach)
    {
        if (lParam == iSkypeControlApiAttachSuccess)
        {
            const wchar_t *wIt = wSoundCardName;
            while (*wIt++);
            int iLen = wIt-wSoundCardName-1;
            if (iLen <= 256)
            {
                char cBuf[14+256*sizeof(wchar_t)] = "SET AUDIO_OUT ";
                if (const int iSize = WideCharToMultiByte(CP_UTF8, 0, wSoundCardName, -1, cBuf+14, iLen*sizeof(wchar_t), nullptr, nullptr))
                {
                    COPYDATASTRUCT copyData;
                    copyData.dwData = 0;
                    copyData.cbData = 14 + iSize;
                    copyData.lpData = cBuf;
                    SendMessageTimeoutW(reinterpret_cast<HWND>(wParam), WM_COPYDATA, reinterpret_cast<WPARAM>(hWnd), reinterpret_cast<LPARAM>(&copyData), SMTO_ABORTIFHUNG, 0, nullptr);
                }
            }
        }
        return 0;
    }
    //Skype end

    return DefWindowProcW(hWnd, uMsg, wParam, lParam);
}
Beispiel #20
0
BOOL
PaintText(LPDRAWITEMSTRUCT drawItem,
          PCONSOLE_STATE_INFO pConInfo,
          TEXT_TYPE TextMode)
{
    USHORT CurrentAttrib;
    COLORREF pbkColor, ptColor;
    COLORREF nbkColor, ntColor;
    HBRUSH hBrush;
    HFONT Font, OldFont;

    COORD FontSize = pConInfo->FontSize;

    if (TextMode == Screen)
        CurrentAttrib = pConInfo->ScreenAttributes;
    else if (TextMode == Popup)
        CurrentAttrib = pConInfo->PopupAttributes;
    else
        return FALSE;

    nbkColor = pConInfo->ColorTable[BkgdAttribFromAttrib(CurrentAttrib)];
    ntColor  = pConInfo->ColorTable[TextAttribFromAttrib(CurrentAttrib)];

    hBrush = CreateSolidBrush(nbkColor);
    if (!hBrush) return FALSE;

    FontSize.Y = FontSize.Y > 0 ? -MulDiv(FontSize.Y, GetDeviceCaps(drawItem->hDC, LOGPIXELSY), 72)
                                : FontSize.Y;

    Font = CreateFontW(FontSize.Y,
                       FontSize.X,
                       0,
                       TA_BASELINE,
                       pConInfo->FontWeight,
                       FALSE,
                       FALSE,
                       FALSE,
                       OEM_CHARSET,
                       OUT_DEFAULT_PRECIS,
                       CLIP_DEFAULT_PRECIS,
                       DEFAULT_QUALITY,
                       FIXED_PITCH | pConInfo->FontFamily,
                       pConInfo->FaceName);
    if (Font == NULL)
    {
        DPRINT1("PaintText: CreateFont failed\n");
        return FALSE;
    }

    OldFont = SelectObject(drawItem->hDC, Font);
    if (OldFont == NULL)
    {
        DeleteObject(Font);
        return FALSE;
    }

    FillRect(drawItem->hDC, &drawItem->rcItem, hBrush);

    ptColor = SetTextColor(drawItem->hDC, ntColor);
    pbkColor = SetBkColor(drawItem->hDC, nbkColor);
    DrawTextW(drawItem->hDC, szPreviewText, wcslen(szPreviewText), &drawItem->rcItem, 0);
    SetTextColor(drawItem->hDC, ptColor);
    SetBkColor(drawItem->hDC, pbkColor);
    DeleteObject(hBrush);

    SelectObject(drawItem->hDC, OldFont);
    DeleteObject(Font);

    return TRUE;
}
Beispiel #21
0
static void add_ruler_units(HDC hdcRuler, RECT* drawRect, BOOL NewMetrics, LONG EditLeftmost)
{
    static HDC hdc;

    if(NewMetrics)
    {
        static HBITMAP hBitmap;
        int i, x, y, RulerTextEnd;
        int CmPixels;
        int QuarterCmPixels;
        HFONT hFont;
        WCHAR FontName[] = {'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0};

        if(hdc)
        {
            DeleteDC(hdc);
            DeleteObject(hBitmap);
        }

        hdc = CreateCompatibleDC(0);

        CmPixels = twips_to_pixels(centmm_to_twips(1000), GetDeviceCaps(hdc, LOGPIXELSX));
        QuarterCmPixels = (int)((float)CmPixels / 4.0);

        hBitmap = CreateCompatibleBitmap(hdc, drawRect->right, drawRect->bottom);
        SelectObject(hdc, hBitmap);
        FillRect(hdc, drawRect, GetStockObject(WHITE_BRUSH));

        hFont = CreateFontW(10, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, FontName);

        SelectObject(hdc, hFont);
        SetBkMode(hdc, TRANSPARENT);
        SetTextAlign(hdc, TA_CENTER);
        y = (int)(((float)drawRect->bottom - (float)drawRect->top) / 2.0) + 1;
        RulerTextEnd = drawRect->right - EditLeftmost + 1;
        for(i = 1, x = EditLeftmost; x < (drawRect->right - EditLeftmost + 1); i ++)
        {
            WCHAR str[3];
            WCHAR format[] = {'%','d',0};
            int x2 = x;

            x2 += QuarterCmPixels;
            if(x2 > RulerTextEnd)
                break;

            MoveToEx(hdc, x2, y, NULL);
            LineTo(hdc, x2, y+2);

            x2 += QuarterCmPixels;
            if(x2 > RulerTextEnd)
                break;

            MoveToEx(hdc, x2, y - 3, NULL);
            LineTo(hdc, x2, y + 3);

            x2 += QuarterCmPixels;
            if(x2 > RulerTextEnd)
                break;

            MoveToEx(hdc, x2, y, NULL);
            LineTo(hdc, x2, y+2);

            x += CmPixels;
            if(x > RulerTextEnd)
                break;

            wsprintfW(str, format, i);
            TextOutW(hdc, x, 5, str, lstrlenW(str));
        }
        DeleteObject(hFont);
    }

    BitBlt(hdcRuler, 0, 0, drawRect->right, drawRect->bottom, hdc, 0, 0, SRCAND);
}
bool DisplayMessageBox(const char* pTitle, const char* pText)
{
    #define ID_EDIT 100

    struct Dialog
    {
        static size_t LineCount(const char* pText)
        {
            size_t count = 0;
            while(*pText)
            {
                if(*pText++ == '\n')
                    count++;
            }
            return count;
        }

        static WORD* WordUp(WORD* pIn){ return (WORD*)((((uintptr_t)pIn + 3) >> 2) << 2); }

        static BOOL CALLBACK Proc(HWND hDlg, UINT iMsg, WPARAM wParam, LPARAM lParam)
        {
            switch (iMsg)
            {
                case WM_INITDIALOG:
                {
                    HWND hWndEdit = GetDlgItem(hDlg, ID_EDIT);

                    const wchar_t* pText = (const wchar_t*)lParam;
                    SetWindowTextW(hWndEdit, pText);

                    HFONT hFont = CreateFontW(-11, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, L"Courier New");
                    if(hFont)
                        SendMessage(hWndEdit, WM_SETFONT, WPARAM(hFont), TRUE);

                    SendMessage(hWndEdit, EM_SETSEL, (WPARAM)0, (LPARAM)0);

                    return TRUE;
                }

                case WM_COMMAND:
                    switch (LOWORD(wParam))
                    {
                        case ID_EDIT:
                        {
                            // Handle messages from the edit control here.
                            HWND hWndEdit = GetDlgItem(hDlg, ID_EDIT);
                            SendMessage(hWndEdit, EM_SETSEL, (WPARAM)0, (LPARAM)0);
                            return TRUE;
                        }

                        case IDOK:
                            EndDialog(hDlg, 0);
                            return TRUE;
                        case IDABORT:
                            _exit(0); // We don't call abort() because the visual studio runtime
                                      // will capture the signal and throw up another dialog
                    }
                    break;
                case WM_CLOSE:

                    EndDialog(hDlg, 0);
                    return TRUE;
            }

            return FALSE;
        }
    };
Beispiel #23
0
void DrawPixels(HWND hwnd) {

	PAINTSTRUCT ps;
	RECT r;

	GetClientRect(hwnd, &r);

	if (r.bottom == 0)
	  return;

	HDC hdc = BeginPaint(hwnd, &ps);

	// pixels
	for (int i = 0; i < 1000; i++) {
	  int x = rand() % r.right;
	  int y = rand() % r.bottom;
	  SetPixel(hdc, x, y, RGB(rand() % 255, rand() % 255, rand() % 255));
	}
	
	// rectangle
	Rectangle(hdc, 30, 30, 240, 140);
	
	// pens and lines (stroke)
	HPEN hPen1 = CreatePen(PS_SOLID, 1, RGB(0, 0, 0));
	HPEN hPen2 = CreatePen(PS_DASH, 1, RGB(0, 0, 0));
	HPEN hPen3 = CreatePen(PS_DOT, 1, RGB(0, 0, 0));
	HPEN hPen4 = CreatePen(PS_DASHDOT, 1, RGB(0, 0, 0));
	HPEN hPen5 = CreatePen(PS_DASHDOTDOT, 1, RGB(0, 0, 0));

	HPEN holdPen = SelectObject(hdc, hPen1);
	MoveToEx(hdc, 50, 30, NULL);
	LineTo(hdc, 200, 30);

	SelectObject(hdc, hPen2);
	MoveToEx(hdc, 50, 50, NULL);
	LineTo(hdc, 200, 50);

	SelectObject(hdc, hPen2);
	MoveToEx(hdc, 50, 70, NULL);
	LineTo(hdc, 200, 70);

	SelectObject(hdc, hPen3);
	MoveToEx(hdc, 50, 90, NULL);
	LineTo(hdc, 200, 90);

	SelectObject(hdc, hPen4);
	MoveToEx(hdc, 50, 110, NULL);
	LineTo(hdc, 200, 110);

	SelectObject(hdc, holdPen);
	DeleteObject(hPen1);
	DeleteObject(hPen2);
	DeleteObject(hPen3);
	DeleteObject(hPen4);
	DeleteObject(hPen5);
	
	// brushes and fill
	HPEN hPen = CreatePen(PS_NULL, 1, RGB(0, 0, 0));
	holdPen = SelectObject(hdc, hPen);

	HBRUSH hBrush1 = CreateSolidBrush(RGB(121, 90, 0));
	HBRUSH hBrush2 = CreateSolidBrush(RGB(240, 63, 19));
	HBRUSH hBrush3 = CreateSolidBrush(RGB(240, 210, 18));
	HBRUSH hBrush4 = CreateSolidBrush(RGB(9, 189, 21));

	HBRUSH holdBrush = SelectObject(hdc, hBrush1);

	int top = 200;
	int size = 70;
	Rectangle(hdc, 30, top, 100, top+size);
	SelectObject(hdc, hBrush2);
	Rectangle(hdc, 110, top, 180, top+size);
	SelectObject(hdc, hBrush3);
	Rectangle(hdc, 30, top+70, 100, top+size+70);
	SelectObject(hdc, hBrush4);
	Rectangle(hdc, 110, top+70, 180, top+size+70);

	SelectObject(hdc, holdPen);
	SelectObject(hdc, holdBrush);

	DeleteObject(hPen);
	DeleteObject(hBrush1);
	DeleteObject(hBrush2);
	DeleteObject(hBrush3);
	DeleteObject(hBrush4);
	
	// draw shapes
	int left = 370;
	Ellipse(hdc, left, 30, left + 60, 90);
	RoundRect(hdc, left+80, 30, left+160, 90, 15, 20);
	Chord(hdc, 270, 30, 360, 90, 270, 45, 360, 45);
	const POINT polygon[10] = { left+30, 145, left+85, 165, left+105, 
      110, left+65, 125, left+30, 105 };
	const POINT bezier[4] = {280, 160, 320, 160, 
      325, 110, 350, 110};
	Polygon(hdc, polygon, 5);
	PolyBezier(hdc, bezier, 4);
	
	// draw text
	DWORD color;
	HFONT hFont, holdFont;
	static wchar_t *ver1 = L"Not marble, nor the gilded monuments";
	static wchar_t *ver2 = L"Of princes, shall outlive this powerful rhyme;";
	static wchar_t *ver3 = L"But you shall shine more bright in these contents";
	static wchar_t *ver4 = L"Than unswept stone, besmear'd with sluttish time.";
	static wchar_t *ver5 = L"When wasteful war shall statues overturn,";
	static wchar_t *ver6 = L"And broils root out the work of masonry,";
	static wchar_t *ver7 = L"Nor Mars his sword, nor war's quick fire shall burn";
	static wchar_t *ver8 = L"The living record of your memory.";
	static wchar_t *ver9 = L"'Gainst death, and all oblivious enmity";
	static wchar_t *ver10 = L"Shall you pace forth; your praise shall still find room";
	static wchar_t *ver11 = L"Even in the eyes of all posterity";
	static wchar_t *ver12 = L"That wear this world out to the ending doom.";
	static wchar_t *ver13 = L"So, till the judgment that yourself arise,";
	static wchar_t *ver14 = L"You live in this, and dwell in lovers' eyes.";

	color = GetSysColor(COLOR_BTNFACE);
	SetBkColor(hdc, color);

	hFont = CreateFontW(15, 0, 0, 0, FW_MEDIUM, 0, 0, 0, 0,
	  0, 0, 0, 0, L"Georgia");
	holdFont = SelectObject(hdc, hFont);

	left = 270;
	top = 160;
	TextOutW(hdc, left, top + 20,  ver1,  lstrlenW(ver1));
	TextOutW(hdc, left, top + 40,  ver2,  lstrlenW(ver2));
	TextOutW(hdc, left, top + 60,  ver3,  lstrlenW(ver3));
	TextOutW(hdc, left, top + 80,  ver4,  lstrlenW(ver4));
	TextOutW(hdc, left, top + 100, ver5,  lstrlenW(ver5));
	TextOutW(hdc, left, top + 120, ver6,  lstrlenW(ver6));
	TextOutW(hdc, left, top + 140, ver7,  lstrlenW(ver7));
	TextOutW(hdc, left, top + 160, ver8,  lstrlenW(ver8));
	TextOutW(hdc, left, top + 180, ver9,  lstrlenW(ver9));
	TextOutW(hdc, left, top + 200, ver10, lstrlenW(ver10));
	TextOutW(hdc, left, top + 220, ver11, lstrlenW(ver11));
	TextOutW(hdc, left, top + 240, ver12, lstrlenW(ver12));
	TextOutW(hdc, left, top + 260, ver13, lstrlenW(ver13));
	TextOutW(hdc, left, top + 280, ver14, lstrlenW(ver14));

	SelectObject(hdc, holdFont);
	DeleteObject(hFont);
	
	// draw bitmap
	BITMAP bitmap;
	HDC hdcMem;
	HGDIOBJ oldBitmap;
	
	hdcMem = CreateCompatibleDC(hdc);
	oldBitmap = SelectObject(hdcMem, hBitmap);

	GetObject(hBitmap, sizeof(bitmap), &bitmap);
	BitBlt(hdc, 550, 5, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, SRCCOPY);

	SelectObject(hdcMem, oldBitmap);
	DeleteDC(hdcMem);


	EndPaint(hwnd, &ps);
}
void OnPaint(HDC hdc)
{
    HRESULT hr = S_OK;

    HFONT hfont = NULL;
    long height = 0;
    HDC memoryHdc = NULL;
    SIZE size = {};
    
    // Set the height, equivalent to 50 em for DirectWrite.
    height = -MulDiv(50, GetDeviceCaps(hdc, LOGPIXELSY), 96);

    hfont = CreateFontW(height, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, L"Times New Roman");

    wchar_t dwriteText[ ] = L"Sample text using DirectWrite.";  
    wchar_t gdiText[ ] = L"Sample text using GDI TextOut."; 

    // The DirectWrite objects need only be created once and can be reused each time the window paints
    hr = DWriteCreateResources(hdc, dwriteText, hfont);

    // Get the memory device context, the drawing is done offscreen.
    if (SUCCEEDED(hr))
    {
        memoryHdc = g_pBitmapRenderTarget->GetMemoryDC();
        SetBoundsRect(memoryHdc, NULL, DCB_ENABLE|DCB_RESET);
    }

    // Get the size of the target.
    if (SUCCEEDED(hr))
    {
        hr = g_pBitmapRenderTarget->GetSize(&size);
    }

    // Clear the background
    if (SUCCEEDED(hr))
    {
        SetDCBrushColor(memoryHdc, 0xFFFFFF);
        SelectObject(memoryHdc, GetStockObject(NULL_PEN));
        SelectObject(memoryHdc, GetStockObject(DC_BRUSH));
        Rectangle(memoryHdc, 0, 0, size.cx + 1, size.cy + 1);
    }

    // Draw the string to the memory HDC using GDI.
    if (SUCCEEDED(hr))
    {
        GdiOnPaint(memoryHdc, gdiText, hfont);
    }

    // Draw the same string below the first to the memory HDC using DirectWrite.
    if (SUCCEEDED(hr))
    {
        hr = DWriteOnPaint(memoryHdc, dwriteText, hfont);
    }

    // Transfer from DWrite's rendering target to the window.
    BitBlt(
        hdc,
        0, 0,
        size.cx + 1, size.cy + 1,
        memoryHdc,
        0, 0, 
        SRCCOPY
        );

    // If the DirectWrite drawing failed, exit and display an error.
    if (FAILED(hr))
    {
        wchar_t error[255];

        swprintf_s(error, 254, L"HRESULT = %x", hr);

        MessageBox(0, error, L"Error, exiting.", 0);

        exit(1);
    }
}
Beispiel #25
0
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	HANDLE hPipe;
#ifdef _DEBUG
	RECT r;
	HDC hDC;
#endif

	switch(message)
	{
	case WM_CREATE:
#ifdef _DEBUG
		GetClientRect(hWnd, &r);
		hwndEdit = CreateWindowW(L"EDIT", L"",
			WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_LEFT | ES_MULTILINE | ES_READONLY,
			0, 0, r.right, r.bottom, hWnd, NULL, hInst, NULL);
		hDC = GetDC(hwndEdit);
		hFont = CreateFontW(-MulDiv(10, GetDeviceCaps(hDC, LOGPIXELSY), 72), 0, 0, 0,
			FW_NORMAL, FALSE, FALSE, FALSE, SHIFTJIS_CHARSET,
			OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY, DEFAULT_PITCH,
			L"Meiryo");
		SendMessageW(hwndEdit, WM_SETFONT, (WPARAM)hFont, 0);
		ReleaseDC(hwndEdit, hDC);
#endif
		InitializeCriticalSection(&csUserDataSave);

		bUserDicChg = FALSE;
		LoadSKKUserDic();

		bSrvThreadExit = FALSE;
		hThreadSrv = SrvStart();
		if(hThreadSrv == NULL)
		{
			DestroyWindow(hWnd);
		}
		break;

#ifdef _DEBUG
	case WM_SIZE:
		GetClientRect(hWnd, &r);
		MoveWindow(hwndEdit, 0, 0, r.right, r.bottom, TRUE);
		break;
#endif

	case WM_POWERBROADCAST:
		if(wParam == PBT_APMSUSPEND)
		{
			StartSaveSKKUserDic(FALSE);

			BackUpSKKUserDic();
		}
		break;

	case WM_DESTROY:
	case WM_ENDSESSION:
#ifdef _DEBUG
		DeleteObject(hFont);
#endif
		bSrvThreadExit = TRUE;
		hPipe = CreateFileW(mgrpipename, GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
			NULL, OPEN_EXISTING, SECURITY_SQOS_PRESENT | SECURITY_EFFECTIVE_ONLY | SECURITY_IDENTIFICATION, NULL);
		if(hPipe != INVALID_HANDLE_VALUE)
		{
			CloseHandle(hPipe);
			WaitForSingleObject(hThreadSrv, INFINITE);
		}

		CloseHandle(hThreadSrv);

		StartSaveSKKUserDic(FALSE);

		if(message == WM_ENDSESSION)
		{
			BackUpSKKUserDic();
		}

		DeleteCriticalSection(&csUserDataSave);

		ReleaseMutex(hMutex);
		CloseHandle(hMutex);

		PostQuitMessage(0);
		break;

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