您的位置:首页 > 其它

win32汇编--加载对话框资源

2012-09-04 13:17 369 查看
应用程序可以弹出一个窗口,就像之前通过一系统列步骤来完成一个窗口的显示,同样的,应用程序

也可以弹出一个对话框,对话框通过资源文件来实现,然后在程序中调用DialogBoxParam()来加载

该对话框

下面是源代码(完整工程下载)

// //
// create namespaces
//
var dp = {
sh :
{
Toolbar : {},
Utils : {},
RegexLib: {},
Brushes : {},
Strings : {
AboutDialog : 'About...
dp.SyntaxHighlighterVersion: {V}

http://www.dreamprojections.com/syntaxhighlighter

©2004-2007 Alex Gorbatchev.
'
},
ClipboardSwf : null,
Version : '1.5.1'
}
};

// make an alias
dp.SyntaxHighlighter = dp.sh;

dp.sh.Utils.FixForBlogger = function(str)
{
return (dp.sh.isBloggerMode == true) ? str.replace(/
|<br\s*\/?>/gi, '\n') : str;
}

//
// Common reusable regular expressions
//
dp.sh.RegexLib = {
MultiLineCComments : new RegExp('/\\*[\\s\\S]*?\\*/', 'gm'),
SingleLineCComments : new RegExp('//.*$', 'gm'),
SingleLinePerlComments : new RegExp('#.*$', 'gm'),
DoubleQuotedString : new RegExp('"(?:\\.|(\\\\\\")|[^\\""\\n])*"','g'),
SingleQuotedString : new RegExp("'(?:\\.|(\\\\\\')|[^\\''\\n])*'", 'g')
};

//
// Match object
//
dp.sh.Match = function(value, index, css)
{
this.value = value;
this.index = index;
this.length = value.length;
this.css = css;
}

//
// Highlighter object
//
dp.sh.Highlighter = function()
{
this.noGutter = false;
this.addControls = true;
this.collapse = false;
this.tabsToSpaces = true;
this.wrapColumn = 80;
this.showColumns = true;
}

// static callback for the match sorting
dp.sh.Highlighter.SortCallback = function(m1, m2)
{
// sort matches by index first
if(m1.index < m2.index)
return -1;
else if(m1.index > m2.index)
return 1;
else
{
// if index is the same, sort by length
if(m1.length < m2.length)
return -1;
else if(m1.length > m2.length)
return 1;
}
return 0;
}

dp.sh.Highlighter.prototype.CreateElement = function(name)
{
var result = document.createElement(name);
result.highlighter = this;
return result;
}

// gets a list of all matches for a given regular expression
dp.sh.Highlighter.prototype.GetMatches = function(regex, css)
{
var index = 0;
var match = null;

while((match = regex.exec(this.code)) != null)
this.matches[this.matches.length] = new dp.sh.Match(match[0], match.index, css);
}

dp.sh.Highlighter.prototype.AddBit = function(str, css)
{
if(str == null || str.length == 0)
return;

var span = this.CreateElement('SPAN');

// str = str.replace(/&/g, '&');
str = str.replace(/ /g, ' ');
str = str.replace(//g, '>');
str = str.replace(/\n/gm, '
');

// when adding a piece of code, check to see if it has line breaks in it
// and if it does, wrap individual line breaks with span tags
if(css != null)
{
if((/br/gi).test(str))
{
var lines = str.split('
');

for(var i = 0; i < lines.length; i++)
{
span = this.CreateElement('SPAN');
span.className = css;
span.innerHTML = lines[i];

this.div.appendChild(span);

// don't add a
for the last line
if(i + 1 < lines.length)
this.div.appendChild(this.CreateElement('BR'));
}
}
else
{
span.className = css;
span.innerHTML = str;
this.div.appendChild(span);
}
}
else
{
span.innerHTML = str;
this.div.appendChild(span);
}
}

// checks if one match is inside any other match
dp.sh.Highlighter.prototype.IsInside = function(match)
{
if(match == null || match.length == 0)
return false;

for(var i = 0; i < this.matches.length; i++)
{
var c = this.matches[i];

if(c == null)
continue;

if((match.index > c.index) && (match.index < c.index + c.length))
return true;
}

return false;
}

dp.sh.Highlighter.prototype.ProcessRegexList = function()
{
for(var i = 0; i < this.regexList.length; i++)
this.GetMatches(this.regexList[i].regex, this.regexList[i].css);
}

dp.sh.Highlighter.prototype.ProcessSmartTabs = function(code)
{
var lines = code.split('\n');
var result = '';
var tabSize = 4;
var tab = '\t';

// This function inserts specified amount of spaces in the string
// where a tab is while removing that given tab.
function InsertSpaces(line, pos, count)
{
var left = line.substr(0, pos);
var right = line.substr(pos + 1, line.length); // pos + 1 will get rid of the tab
var spaces = '';

for(var i = 0; i < count; i++)
spaces += ' ';

return left + spaces + right;
}

// This function process one line for 'smart tabs'
function ProcessLine(line, tabSize)
{
if(line.indexOf(tab) == -1)
return line;

var pos = 0;

while((pos = line.indexOf(tab)) != -1)
{
// This is pretty much all there is to the 'smart tabs' logic.
// Based on the position within the line and size of a tab,
// calculate the amount of spaces we need to insert.
var spaces = tabSize - pos % tabSize;

line = InsertSpaces(line, pos, spaces);
}

return line;
}

// Go through all the lines and do the 'smart tabs' magic.
for(var i = 0; i < lines.length; i++)
result += ProcessLine(lines[i], tabSize) + '\n';

return result;
}

dp.sh.Highlighter.prototype.SwitchToList = function()
{
// thanks to Lachlan Donald from SitePoint.com for this
tag fix.
var html = this.div.innerHTML.replace(/<(br)\/?>/gi, '\n');
var lines = html.split('\n');

//if(this.addControls == true)
//this.bar.appendChild(dp.sh.Toolbar.Create(this));

// add columns ruler
if(this.showColumns)
{
var div = this.CreateElement('div');
var columns = this.CreateElement('div');
var showEvery = 10;
var i = 1;

while(i <= 150)
{
if(i % showEvery == 0)
{
div.innerHTML += i;
i += (i + '').length;
}
else
{
div.innerHTML += '·';
i++;
}
}

columns.className = 'columns';
columns.appendChild(div);
this.bar.appendChild(columns);
}

for(var i = 0, lineIndex = this.firstLine; i < lines.length - 1; i++, lineIndex++)
{
var li = this.CreateElement('LI');
var span = this.CreateElement('SPAN');

// uses .line1 and .line2 css styles for alternating lines
li.className = (i % 2 == 0) ? 'alt' : '';
span.innerHTML = lines[i] + ' ';

li.appendChild(span);
this.ol.appendChild(li);
}

this.div.innerHTML = '';
}

dp.sh.Highlighter.prototype.Highlight = function(code)
{
function Trim(str)
{
return str.replace(/^\s*(.*?)[\s\n]*$/g, '$1');
}

function Chop(str)
{
return str.replace(/\n*$/, '').replace(/^\n*/, '');
}

function Unindent(str)
{
var lines = dp.sh.Utils.FixForBlogger(str).split('\n');
var indents = new Array();
var regex = new RegExp('^\\s*', 'g');
var min = 1000;

// go through every line and check for common number of indents
for(var i = 0; i < lines.length && min > 0; i++)
{
if(Trim(lines[i]).length == 0)
continue;

var matches = regex.exec(lines[i]);

if(matches != null && matches.length > 0)
min = Math.min(matches[0].length, min);
}

// trim minimum common number of white space from the begining of every line
if(min > 0)
for(var i = 0; i < lines.length; i++)
lines[i] = lines[i].substr(min);

return lines.join('\n');
}

// This function returns a portions of the string from pos1 to pos2 inclusive
function Copy(string, pos1, pos2)
{
return string.substr(pos1, pos2 - pos1);
}

var pos = 0;

if(code == null)
code = '';

this.originalCode = code;
this.code = Chop(Unindent(code));
this.div = this.CreateElement('DIV');
this.bar = this.CreateElement('DIV');
this.ol = this.CreateElement('OL');
this.matches = new Array();

this.div.className = 'dp-highlighter';
this.div.highlighter = this;

this.bar.className = 'bar';

// set the first line
this.ol.start = this.firstLine;

if(this.CssClass != null)
this.ol.className = this.CssClass;

if(this.collapse)
this.div.className += ' collapsed';

if(this.noGutter)
this.div.className += ' nogutter';

// replace tabs with spaces
if(this.tabsToSpaces == true)
this.code = this.ProcessSmartTabs(this.code);

this.ProcessRegexList();

// if no matches found, add entire code as plain text
if(this.matches.length == 0)
{
this.AddBit(this.code, null);
this.SwitchToList();
this.div.appendChild(this.bar);
this.div.appendChild(this.ol);
return;
}

// sort the matches
this.matches = this.matches.sort(dp.sh.Highlighter.SortCallback);

// The following loop checks to see if any of the matches are inside
// of other matches. This process would get rid of highligted strings
// inside comments, keywords inside strings and so on.
for(var i = 0; i < this.matches.length; i++)
if(this.IsInside(this.matches[i]))
this.matches[i] = null;

// Finally, go through the final list of matches and pull the all
// together adding everything in between that isn't a match.
for(var i = 0; i < this.matches.length; i++)
{
var match = this.matches[i];

if(match == null || match.length == 0)
continue;

this.AddBit(Copy(this.code, pos, match.index), null);
this.AddBit(match.value, match.css);

pos = match.index + match.length;
}

this.AddBit(this.code.substr(pos), null);

this.SwitchToList();
this.div.appendChild(this.bar);
this.div.appendChild(this.ol);
}

dp.sh.Highlighter.prototype.GetKeywords = function(str)
{
return '\\b' + str.replace(/ /g, '\\b|\\b') + '\\b';
}

dp.sh.BloggerMode = function()
{
dp.sh.isBloggerMode = true;
}

// highlightes all elements identified by name and gets source code from specified property
dp.sh.HighlightAll = function(name, showGutter /* optional */, showControls /* optional */, collapseAll /* optional */, firstLine /* optional */, showColumns /* optional */)
{
function FindValue()
{
var a = arguments;

for(var i = 0; i < a.length; i++)
{
if(a[i] == null)
continue;

if(typeof(a[i]) == 'string' && a[i] != '')
return a[i] + '';

if(typeof(a[i]) == 'object' && a[i].value != '')
return a[i].value + '';
}

return null;
}

function IsOptionSet(value, list)
{
for(var i = 0; i < list.length; i++)
if(list[i] == value)
return true;

return false;
}

function GetOptionValue(name, list, defaultValue)
{
var regex = new RegExp('^' + name + '\\[(\\w+)\\]$', 'gi');
var matches = null;

for(var i = 0; i < list.length; i++)
if((matches = regex.exec(list[i])) != null)
return matches[1];

return defaultValue;
}

function FindTagsByName(list, name, tagName)
{
var tags = document.getElementsByTagName(tagName);

for(var i = 0; i < tags.length; i++)
if(tags[i].getAttribute('name') == name)
list.push(tags[i]);
}

var elements = [];
var highlighter = null;
var registered = {};
var propertyName = 'innerHTML';

// for some reason IE doesn't find by name, however it does see them just fine by tag name...
FindTagsByName(elements, name, 'pre');
FindTagsByName(elements, name, 'textarea');

if(elements.length == 0)
return;

// register all brushes
for(var brush in dp.sh.Brushes)
{
var aliases = dp.sh.Brushes[brush].Aliases;

if(aliases == null)
continue;

for(var i = 0; i < aliases.length; i++)
registered[aliases[i]] = brush;
}

for(var i = 0; i < elements.length; i++)
{
var element = elements[i];
var options = FindValue(
element.attributes['class'], element.className,
element.attributes['language'], element.language
);
var language = '';

if(options == null)
continue;

options = options.split(':');

language = options[0].toLowerCase();

if(registered[language] == null)
continue;

// instantiate a brush
highlighter = new dp.sh.Brushes[registered[language]]();

// hide the original element
element.style.display = 'none';

highlighter.noGutter = (showGutter == null) ? IsOptionSet('nogutter', options) : !showGutter;
highlighter.addControls = (showControls == null) ? !IsOptionSet('nocontrols', options) : showControls;
highlighter.collapse = (collapseAll == null) ? IsOptionSet('collapse', options) : collapseAll;
highlighter.showColumns = (showColumns == null) ? IsOptionSet('showcolumns', options) : showColumns;

// write out custom brush style
var headNode = document.getElementsByTagName('head')[0];
if(highlighter.Style && headNode)
{
var styleNode = document.createElement('style');
styleNode.setAttribute('type', 'text/css');

if(styleNode.styleSheet) // for IE
{
styleNode.styleSheet.cssText = highlighter.Style;
}
else // for everyone else
{
var textNode = document.createTextNode(highlighter.Style);
styleNode.appendChild(textNode);
}

headNode.appendChild(styleNode);
}

// first line idea comes from Andrew Collington, thanks!
highlighter.firstLine = (firstLine == null) ? parseInt(GetOptionValue('firstline', options, 1)) : firstLine;

highlighter.Highlight(element[propertyName]);

highlighter.source = element;

element.parentNode.insertBefore(highlighter.div, element);
}
}

dp.sh.Brushes.Cpp = function()
{
var datatypes =
'ATOM BOOL BOOLEAN BYTE CHAR COLORREF DWORD DWORDLONG DWORD_PTR ' +
'DWORD32 DWORD64 FLOAT HACCEL HALF_PTR HANDLE HBITMAP HBRUSH ' +
'HCOLORSPACE HCONV HCONVLIST HCURSOR HDC HDDEDATA HDESK HDROP HDWP ' +
'HENHMETAFILE HFILE HFONT HGDIOBJ HGLOBAL HHOOK HICON HINSTANCE HKEY ' +
'HKL HLOCAL HMENU HMETAFILE HMODULE HMONITOR HPALETTE HPEN HRESULT ' +
'HRGN HRSRC HSZ HWINSTA HWND INT INT_PTR INT32 INT64 LANGID LCID LCTYPE ' +
'LGRPID LONG LONGLONG LONG_PTR LONG32 LONG64 LPARAM LPBOOL LPBYTE LPCOLORREF ' +
'LPCSTR LPCTSTR LPCVOID LPCWSTR LPDWORD LPHANDLE LPINT LPLONG LPSTR LPTSTR ' +
'LPVOID LPWORD LPWSTR LRESULT PBOOL PBOOLEAN PBYTE PCHAR PCSTR PCTSTR PCWSTR ' +
'PDWORDLONG PDWORD_PTR PDWORD32 PDWORD64 PFLOAT PHALF_PTR PHANDLE PHKEY PINT ' +
'PINT_PTR PINT32 PINT64 PLCID PLONG PLONGLONG PLONG_PTR PLONG32 PLONG64 POINTER_32 ' +
'POINTER_64 PSHORT PSIZE_T PSSIZE_T PSTR PTBYTE PTCHAR PTSTR PUCHAR PUHALF_PTR ' +
'PUINT PUINT_PTR PUINT32 PUINT64 PULONG PULONGLONG PULONG_PTR PULONG32 PULONG64 ' +
'PUSHORT PVOID PWCHAR PWORD PWSTR SC_HANDLE SC_LOCK SERVICE_STATUS_HANDLE SHORT ' +
'SIZE_T SSIZE_T TBYTE TCHAR UCHAR UHALF_PTR UINT UINT_PTR UINT32 UINT64 ULONG ' +
'ULONGLONG ULONG_PTR ULONG32 ULONG64 USHORT USN VOID WCHAR WORD WPARAM WPARAM WPARAM ' +
'char bool short int __int32 __int64 __int8 __int16 long float double __wchar_t ' +
'clock_t _complex _dev_t _diskfree_t div_t ldiv_t _exception _EXCEPTION_POINTERS ' +
'FILE _finddata_t _finddatai64_t _wfinddata_t _wfinddatai64_t __finddata64_t ' +
'__wfinddata64_t _FPIEEE_RECORD fpos_t _HEAPINFO _HFILE lconv intptr_t ' +
'jmp_buf mbstate_t _off_t _onexit_t _PNH ptrdiff_t _purecall_handler ' +
'sig_atomic_t size_t _stat __stat64 _stati64 terminate_function ' +
'time_t __time64_t _timeb __timeb64 tm uintptr_t _utimbuf ' +
'va_list wchar_t wctrans_t wctype_t wint_t signed';

var keywords =
'break case catch class const __finally __exception __try ' +
'const_cast continue private public protected __declspec ' +
'default delete deprecated dllexport dllimport do dynamic_cast ' +
'else enum explicit extern if for friend goto inline ' +
'mutable naked namespace new noinline noreturn nothrow ' +
'register reinterpret_cast return selectany ' +
'sizeof static static_cast switch template this ' +
'thread throw true false try typedef typeid typename union ' +
'using uuid virtual void volatile whcar_t while';

var asmkeywords =
'386 model option data const stack code struct '+
'proc endp struc ends end include includelib if else elseif '+
'endif while endw repeat break continue until null';
var asmlibs=
'windows.inc kernel32.inc user32.inc debug.inc masm32.inc '+
'windows.lib kernel32.lib user32.lib debug.lib masm32.lib';
var registers=
'flat stdcall casemap '+
'none dup proto local invoke '+
'eax ax ah al ebx bh bl bx '+
'ecx cx ch cl edx dx dh dl '+
'esi si edi di ebp bp esp '+
'sp carry overflow parity sign zero '+
'true false';
var reservedwords=
'db dw dd dq mov movsx movzx equ '+
'xchg push pusha pop popa in out xlat '+
'lea lds les lfs lgs lss lahf sahf pushf pushfd '+
'popf popfd add sub adc sbb inc dec mul div imul '+
'idiv cbw cwd cwde cdq neg daa das aaa aas aam '+
'aad and or xor not shl sal rol ror rcl rcr '+
'shld shrd movs movsb movsw movsd cmps cmpsb cmpsw cmpsd '+
'scas scasb scasw scasd lods lodsb lodsw lodsd stos stosb '+
'stosw stosd ins insb insw insd outs outsb outsw outsd '+
'ret retn retf int into iret iretd set clc stc cmc cld '+
'std cli sti hlt wait esc lock nop bt btc btr bts bsf '+
'bsr bound enter leave lar lsl lgdt lidt sgdt sidt ltr '+
'str lmsw smsw lldt sldt arpl clts verr verw';
var jumpers=
'jmp jc jnc jz je jnz jne js jns jo jno jp jpe jnp '+
'jpo ja jneb jae jnb jb jnae jbe jna jg jnle jge jnl '+
'jl jnge jle jng jcxz jecxz loop loopz loope loopnz loopne '+
'pushad popad cmp test call';
var descriptions=
'ds cs es ss fs gs addr offset byte word dword ptr';
var win32functions=
'MessageBox PrintDec PrintHex PrintLine PrintDouble PrintString '+
'PrintStringByAddr PrintText PrintError PrintException Spy ASSERT '+
'TrapException DumpMem DbgDump DumpFPU Fix '+
'CreateWindow RegisterClass RegisterClassEx CreateWindowEx '+
'ShowWindow UpdateWindow WindowProc DefWindowProc LodaAccelerators GetMessage '+
'TranslateMessage DispatchMessage PostQuitMessage BeginPaint EndPaint DialogBox '+
'DialogBoxParam EndDialog DestroyWindow LoadString LoadIcon LoadCursor '+
'SetWindowLongPtr GetWindowLongPtr SetTextColor DrawText CreateSolidBrush '+
'SetBkMode CreateFont SelectObject DeleteObject GetTextMetrics MoveToEx LineTo '+
'CreatePen ExtCreatePen GetSysColor SetWindowText MoveWindow SetWindowPos '+
'AnimateWindow CreateRectRgn CombineRgn FindWindowEx CreateThread '+
'WaitForSingleObject wsprintf CreateEvent SetEvent EnterCriticalSection '+
'LeaveCriticalSelection CreateSemaphore ReleaseSemaphore PostThreadMessage '+
'SetThreadPriority GetThreadPriority SuspendThread ResumeThread CreateDirectory '+
'GetCurrentDirectory SetCurrentDirectory CreateFile WriteFile ReadFile '+
'FlushFileBuffers SetFilePointer SetEndOfFile GetFileSizeEx CopyFile MoveFile '+
'FindFirstFile FindNextFile CreateFileMapping MapViewOfFile GetDriveType '+
'SetDiskFreeSpaceEx RegOpenKeyEx RegCreateKeyEx RegSetValueEx RegDeleteValue '+
'RegQueryValueEx CreateWaitableTimer SetWaitableTimer SetTimer KillTimer '+
'QueryPerformanceCounter GetTickCount GetSystemTime GetLocalTime GetComputerName '+
'GetUserName GetVersionEx RtlZeroMemory GetModuleHandle ExitProcess GetSystemMetrics '+
'GetCursorPos TrackPopupMenu SendMessage CheckMenuRadioItem SetClassLong';

this.regexList = [
{ regex: dp.sh.RegexLib.SingleLineCComments, css: 'comment' }, // one line comments
{ regex: dp.sh.RegexLib.MultiLineCComments, css: 'comment' }, // multiline comments
{ regex: dp.sh.RegexLib.DoubleQuotedString, css: 'string' }, // strings
{ regex: dp.sh.RegexLib.SingleQuotedString, css: 'string' }, // strings
{ regex: new RegExp(';.*$', 'gm'), css: 'comment'},
{ regex: new RegExp('^ *#.*', 'gm'), css: 'preprocessor' },
{ regex: new RegExp('(?:\<|<)/*\\?*\\s*([:\\w-\.]+)', 'gm'), css: 'jiankuohao'},
{ regex: new RegExp(this.GetKeywords(datatypes), 'gm'), css: 'datatypes' },
//{ regex: new RegExp(this.GetKeywords(keywords), 'gm'), css: 'keyword' },
{ regex: new RegExp(this.GetKeywords(asmkeywords), 'gm'), css: 'asmkeyword' },
{ regex: new RegExp(this.GetKeywords(asmlibs), 'gm'), css: 'asmlib' },
{ regex: new RegExp(this.GetKeywords(registers), 'gm'), css: 'asmreg' },
{ regex: new RegExp(this.GetKeywords(reservedwords), 'gm'), css: 'asmreserved' },
{ regex: new RegExp(this.GetKeywords(jumpers), 'gm'), css: 'asmjumper' },
{ regex: new RegExp(this.GetKeywords(descriptions), 'gm'), css: 'asmdescript' },
{ regex: new RegExp(this.GetKeywords(win32functions), 'gm'),css: 'asmfunction' }
];

this.CssClass = 'dp-cpp';
this.Style = '.dp-cpp .datatypes { color: #2E8B57; font-weight: bold; }';
}

dp.sh.Brushes.Cpp.prototype = new dp.sh.Highlighter();
dp.sh.Brushes.Cpp.Aliases = ['cpp', 'c', 'c++','asm'];
// ]]>

.386
.model flat,stdcall
option casemap:none

include windows.inc
include kernel32.inc
include user32.inc
include debug.inc
includelib kernel32.lib
includelib user32.lib
includelib debug.lib

.data?
hInstance dd ?
.const
IDD_DLG_MAIN EQU 1000
.code
_ProcDlgMain proc uses ebx edi esi hWnd,wMsg,wParam,lParam
mov eax,wMsg
.if eax==WM_CLOSE
invoke EndDialog,hWnd,NULL
.elseif eax==WM_INITDIALOG
.elseif eax==WM_COMMAND
mov eax,wParam
movzx eax,ax
.if eax==IDOK
invoke EndDialog,hWnd,NULL
.endif
.else
mov eax,FALSE
ret
.endif
mov eax,TRUE
ret
_ProcDlgMain endp
;=========================================================
start:
invoke GetModuleHandle,NULL
mov hInstance,eax
invoke DialogBoxParam,hInstance,IDD_DLG_MAIN,NULL,\
offset _ProcDlgMain,NULL
invoke ExitProcess,NULL
end start

// dp.SyntaxHighlighter.ClipboardSwf = 'clipboard.swf';
dp.SyntaxHighlighter.HighlightAll('code');
// ]]>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: