You are not logged in. You can browse in the PowerBASIC Community, but you must click Login (top right) before you can post. If this is your first visit, check out the FAQ or Sign Up.
I was using GRAPHIC windows, but in some machines they are REALLY slow, the drawing of "natural" Windows dialogs are much faster. I think it is because Directx... Who knows...
Sorry, I didn't mean to be rude, just thought you didn't know that in PBCC you could use dialogs !
Richard, I'm using console compiler, but I needed an Dialog ! Yes you can use dialogs in PBCC !!! The problem is that you have to deal with Windows API !
Yes, you can ... but I was trying to make sure that is what you were really trying to do. For that matter you can do a "dialog", depending on what is in it, with PB's GRAPHICS in a subclassed GW. Many examples since 8.0 was released years ago. and with 9.0 much easier.
Richard, I'm using console compiler, but I needed an Dialog ! Yes you can use dialogs in PBCC !!! The problem is that you have to deal with Windows API !
It worked ok, with some minors adaptations in Jerry's code, because I had the dialog created in a resource file, not by code.
After all, the only thing I had to do is create the brush to use in the callback.
This is wrong, you can only return a HBRUSH (brush handle) from the WM_CTLCOLORXX functions. If you need a fixed, non-system color, then create the brush with CreateSolidBrush() in somewhere like WM_INITDIALOG and save the handle in a STATIC variable, then you can return this handle in WM_CTLCOLORSTATIC. The brush can be deleted in WM_DESTROY or wherever you are done with it.
If you need to use a system color, it's very simple: just use GetSysColorBrush().
I don't know if this is what you are looking for, but here's an example generated by Jaxgui that should work in PBCC.
Code:
#CONSOLE OFF ' Delete if using older than PBCC4.03
#COMPILE EXE
#DIM ALL
#INCLUDE "C:\PBCC40\WINAPI\WIN32API.INC"
GLOBAL hInstance, hwnd AS LONG
FUNCTION ProcessWindow (BYVAL hDlg AS DWORD, BYVAL wMsg AS DWORD, BYVAL wParam _
AS DWORD, BYVAL lParam AS LONG) AS LONG
STATIC hStBrush1 AS LONG
LOCAL wmID AS LONG, wmEvent AS LONG
LOCAL ps AS PAINTSTRUCT
LOCAL BrushClr AS LONG
LOCAL hDC, hBrush, hPen AS DWORD
LOCAL StBgColor1 AS LONG, StFgColor1 AS LONG
LOCAL Lt1 AS STRING
STbgColor1 = &H0000FF ' Selected background color for a Static control
STfgColor1 = &H80FFFF ' Selected foreground color for a Static control
SELECT CASE wMSG
CASE %WM_CREATE 'Create and initialize Controls
hSTbrush1 = CreateSolidBrush(STbgColor1)' Create a logical brush with selected color for a Static/Label control
Lt1=Lt1 + "Now is the time for all good"
CreateWindowEx(0, "static", BYVAL STRPTR( LT1 ), _
%WS_CHILD OR %WS_VISIBLE, _
80, 76, 290, 171, _
hdlg, 1001, hInstance, BYVAL %NULL)
SetWindowPos hDlg, %HWND_TOP, 0, 0, 0, 0, %SWP_NoSize OR %SWP_NoMove
CASE %WM_CTLCOLORSTATIC
IF GetDlgCtrlId(lParam) = 1001 THEN ' Check for Static controls ID number
SetTextColor Wparam, STfgColor1 ' Set the foreground colors for a Static control
SetBkColor Wparam, STbgColor1 ' Set the background colors for a Static control
ProcessWindow = hStBrush1 : EXIT FUNCTION ' Apply the colors for a Static control
END IF
CASE %WM_DESTROY
DeleteObject hStBrush1 ' Frees all system resources associated with this brush
CASE %WM_PAINT ' dialog is to be redrawn
BeginPaint hDlg, ps ' get device context to draw in
BrushClr = &H0000FF
hPen = CreatePen(0, 1, BrushClr) ' Want border? chg BrushClr here
hPen = SelectObject(ps.hDC, hPen) ' select it into given dc
hBrush = CreateSolidBrush(BrushClr)
hBrush = SelectObject(ps.hDC, hBrush)
Rectangle ps.hDC, 0, 0, 451, 330
DeleteObject SelectObject(hDC, hPen)
DeleteObject SelectObject(hDC, hBrush)
EndPaint hDlg, ps
CASE %WM_CLOSE ' Message from Clicking on system close Icon
PostQuitMessage 0
END SELECT
ProcessWindow = DefWindowProc(hdlg, wMsg, wParam, lParam)
END FUNCTION
FUNCTION WINMAIN (BYVAL hInstance AS LONG, _
BYVAL hPrevInstance AS LONG, _
BYVAL szCmdLine AS ASCIIZ PTR, _
BYVAL iCmdShow AS LONG) AS LONG
LOCAL wMsg AS tagMsg, hMenu AS LONG
LOCAL WindClass AS wndclassex
DIM szpgmname AS ASCIIZ * 20, STYLE AS LONG
'ShowWindow CONSHNDL, %SW_Hide ' Use for older PBCC
szpgmname = "SDK Samples"
windclass.cbSize = SIZEOF(windclass)
windclass.lpfnWndProc = CODEPTR(ProcessWindow) 'point to callback
windclass.hInstance = hInstance
windclass.hIcon = LoadIcon( hInstance, "MAINICON" )
windclass.hCursor = LoadCursor( %NULL, BYVAL %IDC_ARROW )
windclass.hbrBackground = %COLOR_3DFACE + 1
windclass.lpszClassName = VARPTR(szpgmname)
RegisterClassEX windclass
STYLE = %WS_VISIBLE OR %WS_OVERLAPPEDWINDOW OR %WS_CLIPCHILDREN
CreateWindowEx(0, szpgmname, "JaxGUI Example", _
STYLE, 200, 114, 459, 355, _
%HWND_DESKTOP, hMenu, hInstance, BYVAL %NULL)
ShowWindow hWnd, iCmdShow
UpdateWindow hWnd
WHILE (GetMessage(wMsg, %NULL, 0, 0) <> %false )
IF IsDialogMessage(hWnd, wMsg) = %FALSE THEN 'For TabKey, Comment out if using WM_KEYDOWN
TranslateMessage wMsg
DispatchMessage wMsg
END IF 'For TabKey, Comment out if using WM_KEYDOWN
WEND
WINMAIN = wMsg.wParam
END FUNCTION
Anyone could help me ?
I created a dialog using ResEdit/RC. I've managed to change the text and font of the created static controls in it, ie. labels, but I'm having difficulties
in changing the color of them.
I know that I have to use the API functions "SetBkColor" and "SetTextColor", but I do not know how to use them.
Code:
LOCAL hFont AS LONG ' Handle for font
LOCAL hControl AS LONG ' Handle for control
LOCAL hWnd AS LONG ' Handle for window
LOCAL hDC AS DWORD ' Handle for device context
LOCAL szText AS ASCIIZ * 50
.
.
.
' Changing font... Works fine !
hFont = PBFormsMakeFont("Courier", 9, %FW_EXTRABOLD, %FALSE, %FALSE, %FALSE, %DEFAULT_CHARSET)
SendMessage hControl, %WM_SETFONT, hFont, 0&
' Changing caption... Works fine !
szText = "Test"
SetWindowText(hControl, szText)
' What I'm trying... Didn't work completely right !...
' This is the code of my callback procedure
SELECT CASE wMsg
CASE %WM_CTLCOLORSTATIC
SELECT CASE GetDlgCtrlId(lParam)
CASE %IDC_VISOR5
SetBkColor wParam, %RED
SetTextColor wParam, %WHITE
SetBkMode wParam, %OPAQUE
' The objective is to change the background in the hole control to RED ! Now I'm getting only the text to the colors I needed. Not the hole background !
' Don't know which object to use ! Tried BLACK_PEN, BLACK_BRUSH, DC_BRUSH, DC_PEN, neither one worked as I expected.
FUNCTION = GetStockObject(%WHITE_PEN)
EXIT FUNCTION
END SELECT
.
.
.
Anyone could point me in the right direction ?
Thanks !
We process personal data about users of our site, through the use of cookies and other technologies, to deliver our services, and to analyze site activity. For additional details, refer to our Privacy Policy.
By clicking "I AGREE" below, you agree to our Privacy Policy and our personal data processing and cookie practices as described therein. You also acknowledge that this forum may be hosted outside your country and you consent to the collection, storage, and processing of your data in the country where this forum is hosted.
Leave a comment: