// 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;
}
-

Mark
Марк
- Публикаций:
-
0
- Регистрация:
- 15 сен 2011
- Сообщения:
- 304
Решил создать эту тему т.к. в предыдущей никто не ответил.
Ругается Visual S – “Функция WinMain не может быть перегружена”
-
const int EditCtrlID = 12;
-
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
-
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
-
if(LOWORD(wParam)==10000)
-
char f[] = {«Name.txt»};
-
HANDLE hFile = CreateFileA(
-
GENERIC_READ | GENERIC_WRITE,
-
FILE_SHARE_READ | FILE_SHARE_WRITE,
-
WriteFile(hFile, st, ARRAYSIZE(st), &dwBytesWritten, NULL);
-
return DefWindowProc(hWnd, message, wParam, lParam);
-
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, INT nCmdShow)
-
{ < ———————-Вот тут. Функция не может быть перегружена
-
wchar_t cname[] = L»Class»;
-
wchar_t title[] = L»Заметки. Ver 1.0 Beta»;
-
wc.lpfnWndProc = (WNDPROC)WndProc;
-
wc.hInstance = hInstance;
-
wc.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_APPLICATION);
-
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
-
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
-
wc.lpszClassName = cname;
-
if(!RegisterClass(&wc)) return 0;
-
HWND hWnd = CreateWindow(
-
WS_MINIMIZEBOX|WS_CLIPSIBLINGS|WS_CLIPCHILDREN|WS_MAXIMIZEBOX|WS_CAPTION|WS_BORDER|WS_SYSMENU|WS_THICKFRAME,
-
HWND hWnd_button = CreateWindow(
-
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
-
ShowWindow(hWnd, nCmdShow);
-
hWnd = CreateWindow(L»edit», L»nnnВаши заметки: «,
-
WS_VISIBLE | WS_CHILD | WS_HSCROLL |WS_VSCROLL|ES_NOHIDESEL|ES_MULTILINE|WS_VISIBLE|WS_BORDER|ES_AUTOVSCROLL|ES_MULTILINE|ES_LEFT,
-
ShowWindow(hWnd, nCmdShow);
-
while(GetMessage(&msg, NULL,0 ,0))
-

Sholar
New Member
- Публикаций:
-
0
- Регистрация:
- 16 окт 2011
- Сообщения:
- 189
Убери T и попробуй скомпилить.
-

Blackbeam
New Member
- Публикаций:
-
0
- Регистрация:
- 28 дек 2008
- Сообщения:
- 965
-

Mark
Марк
- Публикаций:
-
0
- Регистрация:
- 15 сен 2011
- Сообщения:
- 304
-

Mark
Марк
- Публикаций:
-
0
- Регистрация:
- 15 сен 2011
- Сообщения:
- 304
Sholar
Спасибо. Тема закрыта.
-

K10
New Member
- Публикаций:
-
0
- Регистрация:
- 3 окт 2008
- Сообщения:
- 1.590
-

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 в помощь. -

K10
New Member
- Публикаций:
-
0
- Регистрация:
- 3 окт 2008
- Сообщения:
- 1.590
Ezrah
Принципиально не желает изучить основы и дублирует темы, нервируя достопочтенную публику.
Я понимаю, что все с чего то начинали, но никто такие rtfm вопросы на форуме не задавал. -

Mark
Марк
- Публикаций:
-
0
- Регистрация:
- 15 сен 2011
- Сообщения:
- 304
-

Ezrah
Member
- Публикаций:
-
0
- Регистрация:
- 22 мар 2011
- Сообщения:
- 412
K10
Ну что ж, сложно не согласиться. Будь в дурном расположении духа, я, возможно, поддержал бы вас
// 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;
}