dave@wucs1.wustl.edu (David T Mitchell III) (01/11/91)
I'm trying to create a *simple* button control that functions exactly like a BS_PUSHBUTTON with three slight differences: (1) no grey button region; should look (and function with SetText) as if it was a "static" class. (2) text appears in a different color (3) cursor changes when over the control This should look familiar--it's basically what winhelp does for hyper- text stuff. The word is in green and the cursor changes to a finger when over it. (but note that I also want to be able to do enable/disable, SetText/ GetText, etc, just as if it was a BS_PUSHBUTTON or a static). So... Methinks there should be an easy, clever way to do this. Here's what I've been trying: Create a new window class, "mybutton," with: wc.hCursor= LoadCursor(hinst, "handicon"); wc.lpfnWndProc= MyButtonProc; ...Now set up some window subclassing for button by doing: WNDCLASS wc; FARPROC lpfnButton; ... case WM_CREATE: /* in WinMainProc */ GetClassInfo(NULL, "button", &wc) lpfnButton= wc.lpfnWndProc; return 0; ...And MyButtonProc ends with: ... return CallWinProc(lpfnButton, hwnd, message, wParam, lParam); Okay. Suppose MyButtonProc contains nothing but the return statment. I've found that if the resource script contains: CONTROL "test", IDD_TEST, "mybutton", BS_PUSHBUTTON | SS_LEFT | WS_CHILD,... then everything works just like I want it to except, of course, for the grey button area and the text color. But if I change BS_PUSHBUTTON above to BS_USERBUTTON, then the text stuff drops out. If I add the following to MyButtonProc: switch(message) { case WM_SETTEXT: GetClientRect(hwnd, &rect); hdc= GetDC(hwnd); DrawText(hdc, LPSTR(lParam), -1 &rect, DT_SINGLELINE...); ReleaseDC(hwnd, hdc); return 0; ...It seems to work, SOMETIMES. About 1/2 the time I get unrecov app errors when I run it. Can't figure out where the problem lies. Is it that my string area moves? (In the dialog loop I do a SendDlgItemText(hDC, wParam, (LPSTR)szValues[val]); ...where szValues[] is in the dialog module.) Could it be caused by the subclassing calls? I tried making them into thunks with MakeProcInstance, but the examples I've seen just do it the way shown above. Suggestions? Thanks! dave dave@wucs1.wustl.edu