星期五, 2月 27, 2009

Form要趨動按鍵有功能

屬性keypreview設為TRUE
接著即可在onkeypressj寫事件囉~

星期二, 2月 24, 2009

windows各種狀態判斷

判斷是否正在螢幕保護程式

function GetScreenSaverRunning : boolean;
var
res : integer
begin
SystemParametersInfo(GETSCREENSAVERRUNNING , 0, @res, 0);
Result := boolean(res);
end;


判斷是否正在電腦鎖定(螢幕保護及CTRL+ALT+DEL跳出另外的視窗也會判斷到)

function IsWorkstationLocked: Boolean;
var
hDesktop: HDESK;
begin
Result := False;
hDesktop := OpenDesktop('default', 0, False, DESKTOP_SWITCHDESKTOP);
if hDesktop <> 0 then
begin
Result := not SwitchDesktop(hDesktop);
CloseDesktop(hDesktop);
end;
end;


判斷是否正在關機、待命、休眠或關閉硬碟

function TEncodeVideoWindowProc(hWnd:HWND; iMsg:Integer; wParam:WPARAM; lParam:LPARAM): Integer; stdcall;
begin
Result:=0;
case iMsg of
WM_DESTROY :
begin
PostQuitMessage(0); //跟Windows說我要退出囉。
exit;
end;

WM_POWERBROADCAST: begin
case wParam of
PBT_APMQUERYSUSPEND:begin
//LogToFile('收到待命、休眠或關閉硬碟的須求');
end;
PBT_APMRESUMESUSPEND:begin
//LogTofile('收到電腦從待命、休眠或關閉硬碟返回的須求,及前錄影格數');
end;
end;

end;

WM_QUERYENDSESSION:
begin
;
end;
end;

Result := DefWindowProc(hWnd,iMsg,wParam,lParam); //不感興趣的消息,由windows去處理
end;

星期三, 2月 18, 2009

cxgrid 欄位 重新排序的popmenu

表單上放上TcxGridPopupMenu元件

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData,
cxDataStorage, cxEdit, DB, cxDBData, cxGridCustomTableView,
cxGridTableView, cxGridDBTableView, cxGridCustomPopupMenu,
cxGridPopupMenu, cxGridLevel, cxClasses, cxControls, cxGridCustomView,
cxGrid, cxGridStdPopupMenu;

type
TMenuStringForCxGrid = class(TObject)
class procedure HeaderMenuProc(Sender:TObject);
end;

type
TForm1 = class(TForm)
cxGrid1: TcxGrid;
cxGDBTV1: TcxGridDBTableView;
cxGLv1: TcxGridLevel;
cxGDBTV1Column1: TcxGridDBColumn;
cxGDBTV1Column2: TcxGridDBColumn;
cxGDBTV1Column3: TcxGridDBColumn;
cxGridPopupMenu1: TcxGridPopupMenu;
procedure cxGridPopupMenu1Popup(ASenderMenu: TComponent;
AHitTest: TcxCustomGridHitTest; X, Y: Integer;
var AllowPopup: Boolean);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
function PopCxGridMenuProc(ASenderMenu: TComponent):boolean;

implementation

{$R *.dfm}

class procedure TMenuStringForCxGrid.HeaderMenuProc(Sender: TObject);
var
HM:TcxGridStdHeaderMenu;
begin
HM:=TcxGridStdHeaderMenu(Sender);
if HM.Items.Count<>17 then exit;
HM.Items[0].Caption:='&'+'遞增排序';//遞增排序
HM.Items[1].Caption:='&'+'遞減排序';//
HM.Items[2].Caption:='&'+'取消排序';//

HM.Items[4].Caption:='&'+'以此欄位分組';//
HM.Items[5].Caption:='&'+'分組視窗';//
HM.Items[6].Visible:=false;
HM.Items[7].Visible:=false;
HM.Items[8].Visible:=false;

HM.Items[10].Caption:='&'+'隱藏此欄位';//
HM.Items[11].Caption:='&'+'欄位選擇視窗';//

HM.Items[13].Visible:=false;
HM.Items[14].Caption:='&'+'最適欄寬';//
HM.Items[15].Visible:=false;
HM.Items[16].Caption:='&'+'最適欄寬(所有欄位)';//

end;

function PopCxGridMenuProc(ASenderMenu: TComponent):boolean;
begin
if ASenderMenu is TcxGridStdHeaderMenu then
TcxGridStdHeaderMenu(ASenderMenu).OnPopup := TMenuStringForCxGrid.HeaderMenuProc;
result:=true;
end;

procedure TForm1.cxGridPopupMenu1Popup(ASenderMenu: TComponent;
AHitTest: TcxCustomGridHitTest; X, Y: Integer; var AllowPopup: Boolean);
begin
PopCxGridMenuProc(ASenderMenu);
end;

end.