api 操控弹出菜单(#32768) 我要选择第一个选项,并确定,请问怎么操作,发什么信息 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 program Setup1;uses Windows, Messages, CommCtrl;//{$R *.RES} //图标资源文件//{$R BMP_Image1.res} //图片资源文件//{$R Ver.res} //文件版本信息资源文件const ID_Open = 4001; ID_Save = 4002; ID_Close = 4003; ID_Copy = 4004; ID_Paste = 4005; ID_About = 4006;var WinClass: TWndClassA; Inst: HINST; hWindow: HWND; StatusBar1: HWND; TheMessage: TMsg; GroupBox1: HWND; Edit1, Label1: HWND; Button1: HWND; MyMenu, MyMenuPop: HWND; Memo1: HWND; ProgressBar1: HWND; Image1: HWND; hImage1: HBITMAP; Button2: HWND; Button3: HWND;// PaintStruct: TPaintStruct;// PaintDC: HDC; hFont: Integer;{ Custom WindowProc function }procedure My_CreateMenu;begin MyMenu := CreateMenu(); MyMenuPop := CreateMenu(); AppendMenu(MyMenuPop, MF_STRING, ID_Open, '打开(&Open)'); AppendMenu(MyMenuPop, MF_SEPARATOR, 0, nil); AppendMenu(MyMenuPop, MF_STRING, ID_Save, '保存(&Save)'); AppendMenu(MyMenuPop, MF_SEPARATOR, 0, nil); AppendMenu(MyMenuPop, MF_STRING, ID_Close, '关闭(&Close)'); AppendMenu(MyMenu, MF_POPUP, MyMenuPop, '文件(&File)'); MyMenuPop := CreateMenu(); AppendMenu(MyMenuPop, MF_STRING, ID_Copy, '复制(&Open)'); AppendMenu(MyMenuPop, MF_SEPARATOR, 0, nil); AppendMenu(MyMenuPop, MF_STRING, ID_Paste, '粘贴(&Save)'); AppendMenu(MyMenu, MF_POPUP, MyMenuPop, '编辑(&Edit)'); MyMenuPop := CreateMenu(); AppendMenu(MyMenuPop, MF_STRING, ID_About, '关于(&About)'); AppendMenu(MyMenu, MF_POPUP, MyMenuPop, '帮助(&Help)');end;procedure My_SetProgress(i: integer);begin SendMessage(ProgressBar1, PBM_SETPOS, i, 0);end;function My_Gettext: string;var Textlength: Integer; Text: PChar; s: string;begin TextLength := GetWindowTextLength(Edit1); GetMem(Text, TextLength + 1); GetWindowText(Edit1, Text, TextLength + 1); s := text; FreeMem(Text, TextLength + 1); Result := s;end;function WindowProc(hWindow: HWnd; Message, wParam, lParam: Integer): Integer; stdcall;var sdir: string; //安装目录 i: integer; //进度条begin Result := 0; { Checks for messages } case Message of WM_Create: begin { Load Image } hImage1 := LoadBitmap(Inst, PChar('BMP_Image1')); end; WM_SIZE: begin SendMessage(StatusBar1, WM_SIZE, wParam, lParam); end; WM_COMMAND: begin if HWND(lParam) = Button1 then // if SelectDirectory(hWindow, '请选择安装目录', '', sdir) // then SetWindowText(Edit1, pchar(sdir)); if HWND(lParam) = Button2 then begin if My_Gettext = '' then begin MessageBox(hWindow, '请先选择安装文件夹!', '信息', MB_ICONINFORMATION + MB_OK); Exit; end; { if FileExists(pchar(My_Gettext + Getmyname)) then if MessageBox(hWindow, pchar('文件' + My_Gettext + Getmyname + '已经存在,你确定继续安装吗?'), '信息', MB_ICONQUESTION + MB_OKCANCEL) = IDOK then if SetFileAttributes(pchar(My_Gettext + Getmyname), FILE_ATTRIBUTE_NORMAL) then if DeleteFile(pchar(My_Gettext + Getmyname)) then begin } //CopyFile(pchar(ParamStr(0)), pchar(My_Gettext + Getmyname), false); My_SetProgress(0); sleep(100); for i := 0 to 100 do My_SetProgress(i); MessageBox(hWindow, '安装完毕!', '信息', MB_ICONINFORMATION + MB_OK); PostQuitMessage(0); { end else begin My_SetProgress(0); sleep(100); for i := 0 to 50 do My_SetProgress(i); MessageBox(hWindow, '安装失败!', '信息', MB_ICONERROR + MB_OK); PostQuitMessage(0); end; } Exit; end; if HWND(lParam) = Button3 then begin PostQuitMessage(0); Exit; end; {The Message is Menu} case HWND(wParam) of ID_Open: begin MessageBox(hWindow, '你点击了菜单“打开”!', '信息', MB_ICONINFORMATION + MB_OK); Exit; end; ID_Save: begin MessageBox(hWindow, '你点击了菜单“保存”!', '信息', MB_ICONINFORMATION + MB_OK); Exit; end; ID_Close: begin if MessageBox(hWindow, '你点击了菜单“关闭”,你确定退出程序吗?', '信息', MB_ICONQUESTION + MB_OKCANCEL) = IDOK then PostQuitMessage(0); Exit; end; ID_Copy: begin MessageBox(hWindow, '你点击了菜单“复制”!', '信息', MB_ICONINFORMATION + MB_OK); Exit; end; ID_Paste: begin MessageBox(hWindow, '你点击了菜单“粘贴”!', '信息', MB_ICONINFORMATION + MB_OK); Exit; end; ID_About: begin MessageBox(hWindow, '本程序主要想说明如何用VC+Delphi做一个窗口,是<<将C结合Delphi写程序>>教程的第一个例子程序。如果直接用普通方法来写,程序大小将为338KB(Delphi5下),现在请看看文件的大小!教程和原代码可以在Http://Lovejingtao.126.com下载.', '关于', MB_ICONINFORMATION + MB_OK); Exit; end; end; //end case exit; end; WM_DESTROY: begin { Delete Pens and Brushes } { Delete Fonts } PostQuitMessage(0); Exit; end; else Result := DefWindowProc(hWindow, Message, wParam, lParam); end;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 := 'MyWindowClass'; hIcon := LoadIcon(Inst, 'Mainicon'); hCursor := LoadCursor(0, IDC_ARROW); end; { with } RegisterClass(WinClass); My_CreateMenu; {Create Main Menu} { Create Main Window } hWindow := CreateWindowEx(WS_EX_WINDOWEDGE, 'MyWindowClass', '我的安装程序', WS_MINIMIZEBOX or WS_SYSMENU or WS_VISIBLE, (GetSystemMetrics(SM_CXSCREEN) - 300) div 2, (GetSystemMetrics(SM_CYSCREEN) - 330) div 2, 300, 330, 0, MyMenu, Inst, nil);{ Create a label (static) ========= } Label1 := Createwindow('Static', 'Label1', WS_VISIBLE or WS_CHILD or SS_LEFT, 48, 4, 182, 83, hWindow, 0, Inst, nil); SendMessage(Label1, WM_SETTEXT, 0, lParam(pChar('第一个范例程序:程序自拷贝。'))); { Create a groupbox ===========} GroupBox1 := CreateWindow('Button', '安装路径:', WS_VISIBLE or WS_CHILD or BS_GROUPBOX, 0, 19, 291, 177, hWindow, 0, Inst, nil); { Create an edit field ========== } Edit1 := CreateWindowEx(WS_EX_CLIENTEDGE, 'Edit', 'C:\', WS_CHILD or WS_VISIBLE or WS_BORDER or WS_TABSTOP, 18, 39, 177, 21, hWindow, 0, Inst, nil); { Create a button ============} Button1 := CreateWindow('Button', '浏览', WS_VISIBLE or WS_CHILD or BS_PUSHLIKE or BS_TEXT or WS_TABSTOP, 202, 37, 75, 25, hWindow, 0, Inst, nil); { Create a memo =========== } Memo1 := CreateWindowEx(WS_EX_CLIENTEDGE, 'Edit', '', WS_CHILD or WS_VISIBLE or WS_BORDER or ES_LEFT or ES_MULTILINE or ES_WANTRETURN or ES_AUTOVSCROLL or WS_VSCROLL, 18, 71, 257, 95, hWindow, 0, Inst, nil); { add lines to memo } SendMessage(Memo1, WM_SETTEXT, 0, lParam(pChar(' 点击“浏览”按钮允许你从文件夹子目录结构中选择目标文件夹。' + #13#10 + ' 请点击“安装”按钮开始安装程序。' + #13#10 + ' 本安装程序是用Delphi5.0写的。具体信息请看文件版本信息。'))); { Create a static image ======= } Image1 := CreateWindow('Static', '', WS_VISIBLE or WS_CHILD or SS_BITMAP, 16, 228, 32, 32, hWindow, 0, Inst, nil); { set image to static control } SendMessage(Image1, STM_SETIMAGE, IMAGE_BITMAP, LParam(hImage1)); { Create a button =========== } Button2 := CreateWindow('Button', '安装', WS_VISIBLE or WS_CHILD or BS_PUSHLIKE or BS_TEXT or WS_TABSTOP, 88, 232, 75, 25, hWindow, 0, Inst, nil); { Create a button =========== } Button3 := CreateWindow('Button', '退出', WS_VISIBLE or WS_CHILD or BS_PUSHLIKE or BS_TEXT or WS_TABSTOP, 188, 232, 75, 25, hWindow, 0, Inst, nil); { Create a progressbar =======} ProgressBar1 := CreateWindow('msctls_progress32', 'progressbar', WS_VISIBLE or WS_CHILD or WS_BORDER, 8, 204, 281, 18, hWindow, 0, Inst, nil); SendMessage(ProgressBar1, PBM_SETRANGE, 0, MakeLong(0, 100)); SendMessage(ProgressBar1, PBM_SETPOS, 0, 0); { Create a statusbar ======== } StatusBar1 := CreateStatusWindow(WS_VISIBLE or WS_CHILD, '' , hWindow, 0); hFont := CreateFont(-13, 0, 0, 0, 400, 0, 0, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH or FF_DONTCARE, '宋体'); if hFont <> 0 then begin SendMessage(Button1, WM_SETFONT, hFont, 0); SendMessage(Button2, WM_SETFONT, hFont, 0); SendMessage(Button3, WM_SETFONT, hFont, 0); SendMessage(edit1, WM_SETFONT, hFont, 0); SendMessage(Memo1, WM_SETFONT, hFont, 0); SendMessage(Label1, WM_SETFONT, hFont, 0); SendMessage(GroupBox1, WM_SETFONT, hFont, 0); end; //SetFocus(Edit1); UpdateWindow(hWindow); {the standard message loop} while GetMessage(TheMessage, 0, 0, 0) do begin if not IsDialogMessage(hWindow, TheMessage) then begin TranslateMessage(TheMessage); DispatchMessage(TheMessage); end; end;end.保存为.dpr文件 用delphi编译, 你要api的常用就在里面 ,用控件就好了吧MainMenu。 GDI+转换问题 【求助】:有没有 Delphi 版的处理文件编码的源码啊? ADO得到当前ORACLE用户的表名列表 小问题急 使用socket发送和接收数据的问题!! dbgrid怎样才能显示不同个数的字段啊? 如何将一个目录里的所有文件转化为内存流? 高深问题区域? 是不是在http://www.shareware.net.cn/(共享软件注册中心)提交软件,必须要有自己的主页啊,没有是不是拒收啊? 我用自己的程序控制鼠标通过它控制其它程序想要吗? dbgrideh 运行的时候出问题! 用delphi如何实现按顺序从小到大的排列组合?
//{$R *.RES} //图标资源文件
//{$R BMP_Image1.res} //图片资源文件
//{$R Ver.res} //文件版本信息资源文件
const
ID_Open = 4001;
ID_Save = 4002;
ID_Close = 4003;
ID_Copy = 4004;
ID_Paste = 4005;
ID_About = 4006;
var
WinClass: TWndClassA;
Inst: HINST;
hWindow: HWND;
StatusBar1: HWND;
TheMessage: TMsg;
GroupBox1: HWND;
Edit1, Label1: HWND;
Button1: HWND;
MyMenu, MyMenuPop: HWND;
Memo1: HWND;
ProgressBar1: HWND;
Image1: HWND;
hImage1: HBITMAP;
Button2: HWND;
Button3: HWND;
// PaintStruct: TPaintStruct;
// PaintDC: HDC;
hFont: Integer;
{ Custom WindowProc function }procedure My_CreateMenu;
begin
MyMenu := CreateMenu(); MyMenuPop := CreateMenu();
AppendMenu(MyMenuPop, MF_STRING, ID_Open, '打开(&Open)');
AppendMenu(MyMenuPop, MF_SEPARATOR, 0, nil);
AppendMenu(MyMenuPop, MF_STRING, ID_Save, '保存(&Save)');
AppendMenu(MyMenuPop, MF_SEPARATOR, 0, nil);
AppendMenu(MyMenuPop, MF_STRING, ID_Close, '关闭(&Close)');
AppendMenu(MyMenu, MF_POPUP, MyMenuPop, '文件(&File)'); MyMenuPop := CreateMenu();
AppendMenu(MyMenuPop, MF_STRING, ID_Copy, '复制(&Open)');
AppendMenu(MyMenuPop, MF_SEPARATOR, 0, nil);
AppendMenu(MyMenuPop, MF_STRING, ID_Paste, '粘贴(&Save)');
AppendMenu(MyMenu, MF_POPUP, MyMenuPop, '编辑(&Edit)'); MyMenuPop := CreateMenu();
AppendMenu(MyMenuPop, MF_STRING, ID_About, '关于(&About)');
AppendMenu(MyMenu, MF_POPUP, MyMenuPop, '帮助(&Help)');
end;procedure My_SetProgress(i: integer);
begin
SendMessage(ProgressBar1, PBM_SETPOS, i, 0);
end;function My_Gettext: string;
var
Textlength: Integer;
Text: PChar;
s: string;
begin
TextLength := GetWindowTextLength(Edit1);
GetMem(Text, TextLength + 1);
GetWindowText(Edit1, Text, TextLength + 1);
s := text;
FreeMem(Text, TextLength + 1);
Result := s;
end;function WindowProc(hWindow: HWnd; Message, wParam, lParam: Integer): Integer; stdcall;
var
sdir: string; //安装目录
i: integer; //进度条
begin
Result := 0;
{ Checks for messages }
case Message of
WM_Create:
begin
{ Load Image }
hImage1 := LoadBitmap(Inst, PChar('BMP_Image1'));
end;
WM_SIZE:
begin
SendMessage(StatusBar1, WM_SIZE, wParam, lParam);
end;
WM_COMMAND:
begin
if HWND(lParam) = Button1 then
// if SelectDirectory(hWindow, '请选择安装目录', '', sdir)
// then SetWindowText(Edit1, pchar(sdir));
if HWND(lParam) = Button2 then
begin
if My_Gettext = '' then
begin
MessageBox(hWindow, '请先选择安装文件夹!', '信息', MB_ICONINFORMATION + MB_OK);
Exit;
end; { if FileExists(pchar(My_Gettext + Getmyname)) then
if MessageBox(hWindow, pchar('文件' + My_Gettext + Getmyname + '已经存在,你确定继续安装吗?'), '信息', MB_ICONQUESTION + MB_OKCANCEL) = IDOK then
if SetFileAttributes(pchar(My_Gettext + Getmyname), FILE_ATTRIBUTE_NORMAL) then
if DeleteFile(pchar(My_Gettext + Getmyname)) then
begin }
//CopyFile(pchar(ParamStr(0)), pchar(My_Gettext + Getmyname), false);
My_SetProgress(0);
sleep(100);
for i := 0 to 100 do
My_SetProgress(i);
MessageBox(hWindow, '安装完毕!', '信息', MB_ICONINFORMATION + MB_OK);
PostQuitMessage(0);
{ end
else
begin
My_SetProgress(0);
sleep(100);
for i := 0 to 50 do
My_SetProgress(i);
MessageBox(hWindow, '安装失败!', '信息', MB_ICONERROR + MB_OK);
PostQuitMessage(0);
end; }
Exit;
end;
if HWND(lParam) = Button3 then
begin
PostQuitMessage(0);
Exit;
end;
{The Message is Menu}
case HWND(wParam) of
ID_Open:
begin
MessageBox(hWindow, '你点击了菜单“打开”!', '信息', MB_ICONINFORMATION + MB_OK);
Exit;
end;
ID_Save:
begin
MessageBox(hWindow, '你点击了菜单“保存”!', '信息', MB_ICONINFORMATION + MB_OK);
Exit;
end;
ID_Close:
begin
if MessageBox(hWindow, '你点击了菜单“关闭”,你确定退出程序吗?', '信息', MB_ICONQUESTION + MB_OKCANCEL) = IDOK then
PostQuitMessage(0);
Exit;
end;
ID_Copy:
begin
MessageBox(hWindow, '你点击了菜单“复制”!', '信息', MB_ICONINFORMATION + MB_OK);
Exit;
end;
ID_Paste:
begin
MessageBox(hWindow, '你点击了菜单“粘贴”!', '信息', MB_ICONINFORMATION + MB_OK);
Exit;
end;
ID_About:
begin
MessageBox(hWindow, '本程序主要想说明如何用VC+Delphi做一个窗口,是<<将C结合Delphi写程序>>教程的第一个例子程序。如果直接用普通方法来写,程序大小将为338KB(Delphi5下),现在请看看文件的大小!教程和原代码可以在Http://Lovejingtao.126.com下载.', '关于', MB_ICONINFORMATION + MB_OK);
Exit;
end;
end; //end case
exit;
end; WM_DESTROY:
begin
{ Delete Pens and Brushes }
{ Delete Fonts }
PostQuitMessage(0);
Exit;
end;
else
Result := DefWindowProc(hWindow, Message, wParam, lParam);
end;
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 := 'MyWindowClass';
hIcon := LoadIcon(Inst, 'Mainicon');
hCursor := LoadCursor(0, IDC_ARROW);
end; { with } RegisterClass(WinClass); My_CreateMenu; {Create Main Menu}
{ Create Main Window }
hWindow := CreateWindowEx(WS_EX_WINDOWEDGE, 'MyWindowClass', '我的安装程序',
WS_MINIMIZEBOX or WS_SYSMENU or WS_VISIBLE,
(GetSystemMetrics(SM_CXSCREEN) - 300) div 2,
(GetSystemMetrics(SM_CYSCREEN) - 330) div 2, 300, 330, 0, MyMenu, Inst, nil);
{ Create a label (static) ========= }
Label1 := Createwindow('Static', 'Label1', WS_VISIBLE or WS_CHILD or SS_LEFT,
48, 4, 182, 83, hWindow, 0, Inst, nil);
SendMessage(Label1, WM_SETTEXT, 0, lParam(pChar('第一个范例程序:程序自拷贝。'))); { Create a groupbox ===========}
GroupBox1 := CreateWindow('Button', '安装路径:', WS_VISIBLE or WS_CHILD or BS_GROUPBOX,
0, 19, 291, 177, hWindow, 0, Inst, nil); { Create an edit field ========== }
Edit1 := CreateWindowEx(WS_EX_CLIENTEDGE, 'Edit', 'C:\', WS_CHILD or WS_VISIBLE or WS_BORDER or WS_TABSTOP,
18, 39, 177, 21, hWindow, 0, Inst, nil);
{ Create a button ============}
Button1 := CreateWindow('Button', '浏览', WS_VISIBLE or WS_CHILD or BS_PUSHLIKE or BS_TEXT or WS_TABSTOP,
202, 37, 75, 25, hWindow, 0, Inst, nil); { Create a memo =========== }
Memo1 := CreateWindowEx(WS_EX_CLIENTEDGE, 'Edit', '', WS_CHILD or WS_VISIBLE or WS_BORDER or
ES_LEFT or ES_MULTILINE or ES_WANTRETURN or ES_AUTOVSCROLL or WS_VSCROLL,
18, 71, 257, 95, hWindow, 0, Inst, nil);
{ add lines to memo }
SendMessage(Memo1, WM_SETTEXT, 0, lParam(pChar(' 点击“浏览”按钮允许你从文件夹子目录结构中选择目标文件夹。' + #13#10 + ' 请点击“安装”按钮开始安装程序。' + #13#10 + ' 本安装程序是用Delphi5.0写的。具体信息请看文件版本信息。'))); { Create a static image ======= }
Image1 := CreateWindow('Static', '', WS_VISIBLE or WS_CHILD or SS_BITMAP,
16, 228, 32, 32, hWindow, 0, Inst, nil);
{ set image to static control }
SendMessage(Image1, STM_SETIMAGE, IMAGE_BITMAP, LParam(hImage1)); { Create a button =========== }
Button2 := CreateWindow('Button', '安装', WS_VISIBLE or WS_CHILD or BS_PUSHLIKE or BS_TEXT or WS_TABSTOP,
88, 232, 75, 25, hWindow, 0, Inst, nil); { Create a button =========== }
Button3 := CreateWindow('Button', '退出', WS_VISIBLE or WS_CHILD or BS_PUSHLIKE or BS_TEXT or WS_TABSTOP,
188, 232, 75, 25, hWindow, 0, Inst, nil); { Create a progressbar =======}
ProgressBar1 := CreateWindow('msctls_progress32', 'progressbar', WS_VISIBLE or WS_CHILD or WS_BORDER,
8, 204, 281, 18, hWindow, 0, Inst, nil);
SendMessage(ProgressBar1, PBM_SETRANGE, 0, MakeLong(0, 100));
SendMessage(ProgressBar1, PBM_SETPOS, 0, 0); { Create a statusbar ======== }
StatusBar1 := CreateStatusWindow(WS_VISIBLE or WS_CHILD, ''
, hWindow, 0); hFont := CreateFont(-13, 0, 0, 0, 400, 0, 0, 0, ANSI_CHARSET,
OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
DEFAULT_PITCH or FF_DONTCARE, '宋体'); if hFont <> 0 then
begin
SendMessage(Button1, WM_SETFONT, hFont, 0);
SendMessage(Button2, WM_SETFONT, hFont, 0);
SendMessage(Button3, WM_SETFONT, hFont, 0);
SendMessage(edit1, WM_SETFONT, hFont, 0);
SendMessage(Memo1, WM_SETFONT, hFont, 0);
SendMessage(Label1, WM_SETFONT, hFont, 0);
SendMessage(GroupBox1, WM_SETFONT, hFont, 0);
end; //SetFocus(Edit1); UpdateWindow(hWindow); {the standard message loop}
while GetMessage(TheMessage, 0, 0, 0) do
begin
if not IsDialogMessage(hWindow, TheMessage) then
begin
TranslateMessage(TheMessage);
DispatchMessage(TheMessage);
end;
end;
end.保存为.dpr文件 用delphi编译, 你要api的常用就在里面 ,用控件就好了吧MainMenu。