Home
Top.Mail.Ru Yandeks.Metrika
Forum: "WinAPI";
Current archive: 2002.01.08;
Download: [xml.tar.bz2];

Down

How to create forms with different controls on a pure API? Find similar branches


Oxy2   (2001-10-23 23:23) [0]

Hello to all!

Can anyone send or at least suggest where to take simple examples of creating forms, different controls on them, creating event handlers for these controls, etc. on pure API (on Delphi or as a last resort on C). In general simple programming examples on the API.



Jochua   (2001-10-24 06:25) [1]

Write tell me what I know.



Oxy2   (2001-10-25 00:55) [2]

Well, like this. It is necessary to make a form on which there will be a ListView and two buttons (Button). It should be possible to handle button and event events from the ListView.



Иван Шихалев   (2001-10-25 01:10) [3]

And what WM_COMMAND and WM_NOTIFY do not suit you?



Alien   (2001-10-25 02:51) [4]

> Oxy2
Forget about events. There are no events in the Win API. There are messages, and process them.



Jochua   (2001-10-25 08:01) [5]

Look, I somehow did an example for the same request:

program listbox;

uses
windows, messages;

var
wc : TWndClassEx;
Wnd : HWND;
Msg : TMsg;

function WindowProc(wnd : HWND; Msg : Integer; WParam : WParam; LParam : Longint): Longint; stdcall;
const
BUFFER = MAX_PATH;
var
I : Integer;
CurDir : array[0..BUFFER-1] of Char;

Begin
Result := 0;
case msg of

wm_destroy :
Begin
postquitmessage(0);
exit;
Result:=0;
End;

wm_command :
Begin
case loword(wParam) of
200 :
case hiWord(wParam) of
lbn_selchange :
begin
I := SendMessage(lParam, LB_GETCURSEL, 0, 0);
SendMessage(lParam, LB_GETTEXT, I, Integer(@CurDir));
SetWindowText(GetDlgItem(Wnd, 222), CurDir);
end;
lbn_dblclk :
begin
I := SendMessage(lParam, LB_GETCURSEL, 0, 0);
SendMessage(lParam, LB_GETTEXT, I, Integer(@CurDir));
SetWindowText(GetDlgItem(Wnd, 221), CurDir);
end;
end;

100 :
begin
GetCurrentDirectory(SizeOf(CurDir), CurDir);
DlgDirList(Wnd, CurDir, 200, 0, DDL_DIRECTORY);
end;

end;
End;
else
Result := DefWindowProc(wnd, msg, wparam, lparam);
end;
End;

begin
wc.cbSize := sizeof(wc);
wc.style := cs_hredraw or cs_vredraw;
wc.lpfnWndProc := @WindowProc;
wc.cbClsExtra := 0;
wc.cbWndExtra := 0;
wc.hInstance := HInstance;
wc.hIcon := LoadIcon(0, IDI_APPLICATION);
wc.hCursor := LoadCursor(0, idc_arrow);
wc.hbrBackground := COLOR_BTNFACE + 1;
wc.lpszMenuName := nil;
wc.lpszClassName := "listbox example";

RegisterClassEx(wc);

Wnd := CreateWindowEx(0, "listbox example", "ListBoxes Demo",
ws_overlapped or ws_sysmenu,
100, 150, 360, 200,
0, 0,
Hinstance, nil);

CreateWindowEx(WS_EX_CLIENTEDGE, "LISTBOX", NIL, WS_BORDER or LBS_NOTIFY or WS_CHILD or WS_VISIBLE or LBS_MULTICOLUMN or LBS_SORT or LBS_EXTENDEDSEL, 10, 70, 200, 100, Wnd, 200, hInstance, NIL);

CreateWindowEx(0, "STATIC", "dbl_click:", WS_VISIBLE or WS_CHILD, 10, 10, 60, 20, Wnd, 0, hInstance, NIL);
CreateWindowEx(0, "STATIC", NIL, WS_VISIBLE or WS_CHILD, 75, 10, 300, 20, Wnd, 221, hInstance, NIL);

CreateWindowEx(0, "STATIC", "Select:", WS_VISIBLE or WS_CHILD, 10, 40, 60, 20, Wnd, 0, hInstance, NIL);
CreateWindowEx(0, "STATIC", NIL, WS_VISIBLE or WS_CHILD, 75, 40, 300, 20, Wnd, 222, hInstance, NIL);

CreateWindowEx(0, "BUTTON", "Scan Directory", BS_PUSHBUTTON or WS_CHILD or WS_VISIBLE, 220, 130, 120, 25, Wnd, 100, hInstance, NIL);

ShowWindow(Wnd, CmdShow);

While GetMessage(Msg, 0, 0, 0) do
begin
TranslateMessage(Msg);
DispatchMessage(Msg);
end;
end.




Jochua   (2001-10-25 08:03) [6]

Look, I somehow did an example for the same request:

program listbox;

uses
windows, messages;

var
wc : TWndClassEx;
Wnd : HWND;
Msg : TMsg;

function WindowProc(wnd : HWND; Msg : Integer; WParam : WParam; LParam : Longint): Longint; stdcall;
const
BUFFER = MAX_PATH;
var
I : Integer;
CurDir : array[0..BUFFER-1] of Char;

Begin
Result := 0;
case msg of

wm_destroy :
Begin
postquitmessage(0);
exit;
Result:=0;
End;

wm_command :
Begin
case loword(wParam) of
200 :
case hiWord(wParam) of
lbn_selchange :
begin
I := SendMessage(lParam, LB_GETCURSEL, 0, 0);
SendMessage(lParam, LB_GETTEXT, I, Integer(@CurDir));
SetWindowText(GetDlgItem(Wnd, 222), CurDir);
end;
lbn_dblclk :
begin
I := SendMessage(lParam, LB_GETCURSEL, 0, 0);
SendMessage(lParam, LB_GETTEXT, I, Integer(@CurDir));
SetWindowText(GetDlgItem(Wnd, 221), CurDir);
end;
end;

100 :
begin
GetCurrentDirectory(SizeOf(CurDir), CurDir);
DlgDirList(Wnd, CurDir, 200, 0, DDL_DIRECTORY);
end;

end;
End;
else
Result := DefWindowProc(wnd, msg, wparam, lparam);
end;
End;

begin
wc.cbSize := sizeof(wc);
wc.style := cs_hredraw or cs_vredraw;
wc.lpfnWndProc := @WindowProc;
wc.cbClsExtra := 0;
wc.cbWndExtra := 0;
wc.hInstance := HInstance;
wc.hIcon := LoadIcon(0, IDI_APPLICATION);
wc.hCursor := LoadCursor(0, idc_arrow);
wc.hbrBackground := COLOR_BTNFACE + 1;
wc.lpszMenuName := nil;
wc.lpszClassName := "listbox example";

RegisterClassEx(wc);

Wnd := CreateWindowEx(0, "listbox example", "ListBoxes Demo",
ws_overlapped or ws_sysmenu,
100, 150, 360, 200,
0, 0,
Hinstance, nil);

CreateWindowEx(WS_EX_CLIENTEDGE, "LISTBOX", NIL, WS_BORDER or LBS_NOTIFY or WS_CHILD or WS_VISIBLE or LBS_MULTICOLUMN or LBS_SORT or LBS_EXTENDEDSEL, 10, 70, 200, 100, Wnd, 200, hInstance, NIL);

CreateWindowEx(0, "STATIC", "dbl_click:", WS_VISIBLE or WS_CHILD, 10, 10, 60, 20, Wnd, 0, hInstance, NIL);
CreateWindowEx(0, "STATIC", NIL, WS_VISIBLE or WS_CHILD, 75, 10, 300, 20, Wnd, 221, hInstance, NIL);

CreateWindowEx(0, "STATIC", "Select:", WS_VISIBLE or WS_CHILD, 10, 40, 60, 20, Wnd, 0, hInstance, NIL);
CreateWindowEx(0, "STATIC", NIL, WS_VISIBLE or WS_CHILD, 75, 40, 300, 20, Wnd, 222, hInstance, NIL);

CreateWindowEx(0, "BUTTON", "Scan Directory", BS_PUSHBUTTON or WS_CHILD or WS_VISIBLE, 220, 130, 120, 25, Wnd, 100, hInstance, NIL);

ShowWindow(Wnd, CmdShow);

While GetMessage(Msg, 0, 0, 0) do
begin
TranslateMessage(Msg);
DispatchMessage(Msg);
end;
end.




Oxy2   (2001-10-25 23:50) [7]

Hello to all!

2Ivan Shikhalev
> And what WM_COMMAND and WM_NOTIFY do not suit you?
They may be fine with me, but I still don’t know about it. :-)))
Well, I wrote that I only learn programming on a pure API. Previously, I also used the API, but only some of the individual functions I needed, but on the pure API I am still just learning. So far I only know how to create windows and handle their mesages. In principle, I tried to create other controls on the window, but for each one I created a separate window function. I didn’t like it very much (and if I have 100 buttons) and I thought that there might be simpler ways. That's why I asked this question.

2Alien
> Forget about the events. There are no events in the Win API. There are messages, here and> process them.
I know that in Windows are not events, but mesages. It just so out of habit, broke. :-))

2Jochua
HUGE thanks for the example. But I have a question again. I would like to use a listview, not a listbox. Do not tell me what his name is class.



Jochua   (2001-10-26 06:28) [8]

Open the file rw32core.dll (this is in BIN from Delphi) and find - SysListView32. If you create objects through WinAPI, then bypass this library. And there everything that Delphi can understand is declared. Then open Messages.pas - this is Source / RTL / Win - and we look at all the messages on the object we need.



Oxy2   (2001-10-26 23:34) [9]

2Jochua
I did not understand anything at all. And how then VC ++ without this rw32core.dll works. Here I am writing instead of creating a ListBox in your example such a line

CreateWindowEx (WS_EX_CLIENTEDGE, "SysListView32", NIL, WS_CHILD Or
WS_VISIBLE Or WS_VSCROLL Or WS_BORDER Or WS_CLIPSIBLINGS, 10, 70, 200, 100, Wnd, 200, hInstance, NIL);

But the ListView doesn’t want to create something. A window appears, but there is no ListView on it.



Jochua   (2001-10-29 10:04) [10]

This file is needed only for Delphi, for VC ++ all descriptions are in files with the extension ".H". Just checked (D5, Win98) everything works. If you want you can write on the soap, in one of the answers is the address.



nikkie   (2001-10-29 13:35) [11]

> Joshua
some kind of crap. where rw32core.dll?
her product name is Borland Resource Compiler DLL
no extras Borland libraries are not required when writing in api.

> Oxy2
Before using Common Controls, call InitCommonControlsEx



Jochua   (2001-10-29 13:53) [12]

> nikkie
Nor what is this nonsense. Take a closer look, BRCC32 in its work calls this particular library and !!! if it does not find the declared component from WinAPI, it will refuse to compile. InitCommonControlsEx naturally call required.



nikkie   (2001-10-29 14:05) [13]

Run brcc32 and read the "Borland Resource Compiler". and where is he?



Иван Шихалев   (2001-10-29 20:22) [14]

> Jochua

What kind of beast is this - "WinAPI Declared Component"



kowdle   (2001-10-30 00:07) [15]

Come on ... KOL http://bonanzas.rinet.ru/rindex.htm



Jochua   (2001-10-30 06:18) [16]

Well, if you look carefully about what was written earlier, then there was a question:
I would like to use a listview, not a listbox. Do not tell me what his name is class.
to which it was answered:
Open the file rw32core.dll (this is in BIN from Delphi) and find - SysListView32.
I would like to know how those that know too much will be able to compile a project that uses a component that is not described in this library. Notice also that the author of the question has not been involved in this verbiage for a long time, I also disconnect. I will answer only to the author.



nikkie   (2001-10-30 09:40) [17]

> Jochua
ok, disconnect. just a few words in dogonku.

the author’s question "what class name" is 2 logical answer
1. We look a help (MSDN or Win32 SDK) - we see WC_LISTVIEW. there we find an example.

2. look at the VCL's keys, namely, commctrl.pas and comctrls.pas. we see there a WC_LISTVIEW declaration and a bunch of curious code, for example, a safe way to use InitCommonControlsEx.

about your answer. "Open the rw32core.dll file" - is it in notepad "e, or what? And if I see BorBtn, BorRadio, ... - does this have to do with WinAPI? And if I see" VasjaPupkin "there, then can I try create a window of this class?

a few of your quotes that got me hooked.

"If you create objects through WinAPI, then by this library [rw32core.dll] does not get through. And there everything is just declared that Delphi can understand." [calmly pass. and Oxy2 passed by ...]

"This file is needed only for Delphi, for VC ++ all descriptions are in files with the extension" .H "." [the analogy between rw32core.dll and sishnymi heders, to put it mildly, is not clear]

These quotations betray some confusion that is in your head regarding this topic. you do not want to disassemble it - for the sake of God, only the others do not load.



_   (2001-10-30 14:49) [18]

> nikkie
What a pity that these forums are visited by such louts. It's a pity. And the ambition - not to carry.



Oxy2   (2001-11-01 00:04) [19]

Hi!

Thank you all for the advice. Sorry for not participating. I just have a session now - I was running and did not read the mail for a couple of days.
And you don’t have to swear because of me, otherwise in the end I’m going to blame for asking a question. And I do not really want this. :-))

Now to the point. From your answers, I finally understood why this ListView was not created. It was necessary to call the InitCommonControlsEx function before creation, but I did not do that (because I did not know anything about it). But now everything is fine and the ListView is created normally. True, I have a small hitch with InitCommonControlsEx out. It is necessary to transfer some structure to this function. I had to figure it out and I just used the InitCommonControls function. Everything works fine with it, but it’s still interesting what the InitCommonControlsEx function does.
Can someone intelligibly explain?
And what is the safe way to use InitCommonControlsEx?



nikkie   (2001-11-01 09:46) [20]

Actually everything is written in MSDN.

void InitCommonControls (VOID);
Registers and initializes the common control window classes. This function is obsolete. New applications should use the InitCommonControlsEx function.

In short, microsoft says that you should use InitCommonControlsEx. Moreover, it is more flexible. The structure consists of all the 2 fields, so using

was
ICC: TInitCommonControlsEx;
begin
ICC.dwSize: = SizeOf (TInitCommonControlsEx);
ICC.dwICC: =
ICC_LISTVIEW_CLASSES | ICC_TREEVIEW_CLASSES | ICC_TAB_CLASSES;
// enumerate the classes that we are going to use
InitCommonControlsEx (ICC);
end;

there is only one thing. Version 4.70 is written in the help on InitCommonControlsEx. Here is the transcript
Version Distribution Platform
4.00 Microsoft® Windows® 95 / Windows NT® 4.0.
4.70 Microsoft® Internet Explorer 3.x.
4.71 Microsoft® Internet Explorer 4.0.
4.72 Microsoft® Internet Explorer 4.01 and Windows® 98.
5.00 Microsoft® Internet Explorer 5.
5.00 Microsoft® Windows® 2000 and Windows Me.
5.80 Microsoft® Internet Explorer 5.
5.81 Microsoft® Windows 2000 and Windows Me.
6.00 Microsoft® Windows XP.

that is, provided that the user has Win95 without any IE, this function in comctl32.dll will not appear. the situation is difficult imaginable, but possible :).

But dolphi (more precisely, commctrl.pas) helps us. InitCommonControlsEx is loaded dynamically, not statically. and as _InitCommonControlsEx, and InitCommonControlsEx is just a pascal function
Result: = Assigned (_InitCommonControlsEx) and _InitCommonControlsEx (ICC);

1 option. just use InitCommonControlsEx
2 option. we are very concerned about the problem of running our program on Win95 without IE and writing something like
if (not InitCommonControlsEx (ICC)) then InitCommonControls;
3 option. we don't fool ourselves and use InitCommonControls. although it is obsolete, but 100%, that MS will not throw it out in the next versions.



Pages: 1 whole branch

Forum: "WinAPI";
Current archive: 2002.01.08;
Download: [xml.tar.bz2];

Top









Memory: 0.92 MB
Time: 0.038 c
1-22105
Gonza
2001-12-19 16:35
2002.01.08
MDI Application ???


1-22209
Diet
2001-12-14 14:10
2002.01.08
Has anyone used the PaintTo function to draw WinControls on a canvas bitmap? Help! I can’t do anything.


1-22138
Serg5
2001-12-20 09:22
2002.01.08
People, tell me, and how to clear Image1, Clear did not find the function ...


1-22208
Nikos77
2001-12-15 18:34
2002.01.08
Tell me how to do the formatting


1-22067
DNT
2001-12-15 16:20
2002.01.08
Dialog & dll





afrikaans albanian Arabic armenian azerbaijani basque belarusian bulgarian catalan Chinese (Simplified) Chinese (Traditional) croatian Czech danish Dutch English estonian filipino finnish French
galician georgian German greek haitian Creole hebrew Hindi hungarian icelandic indonesian Irish italian japanese Korean latvian lithuanian macedonian malay maltese norwegian
persian polish portuguese Romanian russian serbian slovak Slovenian Español swahili Swedish thai turkish Ukrainian urdu vietnamese welsh yiddish bengali bosnian
cebuano Esperanto gujarati hausa hmong igbo javanese kannada khmer lao latin maori marathi mongolian nepali punjabi somali tamil telugu yoruba
zulu
English French German Italian Portuguese Russian Spanish