Модераторы: Poseidon, Snowy, bems, MetalFan
  

Поиск:

Ответ в темуСоздание новой темы Создание опроса
> Создание окна в ручную... Как? 
:(
    Опции темы
dead_ricky
Дата 22.5.2002, 14:13 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Шустрый
*


Профиль
Группа: Участник
Сообщений: 62
Регистрация: 4.4.2002

Репутация: нет
Всего: 1



Народ, скажите плззз, как создать окно в ручную, без помощи VCL.
Ну с кнопакими разумеется и всем чем надо, разумеется, или скажите где почитать можно....

З.Ы. Зараннее благодарен.
PM MAIL   Вверх
Vit
Дата 22.5.2002, 15:08 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Vitaly Nevzorov
****


Профиль
Группа: Экс. модератор
Сообщений: 10964
Регистрация: 25.3.2002
Где: Chicago

Репутация: 48
Всего: 207



Вот пример взятый с www.torry.net:


Код

program testwindow;

uses
 Windows,
 Messages;

var
 WinClass: TWndClassA;
 Inst, Handle, Button1, Label1, Edit1: Integer;
 Msg: TMsg;
 hFont: Integer;

{ Checks if typed password is 'Amigreen' and shows Message }
procedure CheckPassword;
var
 Textlength: Integer;
 Text: PChar;
begin
 TextLength := GetWindowTextLength(Edit1);
 if TextLength = 8 then
 begin
   GetMem(Text, TextLength + 1);
   GetWindowText(Edit1, Text, TextLength + 1);
   if Text = 'Amigreen' then
   begin
     MessageBoxA(Handle, 'Password is correct.', 'Password check', MB_OK);
     FreeMem(Text, TextLength + 1);
     Exit;
   end;
 end;
 MessageBoxA(Handle, 'Password is incorrect.', 'Password check', MB_OK);
end;

{ Custom WindowProc function }
function WindowProc(hWnd, uMsg, wParam, lParam: Integer): Integer; stdcall;
begin
 Result := DefWindowProc(hWnd, uMsg, wParam, lParam);
 { Checks for messages }
 if (lParam = Button1) and (uMsg = WM_COMMAND) then
   CheckPassword;
 if uMsg = WM_DESTROY then
   Halt;
end;

begin
 { ** Register Custom WndClass ** }
 Inst := hInstance;
 with WinClass do
 begin
   style              := CS_CLASSDC or CS_PARENTDC;
   lpfnWndProc        := @WindowProc;
   hInstance          := Inst;
   hbrBackground      := color_btnface + 1;
   lpszClassname      := 'AG_TESTWINDOW';
   hCursor            := LoadCursor(0, IDC_ARROW);
 end; { with }
 RegisterClass(WinClass);

 { ** Create Main Window ** }
 Handle := CreateWindowEx(WS_EX_WINDOWEDGE, 'AG_TESTWINDOW', 'Amigreen TestWindow 1.00',
                          WS_VISIBLE or WS_SIZEBOX or WS_CAPTION or WS_SYSMENU,
                          363, 278, 305, 65, 0, 0, Inst, nil);
 { ** Create a button ** }
 Button1 := CreateWindow('Button', 'OK', WS_VISIBLE or WS_CHILD or BS_PUSHLIKE or BS_TEXT,
                          216, 8, 75, 25, handle, 0, Inst, nil);
 { ** Create a label (static) ** }
 Label1 := Createwindow('Static', '', WS_VISIBLE or WS_CHILD or SS_LEFT,
              8, 12, 76, 13, Handle, 0, Inst, nil);

 { ** Create an edit field ** }
 Edit1 := CreateWindowEx(WS_EX_CLIENTEDGE, 'Edit', '', WS_CHILD or WS_VISIBLE or
                         WS_BORDER or ES_PASSWORD, 88, 8, 121, 21, Handle, 0, Inst, nil);

 { ** Create Font Handle ** }
 hFont := CreateFont(-11, 0, 0, 0, 400, 0, 0, 0, DEFAULT_CHARSET,
                     OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
                     DEFAULT_PITCH or FF_DONTCARE, 'MS Sans Serif');

 { Change fonts }
 if hFont <> 0 then
 begin
   SendMessage(Button1, WM_SETFONT, hFont, 0);
   SendMessage(Label1, WM_SETFONT, hFont, 0);
   SendMessage(Edit1, WM_SETFONT, hFont, 0);
 end;
 { Change label (static) text }
 SetWindowText(Label1, 'Enter password:');
 { Set the focus to the edit control }
 SetFocus(Edit1);

 UpdateWindow(Handle);

 { ** Message Loop ** }
 while(GetMessage(Msg, Handle, 0, 0)) do
 begin
   TranslateMessage(msg);
   DispatchMessage(msg);
 end; { with }
end.


Комментарии автора:

A M I G R E E N   T E S T W I N D O W   1 . 0 0
-----------------------------------------------

I N T R O D U C T I O N
-----------------------
Amigreen TestWindow was made as an experiment and
example of how to create a "small-size" application.
First I made a simpel program in Delphi on the "standard"
way. Then I started to build the program _from scratch_.
I maneged to "shrink" the app. from 212kb to only 16,6kb.
I "saved" 196kb!!!!!


C O M M E N T S   O N   T H E   C O D E
---------------------------------------
First thing to do is to create the main window:
1. Registrering a custom class for the Window.
  (The registrered class is automatically unregistered
   when the application terminates.)
2. Creating the window by using CreateWindowEx.

Next is to create all the controls in the window:
1. Using CreateWindow(Ex) to create the button,
  edit and label.
- It is important that you create the controls
 as childs.

Now I want to change the font - the default is too big:
1. Create a font handle using CreateFont.
2. Send a WM_SETFONT to every control.

The UpdateWindow draws the components at the same time, so you
don't get a build-up look, when the app. starts.

The messageloop ensures that the application does not terminate
by it self.

WindowProc function:
All messages sent to the application is sent to the function specified
in the TWndClass structure.


D I S C L A I M E R
-------------------
This code/program can be distributed freely as long as the author's name
(Janus N. T?ndering, Amigreen Software) is present in both code and readme.


C O N T A C T   I N F O
-----------------------
You can contact with questions about TestWindow or corrections or just
if you want to give me your opinion.

My email address is: [email protected]
My homepage is at: http://www.crosswinds.net/denmark/~amigreen/ (finished in Feb. 1999)

Copyright © Amigreen Software 1998



--------------------
With the best wishes, Vit
I have done so much with so little for so long that I am now qualified to do anything with nothing
Самый большой Delphi FAQ на русском языке здесь: www.drkb.ru
PM MAIL WWW ICQ   Вверх
dead_ricky
Дата 23.5.2002, 05:00 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Шустрый
*


Профиль
Группа: Участник
Сообщений: 62
Регистрация: 4.4.2002

Репутация: нет
Всего: 1



Спасибо!!!
А еще вопрос: Как обработатть нажатие клавиши Enter в Edit1 (из выше приведенного примера).

З.Ы. Зараннее спасибо. :)
PM MAIL   Вверх
Vit
Дата 23.5.2002, 06:44 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Vitaly Nevzorov
****


Профиль
Группа: Экс. модератор
Сообщений: 10964
Регистрация: 25.3.2002
Где: Chicago

Репутация: 48
Всего: 207



Я с этим кодом не разбирался, да и не люблю я этих штучек, просто не понимаю зачем это городить, а не использовать VCL, но исходя из общих соображений надо обрабатывать посылаемые сообщения. Впочем в примере нажатие кнопки обрабатывается - вот и посмотри как...




--------------------
With the best wishes, Vit
I have done so much with so little for so long that I am now qualified to do anything with nothing
Самый большой Delphi FAQ на русском языке здесь: www.drkb.ru
PM MAIL WWW ICQ   Вверх
dead_ricky
Дата 24.5.2002, 05:30 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Шустрый
*


Профиль
Группа: Участник
Сообщений: 62
Регистрация: 4.4.2002

Репутация: нет
Всего: 1



Усё я просёк поляну...
Надо переопределить оконную процедуру компонента (Edit1), и обрабатывать там нужное сообщение...
Пример нашел на www.torry.net

З.Ы. Спасибо тебе Vit :)
PM MAIL   Вверх
  
Ответ в темуСоздание новой темы Создание опроса
Правила форума "Delphi: Общие вопросы"
SnowyMetalFan
bemsPoseidon
Rrader

Запрещается!

1. Публиковать ссылки на вскрытые компоненты

2. Обсуждать взлом компонентов и делиться вскрытыми компонентами

  • Литературу по Дельфи обсуждаем здесь
  • Действия модераторов можно обсудить здесь
  • С просьбами о написании курсовой, реферата и т.п. обращаться сюда
  • Вопросы по реализации алгоритмов рассматриваются здесь
  • 90% ответов на свои вопросы можно найти в DRKB (Delphi Russian Knowledge Base) - крупнейшем в рунете сборнике материалов по Дельфи


Если Вам понравилась атмосфера форума, заходите к нам чаще! С уважением, Snowy, MetalFan, bems, Poseidon, Rrader.

 
0 Пользователей читают эту тему (0 Гостей и 0 Скрытых Пользователей)
0 Пользователей:
« Предыдущая тема | Delphi: Общие вопросы | Следующая тема »


 




[ Время генерации скрипта: 0.1914 ]   [ Использовано запросов: 22 ]   [ GZIP включён ]


Реклама на сайте     Информационное спонсорство

 
По вопросам размещения рекламы пишите на vladimir(sobaka)vingrad.ru
Отказ от ответственности     Powered by Invision Power Board(R) 1.3 © 2003  IPS, Inc.