Article View: borland.public.cppbuilder.nativeapi
Article #3988Re: Length of text in MessageBox function
From: Richard Casten
Date: Wed, 29 Mar 2006 19:23
Date: Wed, 29 Mar 2006 19:23
59 lines
2903 bytes
2903 bytes
"Remy Lebeau (TeamB)" wrote:
> "Richard Casten" <richard.casten@aero.org> wrote in message
> news:4422FA56.83B7F39@aero.org...
>
> > How would I know what is the specific HWND of the text field?
>
> The class name of the text window is "Static".
Thanks Remy. I am calling the SetWindowsHookEx function with idHook parameter
equal to WH_CALLWNDPROC right before I call MessageBox. In the hook function, I
test for the window having class name "Static". I am then trying to use the
DrawText function inside the hook function to draw a string. It is never
drawn. Is there a problem in using the DrawText function inside the hook
function?
This is the sample code: Only the input string to the MessageBox is drawn.
#include <windows.h>
LRESULT CALLBACK hook_proc(int nCode, WPARAM wParam, LPARAM lParam);
int main(int argc, char **argv)
{
HHOOK hook;
hook = SetWindowsHookEx(WH_CALLWNDPROC,hook_proc,NULL,
GetCurrentThreadId());
MessageBox(NULL,"First line of error\n","Error",MB_OK);
UnhookWindowsHookEx(hook);
return(0);
}
LRESULT CALLBACK hook_proc(int nCode, WPARAM wParam, LPARAM lParam)
{
CWPSTRUCT *p;
char class_name[100];
HDC hdc;
RECT rect;
static char first=1;
char *second_line = "Second line of error";
if(nCode < 0)
return(CallNextHookEx(NULL,nCode,wParam,lParam));
p = (CWPSTRUCT *)lParam;
GetClassName(p->hwnd,class_name,sizeof(class_name));
if(first && stricmp(class_name,"Static") == 0)
{
hdc = GetDC(p->hwnd);
GetWindowRect(p->hwnd,&rect);
DrawText(hdc,second_line,strlen(second_line),&rect,
DT_SINGLELINE | DT_BOTTOM);
first = 0;
ReleaseDC(p->hwnd,hdc);
}
return(CallNextHookEx(NULL,nCode,wParam,lParam));
}
Technical Details
Message-ID:
<442ADEA7.B11F561C@aero.org>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newspeer1.nwr.nac.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<4422D533.32E31292@aero.org> <4422ea15$1@newsgroups.borland.com> <4422FA56.83B7F39@aero.org> <442319ab@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,b8d4aea1a094904b X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit Message-ID: <442ADEA7.B11F561C@aero.org> Date: Wed, 29 Mar 2006 11:23:19 -0800 From: Richard Casten <richard.casten@aero.org> X-Mailer: Mozilla 4.75 [en] (Windows NT 5.0; U) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: borland.public.cppbuilder.nativeapi Subject: Re: Length of text in MessageBox function References: <4422D533.32E31292@aero.org> <4422ea15$1@newsgroups.borland.com> <4422FA56.83B7F39@aero.org> <442319ab@newsgroups.borland.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 130.221.27.185 X-Trace: newsgroups.borland.com 1143660096 130.221.27.185 (29 Mar 2006 11:21:36 -0700) Lines: 62 Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newspeer1.nwr.nac.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail