jo-the-ripper
February 9th, 2007, 03:36 PM
Hi. I have some problems with textout in a progressbar(childwindow). there are some error by the painting. if i deactive the transparant there are no problems. could somebody help me?
#include <Windows.h>
#include <StdIO.h>
#include <commctrl.h>
#pragma comment(lib,"Comctl32.lib")
static PrevWndProcEdit;
int i = 50;
LRESULT CALLBACK EditWndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
HWND hwnd, hText, hwndEditAlt, g_hText;
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE prevInstance,
PSTR szCmdLine, int iCmdShow)
{
InitCommonControls();
static TCHAR szAppName[] = TEXT("Progress Bar");
MSG msg;
WNDCLASS wndclass;
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = 0;
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)COLOR_WINDOW;
wndclass.lpszClassName = szAppName;
wndclass.lpszMenuName = NULL;
RegisterClass(&wndclass);
wndclass.lpfnWndProc = EditWndProc;
RegisterClass(&wndclass);
hwnd = CreateWindowEx(WS_EX_OVERLAPPEDWINDOW,szAppName, TEXT("LeWi-"), WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
350, 300,
NULL, NULL, hInstance, NULL);
ShowWindow(hwnd, iCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.lParam;
}
// Hauptnachrichtenschleife
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
//static HWND hwndEditAlt;
switch (message)
{
case WM_CREATE:
// Editfeld erzeugen
hwndEditAlt = CreateWindowEx(0, PROGRESS_CLASS,
"", WS_CHILD | PBS_SMOOTH | WS_VISIBLE,
10, 20,
300, 20,
hwnd, NULL,
((LPCREATESTRUCT) lParam)->hInstance, NULL);
// Den ursprünglichen WND-PROC Pointer sichern und durch den eigenen ersetzen.
PrevWndProcEdit = SetWindowLong (hwndEditAlt, GWL_WNDPROC, (LONG)EditWndProc);
SendMessage(hwndEditAlt, PBM_SETRANGE, 0, MAKELPARAM(0, 1000));
SendMessage(hwndEditAlt, PBM_SETPOS, 0, 0);
return 0;
case WM_DESTROY:
// Den ursprünglichen Pointer wieder einsetzen
SetWindowLong (hwndEditAlt, GWL_WNDPROC, PrevWndProcEdit);
PostQuitMessage (0);
return 0;
}
return DefWindowProc (hwnd, message, wParam, lParam);
}
// Die neue WND-PROC für das Editfeld
LRESULT CALLBACK EditWndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_CREATE:
{
return 0;
}
case WM_LBUTTONDOWN:
case WM_MOUSEMOVE:
{
if (message == WM_MOUSEMOVE && wParam != MK_LBUTTON)
{
break;
}
InvalidateRect(hwnd, NULL, FALSE);
POINT Cursor = { LOWORD(lParam), HIWORD(lParam) };
RECT Size;
GetClientRect(hwnd, &Size);
SendMessage(hwndEditAlt, PBM_SETPOS, (int)(((float)(Cursor.x+1)) / 300.0f * 1000.0f), 0);
//InvalidateRect(hwnd,NULL,TRUE);
char buff[15];
sprintf(buff, "%.0f", ((float)(Cursor.x+1)) / 300.0f * 100.0f);
HDC hdc = GetDC(hwnd);
SetBkMode(hdc,TRANSPARENT);
TextOut(hdc, 100, 0, buff, strlen(buff));
ReleaseDC(hwnd, hdc);
return 0;
}
}
return CallWindowProc ((WNDPROC) PrevWndProcEdit, hwnd, message, wParam, lParam);
}
#include <Windows.h>
#include <StdIO.h>
#include <commctrl.h>
#pragma comment(lib,"Comctl32.lib")
static PrevWndProcEdit;
int i = 50;
LRESULT CALLBACK EditWndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
HWND hwnd, hText, hwndEditAlt, g_hText;
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE prevInstance,
PSTR szCmdLine, int iCmdShow)
{
InitCommonControls();
static TCHAR szAppName[] = TEXT("Progress Bar");
MSG msg;
WNDCLASS wndclass;
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = 0;
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)COLOR_WINDOW;
wndclass.lpszClassName = szAppName;
wndclass.lpszMenuName = NULL;
RegisterClass(&wndclass);
wndclass.lpfnWndProc = EditWndProc;
RegisterClass(&wndclass);
hwnd = CreateWindowEx(WS_EX_OVERLAPPEDWINDOW,szAppName, TEXT("LeWi-"), WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
350, 300,
NULL, NULL, hInstance, NULL);
ShowWindow(hwnd, iCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.lParam;
}
// Hauptnachrichtenschleife
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
//static HWND hwndEditAlt;
switch (message)
{
case WM_CREATE:
// Editfeld erzeugen
hwndEditAlt = CreateWindowEx(0, PROGRESS_CLASS,
"", WS_CHILD | PBS_SMOOTH | WS_VISIBLE,
10, 20,
300, 20,
hwnd, NULL,
((LPCREATESTRUCT) lParam)->hInstance, NULL);
// Den ursprünglichen WND-PROC Pointer sichern und durch den eigenen ersetzen.
PrevWndProcEdit = SetWindowLong (hwndEditAlt, GWL_WNDPROC, (LONG)EditWndProc);
SendMessage(hwndEditAlt, PBM_SETRANGE, 0, MAKELPARAM(0, 1000));
SendMessage(hwndEditAlt, PBM_SETPOS, 0, 0);
return 0;
case WM_DESTROY:
// Den ursprünglichen Pointer wieder einsetzen
SetWindowLong (hwndEditAlt, GWL_WNDPROC, PrevWndProcEdit);
PostQuitMessage (0);
return 0;
}
return DefWindowProc (hwnd, message, wParam, lParam);
}
// Die neue WND-PROC für das Editfeld
LRESULT CALLBACK EditWndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_CREATE:
{
return 0;
}
case WM_LBUTTONDOWN:
case WM_MOUSEMOVE:
{
if (message == WM_MOUSEMOVE && wParam != MK_LBUTTON)
{
break;
}
InvalidateRect(hwnd, NULL, FALSE);
POINT Cursor = { LOWORD(lParam), HIWORD(lParam) };
RECT Size;
GetClientRect(hwnd, &Size);
SendMessage(hwndEditAlt, PBM_SETPOS, (int)(((float)(Cursor.x+1)) / 300.0f * 1000.0f), 0);
//InvalidateRect(hwnd,NULL,TRUE);
char buff[15];
sprintf(buff, "%.0f", ((float)(Cursor.x+1)) / 300.0f * 100.0f);
HDC hdc = GetDC(hwnd);
SetBkMode(hdc,TRANSPARENT);
TextOut(hdc, 100, 0, buff, strlen(buff));
ReleaseDC(hwnd, hdc);
return 0;
}
}
return CallWindowProc ((WNDPROC) PrevWndProcEdit, hwnd, message, wParam, lParam);
}