🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Creating a Window from a Console App... How to?!?

#9849
From: Filippo
Date: Fri, 11 Jun 2004 10:35
102 lines
3775 bytes
Hello,
    I try to create a window from a Console App (so with main() and without
the 'WinMain...').
    To do this I created a new thread inside the main console app that
register the window and show it... seems to work but...
    I have some problem when I try to resize the window... all the desktop
become white! without refreshing it.
    How can I create a window from a console app not in this 'dirty' way?
    Thanks in advance,
            Filippo

______________________
P.S. my program looks like this:


#include <windows.h>
#include <conio.h>
LRESULT CALLBACK WndProcedure(HWND hWnd, UINT Msg,
      WPARAM wParam, LPARAM lParam)
{


    switch(Msg)
    {
    // If the user wants to close the application
    case WM_PAINT:
      HDC hDC;
      PAINTSTRUCT Ps;
      HPEN hPen;
      hDC = BeginPaint(hWnd, &Ps);
        ...
      EndPaint(hWnd, &Ps);
      break;

    case WM_DESTROY:
      PostQuitMessage(WM_QUIT);
      break;
    default:
      return DefWindowProc(hWnd, Msg, wParam, lParam);
    }
  return 0;
}

DWORD WINAPI ThreadFunc( LPVOID lpParam )
{
    WNDCLASSEX  WndCls;
    static char szAppName[] = "test";
    MSG         Msg;
    WndCls.cbSize        = sizeof(WndCls);
    WndCls.style         = CS_OWNDC | CS_VREDRAW | CS_HREDRAW;
    WndCls.lpfnWndProc   = WndProcedure;
    WndCls.cbClsExtra    = 0;
    WndCls.cbWndExtra    = 0;
    WndCls.hInstance     = NULL;
    WndCls.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
    WndCls.hCursor       = LoadCursor(NULL, IDC_ARROW);
    WndCls.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
    WndCls.lpszMenuName  = NULL;
    WndCls.lpszClassName = szAppName;
    WndCls.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);
    RegisterClassEx(&WndCls);

    hWnd=CreateWindowEx(WS_EX_OVERLAPPEDWINDOW,
                   szAppName, "Test Window",
                   WS_OVERLAPPEDWINDOW | WS_VISIBLE,
                   CW_USEDEFAULT, CW_USEDEFAULT, 500, 500,
                               NULL, NULL, NULL, NULL );

    while( GetMessage(&Msg, NULL, 0, 0) )
    {
        TranslateMessage(&Msg);
        DispatchMessage( &Msg);
    }

    return (Msg.wParam);
}

VOID main( VOID )
{
    DWORD dwThreadId, dwThrdParam = 1;

    char szMsg[80];

    hThread = CreateThread(
        NULL,                        // default security attributes
        0,                           // use default stack size
        ThreadFunc,                  // thread function
        &dwThrdParam,                // argument to thread function
        0,                           // use default creation flags
        &dwThreadId);                // returns the thread identifier

   if (hThread == NULL)
   {
      wsprintf( szMsg, "CreateThread failed." );
      MessageBox( NULL, szMsg, "main", MB_OK );
   }
   else
   {
//      _getch();
//      CloseHandle( hThread );
   }
}
Technical Details
Message-ID: <40c98aec$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,3be54e0f405e81ba,start
X-Google-Attributes: gid10cc67,public
From: "Filippo" <filfor_no@spamtin.it>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Creating a Window from a Console App... How to?!?
Date: Fri, 11 Jun 2004 12:35:04 +0200
Lines: 104
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
NNTP-Posting-Host: 82.104.120.51
Message-ID: <40c98aec$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1086950124 82.104.120.51 (11 Jun 2004 03:35:24 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail