From: New Fieend on
I have been working on an odd on a pop-up killer to deal with the ongoing
problem of annoying pop-up ads.

I am sill working on adding functions in the main even loop.

What I am trying to ad is support scrolling around with the keyboard and the
mouse wheel as well as the thumb tab. Here is the code so far.

LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM
lParam) {
static int cxChar, cxCaps, cyChar, cyClient;
int rowcursor = 0;
int rowheight = 15;
std::string str;
std::stringstream out; // not widely used
HDC hdc;
PAINTSTRUCT ps;
RECT rect;
TEXTMETRIC tm;
BOOL hres;
switch (message) {
case WM_CREATE:
hdc = GetDC(hwnd);
GetTextMetrics(hdc, &tm);
cxChar = tm.tmAveCharWidth;
cxCaps = (tm.tmPitchAndFamily & 1 ? 3 : 2) * cxChar / 2;
cyChar = tm.tmHeight + tm.tmExternalLeading;
ReleaseDC (hwnd, hdc);
// Establish a scroll range for the Window
SetScrollRange (hwnd, SB_VERT, 0, 8192, FALSE);
SetScrollPos (hwnd, SB_VERT, displaycursor, TRUE);
return 0;
case WM_SIZE:
cyClient = HIWORD(lParam);
return 0;
case WM_SETCURSOR: // deal with the thumb tab
// look at WM_SETCURSOR and SetCursor(HCURSOR hCursor);
return 0;
case WM_VSCROLL:
switch (LOWORD (wParam)) {
case SB_TOP:
break;
case SB_BOTTOM:
break;
case SB_LINEUP:
displaycursor -= 1;
break;
case SB_LINEDOWN:
displaycursor += 1;
break;
case SB_PAGEUP:
displaycursor -= cyClient / cyChar;
break;
case SB_PAGEDOWN:
displaycursor += cyClient / cyChar;
break;
case SB_THUMBPOSITION:
displaycursor = HIWORD (wParam);
break;
default:
break;
};
displaycursor = max (0, min (displaycursor, 8192));
if (displaycursor != GetScrollPos (hwnd, SB_VERT)) {
SetScrollPos(hwnd, SB_VERT, displaycursor, TRUE);
InvalidateRect(hwnd, NULL, TRUE);
};
return 0;
case WM_HSCROLL: // not needed yet
return 0;
case WM_USER:
return 0;
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
GetClientRect(hwnd, &rect);
hres = EnumWindows(WNDENUMPROC(insert), NULL);
out << activelist.size(); // need to cast various objects
str = out.str() + " active Window(s)"; // paste together the final string
TextOut(hdc, 0, displaycursor, str.c_str(), int(str.size())); // Display
a string
displaycursor += 2 * rowheight;
out.str("");
for (int i = 0; i < activelist.size()-1; i++) {
out << activelist[i].titlebar << " " << activelist[i].r << " by " <<
activelist[i].c;
str = out.str();
TextOut(hdc, 0, displaycursor, str.c_str(), int(str.size())); // Display
a string
displaycursor += rowheight;
out.str("");
};
EndPaint(hwnd, &ps);
return 0;
case WM_DESTROY:
PostQuitMessage (0);
return 0;
}
return DefWindowProc (hwnd, message, wParam, lParam);
}


--
http://contract-developer.dyndns.biz

From: nico on
New Fieend wrote:
> I have been working on an odd on a pop-up killer to deal with the
> ongoing problem of annoying pop-up ads.
>
> I am sill working on adding functions in the main even loop.
>
> What I am trying to ad is support scrolling around with the keyboard and
> the mouse wheel as well as the thumb tab. Here is the code so far.

For text scrolling, you can see the Petzold's sample : POEPOEM.C
From: Sprechen sie von C++ on
I noticed that code in the book, but I wanted to extend the capability to
support the mouse as well. I am also using the main window as the text out
vehicle while that example uses a second window. Eventually that Window that
is created in WinMAIN will be removed as the program moves to dialogs, the
idea was to generalize a text window for misc projects that supports the
keyboard and mouse.

I was working on moving some code into a class where it is better off to
clean up the main look better. The problem is making the active list
available to a pointer so that the windows calls can use it.

I was even thinking of moving the callback into the class as its accessible
in there fine. This is because the class is compartmental in nature.


--
http://contract-developer.dyndns.biz