2012年7月5日星期四

SysTabControl32.Asm


;以前看到一些anti-rootkit的软件的界面大多用tab控件,当时没有用过,今天终于用了。
.386
.model flat,stdcall
option casemap:none
include windows.inc

include kernel32.inc
includelib kernel32.lib

include user32.inc
includelib user32.lib

include comctl32.inc
includelib comctl32.lib

.code
hInstance dd 0
hWinMain dd 0
szClassName db "made by correy",0
pwndclassex dd 48,3,offset liuchunli,0,0,0,0,0,6,0,offset szClassName,0
stMsg MSG <>
icex INITCOMMONCONTROLSEX <>
szSysTabControl32 db "SysTabControl32",0
htab dd 0

hwnd0 dd 0
hwnd1 dd 0
hwnd2 dd 0
hwnd3 dd 0

liuchunli proc uses ebx edi esi,hWnd,uMsg,wParam,lParam
LOCAL hdc:HDC, ps:PAINTSTRUCT
.if uMsg == WM_CLOSE;放置后面会反应更快点。
  invoke DestroyWindow,hWinMain
  invoke PostQuitMessage,0
.elseif uMsg == WM_CREATE
 
.elseif uMsg == WM_NOTIFY
  mov eax,dword ptr [lParam]
  mov eax,[eax+8]
  .if eax == TCN_SELCHANGE
    invoke ShowWindow,hwnd0,SW_HIDE
    invoke ShowWindow,hwnd1,SW_HIDE
    invoke ShowWindow,hwnd2,SW_HIDE
    invoke ShowWindow,hwnd3,SW_HIDE
   
    invoke SendMessage,htab,TCM_GETCURSEL,0,0
    .if eax == 0
      invoke ShowWindow,hwnd0,SW_SHOW
    .elseif eax == 1
      invoke ShowWindow,hwnd1,SW_SHOW
    .elseif eax == 2
      invoke ShowWindow,hwnd2,SW_SHOW
    .elseif eax == 3
      invoke ShowWindow,hwnd3,SW_SHOW
    .else
      nop
    .endif
   
  .endif
.else
  invoke DefWindowProc,hWnd,uMsg,wParam,lParam
  ret;不能去掉。
.endif
xor eax,eax;这两行可以去掉?
ret
liuchunli endp

tie TC_ITEM <>
szhi1 db "hi1",0
szhi2 db "hi2",0
szhi3 db "hi3",0
szhi4 db "hi4",0

szedit db "EDIT",0
szJust1 db "Just1",0
szJust2 db "Just2",0
szJust3 db "Just3",0
szJust4 db "Just4",0

start:invoke GetModuleHandle,0
mov hInstance,eax
mov pwndclassex+20,eax

invoke LoadCursor,0,32512;加载箭头鼠标。
mov pwndclassex+28,eax

invoke RegisterClassEx,addr pwndclassex
invoke CreateWindowEx,200h,offset szClassName,offset szClassName,0Ca0000h,80000000h,80000000h,710,530,0,0,hInstance,0;0Ca0000h 0Cf0000h
mov hWinMain,eax

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;为啥这些内容放置到WM_CREATE中会失败呢?这是个小问题,我想应该很容易解决,暂时没有解决。
invoke InitCommonControls
invoke CreateWindowEx,0, addr szSysTabControl32, 0,WS_CHILD or WS_CLIPSIBLINGS or WS_VISIBLE, 0, 0, 660, 390,hWinMain, 0,hInstance, 0
mov htab,eax

mov tie.imask,1;TCIF_TEXT == 1
lea eax,szhi1
mov tie.pszText,eax
invoke SendMessage,htab,TCM_INSERTITEM,0,addr tie

lea eax,szhi2
mov tie.pszText,eax
invoke SendMessage,htab,TCM_INSERTITEM,1,addr tie

lea eax,szhi3
mov tie.pszText,eax
invoke SendMessage,htab,TCM_INSERTITEM,2,addr tie

lea eax,szhi4
mov tie.pszText,eax
invoke SendMessage,htab,TCM_INSERTITEM,3,addr tie

invoke CreateWindowEx,200h,addr szedit,addr szJust1, WS_CHILD or WS_TABSTOP or WS_BORDER, 9, 50, 100, 25, hWinMain, NULL, hInstance, NULL
mov hwnd0,eax
invoke CreateWindowEx,200h,addr szedit,addr szJust2,WS_CHILD or WS_TABSTOP or WS_BORDER, 9, 50, 100, 25, hWinMain, NULL, hInstance, NULL
mov hwnd1,eax
invoke CreateWindowEx,200h,addr szedit,addr szJust3, WS_CHILD or WS_TABSTOP or WS_BORDER, 9, 50, 100, 25, hWinMain, NULL, hInstance, NULL
mov hwnd2,eax
invoke CreateWindowEx,200h,addr szedit,addr szJust4, WS_CHILD or WS_TABSTOP or WS_BORDER, 9, 50, 100, 25, hWinMain, NULL, hInstance, NULL
mov hwnd3,eax

invoke SendMessage,htab,TCM_SETCURSEL,0,0
invoke ShowWindow,hwnd0,SW_SHOW
invoke SetFocus,hwnd0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

invoke ShowWindow,hWinMain,1;若不想显示,此行也可以去掉。
again:invoke GetMessage,addr stMsg,0,0,0
  cmp eax,0
  je exit
  invoke DispatchMessage,addr stMsg
jmp again
exit:invoke ExitProcess,0
end start
;made at 2011.10.08
;下面是c/c++代码.
#include <windows.h>
#include <commctrl.h>
#pragma comment(lib,"Commctrl.lib")

HWND hwndMain;
HWND hwndTab;
HWND hwnd0;
HWND hwnd1;
HWND hwnd2;
HWND hwnd3;
HINSTANCE hinst;

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
  switch(msg)
  {
  case WM_CLOSE:
    DestroyWindow(hwnd);
    break;
  case WM_DESTROY:
    PostQuitMessage(0);
    break;
  case WM_CREATE:

    break;
  case WM_NOTIFY:
    switch (((LPNMHDR)lParam)->code)
    {
    case TCN_SELCHANGE:
      {
        int iPage = TabCtrl_GetCurSel(hwndTab);//TCM_GETCURSEL
        ShowWindow(hwnd0,SW_HIDE);
        ShowWindow(hwnd1,SW_HIDE);
        ShowWindow(hwnd2,SW_HIDE);
        ShowWindow(hwnd3,SW_HIDE);
        if(iPage == 0)
          ShowWindow(hwnd0,SW_SHOW);
        SetFocus(hwnd0);
        if(iPage == 1)
          ShowWindow(hwnd1,SW_SHOW);
        SetFocus(hwnd1);
        if(iPage == 2)
          ShowWindow(hwnd2,SW_SHOW);
        SetFocus(hwnd2);
        if(iPage == 3)
          ShowWindow(hwnd3,SW_SHOW);
        SetFocus(hwnd3);
        break;
      }
    }
    break;
  default:
    return DefWindowProc(hwnd, msg, wParam, lParam);
  }
  return 0;
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
  WNDCLASSEX wc = {48,3,WndProc,0,0,GetModuleHandle(0),0,LoadCursor(0,IDC_ARROW),(HBRUSH)6,0,"correy",0};
  hinst=hInstance;

  RegisterClassEx(&wc);
  hwndMain = CreateWindowEx(0,"correy","correy",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,0,0, GetModuleHandle(0),0);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  //这一段写入WM_CREATE消息如何?
  InitCommonControls();
  hwndTab=CreateWindowEx(0, "SysTabControl32", "",WS_CHILD|WS_CLIPSIBLINGS|WS_VISIBLE, 0, 0, 300, 250, hwndMain, NULL, GetModuleHandle(0), NULL);

  TCITEM tie;
  tie.mask = TCIF_TEXT;
  tie.pszText = "Hi1";
  TabCtrl_InsertItem(hwndTab, 0, &tie); //TCM_INSERTITEM

  tie.mask = TCIF_TEXT;
  tie.pszText = "Hi2";
  TabCtrl_InsertItem(hwndTab, 1, &tie);

  tie.mask = TCIF_TEXT;
  tie.pszText = "Hi3";
  TabCtrl_InsertItem(hwndTab, 2, &tie);

  tie.mask = TCIF_TEXT;
  tie.pszText = "Hi4";
  TabCtrl_InsertItem(hwndTab, 3, &tie);

  hwnd0=CreateWindow( "EDIT", "Just1", WS_CHILD | WS_TABSTOP | WS_BORDER, 0, 50, 100, 25, hwndMain, NULL, hinst, NULL);
  hwnd1=CreateWindow( "EDIT", "Just2",WS_CHILD | WS_TABSTOP | WS_BORDER, 0, 50, 100, 25, hwndMain, NULL, hinst, NULL);
  hwnd2=CreateWindow( "EDIT", "Just3", WS_CHILD | WS_TABSTOP | WS_BORDER, 0, 50, 100, 25, hwndMain, NULL, hinst, NULL);
  hwnd3=CreateWindow( "EDIT", "Just4", WS_CHILD | WS_TABSTOP | WS_BORDER, 0, 50, 100, 25, hwndMain, NULL, hinst, NULL);

  TabCtrl_SetCurSel(hwndTab, 0);//显示第几个。 TCM_SETCURSEL
  ShowWindow(hwnd0,SW_SHOW);
  SetFocus(hwnd0);
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  ShowWindow(hwndMain, nCmdShow);
  UpdateWindow(hwndMain);

  MSG Msg;
  ShowWindow(hwndTab, SW_SHOW);
  //UpdateWindow(hwndTab);

  while(GetMessage(&Msg, NULL, 0, 0) > 0)
  {
    //TranslateMessage(&Msg);
    DispatchMessage(&Msg);
  }
  return Msg.wParam;
}

没有评论:

发表评论