creating controls using API's functions

Pages: 12
now i know why isn't working.. but i don't understand how can i do the Window Procedure Superclassing: http://msdn.microsoft.com/en-us/library/windows/desktop/ms633569%28v=vs.85%29.aspx
sorry can you help me more that text, please?
1. of all havent programed for 5 years now and newer was great at it just try to get back to it.



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
class X
{
public:
	HINSTANCE hInst;
	HWND mp_hWnd, m_hWnd;
	X(HINSTANCE Inst, HWND hWnd);
	LRESULT CALLBACK contProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
	{
		switch (message)
		{	// just for testing place a breakpoint here to see you get here 
			case WM_DESTROY:
				return 0;
			case WM_USER: 
				return 0;

			default:
				return DefSubclassProc(hWnd, message, wParam, lParam);
		}
	}
};
LRESULT CALLBACK Warp(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData)
{
	return (LRESULT) ((X*)dwRefData)->contProc(hWnd, uMsg, wParam, lParam);
};
X::X(HINSTANCE Inst, HWND hWnd)
{
	hInst = Inst;
	mp_hWnd = hWnd;
	m_hWnd = CreateWindowEx(0, WC_EDIT, L"1235678", WS_CHILD | WS_VISIBLE | WS_BORDER, 
							10, 10, 100, 20, mp_hWnd, 0, hInst, 0);	
	SetWindowSubclass(m_hWnd, Warp, 0, (DWORD_PTR)this);
};


1
2
3
X a = X(hInstance, hWnd);
   PostMessage(a.m_hWnd, WM_USER, 0, 0);
   DestroyWindow(a.m_hWnd);


finally i fix it:
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
        WNDPROC oldproc = (WNDPROC)GetProp(GetParent(hwnd), labelpropname);
        label *inst = (label*)GetProp(GetParent(hwnd), labelclassprop);

        if (oldproc == NULL || inst == NULL)
            MessageBox(NULL, "null", "null", MB_OK);

        static bool TrackingMouse = false;
        static bool WindowStopMoving = NULL;
        static bool WindowStopResize = NULL;
        static const UINT_PTR MouseStopTimerID = 1;
        HBRUSH g_hbrBackground = CreateSolidBrush(RGB(0, 0, 0));

        switch(msg)
        {
            case WM_CREATE:
            {
                static int xPos = (int)(short) LOWORD(lParam);
                static int yPos = (int)(short) HIWORD(lParam);
                inst->Create(xPos,yPos);
            }
            break;
            case WM_CTLCOLORDLG:
                return (LONG)g_hbrBackground;
            case WM_CTLCOLORSTATIC:
            {
                HDC hdcStatic = (HDC)wParam;
                SetTextColor(hdcStatic, RGB(255, 255, 255));
                SetBkMode(hdcStatic, TRANSPARENT);
                UpdateWindow(inst->hwnd);
                return (LONG)g_hbrBackground;
            }
            break;
            case WM_MOVE:
            {
                static int xPos = (int)(short) LOWORD(lParam);
                static int yPos = (int)(short) HIWORD(lParam);
                inst->Move(xPos,yPos);
                WindowStopMoving=false;
                WindowStopResize=true;
            }
            break;
            case WM_SIZE :
            {
                WindowStopResize=false;
                WindowStopMoving=true;
            }
            break;
            case WM_EXITSIZEMOVE:
            {
                if(WindowStopResize==false)
                {
                    WindowStopResize=true;
                    inst->NotResize();
                }
                else if (WindowStopMoving==false)
                {
                    WindowStopMoving=true;
                    inst->Stop();
                }
            }
            break;

            case WM_NCHITTEST:
                return DefWindowProc(hwnd, msg, wParam, lParam);

            case WM_LBUTTONDOWN:
            case WM_RBUTTONDOWN:
            case WM_MBUTTONDOWN:
            case WM_XBUTTONDOWN:
            {
                SetFocus(inst->hwnd);
                static int xPos = (int)(short) LOWORD(lParam);
                static int yPos = (int)(short) HIWORD(lParam);
                bool blControl = ((wParam & MK_CONTROL) == MK_CONTROL);
                bool blshift = ((wParam & MK_SHIFT) == MK_SHIFT);
                MouseButtons MBButtons;
                if((wParam & MK_LBUTTON)!= false)
                    MBButtons=Left;
                else if (wParam & MK_RBUTTON)
                    MBButtons=Right;
                else if (wParam & MK_MBUTTON)
                    MBButtons=Middle;
                else if (wParam & MK_XBUTTON1)
                    MBButtons=X1;
                else if (wParam & MK_XBUTTON2)
                    MBButtons=X2;
                else
                    MBButtons=None;
                inst->MouseDown(MBButtons,blControl,blshift,xPos,yPos);
            }
            break;
            case WM_LBUTTONUP:
            case WM_RBUTTONUP:
            case WM_MBUTTONUP:
            case WM_XBUTTONUP:
            {
                SetFocus(inst->hwnd);
                static int xPos = (int)(short) LOWORD(lParam);
                static int yPos = (int)(short) HIWORD(lParam);
                bool blControl = ((wParam & MK_CONTROL) == MK_CONTROL);
                bool blshift = ((wParam & MK_SHIFT) == MK_SHIFT);
                MouseButtons MBButtons;
                if (msg == WM_LBUTTONUP)
                    MBButtons=Left;
                else if (msg == WM_RBUTTONUP)
                    MBButtons=Right;
                else if (msg == WM_MBUTTONUP)
                    MBButtons=Middle;
				else if (msg == WM_XBUTTONUP)
                {
                    if (wParam & MK_XBUTTON1)
                        MBButtons=X1;
                    else if (wParam & MK_XBUTTON2)
                        MBButtons=X2;
                }
                else
                    MBButtons=None;
                inst->MouseUp(MBButtons,blControl,blshift,xPos,yPos);
            }
            break;

            case WM_MOUSELEAVE :
            {
                TrackingMouse = false;
                inst->MouseLeave();
            }
            break;
            case WM_MOUSEMOVE:
            {
                if (!TrackingMouse)
                {
                    inst->TrackMouse(hwnd);
                    TrackingMouse = true;
                    inst->MouseEnter();
                }
                static int xPos = (int)(short) LOWORD(lParam);
                static int yPos = (int)(short) HIWORD(lParam);
                static bool blControl = ((wParam & MK_CONTROL) == MK_CONTROL);
                static bool blshift = ((wParam & MK_SHIFT) == MK_SHIFT);
                static MouseButtons MBButtons;
                if((wParam & MK_LBUTTON)!= false)
                    MBButtons=Left;
                else if ((wParam & MK_RBUTTON)!= false)
                    MBButtons=Right;
                else if ((wParam & MK_MBUTTON)!= false)
                    MBButtons=Middle;
                else if ((wParam & MK_XBUTTON1)!= false)
                    MBButtons=X1;
                else if ((wParam & MK_XBUTTON2)!= false)
                    MBButtons=X2;
                else
                    MBButtons=None;

                inst->MouseMove(MBButtons,blControl,blshift,xPos,yPos);
                KillTimer(hwnd, MouseStopTimerID);
                SetTimer(hwnd, MouseStopTimerID, 500, NULL);
            }
			break;
            case WM_MOUSEHOVER:
            {
                inst->MouseHover();
            }
            break;
            case WM_TIMER:
            switch(wParam)
            {
                case MouseStopTimerID:
                {
                    KillTimer(hwnd, MouseStopTimerID);
                    inst->MouseStoped();
                }
            }
            break;
            case WM_KEYUP:
                inst->KeyUp(lParam,wParam);
			break;
            case WM_KEYDOWN:
                inst->KeyDown(lParam,wParam);
			break;

            default:
			break;
        }

        return oldproc ? CallWindowProc(oldproc, hwnd, msg, wParam, lParam) : DefWindowProc(hwnd, msg, wParam, lParam);
    }
but by some reason i can't change the backcolor and textcolor :(
i even try these: http://www.winprog.org/tutorial/dlgfaq.html
but without sucess :(
please tell me what you know



Moderator: i have found 1 error on these forum... the thread have more than 1 pages, and i have send a big text... but the text was too long, so i recive the error message. until here normal. but why goes to the 1st page and continue with page 2 selected???
for resolve these, i must select the 1st page(because is unselected) and then i click on page 2.
(in these situation, the refresh of the browser don't resolve it)
Last edited on
controls dont RECIVE WM_CTLCOLOR.... messages they SEND them to there parent
not sure i think after they recive a NM_CUSTOMDRAW

i think i was try something similair to you but it wont work out
its easier to make a NEW label control then use the win own
in this way you get no additional control over the control you just ending
whit a big mess
in this case you need to figure out where the "label" holds its color informations
and set it there
now i know why isn't working:
the WM_CTLCOLORDLG or WM_CTLCOLORSTATIC are reciving from main window.
but it's there another message that i can use it?
no

just think on it

what message would that by ?

hi i am your parent window your color is red and stored in address xxxx nice to
contact you bey



Edit

just the label nows its color and where its stored so he cant recive a message whit this info unles from it self wich would by senseless as he already knows
Last edited on
now works fine:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
HBRUSH g_hbrBackground = CreateSolidBrush(NULL_BRUSH);

        switch(msg)
        {
            case WM_CTLCOLORSTATIC:
            {
                HDC hdcStatic = (HDC)wParam;
                SetTextColor(hdcStatic, inst->clrTextColor);
                SetBkMode(hdcStatic, TRANSPARENT);
                SetBkColor(hdcStatic,inst->clrBackColor);
                g_hbrBackground = CreateSolidBrush(inst->clrBackColor);
                return (LONG)g_hbrBackground;
            }
            break;
now have 1 big problem with my class(too big for put the code :().
can i put the window procedure inside the class without use the 'static' keyword? :(
No, if WndProc is member of a class, then it must be a static member.
i'm getting several problems with instances\objects because of that :(
heres the entire class: http://ideone.com/1fQEmp

my problem is only with instances, but the code works(except these one that i'm trying to fix) :(
Topic archived. No new replies allowed.
Pages: 12