AutoHotkey Community

It is currently May 27th, 2012, 1:23 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 20 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Help, please?
PostPosted: February 1st, 2011, 12:08 pm 
Offline

Joined: December 17th, 2010, 5:44 am
Posts: 8
Location: Missouri, United States
No suggestions?

I realize this is pretty complex stuff, esp. since it involves DllCall.
But I suspect the problem I have with calling this function twice (it lags badly and nearly times out) is most likely a simple oversight on my part.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 7th, 2011, 5:00 am 
Offline

Joined: December 17th, 2010, 5:44 am
Posts: 8
Location: Missouri, United States
Over a week now and this thread gets buried under other threads.
:( Can anybody help? Please?

Edit:
I finally figured some basics of how DllCall works. And a Goggle search for "SetBkColor" lead me here: MSDN Library After a couple hours of trying to interpret some things on the MSDN Library (a lot of which is over my head) I figured that I needed to add a SetTextColor function.

A bit of trial and error later and I got this code to change the background and foreground colors!
Code:
; Example: The following is a working script that demonstrates how to subclass a GUI window by
; redirecting its WindowProc to a new WindowProc in the script. In this case, the background
; color and foreground color of a text control is changed to specified custom colors.

TextBackgroundColor := 0xFFBBBB  ; A custom color in BGR format.
TextForegroundColor := 0x0000FF  ; A custom color in BGR format.
TextBackgroundBrush := DllCall("CreateSolidBrush", UInt, TextBackgroundColor)

Gui, Add, Text, HwndMyTextHwnd, Here is some text that is given`na custom background color
    ,`nand a custom foreground color.
Gui +LastFound
GuiHwnd := WinExist()

WindowProcNew := RegisterCallback("WindowProc", ""  ; Specifies "" to avoid fast-mode for subclassing.
    , 4, MyTextHwnd)  ; Must specify exact ParamCount when EventInfo parameter is present.
WindowProcOld := DllCall("SetWindowLong", UInt, GuiHwnd, Int, -4  ; -4 is GWL_WNDPROC
    , Int, WindowProcNew, UInt)  ; Return value must be set to UInt vs. Int.

Gui Show
return

WindowProc(hwnd, uMsg, wParam, lParam)
{
    Critical
    global TextBackgroundColor, TextBackgroundBrush, WindowProcOld, TextForegroundColor
    if (uMsg = 0x138 && lParam = A_EventInfo)  ; 0x138 is WM_CTLCOLORSTATIC.
    {
        DllCall("SetBkColor", UInt, wParam, UInt, TextBackgroundColor)
        DllCall("SetTextColor", UInt, wParam, UInt, TextForegroundColor)
        return TextBackgroundBrush  ; Return the HBRUSH to notify the OS that we altered the HDC.
    }
    ; Otherwise (since above didn't return), pass all unhandled events to the original WindowProc.
    return DllCall("CallWindowProcA", UInt, WindowProcOld, UInt, hwnd, UInt, uMsg, UInt, wParam, UInt, lParam)
}

GuiClose:
ExitApp

So, I managed to solve one of my problems. But I still can't figured out how to change the background & foreground text on more than one line of text by calling this function more than once. Doing so still locks up the script.

Could my problem be that the original script left out something important?

This article on CreateSolidBrush says that:
Quote:
After it is finished using the brush, the program should use DeleteObject to delete the brush and free up system resources.

And this article says something similar.

I'm afraid that if I want to use this more than once, I might need to rewrite the script to replace the use of CreateSolidBrush with something else. I suspect I may end up having to use the ExtTextOut function instead. Unfortunately, defining the font to use must be unnecessarily complicated because I can't figure that out.

I wonder if this Multicolor Text Strings with Managed Code article on a C# program could help with that?


Report this post
Top
 Profile  
Reply with quote  
PostPosted: February 10th, 2011, 11:36 pm 
Offline

Joined: December 17th, 2010, 5:44 am
Posts: 8
Location: Missouri, United States
Hmm... Nobody with the knowledge to help me has read this thread yet?

Anyway, I've been experimenting around with variations to see if I can get this background/forground text color change script to process more than one line of text.

First, I tried to have the code called in a subroutine:
Code:
Gui, Add, Text, HwndMyTextHwnd, Here is some text that is given`na custom background color

Gosub ColorMe

Gui, Add, Text, HwndMyTextHwnd, and a custom foreground color.

Gosub ColorMe

Gui Show
return


ColorMe:
Gui +LastFound
GuiHwnd := WinExist()

TextBackgroundColor := 0xFFFFFF  ; A custom color in BGR format.
TextForegroundColor := 0x0000FF  ; A custom color in BGR format.
TextBackgroundBrush := DllCall("CreateSolidBrush", UInt, TextBackgroundColor)

WindowProcNew := RegisterCallback("WindowProc", ""  ; Specifies "" to avoid fast-mode for subclassing.
    , 4, MyTextHwnd)  ; Must specify exact ParamCount when EventInfo parameter is present.
WindowProcOld := DllCall("SetWindowLong", UInt, GuiHwnd, Int, -4  ; -4 is GWL_WNDPROC
    , Int, WindowProcNew, UInt)  ; Return value must be set to UInt vs. Int.

return


WindowProc(hwnd, uMsg, wParam, lParam)
{
    Critical
    global TextBackgroundColor, TextBackgroundBrush, WindowProcOld, TextForegroundColor
    if (uMsg = 0x138 && lParam = A_EventInfo)  ; 0x138 is WM_CTLCOLORSTATIC.
    {
        DllCall("SetBkColor", UInt, wParam, UInt, TextBackgroundColor)
        DllCall("SetTextColor", UInt, wParam, UInt, TextForegroundColor)
        return TextBackgroundBrush  ; Return the HBRUSH to notify the OS that we altered the HDC.
    }
    ; Otherwise (since above didn't return), pass all unhandled events to the original WindowProc.
    return DllCall("CallWindowProcA", UInt, WindowProcOld, UInt, hwnd, UInt, uMsg, UInt, wParam, UInt, lParam)
}

GuiClose:
ExitApp

That was another failure. It still locked up.

Then I tried a variation where part of the code was rewritten so it was not an exact duplicate. (Changed the variable and fuction names slightly.)
Code:
TextBackgroundColor := 0xFFBBBB  ; A custom color in BGR format.
TextForegroundColor := 0x0000FF  ; A custom color in BGR format.
TextBackgroundBrush := DllCall("CreateSolidBrush", UInt, TextBackgroundColor)

Gui, Add, Text, HwndMyTextHwnd, Here is some text that is given`na custom background color

Gui +LastFound
GuiHwnd := WinExist()

WindowProcNew := RegisterCallback("WindowProc", ""  ; Specifies "" to avoid fast-mode for subclassing.
    , 4, MyTextHwnd)  ; Must specify exact ParamCount when EventInfo parameter is present.
WindowProcOld := DllCall("SetWindowLong", UInt, GuiHwnd, Int, -4  ; -4 is GWL_WNDPROC
    , Int, WindowProcNew, UInt)  ; Return value must be set to UInt vs. Int.

Gui, Add, Text, HwndAddedTextHwnd, and a custom foreground color.

Gui +LastFound
GuiHwnd_more := WinExist()

WindowProcNew_more := RegisterCallback("WindowProc", ""  ; Specifies "" to avoid fast-mode for subclassing.
    , 4, AddedTextHwnd)  ; Must specify exact ParamCount when EventInfo parameter is present.
WindowProcOld := DllCall("SetWindowLong", UInt, GuiHwnd_more, Int, -4  ; -4 is GWL_WNDPROC
    , Int, WindowProcNew_more, UInt)  ; Return value must be set to UInt vs. Int.

Gui Show
return

WindowProc(hwnd, uMsg, wParam, lParam)
{
    Critical
    global TextBackgroundColor, TextBackgroundBrush, WindowProcOld, TextForegroundColor
    if (uMsg = 0x138 && lParam = A_EventInfo)  ; 0x138 is WM_CTLCOLORSTATIC.
    {
        DllCall("SetBkColor", UInt, wParam, UInt, TextBackgroundColor)
        DllCall("SetTextColor", UInt, wParam, UInt, TextForegroundColor)
        return TextBackgroundBrush  ; Return the HBRUSH to notify the OS that we altered the HDC.
    }
    ; Otherwise (since above didn't return), pass all unhandled events to the original WindowProc.
    return DllCall("CallWindowProcA", UInt, WindowProcOld, UInt, hwnd, UInt, uMsg, UInt, wParam, UInt, lParam)
}

GuiClose:
ExitApp

Nope. Another failure, another lock-up.
I'm running out of ideas here. And I really wanted to finish my project...


Report this post
Top
 Profile  
Reply with quote  
PostPosted: May 24th, 2012, 4:04 am 
Offline

Joined: February 6th, 2012, 9:57 am
Posts: 26
Um.. Is this to hard
Code:
Gui, Color, , Red
Gui, Add, Edit, w300 -Background
Gui, Add, Edit, w300
Gui, Show


Report this post
Top
 Profile  
Reply with quote  
PostPosted: May 24th, 2012, 8:26 am 
Offline
User avatar

Joined: September 5th, 2009, 2:06 pm
Posts: 1718
Location: Somewhere near you
Actually, what are you trying to achieve? If you provide a screenshot of what you're trying to achieve, it will be easier for us to understand.

_________________
Image
The quick onyx goblin jumps over the lazy dwarf


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 20 posts ]  Go to page Previous  1, 2

All times are UTC [ DST ]


Who is online

Users browsing this forum: BrandonHotkey, oldbrother and 17 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group