Author Topic: RegisterClass ?  (Read 5809 times)

0 Members and 1 Guest are viewing this topic.

Aurel

  • Guest
Re: RegisterClass ?
« Reply #15 on: February 08, 2014, 04:15:18 PM »
ok i do this and again nothing  ???
here is my code so you can try:..

Code: [Select]
'skeleton VB way...
$ filename "skeleton.exe"
'include "rtl32.inc"
'#lookahead
'structures
Type WNDCLASSEX
 cbSize        as int
 Style         as int
 lpfnwndproc   as sys
 cbClsextra    as int
 cbWndExtra    as int
 hInstance     as sys
 hIcon         as sys
 hCursor       as sys
 hbrBackground as sys
 lpszMenuName  as sys
 lpszClassName as sys
 hIconSm       AS sys
End Type

Type POINTAPI
 x as long
 y as long
End Type

Type MSG
 hwnd    as sys
 message as int
 wParam  as sys
 lParam  as sys
 time    as dword
 pt      as POINTAPI
End Type

'constants
% IDI_WINLOGO     = 32517
% IDI_APPLICATION = 32512
% IDC_ARROW       = 32512
% CS_OWNDC        = 32
% CS_DBLCLKS      =  &H8
% SW_NORMAL       = 1
% SW_SHOW         = 5

% WM_CREATE      = 1
% WM_DESTROY     = 2
% WM_PAINT       = 15
% WM_QUIT        = 18
% WM_SIZE        = 5
% WM_MOVE        = 3
% WM_CHAR        = 258
% WM_KEYDOWN     = 256
% WM_KEYUP       = 257
% WM_MOUSEMOVE   = 512
% WM_MBUTTONDOWN = 519
% WM_LBUTTONDOWN = 513
% WM_RBUTTONDOWN = 516
% WM_LBUTTONUP   = 514
% WM_RBUTTONUP   = 517
% WM_MBUTTONUP   = 520

% WS_OVERLAPPEDWINDOW = 0x00CF0000
% WS_SYSMENU     = 0x80000
% WS_OVERLAPPED  = WS_SYSMENU     
% WS_POPUP       = 0x80000000
% WS_DLGFRAME    = 0x400000
% WS_VISIBLE     = 0x10000000
'defines...
Def WHITE_BRUSH   0
Def BLACK_BRUSH   4

'declarations...
'Declare Function MessageBox Lib "kernel32.dll" Alias "MessageBoxA" (ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long) As Long
Declare Function LoadIcon Lib "user32.dll" Alias "LoadIconA" (ByVal hInstance As Long, ByVal lpIconName As Any) As Long
Declare Function LoadCursor Lib "user32.dll" Alias "LoadCursorA" (ByVal hInstance As Long, ByVal lpCursorName As Any) As Long
Declare Function GetModuleHandle Lib "kernel32.dll" Alias "GetModuleHandleA" (sys lpModuleName) as Long
Declare Function RegisterClassEx Lib "user32.dll" Alias "RegisterClassExA" (WNDCLASSEX *lpwcx) as Long
'Declare Function RegisterClass Lib "user32.dll" Alias "RegisterClassA" (byref lpwcx as WNDCLASS) as Long
Declare Function CreateWindowEx Lib "user32.dll" Alias "CreateWindowExA" (byval dwExStyle AS INT,byval lpClassName AS STRING,byval lpWindowName AS STRING,byval dwStyle AS INT,byval x AS INT,byval y AS INT,byval nWidth AS INT,byval nHeight AS INT,byval hWndParent AS INT,byval hMenu AS INT,byval hInstance AS INT,byval lpParam AS INT) as Long
Declare Function TranslateMessage Lib "user32.dll" (lpMsg as Long) as Long
Declare Function DispatchMessage  Lib "user32.dll" Alias "DispatchMessageA" (lpMsg as Long) as Long
Declare Function GetMessage Lib "user32.dll" Alias "GetMessageA" (byval lpMsg As MSG, ByVal hWnd As Long, ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long) As Long
Declare Function ShowWindow Lib "user32.dll" (ByVal hWnd As Long, ByVal nCmdShow As Long) As Long
Declare Function DefWindowProc Lib "user32.dll" Alias "DefWindowProcA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Declare Sub PostQuitMessage Lib "user32.dll" (ByVal nExitCode As Long)

Dim wcx as WNDCLASSEX
Dim wm as MSG

'FILL WNDCLASSEX structure
inst = GetModuleHandle 0
wcx.cbSize        = sizeOf(WNDCLASSEX)
wcx.style         = CS_DBLCLKS Or CS_OWNDC
wcx.lpfnWndProc   = &WndProc
wcx.cbClsExtra    = 0
wcx.cbWndExtra    = 0
wcx.hInstance     = inst
wcx.hIcon         = LoadIcon 0,IDI_APPLICATION         
wcx.hCursor       = LoadCursor 0,IDC_ARROW 
wcx.hbrBackground = WHITE_BRUSH     
wcx.lpszMenuName  = strptr "menu"
wcx.lpszClassName = strptr "Oxygen"
wcx.hIconSm       = 0

'register window class Ex
RegisterClassEx wcx

'create window -------------------------------
Dim hwnd,style, Wx, Wy, Ww, Wh, wparent as Long
Dim caption as String
'-------------------------------
caption = "MyWindow"
style   = WS_OVERLAPPEDWINDOW
Wx=0 : Wy=0 : Ww=640 : Wh=480
wparent = 0 'HWND_DESKTOP
'-------------------------------
Hwnd = CreateWindowEx 0, wcx.lpszClassName, caption, style, Wx, Wy, Ww, Wh, wparent, 0, inst,0
ShowWindow Hwnd,SW_SHOW
'-------------------------------
'message loop
WHILE GetMessage(wm,0,0,0) <> 0
     TranslateMessage wm
     DispatchMessage  wm
WEND

'main callback procedure ---------------------------------------
Function WndProc (sys hwnd,wMsg,wParam,lParam) as sys callback
Select wMsg
CASE WM_DESTROY
      PostQuitMessage 0
End Select
Return DefWindowProc(Hwnd,wMsg,wParam,lParam)

End Function
'------------------------------------------

Charles Pegge

  • Guest
Re: RegisterClass ?
« Reply #16 on: February 08, 2014, 05:33:30 PM »
Lots of errors, too hard to read, but I got it working after a fashion..


.

Aurel

  • Guest
Re: RegisterClass ?
« Reply #17 on: February 08, 2014, 11:41:05 PM »
First of all thank you Charles..
and there is no lots of errors at all
the main problem I was made in
udt :
wcx.lpszClassName inside
CreateWindowEx which need string pointer

and just one thing i have never made default return inside SELECT
in WndProc

Another point i have made mistake with WHITE_BRUSH which must be 4 not 0.

Hard to read  ???
It is very easy to read and i don't see why is hard because represent classic VB way of
window creation.
All in all it is easier to use Bind which i use in my other programs.
Thanks again  ;)

Aurel

  • Guest
Re: RegisterClass ?
« Reply #18 on: February 09, 2014, 01:14:03 AM »
So
Here we are ... after creating exe file on this (almost VB way) i get only
3 alert from Virus Total site and this is the proof that using VB or if you
whish most standard way of declared Api functions cose less virus alerts.
and that is good!

Quote
AntiVir      TR/Crypt.XPACK.Gen2      20140208
Emsisoft    Backdoor.Generic.840440 (B)    20140209
Rising    PE:Malware.XPACK-LNR/Heur!1.5594    20140208
AVG       20140209
Ad-Aware       20140209
Agnitum       20140208
AhnLab-V3       20140208
Antiy-AVL       20140208
Avast       20140209
Baidu-International       20140209
BitDefender       20140209
Bkav       20140208
ByteHero       20140209
CAT-QuickHeal       20140208
CMC       20140122
ClamAV       20140209
Commtouch       20140209
Comodo       20140209
DrWeb       20140209
ESET-NOD32       20140208
F-Prot       20140209
F-Secure       20140209
Fortinet       20140209
GData       20140209
Ikarus       20140209
Jiangmin       20140209
K7AntiVirus       20140207
K7GW       20140207
Kaspersky       20140209
Kingsoft       20140209
Malwarebytes       20140209
McAfee       20140209
McAfee-GW-Edition       20140209
MicroWorld-eScan       20140209
Microsoft       20140209
NANO-Antivirus       20140209
Norman       20140209
Panda       20140208
Qihoo-360       20140209
SUPERAntiSpyware       20140208
Sophos       20140209
Symantec       20140209
TheHacker       20140208
TotalDefense       20140208
TrendMicro       20140209
TrendMicro-HouseCall       20140209
VBA32       20140207
VIPRE       20140209
ViRobot       20140209
nProtect       20140209

Charles Pegge

  • Guest
Re: RegisterClass ?
« Reply #19 on: February 09, 2014, 02:28:28 AM »
Hi Aurel,

If you want to use VB-style headers then I recommend looking at /projectsB/WinApiVB6/

There is a substantial hunk of the VB headers in there, which Kent put together.

All the type definitions containing string have been replaced by char*.
This will allow you to assign strings to these members in the normal way without strptr

But this API will not support 64 bit binaries due to using 'long' and 'dword' for pointers/handles.

Aurel

  • Guest
Re: RegisterClass ?
« Reply #20 on: February 09, 2014, 03:39:54 AM »
Quote
Hi Aurel,
If you want to use VB-style headers then I recommend looking at /projectsB/WinApiVB6/
There is a substantial hunk of the VB headers in there, which Kent put together.
All the type definitions containing string have been replaced by char*.
This will allow you to assign strings to these members in the normal way without strptr
But this API will not support 64 bit binaries due to using 'long' and 'dword' for pointers/handles.

Hi Charles,
Main point ,as you can see , is security and avoid so many virus alerts .
And it looks that i have a right about that.
If you ask me i like to use Bind(),but as you see it looks that using Bind() we produce virus alerts
and i want that my exe-s are clean as possible.
If you ask me about strptr ...i like to use strptr  ;)
Thanks for help  ;)

Charles Pegge

  • Guest
Re: RegisterClass ?
« Reply #21 on: February 09, 2014, 04:12:58 AM »
The more recent MinWins no longer use bind. The conversion is very simple:

Example: User32.dll
Code: [Select]
 extern lib "User32.dll"
  ! LoadIcon              "LoadIconA"             '2
  ! LoadCursor            "LoadCursorA"           '2
  ! LoadImage             "LoadImageA"            '6
  ! RegisterClass         "RegisterClassA"        '1
  ! RegisterClassEx       "RegisterClassExA"      '1
  ! UnregisterClass       "UnregisterClassA"      '1
  ! ShowCursor                                    '1
  ! MessageBox            "MessageBoxA"           '1
  ! CreateWindowEx        "CreateWindowExA"       '12
  ! ShowWindow                                    '2
  ! UpdateWindow                                  '1
  ! AdjustWindowRectEx                            '4
  ! GetMessage            "GetMessageA"           '4
  ! PeekMessage           "PeekMessageA"          '5
  ! TranslateAccelerator                          '3
  ! TranslateMessage                              '1
  ! DispatchMessage       "DispatchMessageA"      '1
  ! PostQuitMessage                               '1
  ! BeginPaint                                    '2
  ! EndPaint                                      '2
  ! GetClientRect                                 '2  
  ! GetWindowRect                                 '2  
  ! DrawText              "DrawTextA"             '5
  ! PostMessage           "PostMessageA"          '4
  ! DefWindowProc         "DefWindowProcA"        '4
  ! EnumChildWindows                              '3
  ! MoveWindow                                    '6
  ! DestroyWindow                                 '1
  ! GetWindowLong         "GetWindowLongA"        '2
  ! FillRect                                      '3
  ! GetDC                                         '1
  ! GetWindowDC                                   '1
  ! ReleaseDC                                     '2
  ! SetTimer                                      '4
  ! KillTimer                                     '2
  ! GetCapture                                    '0
  ! ReleaseCapture                                '0
  ! SetCapture                                    '1
  ! GetAsyncKeyState                              '1
  ! InvalidateRect                                '3
  ! ValidateRect                                  '2
  ! SendMessage           "SendMessageA"          '4
  ! GetSystemMetrics                              '1
  ! EmptyClipboard                                '0
  ! OpenClipboard                                 '1
  ! CloseClipboard                                '1
  ! GetClipboardData                              '1
  ! SetClipboardData                              '2
  ! GetFocus                                      '0
  ! SetFocus                                      '1
  ! SetWindowText         "SetWindowTextA"        '2
  ! SetWindowPos                                  '7
  ! SetForegroundWindow                           '1
  ! EnumDisplaySettings   "EnumDisplaySettingsA"  '3
  ! ChangeDisplaySettings "ChangeDisplaySettingsA"'2
  ! LoadAccelerators      "LoadAcceleratorsA"     '2
  ! DialogBoxParam        "DialogBoxParamA"       '5
  ! EndDialog                                     '2
  ! CreateMenu                                    '0
  ! InsertMenu             "InsertMenuA"          '5
  ! CreatePopupMenu                               '0
  ! TrackPopupMenu                                '7
  ! DestroyMenu                                   '1
  ! GetMenu                                       '1
  ! GetSystemMenu                                 '0
  ! SetMenu                                       '2
  ! AppendMenu            "AppendMenuA"           '4
  ! CheckMenuItem                                 '3
  ! EnableMenuItem                                '3
  end extern

These are the same as declare function statements, but prototypes are optional :)