I have created a working application with pure win32 APIs and C. It has a shared "status area" on top. Rest of the area displays device information (multiple fields per device).
How do I make the device information area only scrollable?
All my widgets are currently attached to single main window handle. See here the picture about what I want :
There must be a simple way to like group the widgets of bottom page and attach scrollbar to only the group, but I cannot seem to find a working technique with google. I guess my problem is I do not know hot to create groups of widgets or something. Attaching scrollbar to to the full window works fine but I want only partial.
For those interested: I'm using Dev-C 5.11 with TDM-GCC 4.9.2 . I don't have and won't have a resource editor. It is all in C code.
Help!
Edit1: Ok, I believe the correct term I need to search for is "child windows" per
CodePudding user response:
Ok, i reduced the code into a minimum:
CodePudding user response:
you dont need call to ShowWindow
twice, I edited it a bit
#include <windows.h>
#define WIDTH 480
#define HEIGHT 560
#define WC_HELLOW TEXT("HelloApplication")
#define WC_CHILDWINDOW TEXT("ChildWindow")
HWND topHwnd, childHwnd[2];
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK ChildWndProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCMLine, int iCmdShow)
{
WNDCLASS wc;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = sizeof(long);
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(GRAY_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = WC_HELLOW;
RegisterClass(&wc);
wc.lpszClassName = WC_CHILDWINDOW;
wc.lpfnWndProc = ChildWndProc;
wc.hbrBackground = (HBRUSH)GetStockObject(DKGRAY_BRUSH);
RegisterClass(&wc);
int x = (GetSystemMetrics(SM_CXSCREEN) - WIDTH) / 2;
int y = (GetSystemMetrics(SM_CYSCREEN) - HEIGHT) / 2;
topHwnd = CreateWindow(WC_HELLOW,
TEXT("Hello World for Windows"),
WS_OVERLAPPEDWINDOW,
x,
y,
WIDTH,
HEIGHT,
NULL,
NULL,
hInstance,
NULL);
ShowWindow(topHwnd, iCmdShow);
UpdateWindow(topHwnd);
MSG msg;
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
RECT rect;
switch (message)
{
case WM_CREATE: {
HINSTANCE hInst = (HINSTANCE)GetWindowLongPtr(hwnd, GWLP_HINSTANCE);
GetClientRect(hwnd, &rect);
RECT rc[2];
rc[0] = rc[1] = rect;
rc[0].bottom = rc[0].top 100;
rc[1].top = rc[1].top 100;
for (int i = 0; i < 2; i ) InflateRect(&rc[i], -5, -5);
childHwnd[0] = CreateWindow(WC_CHILDWINDOW, "", WS_CHILD | WS_VISIBLE, rc[0].left, rc[0].top, rc[0].right - rc[0].left, rc[0].bottom - rc[0].top, hwnd, 0, hInst, 0);
childHwnd[1] = CreateWindow(WC_CHILDWINDOW, "", WS_CHILD | WS_VISIBLE | WS_VSCROLL,
rc[1].left, rc[1].top, rc[1].right - rc[1].left, rc[1].bottom - rc[1].top, hwnd, 0, hInst, 0);
}break;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, message, wParam, lParam);
}
LRESULT CALLBACK ChildWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
RECT rc;
switch (message) {
case WM_CREATE:
return 0;
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
GetClientRect(hwnd, &rc);
SetBkMode(hdc, TRANSPARENT);
SetTextColor(hdc, RGB(200, 200, 200));
SelectObject(hdc, GetStockObject(DKGRAY_BRUSH));
Rectangle(hdc, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top);
DrawText(hdc, TEXT("Hello, Childs"), -1, &rc,
DT_SINGLELINE | DT_CENTER | DT_VCENTER);
EndPaint(hwnd, &ps);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, message, wParam, lParam);
}
I hope this helps