Button class problem

Can you please help me find problem in my code?
ti works fine until sends message to parent window.
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
 HANDLE CALLBACK GetScreenshot(RECT rc)
{
           HDC Screens;
           HDC ScreensMemory;
           HANDLE Screenshots;
           HANDLE ScreenOld;
           Screens = CreateDC("DISPLAY", NULL, NULL, NULL);     
           ScreensMemory = CreateCompatibleDC(Screens);
           Screenshots = CreateCompatibleBitmap(Screens, rc.right, rc.bottom);

           ScreenOld = SelectObject(ScreensMemory, Screenshots);
           BitBlt(ScreensMemory, -rc.left, -rc.top, rc.right, rc.bottom, Screens, 0, 0, SRCCOPY);
           Screenshots = SelectObject(ScreensMemory, ScreenOld);
           DeleteDC(Screens);
           DeleteDC(ScreensMemory);
           return Screenshots;
}
LRESULT APIENTRY PogasProc(HWND,UINT,WPARAM,LPARAM);
int  PogaReg()
{
     HWND hwnd;
	WNDCLASS Poga;
	HINSTANCE hInst = GetModuleHandle(NULL);
	ZeroMemory( &Poga , sizeof(Poga));
    Poga.hInstance = hInst;
    Poga.lpszClassName = "Poga";
    Poga.lpfnWndProc = PogasProc;
    Poga.style = CS_HREDRAW | CS_OWNDC | CS_VREDRAW;
    Poga.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    Poga.hCursor = LoadCursor (NULL, IDC_ARROW);
    Poga.lpszMenuName = NULL;
    Poga.cbClsExtra = 0;
    Poga.cbWndExtra = 20;
    Poga.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
    
	if (!RegisterClass (&Poga))
        {MessageBox(0,"Neizdodas Registret klasi","Poga",0);}
        return 1;
}
enum{SIZ_X,SIZ_Y};
HBITMAP TaisitMasku(HANDLE Bilde, HDC hdc)
{
    HDC hdcTempMem, hdcTempMem2;
    HBITMAP Maska;
    BITMAP bm;
    COLORREF FonKrasa;
    int BmSizX, BmSizY;
    BmSizX = GetBmpSize(Bilde, SIZ_X);
    BmSizY = GetBmpSize(Bilde, SIZ_Y);
    Maska = CreateBitmap(BmSizX, BmSizY, 1, 1, NULL);

    hdcTempMem = CreateCompatibleDC(hdc);
    hdcTempMem2 = CreateCompatibleDC(0);
    SelectObject(hdcTempMem, Bilde);
    SelectObject(hdcTempMem2, Maska);
    FonKrasa = GetPixel(hdcTempMem, 1, 1);
    SetBkColor(hdcTempMem, FonKrasa);
    BitBlt(hdcTempMem2, 0, 0, BmSizX, BmSizY, hdcTempMem, 0, 0, SRCCOPY);
    BitBlt(hdcTempMem, 0, 0, BmSizX, BmSizY, hdcTempMem2, 0, 0, SRCINVERT);

    DeleteDC(hdcTempMem);
    DeleteDC(hdcTempMem2);
    DeleteObject(SelectObject(hdcTempMem, Bilde));
    DeleteObject(SelectObject(hdcTempMem2, Maska));
    return Maska;
}
enum{POGA_NORM, POGA_OWER, POGA_PUSH, SET_TEXTCOL};
int zimetPogu(HANDLE Fons, char texts[12],HANDLE skriins, int PosX, int PosY, HWND hwnd, HFONT TextFont, COLORREF TextCol)
{
               HDC hdc;
               hdc = GetDC(hwnd);
               HDC hdcMemory;
               HANDLE maska, MaskaOver;
               hdcMemory = CreateCompatibleDC(hdc);
               RECT rc;
               RECT rect;
               SetRect(&rect, 0, 0 , GetBmpSize(skriins, SIZ_X),GetBmpSize(skriins, SIZ_Y));
               SetRect(&rc, PosX, PosY, PosX +GetBmpSize(Fons, SIZ_X), PosY+GetBmpSize(Fons, SIZ_Y));
               maska = TaisitMasku(Fons, hdc);
               //FillRect(hdc, &rect, (HBRUSH) GetStockObject(BLACK_BRUSH));
               SelectObject(hdcMemory, skriins);
               BitBlt(hdc, 0, 0, GetBmpSize(skriins, SIZ_X), GetBmpSize(skriins,SIZ_Y), hdcMemory, 0, 0, SRCPAINT);
               SelectObject(hdcMemory, maska);
               BitBlt(hdc, PosX, PosY, GetBmpSize(Fons, SIZ_X),GetBmpSize(Fons, SIZ_Y), hdcMemory, 0, 0, SRCAND);
               SelectObject(hdcMemory, Fons);
               BitBlt(hdc, PosX, PosY, GetBmpSize(Fons, SIZ_X),GetBmpSize(Fons, SIZ_Y), hdcMemory, 0, 0, SRCPAINT);
               SelectObject(hdc, TextFont);
               SetBkMode(hdc, TRANSPARENT);
               SetTextColor(hdc, TextCol);
               DrawText (hdc, texts, -1, &rc,DT_SINGLELINE | DT_CENTER | DT_VCENTER);

               DeleteObject(SelectObject(hdcMemory, maska));
               DeleteObject(SelectObject(hdcMemory, Fons));
               DeleteObject(SelectObject(hdcMemory, skriins));
               DeleteDC(hdcMemory);
               ReleaseDC(hwnd, hdc);
}

enum{PG_NORMAL,PG_OVER,PG_PRESSED, PG_FIRSTS};
enum{SET_BILDE,SET_CURSOR};
LRESULT APIENTRY PogasProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
        int Statuss;
        POINT pt;
	switch(msg)
	{
	case STM_SETIMAGE:
         if(wParam == SET_BILDE)
         SetWindowLong(hwnd, 0, lParam);
         if(wParam == SET_TEXTCOL)
         SetWindowLong(hwnd, 4, lParam);
         break;
    case WM_CREATE:
         //SetWindowLong(hwnd, 12, PG_FIRSTS);
         SetWindowLong(hwnd, 16, (LONG) GetMenu(hwnd));
         break;
    case WM_CLOSE:
         break;
    case WM_PAINT:
               HANDLE Fons;
               HDC hdc, HdcMemory;
               COLORREF FonaKr;
               static HFONT TextFont;
               hdc = GetDC(hwnd);
               HANDLE screens;
               RECT rc;
               RECT rect;
               PAINTSTRUCT ps;
               int Statuss;
               GetWindowRect(hwnd, &rect);
               FonaKr = GetWindowLong(hwnd, 4);
               GetClientRect(hwnd, &rc);
               screens = GetScreenshot(rect);
               char Texts[8];
               Fons = LoadBitmap(GetModuleHandle(NULL),MAKEINTRESOURCE(GetWindowLong(hwnd, 0)));
               TextFont=CreateFont(26,0,0,0,FW_BLACK,FALSE,FALSE,FALSE,DEFAULT_CHARSET,OUT_OUTLINE_PRECIS,CLIP_DEFAULT_PRECIS,ANTIALIASED_QUALITY, FF_DECORATIVE,TEXT("Courier New"));
               GetWindowText(hwnd, Texts,10);
               hdc = BeginPaint (hwnd, &ps);
               Statuss = GetWindowLong(hwnd,12);
               switch(Statuss)
               {
                              case PG_NORMAL:
                                   FillRect(hdc, &rc, (HBRUSH)GetStockObject(BLACK_BRUSH));
                            zimetPogu(Fons, Texts, screens, 0, 0, hwnd,TextFont,FonaKr);
                                   break;
                              case PG_OVER:
                                   FillRect(hdc, &rc, (HBRUSH) GetStockObject(BLACK_BRUSH));
                                   zimetPogu(Fons, Texts, screens, -1, -1, hwnd, TextFont, FonaKr);
                                   break;
                              case PG_PRESSED:
                                   FillRect(hdc, &rc, (HBRUSH) GetStockObject(BLACK_BRUSH));
                                   zimetPogu(Fons, Texts, screens, 1, 1, hwnd, TextFont, FonaKr);
                                   break;
               }
               EndPaint (hwnd, &ps);
               DeleteDC(hdc);
               DeleteDC(HdcMemory);
    break;
	case WM_LBUTTONDOWN:
         {
         SetWindowLong(hwnd, 12, PG_PRESSED);
         InvalidateRect(hwnd,NULL,0);
         }
		break;
	case WM_SETCURSOR:
         if(wParam == SET_CURSOR)
         SetCursor(LoadCursor(GetModuleHandle(NULL),MAKEINTRESOURCE(lParam)));
         break;
    case WM_LBUTTONUP:
         Statuss = GetWindowLong(hwnd,12);
         GetCursorPos(&pt);
         if(Statuss == PG_PRESSED && PtInWin(pt, hwnd) == true)
         {
              SendMessage(GetParent(hwnd), WM_COMMAND, GetWindowLong(hwnd, 16),0);
              SetWindowLong(hwnd, 12, PG_OVER);
              InvalidateRect(hwnd,NULL,0);
         }
         else if(Statuss != PG_NORMAL)
         {
              SetWindowLong(hwnd, 12, PG_NORMAL);          
              InvalidateRect(hwnd,NULL,0);
         }
        break;
    case WM_MOUSEMOVE:
         GetCursorPos(&pt);
         Statuss = GetWindowLong(hwnd,12);
         if(PtInWin(pt, hwnd) == true && Statuss != PG_OVER && Statuss != PG_PRESSED)
         {
                     SetWindowLong(hwnd, 12, PG_OVER);
                     InvalidateRect(hwnd,NULL,0);
                     SetCapture(hwnd);
         }
         else if(PtInWin(pt, hwnd) != true && Statuss != PG_NORMAL)
         {
              ReleaseCapture();
              SetWindowLong(hwnd, 12, PG_NORMAL);
              InvalidateRect(hwnd,NULL,0);
         }
        break;
    default: return DefWindowProc(hwnd,msg,wParam,lParam);
	}
	return 0;
} 

problem is- when i call OpenFileDialog
it returns 0 value without calling load bmp.
if i use window "BUTTON" class it works without problems!
P.s. - sry for poasting all code. i simply dont cnow where the problem comees from.
Last edited on
Topic archived. No new replies allowed.