Win32 edit control fonts

Hi,I am writing a program with an edit control.When i try to change font modifing
device context option with SelectObject nothing appen.Why?.I don't want to use WM_SETFONT message because it makes the whole text change.
here the code,(problably there are some nonsense because i rewrited it many times):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include <windows.h>
#include <windowsx.h>
#include <stdlib.h>
#include <string.h>
#include <tchar.h>
#include<iostream>
#include<locale>
#include<iomanip>

using namespace std;



static TCHAR szWindowClass[] =_T("win32app");
static TCHAR szTitle[]=_T("Finestra");
HWND edit2,hwnd,bottoneFont;/*EDIT CONTROL HANDLE, BUTTON HENDLE*/
HDC edit2hdc;
LOGFONTW Logicfont;
CHOOSEFONTW Myfont;
HFONT fontt;
PAINTSTRUCT paint;





//=======================WINDOWS WNDPROCS====================================//
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
LRESULT CALLBACK edit2Proc(HWND,UINT,WPARAM,LPARAM);
LRESULT (CALLBACK* pointerEdit2)(HWND,UINT,WPARAM,LPARAM);


//=========================================WINMAIN=====================================//
int WINAPI WinMain(HINSTANCE pInstance,HINSTANCE pPrecIstance,LPSTR CmdLine,int CmsShow){
	WNDCLASSEX wcex,ed2;
	
	wcex.cbSize = sizeof(WNDCLASSEX);
	wcex.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
	wcex.lpfnWndProc = WndProc;
	wcex.cbClsExtra =0;
	wcex.cbWndExtra =0;
	wcex.hInstance =pInstance;
	wcex.hIcon          = LoadIcon(pInstance,"mysys");
	wcex.hCursor        = LoadCursor(NULL, IDC_ARROW);
	wcex.hbrBackground  = (HBRUSH)(COLOR_MENU+1);
	wcex.lpszMenuName   = NULL;
	wcex.lpszClassName  = szWindowClass;
	wcex.hIconSm        = LoadIcon(wcex.hInstance,"mysys" );
	
	
	 if (!RegisterClassEx(&wcex))
    {
        MessageBox(NULL,
            _T("Call to RegisterClassEx failed!"),
            _T("Win32 Guided Tour"),
            MB_OK);

        return 1;
    }
	 
	 
	 //===================WINDOWS CREATION====================//
	 hwnd =CreateWindow(szWindowClass,szTitle,WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,575,550,NULL,NULL,pInstance,NULL);
	 bottoneFont =CreateWindow("BUTTON","Seleziona font",WS_CHILD|WS_TABSTOP|WS_VISIBLE|BS_DEFPUSHBUTTON,328,80,100,40,hwnd,NULL,pInstance,NULL);
	 edit2=CreateWindow("EDIT","",WS_CHILD|WS_TABSTOP|WS_VISIBLE|WS_VSCROLL|WS_BORDER,25,80,300,300,hwnd,NULL,pInstance,NULL);
	 edit2hdc=GetDC(edit2);
	 pointerEdit2=reinterpret_cast<WNDPROC>(SetWindowLongPtr(edit2,GWLP_WNDPROC,(LONG)edit2Proc));
	 
	 
	 
	 	
	
	  if (!hwnd)
    {
        MessageBox(NULL,
            _T("Call to CreateWindow failed!"),
            _T("Win32 Guided Tour"),
            MB_OK);

        return 1;
    }
	
	ShowWindow(hwnd, CmsShow);
    UpdateWindow(hwnd);

	MSG msg;
    while (GetMessage(&msg, NULL, 0, 0))
    {	
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
	return 0;
	}
	
	//=================================== ROUTINE DI FINESTRA PRINCIPALE==============================//
	LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    PAINTSTRUCT ps;
    HDC hdc;
    TCHAR greeting[] = _T("FINESTRA DI PROVA");
	int n;
    switch (message)
    {
	case WM_COMMAND:
		if(lParam==reinterpret_cast<LPARAM>(bottoneFont)){
		Myfont.lStructSize=sizeof(CHOOSEFONTW);
		Myfont.lpLogFont=&Logicfont;
		ChooseFontW(&Myfont);
		fontt=CreateFontIndirectW(Myfont.lpLogFont);
		SelectObject(edit2hdc,fontt);
		}
		break;
    case WM_PAINT:
        hdc = BeginPaint(hwnd, &paint);

       
        TextOut(hdc,
            5, 5,
            greeting, _tcslen(greeting));
       

        EndPaint(hwnd, &ps);
        break;
    case WM_DESTROY: 
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hwnd, message, wParam, lParam);
        break;
    }

    return 0;
}

//======================================== wndproc EDIT2===============================//

LRESULT CALLBACK edit2Proc(HWND edit2,UINT msg,WPARAM wParam,LPARAM lParam){
		switch(msg){
		default:
		return pointerEdit2(edit2,msg,wParam,lParam);
		break;
	}
	return 0;
}
Last edited on
Topic archived. No new replies allowed.