Add scrollbar win32 API Delphi7



  • How to add scrollbar win32 API Delphi7. I need to add three scrollbar min=0 max=255 each. And to change the values in the relevant edit when moving the shelf. введите сюда описание изображения

    program Project1;
    

    uses
    Windows,
    Messages,
    SysUtils;

    var
    Msg : TMSG;
    LWndClass : TWndClass;
    hMainHandle: HWND;
    hButton : HWND;
    hStatic : HWND;
    hEdit : HWND;
    hEdit1 : HWND;
    hEdit2 : HWND;
    hFontText : HWND;
    hFontButton: HWND;

    procedure ReleaseResources;
    begin
    DestroyWindow(hButton);
    DestroyWindow(hStatic);
    DestroyWindow(hEdit);
    DestroyWindow(hEdit1);
    DestroyWindow(hEdit2);
    DeleteObject(hFontText);
    DeleteObject(hFontButton);
    PostQuitMessage(0);
    end;

    function SetScrollRange(hWnd: HWND; nBar, nMinPos, nMaxPos: Integer;
    bRedraw: BOOL): BOOL;
    begin
    end;
    function WindowProc(hWnd,Msg:Longint; wParam : WPARAM; lParam: LPARAM):Longint; stdcall;
    begin
    case Msg of
    WM_COMMAND: if lParam = hButton then
    MessageBox(hMainHandle,'You pressed the button Hello', 'Hello',MB_OK or MB_ICONINFORMATION);
    WM_DESTROY: ReleaseResources;
    end;
    Result:=DefWindowProc(hWnd,Msg,wParam,lParam);
    end;

    begin
    //create the window
    LWndClass.hInstance := hInstance;
    with LWndClass do
    begin
    lpszClassName := 'MyWinApiWnd';
    Style := CS_PARENTDC or CS_BYTEALIGNCLIENT;
    hIcon := LoadIcon(hInstance,'MAINICON');
    lpfnWndProc := @WindowProc;
    hbrBackground := COLOR_BTNFACE+1;
    hCursor := LoadCursor(0,IDC_ARROW);
    end;

    RegisterClass(LWndClass);
    hMainHandle := CreateWindow(LWndClass.lpszClassName,'RGB', WS_CAPTION or WS_MINIMIZEBOX or WS_SYSMENU or WS_VISIBLE, (GetSystemMetrics(SM_CXSCREEN) div 2)-190,
    (GetSystemMetrics(SM_CYSCREEN) div 2)-170, 386,200,0,0,hInstance,nil);

    //Create the fonts to use
    hFontText := CreateFont(-14,0,0,0,0,0,0,0,DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,VARIABLE_PITCH or FF_SWISS,'Tahoma');
    hFontButton := CreateFont(-14,0,0,0,0,0,0,0,DEFAULT_CHARSET,OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,VARIABLE_PITCH or FF_SWISS,'Tahoma');

    //create the edit
    hEdit:=CreateWindowEx(WS_EX_CLIENTEDGE,'Edit','0', WS_VISIBLE or WS_CHILD or ES_LEFT or ES_AUTOHSCROLL,200,35,160,23,hMainHandle,0,hInstance,nil);
    hEdit1:=CreateWindowEx(WS_EX_CLIENTEDGE,'Edit','0', WS_VISIBLE or WS_CHILD or ES_LEFT or ES_AUTOHSCROLL,200,65,160,23,hMainHandle,0,hInstance,nil);
    hEdit2:=CreateWindowEx(WS_EX_CLIENTEDGE,'Edit','0', WS_VISIBLE or WS_CHILD or ES_LEFT or ES_AUTOHSCROLL,200,95,160,23,hMainHandle,0,hInstance,nil);

    SendMessage(hEdit,WM_SETFONT,hFontText,0);
    SendMessage(hEdit1,WM_SETFONT,hFontText,0);
    SendMessage(hEdit2,WM_SETFONT,hFontText,0);

    end.

    введите сюда описание изображения



  • program Project1;
    
    uses
      Windows,
      Messages,
      SysUtils;
    
    var
      Msg        : TMSG;
      LWndClass  : TWndClass;
      hMainHandle: HWND;
      hButton    : HWND;
      hStatic    : HWND;
      hEdit      : HWND;
      hEdit1     : HWND;
      hEdit2     : HWND;
      hFontText  : HWND;
      hFontButton: HWND;
      hScroll    : HWND;
      hScroll1    : HWND;
      hScroll2    : HWND;
    
    procedure ReleaseResources;
    begin
      DestroyWindow(hButton);
      DestroyWindow(hStatic);
      DestroyWindow(hEdit);
      DestroyWindow(hEdit1);
      DestroyWindow(hEdit2);
      DestroyWindow(hScroll);
      DestroyWindow(hScroll1);
      DestroyWindow(hScroll2);
      DeleteObject(hFontText);
      DeleteObject(hFontButton);
      PostQuitMessage(0);
    end;
    
    function SetScrollRange(hWnd: HWND; nBar, nMinPos, nMaxPos: Integer;
    bRedraw: BOOL): BOOL;
     begin
         Result:=true;
     end;
    function WindowProc(hWnd,Msg:Longint; wParam : WPARAM; lParam: LPARAM):Longint; stdcall;
    begin
      case Msg of
          WM_DESTROY: ReleaseResources;
      end;
      Result:=DefWindowProc(hWnd,Msg,wParam,lParam);
    end;
    
    begin
      //create the window
      LWndClass.hInstance := hInstance;
      with LWndClass do
        begin
          lpszClassName := 'MyWinApiWnd';
          Style         := CS_PARENTDC or CS_BYTEALIGNCLIENT;
          hIcon         := LoadIcon(hInstance,'MAINICON');
          lpfnWndProc   := @WindowProc;
          hbrBackground := 14;
          hCursor       := LoadCursor(0,IDC_ARROW);
        end;
    
      RegisterClass(LWndClass);
      hMainHandle := CreateWindow(LWndClass.lpszClassName,'RGB', WS_CAPTION or WS_MINIMIZEBOX or WS_SYSMENU or WS_VISIBLE, (GetSystemMetrics(SM_CXSCREEN) div 2)-190,
          (GetSystemMetrics(SM_CYSCREEN) div 2)-170, 386,200,0,0,hInstance,nil);
    
      //Create the fonts to use
      hFontText := CreateFont(-14,0,0,0,0,0,0,0,DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,VARIABLE_PITCH or FF_SWISS,'Tahoma');
      hFontButton := CreateFont(-14,0,0,0,0,0,0,0,DEFAULT_CHARSET,OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,VARIABLE_PITCH or FF_SWISS,'Tahoma');
    
      //create the edit
      hEdit:=CreateWindowEx(WS_EX_CLIENTEDGE,'Edit','0', WS_VISIBLE or WS_CHILD or ES_LEFT or ES_AUTOHSCROLL,200,35,160,23,hMainHandle,0,hInstance,nil);
      hEdit1:=CreateWindowEx(WS_EX_CLIENTEDGE,'Edit','0', WS_VISIBLE or WS_CHILD or ES_LEFT or ES_AUTOHSCROLL,200,65,160,23,hMainHandle,0,hInstance,nil);
      hEdit2:=CreateWindowEx(WS_EX_CLIENTEDGE,'Edit','0', WS_VISIBLE or WS_CHILD or ES_LEFT or ES_AUTOHSCROLL,200,95,160,23,hMainHandle,0,hInstance,nil);
    
      SendMessage(hEdit,WM_SETFONT,hFontText,0);
      SendMessage(hEdit1,WM_SETFONT,hFontText,0);
      SendMessage(hEdit2,WM_SETFONT,hFontText,0);
    
      hScroll:=CreateWindowEx(WM_HSCROLL, 'Scrollbar','0', WS_VISIBLE or WS_CHILD or ES_LEFT or ES_AUTOHSCROLL,10,35,160,23,hMainHandle,0,hInstance,nil);
      hScroll1:=CreateWindowEx(WM_HSCROLL, 'Scrollbar','0', WS_VISIBLE or WS_CHILD or ES_LEFT or ES_AUTOHSCROLL,10,65,160,23,hMainHandle,0,hInstance,nil);
      hScroll2:=CreateWindowEx(WM_HSCROLL, 'Scrollbar','0', WS_VISIBLE or WS_CHILD or ES_LEFT or ES_AUTOHSCROLL,10,95,160,23,hMainHandle,0,hInstance,nil);
      SetScrollRange(hScroll,SB_HORZ,0,255,true);
    
    
    
      SendMessage(hScroll,WM_SETFONT,hFontText,0);
      SendMessage(hScroll1,WM_SETFONT,hFontText,0);
      SendMessage(hScroll2,WM_SETFONT,hFontText,0);
    
    
      //message loop
      while GetMessage(Msg,0,0,0) do
      begin
        TranslateMessage(Msg);
        DispatchMessage(Msg);
      end;
    
    end.
    


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2