🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #3990

Re: Length of text in MessageBox function

#3990
From: Richard Casten
Date: Wed, 29 Mar 2006 22:53
73 lines
3560 bytes
"Remy Lebeau (TeamB)" wrote:

> A better approach would be to resize both the "Dialog" itself and the
> "Static" window when it is created to accomodate the added size of your
> asterik.  Then use SetWindowLong() to subclass the "Static" window's message
> procedure (or use a second hook) to do your asterik drawing only when the
> WM_PAINT message is actually received, after passing the WM_PAINT message to
> the default handler.

I've tried your suggestion (assuming I've done it right) with the following
code, but I still do not get the second line of the message.  Note:  the window
will be the right height (I've checked) because of the "\n " at the end of the
first line string.

#include <windows.h>
LRESULT CALLBACK (*old_window_proc)(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM
lParam);
LRESULT CALLBACK new_window_proc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM
lParam);

LRESULT CALLBACK hook_proc(int nCode, WPARAM wParam, LPARAM lParam);
int main(int argc, char **argv)
{
     HHOOK hook;

     hook = SetWindowsHookEx(WH_CBT,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)
{
     char class_name[100];
     HWND hwnd;

     if(nCode < 0)
          return(CallNextHookEx(NULL,nCode,wParam,lParam));

     if(nCode == HCBT_CREATEWND)
     {
          hwnd = (HWND)wParam;
          GetClassName(hwnd,class_name,sizeof(class_name));
          if(stricmp(class_name,"Static") == 0)
               old_window_proc = (WNDPROC)SetWindowLong(hwnd,GWL_WNDPROC,
                                                       (LONG)new_window_proc);
     }

     return(CallNextHookEx(NULL,nCode,wParam,lParam));
}
LRESULT CALLBACK new_window_proc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM
lParam)
{
     char *second_line = "Second line of error";
     RECT rect;
     HDC hdc;

     if(uMsg == WM_PAINT)
     {
          CallWindowProc(old_window_proc,hwnd,uMsg,wParam,lParam);
          hdc = GetDC(hwnd);

          GetWindowRect(hwnd,&rect);
          DrawText(hdc,second_line,strlen(second_line),&rect,
                   DT_SINGLELINE | DT_BOTTOM);

          ReleaseDC(hwnd,hdc);
          SetWindowLong(hwnd,GWL_WNDPROC,(LONG)old_window_proc);
          return(0);
     }

     return(CallWindowProc(old_window_proc,hwnd,uMsg,wParam,lParam));
}
Technical Details
Message-ID: <442B0FD5.F2E84D5D@aero.org>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <4422D533.32E31292@aero.org> <4422ea15$1@newsgroups.borland.com> <4422FA56.83B7F39@aero.org> <442319ab@newsgroups.borland.com> <442ADEA7.B11F561C@aero.org> <442af3e1$1@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: <442B0FD5.F2E84D5D@aero.org>
Date: Wed, 29 Mar 2006 14:53:09 -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> <442ADEA7.B11F561C@aero.org> <442af3e1$1@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 1143672686 130.221.27.185 (29 Mar 2006 14:51:26 -0700)
Lines: 76
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail