Меню

Ошибка c2731 winmain функция не может быть перегружена

// Include the Windows header file that’s needed for all Windows applications

#include <windows.h>
#include <string.h>
#include <string>
#include <tchar.h>
#include <stdlib.h>
#include <list>
#include <iostream>
HINSTANCE hInst; // global handle to hold the application instance
HWND wndHandle; // global variable to hold the window handle
// make class name into a global variable
TCHAR szClassName[ ] = _T(«WindowsApp»);

// forward declarations
bool initWindow( HINSTANCE hInstance );
LRESULT CALLBACK WndProc( HWND, UINT, WPARAM, LPARAM );
// This is winmain, the main entry point for Windows applications
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPTSTR lpCmdLine, int nCmdShow )
{
// Initialize the window
if ( !initWindow( hInstance ) )
return false;
// main message loop:
MSG msg;
ZeroMemory( &msg, sizeof( msg ) );
while( msg.message!=WM_QUIT )
{
// Check the message queue
while (GetMessage(&msg, wndHandle, 0, 0) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
}
return (int) msg.wParam;
}

// bool initWindow( HINSTANCE hInstance )
//initWindow registers the window class for the application, creates the window

bool initWindow( HINSTANCE hInstance )
{
WNDCLASSEX wcex;
// Fill in the WNDCLASSEX structure. This describes how the window
// will look to the system
wcex.cbSize = sizeof(WNDCLASSEX); // the size of the structure
wcex.style = CS_HREDRAW | CS_VREDRAW; // the class style
wcex.lpfnWndProc = (WNDPROC)WndProc; // the window procedure callback
wcex.cbClsExtra = 0; // extra bytes to allocate for this class
wcex.cbWndExtra = 0; // extra bytes to allocate for this instance
wcex.hInstance = hInstance; // handle to the application instance
wcex.hIcon = 0; // icon to associate with the application
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);// the default cursor
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); // the background color
wcex.lpszMenuName  = NULL; // the resource name for the menu
wcex.lpszClassName = _T(«WindowsApp»); // the class name being created
wcex.hIconSm = 0; // the handle to the small icon

if (!RegisterClassEx(&wcex));
return 0;
// Create the window
wndHandle = CreateWindowEx(
0,
 szClassName,
 _T(«Windows App»),
WS_OVERLAPPEDWINDOW,
// the window class to use
// the title bar text
// the window style

CW_USEDEFAULT, // the starting x coordinate
CW_USEDEFAULT, // the starting y coordinate
640, // the pixel width of the window
480, // the pixel height of the window
NULL, // the parent window; NULL for desktop
NULL, // the menu for the application; NULL for
// none
hInstance, // the handle to the application instance
NULL); // no values passed to the window
// Make sure that the window handle that is created is valid
if (!wndHandle)
return false;
// Display the window on the screen
ShowWindow(wndHandle, SW_SHOW);
UpdateWindow(wndHandle);
return true;
}


  1. Mark

    Mark

    Марк

    Публикаций:

    0

    Регистрация:
    15 сен 2011
    Сообщения:
    304

    Решил создать эту тему т.к. в предыдущей никто не ответил.

    Ругается Visual S – “Функция WinMain не может быть перегружена”

    1. const int EditCtrlID = 12;
    2. LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
    3. LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    4.         if(LOWORD(wParam)==10000)
    5.             char f[] = {«Name.txt»};
    6.             HANDLE hFile = CreateFileA(
    7.                                         GENERIC_READ | GENERIC_WRITE,
    8.                                         FILE_SHARE_READ | FILE_SHARE_WRITE,
    9.             WriteFile(hFile, st, ARRAYSIZE(st), &dwBytesWritten, NULL);
    10.             return DefWindowProc(hWnd, message, wParam, lParam);
    11. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, INT nCmdShow)
    12. {                                                       < ———————-Вот тут. Функция не может быть перегружена
    13.     wchar_t cname[] = L»Class»;
    14.     wchar_t title[] = L»Заметки. Ver 1.0 Beta»;
    15.     wc.lpfnWndProc = (WNDPROC)WndProc;
    16.     wc.hInstance = hInstance;
    17.     wc.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_APPLICATION);
    18.     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    19.     wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
    20.     wc.lpszClassName = cname;
    21.     if(!RegisterClass(&wc)) return 0;
    22.     HWND hWnd = CreateWindow(
    23.                              WS_MINIMIZEBOX|WS_CLIPSIBLINGS|WS_CLIPCHILDREN|WS_MAXIMIZEBOX|WS_CAPTION|WS_BORDER|WS_SYSMENU|WS_THICKFRAME,  
    24.     HWND hWnd_button = CreateWindow(
    25.                                     WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
    26.     ShowWindow(hWnd, nCmdShow);
    27.     hWnd = CreateWindow(L»edit», L»nnnВаши заметки: «,
    28.                            WS_VISIBLE | WS_CHILD | WS_HSCROLL |WS_VSCROLL|ES_NOHIDESEL|ES_MULTILINE|WS_VISIBLE|WS_BORDER|ES_AUTOVSCROLL|ES_MULTILINE|ES_LEFT,
    29.     ShowWindow(hWnd, nCmdShow);
    30.     while(GetMessage(&msg, NULL,0 ,0))

  2. Sholar

    Sholar

    New Member

    Публикаций:

    0

    Регистрация:
    16 окт 2011
    Сообщения:
    189

    Убери T и попробуй скомпилить.


  3. Blackbeam

    Blackbeam

    New Member

    Публикаций:

    0

    Регистрация:
    28 дек 2008
    Сообщения:
    965


  4. Mark

    Mark

    Марк

    Публикаций:

    0

    Регистрация:
    15 сен 2011
    Сообщения:
    304


  5. Mark

    Mark

    Марк

    Публикаций:

    0

    Регистрация:
    15 сен 2011
    Сообщения:
    304

    Sholar

    Спасибо. Тема закрыта.


  6. K10

    K10

    New Member

    Публикаций:

    0

    Регистрация:
    3 окт 2008
    Сообщения:
    1.590


  7. Ezrah

    Ezrah

    Member

    Публикаций:

    0

    Регистрация:
    22 мар 2011
    Сообщения:
    412

    K10
    За что?
    Mark
    Несколько замечаний.
    0) Раз используете UNICODE, WinMain должна обзываться wWinMain, и тогда компилироваться будет без исправлений (но, лучше будет исправить тогда LPTSTR на LPWSTR).
    1) Структуру MSG нет смысла объявлять глобальной, т.к. она не используется нигде кроме WinMain. То же касается dwBytesWritten и button.
    2) Макрос ARRAYSIZE возвращает число элементов, а не количество байтов, в то время как в WriteFile нужно передавать именно число байтов. Используйте sizeof().
    3) char f[] = {«Name.txt»}; Тут добавлять не нужно, и вообще строки объявляют так: char f[] = «Name.txt», т.е. без скобок.
    4) Стили WS_OVERLAPPED, WS_CAPTION, WS_SYSMENU, WS_THICKFRAME, WS_MINIMIZEBOX, WS_MAXIMIZEBOX вместе эквивалентны применению стиля WS_OVERLAPPEDWINDOW, т.о. можно сократить объем текста и сделать текст более наглядным.
    5) Рекомендуется, чтобы все дочерние элементы окна имели стиль WS_CLIPSIBLINGS, это позволяет частично избежать мерцания при изменении размеров главного окна.
    6) Оставлять пустой обработчик WM_PAINT плохая идея, должны быть как минимум BeginPaint/EndPaint, иначе происходит что-то не хорошее (по своему опыту), не помню что.
    7) После завершения работы с файлом его полагается закрыть. CloseHandle в помощь.


  8. K10

    K10

    New Member

    Публикаций:

    0

    Регистрация:
    3 окт 2008
    Сообщения:
    1.590

    Ezrah

    Принципиально не желает изучить основы и дублирует темы, нервируя достопочтенную публику.
    Я понимаю, что все с чего то начинали, но никто такие rtfm вопросы на форуме не задавал.


  9. Mark

    Mark

    Марк

    Публикаций:

    0

    Регистрация:
    15 сен 2011
    Сообщения:
    304


  10. Ezrah

    Ezrah

    Member

    Публикаций:

    0

    Регистрация:
    22 мар 2011
    Сообщения:
    412

    K10
    Ну что ж, сложно не согласиться. Будь в дурном расположении духа, я, возможно, поддержал бы вас :)


WASM

// Include the Windows header file that’s needed for all Windows applications

#include <windows.h>
#include <string.h>
#include <string>
#include <tchar.h>
#include <stdlib.h>
#include <list>
#include <iostream>
HINSTANCE hInst; // global handle to hold the application instance
HWND wndHandle; // global variable to hold the window handle
// make class name into a global variable
TCHAR szClassName[ ] = _T(«WindowsApp»);

// forward declarations
bool initWindow( HINSTANCE hInstance );
LRESULT CALLBACK WndProc( HWND, UINT, WPARAM, LPARAM );
// This is winmain, the main entry point for Windows applications
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPTSTR lpCmdLine, int nCmdShow )
{
// Initialize the window
if ( !initWindow( hInstance ) )
return false;
// main message loop:
MSG msg;
ZeroMemory( &msg, sizeof( msg ) );
while( msg.message!=WM_QUIT )
{
// Check the message queue
while (GetMessage(&msg, wndHandle, 0, 0) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
}
return (int) msg.wParam;
}

// bool initWindow( HINSTANCE hInstance )
//initWindow registers the window class for the application, creates the window

bool initWindow( HINSTANCE hInstance )
{
WNDCLASSEX wcex;
// Fill in the WNDCLASSEX structure. This describes how the window
// will look to the system
wcex.cbSize = sizeof(WNDCLASSEX); // the size of the structure
wcex.style = CS_HREDRAW | CS_VREDRAW; // the class style
wcex.lpfnWndProc = (WNDPROC)WndProc; // the window procedure callback
wcex.cbClsExtra = 0; // extra bytes to allocate for this class
wcex.cbWndExtra = 0; // extra bytes to allocate for this instance
wcex.hInstance = hInstance; // handle to the application instance
wcex.hIcon = 0; // icon to associate with the application
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);// the default cursor
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); // the background color
wcex.lpszMenuName  = NULL; // the resource name for the menu
wcex.lpszClassName = _T(«WindowsApp»); // the class name being created
wcex.hIconSm = 0; // the handle to the small icon

if (!RegisterClassEx(&wcex));
return 0;
// Create the window
wndHandle = CreateWindowEx(
0,
 szClassName,
 _T(«Windows App»),
WS_OVERLAPPEDWINDOW,
// the window class to use
// the title bar text
// the window style

CW_USEDEFAULT, // the starting x coordinate
CW_USEDEFAULT, // the starting y coordinate
640, // the pixel width of the window
480, // the pixel height of the window
NULL, // the parent window; NULL for desktop
NULL, // the menu for the application; NULL for
// none
hInstance, // the handle to the application instance
NULL); // no values passed to the window
// Make sure that the window handle that is created is valid
if (!wndHandle)
return false;
// Display the window on the screen
ShowWindow(wndHandle, SW_SHOW);
UpdateWindow(wndHandle);
return true;
}

0 0 голоса
Рейтинг статьи
Подписаться
Уведомить о
guest

0 комментариев
Старые
Новые Популярные
Межтекстовые Отзывы
Посмотреть все комментарии

А вот еще интересные материалы:

  • Яшка сломя голову остановился исправьте ошибки
  • Ясность цели позволяет целеустремленно добиваться намеченного исправьте ошибки
  • Ясность цели позволяет целеустремленно добиваться намеченного где ошибка
  • Ошибка c1a03 ford mondeo
  • Ошибка c2730 kyocera 3051ci