🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Child Window Edit Control Problem

#16529
From: Bill Carson
Date: Mon, 12 May 2003 19:40
52 lines
3100 bytes
I can't get the text to display in a child window
edit control, unless I click on either the vertical
scroll bar or a parent window menu item first.

I'm currently learning to program with Win32 API,
and have been trying to get a small program to
open a file and display it's contents in a child
window edit control. I've basically taken Petzold's
Poppad example and altered it for my purposes. The
main change I have made to his example is that I create
the child window edit control as invisible, then by menu
command I open and read in text from a file, use ShowWindow
to make the child control visible, then either SetWindowText,
or send a WM_SETTEXT message to the control to display the
text. The guts of the code follows:

case WM_COMMAND:
  switch(LOWORD(wParam))
  {
  case FILE_OPEN:
    OfnInit(hwnd); // initialize OPENFILENAME structure, display open
dialog
    hDemFile = CreateFile(ofn.lpstrFile, GENERIC_READ, 0, NULL,
OPEN_EXISTING,  FILE_ATTRIBUTE_NORMAL, NULL);
    iFileSize = GetFileSize(hDemFile, NULL);
    pFileBuffer = malloc(iFileSize + 2);
    ReadFile(hDemFile, pFileBuffer, iFileSize, &dwBytesRead, NULL);
    CloseHandle(hDemFile);
    pFileBuffer[iFileSize] = '\0';
    pFileBuffer[iFileSize + 1] = '\0';
    pText = pFileBuffer;
    pConv = malloc(2 * iFileSize + 2);
    lstrcpy((PTSTR) pConv, (PTSTR) pText); // copy file buffer into
text buffer
    ShowWindow(hwndView, SW_SHOW); // show child window edit control
//      SendMessage(hwndView, WM_SETTEXT, 0, (LPARAM) pConv);
    SetWindowText(hwndView, (PTSTR) pConv);
  break;

All the examples I've been able to find usually make the child window
visible first before putting text in the control, so I assume that
the problem is because I have made the control invisible to begin
with.
The problem, as stated above, is the same whether I send a message or
use SetWindowText. I suspect that the act of putting text in a control
does not automatically change the focus to that control.  But I have a
lot yet to learn about the Win32 API, so any suggestions would be most
appreciated.

Thanks,

Bill
Technical Details
Message-ID: <3ebff8a8@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-01!sn-xit-08!supernews.com!216.166.71.118.MISMATCH!small1.nntp.aus1.giganews.com!border1.nntp.aus1.giganews.com!nntp.giganews.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,575e875ad3e11327,start
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2003-05-12 12:41:24 PST
From: "Bill Carson" <bcarson892003atyahoodotcom>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Child Window Edit Control Problem
Date: Mon, 12 May 2003 12:40:05 -0700
Lines: 54
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.00.2615.200
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2615.200
NNTP-Posting-Host: 66.119.208.158
Message-ID: <3ebff8a8@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1052768424 66.119.208.158 (12 May 2003 12:40:24 -0700)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-01!sn-xit-08!supernews.com!216.166.71.118.MISMATCH!small1.nntp.aus1.giganews.com!border1.nntp.aus1.giganews.com!nntp.giganews.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail