HOME FORUMS MEMBERS RECENT POSTS LOG IN  
× Авторизация
Имя пользователя:
Пароль:
Нет аккаунта? Регистрация
Баннер 1   Баннер 2
НОВЫЕ ТОРГОВАЯ НОВОСТИ ЧАТ
loading...
Скрыть
Вернуться   ANTICHAT > ПРОГРАММИРОВАНИЕ > С/С++, C#, Rust, Swift, Go, Java, Perl, Ruby
   
Ответ
 
Опции темы Поиск в этой теме Опции просмотра

  #3921  
Старый 09.10.2009, 08:17
CaraL
Новичок
Регистрация: 03.12.2008
Сообщений: 4
С нами: 9176808

Репутация: 0
По умолчанию

Приведие простой пример оконного приложения windows на c++
 
Ответить с цитированием

  #3922  
Старый 09.10.2009, 08:25
POS_troi
Познавший АНТИЧАТ
Регистрация: 01.12.2006
Сообщений: 1,769
С нами: 10233548

Репутация: 1118


По умолчанию

Код:
 



#include <windows.h>
#include <string.h>
#include <iostream>

/*
 * This is the window function for the main window. Whenever a message is
 * dispatched using DispatchMessage (or sent with SendMessage) this function
 * gets called with the contents of the message.
 */
LRESULT CALLBACK
MainWndProc (HWND hwnd, UINT nMsg, WPARAM wParam, LPARAM lParam)
{
/* The window handle for the "Click Me" button. */
static HWND hwndButton = 0;
static int cx, cy;/* Height and width of our button. */

HDC hdc;/* A device context used for drawing */
PAINTSTRUCT ps;/* Also used during window drawing */
RECT rc;/* A rectangle used during drawing */
/*
 * Perform processing based on what kind of message we got.
 */
switch (nMsg)
{
case WM_CREATE:
{
/* The window is being created. Create our button
 * window now. */
TEXTMETRIC tm;

/* First we use the system fixed font size to choose
 * a nice button size. */
hdc = GetDC (hwnd);
SelectObject (hdc, GetStockObject (SYSTEM_FIXED_FONT));
GetTextMetrics (hdc, &tm);
cx = tm.tmAveCharWidth * 30;
cy = (tm.tmHeight + tm.tmExternalLeading) * 2;
ReleaseDC (hwnd, hdc);

/* Now create the button */
hwndButton = CreateWindow (
"button",/* Builtin button class */
"Click Here",
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
0, 0, cx, cy,
hwnd,/* Parent is this window. */
(HMENU) 1,/* Control ID: 1 */
((LPCREATESTRUCT) lParam)->hInstance,
NULL
);

return 0;
break;
}

case WM_DESTROY:
/* The window is being destroyed, close the application
 * (the child button gets destroyed automatically). */
PostQuitMessage (0);
return 0;
break;

case WM_PAINT:
/* The window needs to be painted (redrawn). */
hdc = BeginPaint (hwnd, &ps);
GetClientRect (hwnd, &rc);

/* Draw "Hello, World" in the middle of the upper
 * half of the window. */
rc.bottom = rc.bottom / 2;
DrawText (hdc, "Hello, World!", -1, &rc,
DT_SINGLELINE | DT_CENTER | DT_VCENTER);

EndPaint (hwnd, &ps);
return 0;
break;

case WM_SIZE:
/* The window size is changing. If the button exists
 * then place it in the center of the bottom half of
 * the window. */
if (hwndButton &&
(wParam == SIZEFULLSCREEN ||
 wParam == SIZENORMAL)
   )
{
rc.left = (LOWORD(lParam) - cx) / 2;
rc.top = HIWORD(lParam) * 3 / 4 - cy / 2;
MoveWindow (
hwndButton,
rc.left, rc.top, cx, cy, TRUE);
}
break;

case WM_COMMAND:
/* Check the control ID, notification code and
 * control handle to see if this is a button click
 * message from our child button. */
if (LOWORD(wParam) == 1 &&
    HIWORD(wParam) == BN_CLICKED &&
    (HWND) lParam == hwndButton)
{
/* Our button was clicked. Close the window. */
DestroyWindow (hwnd);
}
return 0;
break;
}

/* If we don't handle a message completely we hand it to the system
 * provided default window function. */
return DefWindowProc (hwnd, nMsg, wParam, lParam);
}


int STDCALL
WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmd, int nShow)
{
HWND hwndMain;/* Handle for the main window. */
MSG msg;/* A Win32 message structure. */
WNDCLASSEX wndclass;/* A window class structure. */
char*szMainWndClass = "WinTestWin";
/* The name of the main window class */

/*
 * First we create a window class for our main window.
 */

/* Initialize the entire structure to zero. */
memset (&wndclass, 0, sizeof(WNDCLASSEX));

/* This class is called WinTestWin */
wndclass.lpszClassName = szMainWndClass;

/* cbSize gives the size of the structure for extensibility. */
wndclass.cbSize = sizeof(WNDCLASSEX);

/* All windows of this class redraw when resized. */
wndclass.style = CS_HREDRAW | CS_VREDRAW;

/* All windows of this class use the MainWndProc window function. */
wndclass.lpfnWndProc = MainWndProc;

/* This class is used with the current program instance. */
wndclass.hInstance = hInst;

/* Use standard application icon and arrow cursor provided by the OS */
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wndclass.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);

/* Color the background white */
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);

/*
 * Now register the window class for use.
 */
RegisterClassEx (&wndclass);

/*
 * Create our main window using that window class.
 */
hwndMain = CreateWindow (
szMainWndClass,/* Class name */
"Hello",/* Caption */
WS_OVERLAPPEDWINDOW,/* Style */
CW_USEDEFAULT,/* Initial x (use default) */
CW_USEDEFAULT,/* Initial y (use default) */
CW_USEDEFAULT,/* Initial x size (use default) */
CW_USEDEFAULT,/* Initial y size (use default) */
NULL,/* No parent window */
NULL,/* No menu */
hInst,/* This program instance */
NULL/* Creation parameters */
);

/*
 * Display the window which we just created (using the nShow
 * passed by the OS, which allows for start minimized and that
 * sort of thing).
 */
ShowWindow (hwndMain, nShow);
UpdateWindow (hwndMain);

/*
 * The main message loop. All messages being sent to the windows
 * of the application (or at least the primary thread) are retrieved
 * by the GetMessage call, then translated (mainly for keyboard
 * messages) and dispatched to the appropriate window procedure.
 * This is the simplest kind of message loop. More complex loops
 * are required for idle processing or handling modeless dialog
 * boxes. When one of the windows calls PostQuitMessage GetMessage
 * will return zero and the wParam of the message will be filled
 * with the argument to PostQuitMessage. The loop will end and
 * the application will close.
         */
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}
return msg.wParam;
}
а вообще

http://msdn.microsoft.com/ru-ru/library/bb384843.aspx
 
Ответить с цитированием

  #3923  
Старый 09.10.2009, 10:22
cupper
Постоянный
Регистрация: 06.06.2007
Сообщений: 575
С нами: 9963746

Репутация: 180


По умолчанию

некодь так, это чистый WinAPI, несмотря что я сам обеими руками за него, но это уже пережитки прошлого.
 
Ответить с цитированием

  #3924  
Старый 09.10.2009, 11:18
POS_troi
Познавший АНТИЧАТ
Регистрация: 01.12.2006
Сообщений: 1,769
С нами: 10233548

Репутация: 1118


По умолчанию

Цитата:
Сообщение от cupper  
некодь так, это чистый WinAPI, несмотря что я сам обеими руками за него, но это уже пережитки прошлого.
зато как красиво
 
Ответить с цитированием

  #3925  
Старый 09.10.2009, 16:08
-m0rgan-
Постоянный
Регистрация: 29.09.2008
Сообщений: 553
С нами: 9270510

Репутация: 519


По умолчанию

Привет.
Разбирался с апи..написал вот такую фигню:

#include <windows.h>
int main(int argc, char* argv[])
{
char * b = "a";
for(int a = 0; a < 10; b++)
{
MessageBox(NULL,b, "ss", MB_OK);
}
}

Запустил, но бля не могу понять что оно делает о.О
Выводит какие то куски кода о___О
 
Ответить с цитированием

  #3926  
Старый 09.10.2009, 16:25
scrat
Постоянный
Регистрация: 08.04.2007
Сообщений: 853
С нами: 10048706

Репутация: 1540


По умолчанию

Цитата:
Сообщение от -m0rgan-  
Привет.
Разбирался с апи..написал вот такую фигню:

#include <windows.h>
int main(int argc, char* argv[])
{
char * b = "a";
for(int a = 0; a < 10; b++)
{
MessageBox(NULL,b, "ss", MB_OK);
}
}

Запустил, но бля не могу понять что оно делает о.О
Выводит какие то куски кода о___О
у тебя бред в цикле написан, b++ - ты, наверное, хотел a++
 
Ответить с цитированием

  #3927  
Старый 09.10.2009, 16:45
-m0rgan-
Постоянный
Регистрация: 29.09.2008
Сообщений: 553
С нами: 9270510

Репутация: 519


По умолчанию

Да я понял что бред, меня интересует, что за куски кода выводятся в мессагебоксе?
 
Ответить с цитированием

  #3928  
Старый 09.10.2009, 16:51
POS_troi
Познавший АНТИЧАТ
Регистрация: 01.12.2006
Сообщений: 1,769
С нами: 10233548

Репутация: 1118


По умолчанию

А если к тебе начать прибавлять не девушку а ежика? тоже начнешь черти что пороть
 
Ответить с цитированием

  #3929  
Старый 09.10.2009, 16:54
rudvil
Участник форума
Регистрация: 25.08.2008
Сообщений: 187
С нами: 9320830

Репутация: 86
По умолчанию

А чего ты там ждал увидеть?
Длина "b" составляет 2 символа, а ты в бесконечном цикле переходишь на след. символ и выводишь все что за пределами этого чара, т.е. хз что...
 
Ответить с цитированием

  #3930  
Старый 09.10.2009, 17:35
-m0rgan-
Постоянный
Регистрация: 29.09.2008
Сообщений: 553
С нами: 9270510

Репутация: 519


По умолчанию

угу, понял спс.
А можно пример использования ф-и sprintf() ?

Нужно перегнать инт в чар, то есть число в строку.

...
int a = &text;

Переменную а необходимо загнать в буффер (тип чар), чтобы потом вывести в мессагебоксе.
Зарание спс.
 
Ответить с цитированием
Ответ



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Часто задаваемые вопросы по MySQL Серый PHP 5 28.12.2006 18:26
Интернетчики задали российскому президенту очень странные вопросы podkashey Мировые новости. Обсуждения. 4 07.07.2006 16:53
Вопросы по Ipb 2.0 Voodoo_People Уязвимости CMS / форумов 26 15.02.2005 22:57



Здесь присутствуют: 1 (пользователей: 0 , гостей: 1)
 


Быстрый переход




ANTICHAT ™ © 2001- Antichat Kft.

×

Создать сделку

Продавец: ник или ID

Название сделки:

Сумма USDT:

Срок сделки, дней:

Кто платит комиссию:

Условия сделки:

После создания сделки средства будут зарезервированы в холде до завершения сделки.

×

Мои сделки

Загрузка...
×

Сделка


Загрузка чата...