Making first windowsclass

This is a discussion on Making first windowsclass within the Windows Programming forums, part of the Platform Specific Boards category; Hi, I downloaded a windowsclass script from a website with tutorials. The website said it would work but in my ...

  1. #1
    C / C++
    Join Date
    Jan 2006
    Location
    The Netherlands
    Posts
    312

    Making first windowsclass

    Hi,

    I downloaded a windowsclass script from a website with tutorials.
    The website said it would work but in my Borland compiler I encountered a strange error:

    "Unresolved external `_main` referenced from C:\Borland'\BCC55\LIB\COX32.OBJ"

    this is the code(it's the full code because Borland doesn't give a line here!):

    Code:
    #include<windows.h> //using win32 api
    //#include <windowsx.h>//for additional win32 api functions
    //#include "identifiers.h"//so I can access my identifiers
    HINSTANCE hInstance;
    const char g_ClassName[]="hwnd window class name";
    
    LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam);
     
    int WINAPI WinMain(HINSTANCE     hInstance,
                       HINSTANCE hPrevInstance,
                       LPSTR          nCmdLine,
                       int            nCmdShow)
    {
        HWND hwnd;
        MSG Message;
        HWND hEdit;
        HWND hBaseC;
        WNDCLASSEX wc;
        
    
        wc.cbSize = sizeof(WNDCLASSEX);
        wc.cbWndExtra = 0;
        wc.cbClsExtra = 0;
        wc.style = CS_DBLCLKS;
        wc.hbrBackground = CreateSolidBrush(RGB(0,0,100));
        wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
        wc.hIconSm = LoadIcon(NULL,IDI_APPLICATION);
        wc.hInstance = hInstance;
        wc.hCursor = LoadCursor(NULL,IDC_ARROW);
        //wc.lpszMenuName = MAKEINTRESOURCE(HWND_MENU);
        wc.lpszClassName = g_ClassName;
        wc.lpfnWndProc = WndProc;
        
        if (!RegisterClassEx (&wc))
            return 0;
        
         
        hwnd = CreateWindowEx(WS_EX_TOOLWINDOW,
                              g_ClassName,
                              "Base Converter/NotePad",
                              WS_SYSMENU,
                              CW_USEDEFAULT,CW_USEDEFAULT,
                              CW_USEDEFAULT,CW_USEDEFAULT,
                              HWND_DESKTOP,
                              NULL,
                              hInstance,
                              NULL);
                              
          ShowWindow(hwnd,nCmdShow);
          
          while(GetMessage(&Message,NULL,0,0)>0)
        {
            TranslateMessage(&Message);
            DispatchMessage (&Message);
        }
        
        return Message.wParam;
    }
    
    LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
            
       static HWND hEdit, hBaseC, HWND_EDIT, EXTRA_BASE_CONVERT;
       
       switch(message)
       {
                      
        case WM_CREATE:  
        
             hEdit = CreateWindow("EDIT", NULL,
                                   WS_CHILD|WS_VISIBLE|WS_VSCROLL|ES_MULTILINE,
                                   40, 290, 500, 100, hwnd,
                                   (HMENU)HWND_EDIT,
                                   (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE),
                                   NULL);
        
             hBaseC = CreateWindow("BUTTON", NULL, WS_CHILD|WS_SYSMENU,
                                    CW_USEDEFAULT,CW_USEDEFAULT,
                                    CW_USEDEFAULT,CW_USEDEFAULT,
                                    hwnd,
                                    (HMENU)EXTRA_BASE_CONVERT,
                                    (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE),
                                    NULL); 
             break; 
             
        case WM_CLOSE:
             
                 DestroyWindow(hwnd);
                 break;     
                                     
        case WM_DESTROY:
             
             PostQuitMessage(0);
             break;   
             
        default:  
                  
             return DefWindowProc(hwnd, message, wParam, lParam);
             }
             
        return 0;
        
    }

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,264
    It sounds like you have main() defined as your application's entry point instead of WinMain(). This is commonly due to creating a console project instead of a windows project.

  3. #3
    Registered User kryptkat's Avatar
    Join Date
    Dec 2002
    Posts
    638
    compile it like this

    bcc32 -tW winnclasstest1.c

    Microsoft Windows XP [Version 5.1.2600]
    (C) Copyright 1985-2001 Microsoft Corp.

    C:\borland\bcc55\bin>bcc32 -tW winnclasstest1.c
    Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
    winnclasstest1.c:
    Warning W8057 winnclasstest1.c 58: Parameter 'hPrevInstance' is never used in fu
    nction WinMain
    Warning W8057 winnclasstest1.c 58: Parameter 'nCmdLine' is never used in functio
    n WinMain
    Turbo Incremental Link 5.00 Copyright (c) 1997, 2000 Borland

    C:\borland\bcc55\bin>winnclasstest1

    C:\borland\bcc55\bin>

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. making sprites
    By DavidP in forum Game Programming
    Replies: 9
    Last Post: 02-20-2010, 07:00 AM
  2. Making great graphics
    By MadCow257 in forum Game Programming
    Replies: 1
    Last Post: 02-20-2006, 11:59 PM
  3. Making control...
    By Finchie_88 in forum C++ Programming
    Replies: 2
    Last Post: 09-07-2004, 02:42 PM
  4. Replies: 2
    Last Post: 01-13-2003, 01:28 PM
  5. About Unix Programming - Making a career desision
    By null in forum C Programming
    Replies: 0
    Last Post: 10-14-2001, 08:37 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21