V
Vegan Fanatic
Guest
OK so far I have the data printing to the Window OK, so now I would like to support the keyboard to scroll up and down as well as the thumb on the window side and finally the mouse to support the wheel etc.
I am leveraging this project on a tangent as the code will ultimately be useful in a range of projects.
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.titlebar << " " << activelist.r << " by " << activelist.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);
}
Vote if answered or helpful, I am running for Office (joke)! IT/Developer, Windows/Linux/Mainframe
Server: ASRock P4-2GHz, 1.5 GB RAM, Linux Server, need IDE/SATA disks for my chess site
Workstation: Asus M2NBP-VM CSM, Athlon64 X2 4200+ 65W CPU, 2GB RAM, x600, 320GB + 160G backup, Windows 7 Ultimate x64.
Continue reading...
I am leveraging this project on a tangent as the code will ultimately be useful in a range of projects.
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.titlebar << " " << activelist.r << " by " << activelist.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);
}
Vote if answered or helpful, I am running for Office (joke)! IT/Developer, Windows/Linux/Mainframe
Server: ASRock P4-2GHz, 1.5 GB RAM, Linux Server, need IDE/SATA disks for my chess site
Workstation: Asus M2NBP-VM CSM, Athlon64 X2 4200+ 65W CPU, 2GB RAM, x600, 320GB + 160G backup, Windows 7 Ultimate x64.
Continue reading...