الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

كيف أقوم بعمل نفس الشيء في لغة السي ؟؟؟

مغلقمُجاب
بدأه The Hidden Ghost في 20 فبراير 2013 · 1 رد · 1,239 مشاهدة · في لغة Assembly لأنظمة 16, 32, 64 بت
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم ورحمة الله تعالى و بركاته :)

 

لقد برمجت تطبيق صغير بلغة الأسمبلي 32 بت ، لكن حينما أردت برمجة نفس البرنامج بلغة السي واجهتني مشكلة عويصة و هي تتجسد في كيفية عمل هذه الخطوات الثلاث :

 

أولا مناداة الدالة GetModuleHandle ...

ثم مناداة الدالة DialogBoxParam ...

وفي الأخير ، مناداة الدالة ExitProcess ...

 

إليكم المثال :lol: ،،،

 

.486
.model flat,stdcall ;; 32 bit Memory Model
option casemap:none ;; case sensitive
include windows.inc ;; for Win Api Functions
include kernel32.inc ;; necessary Header File
include user32.inc ;; necessary Header File
includelib user32.lib    ;; Calling User32 Library
includelib kernel32.lib ;; Calling Kernel32 Library
.data	  ;; Data Section
;; Space		   EQU		  20h ;; 32
;; Enter (\n)	  EQU		  0Dh ;; 10
DialogWindow	    DB		  "TEST",0 ;; The ID Name of my Test.res
WhenClosed		  DB		  20h,20h,20h,20h,"Thanks for using my Application",13,10,13,10
				    DB		  20h,20h,20h,20h,20h,20h,20h,20h,20h,20h,20h,20h,20h,20h,20h,20h,20h,20h,20h
				    DB		  "By the Hidden Ghost <img src='http://www.rohitab.com/discuss/public/style_emoticons/<#EMO_DIR#>/smile.png' class='bbc_emoticon' alt=':)' />",0
MessageBoxCaption   DB		  "Thanks From The Hidden Ghost",0
SendMySpecialText   DB		  "I believe I can fly, I believe I can Touch the Sky !!!",0
SendMyOldText	   DB		  "Welcome to the Hidden Ghost Application",0
CreatedByHamza	  DB		  "Created By Hamza Qdider",0
GetText			 DB		  100 DUP(0) ;; for getting the Caption of the Group-Box Control - ID 2014 -
										   ;; char GetText[100];

.code  ;; Code Section
WinProcedure PROTO :DWORD,:DWORD,:DWORD,:DWORD ;; Declaration of My Window Procedure
begin: ;;;;;;;;;;;;;;;;;;;;;;; Start of Program ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
invoke GetModuleHandle,0 ;; Like Loading Test.res in My program
invoke DialogBoxParam,eax,addr DialogWindow,0,addr WinProcedure,0 ;; the Handle of my dialog is stored in eax for showing my dialog form
invoke ExitProcess,0 ;; Like return 0 in C Language
WinProcedure PROC hwnd:DWORD,messages:DWORD,wparam:DWORD,lparam:DWORD ;; My Window Procedure
;;;;;;;;;;;;;;;;;;;;;;;;; Wparam Story ;;;;;;;;;;;;;;;;;;;;;;;;;;
;; When we have an event, each event, Like Clicking on		 ;;
;; Command Button or some thing else, this event is stored	 ;;
;; in Wparam .Is not the event but the ID was stored in Wparam ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
.if messages == WM_COMMAND ;; if we have a click on Command Button
	 mov eax,wparam ;; store the Command Button ID in eax
   
.if eax == 2013 ;; if eax = the ID of my Only Command Button which is ID 2013

    invoke SetDlgItemText,hwnd,2014,addr SendMySpecialText ;; write a text in ID : 2014
    invoke SetDlgItemText,hwnd,1,addr CreatedByHamza ;; Write a text in ID 1 which is the Label
    ret ;; return
   
.endif

.endif
.if messages == WM_MOUSEMOVE ;; if we have a Mouse Mouvement
 
  invoke GetDlgItemText,hwnd,2014,addr GetText,LENGTHOF SendMyOldText ;; Getting the text of the ID 2014 and store it in GetText Variable, with a length same as SendMyOldText Variable
  mov edx,DWORD PTR[GetText] ;; Store the text in edx register
  cmp edx,DWORD PTR[SendMyOldText] ;; Comparing the Same Text with the text stored in edx
  jne Write ;; if isn't the same goto Write Label and Changing the Value of each ID
  jmp return ;; if is the same goto return Label - nothing do -
 
  Write:
 
  invoke SetDlgItemText,hwnd,1,addr SendMyOldText ;; Change the text of the Label - ID 1 -
  invoke SetDlgItemText,hwnd,2014,addr SendMyOldText ;; Change the text of the Group-Box Control - ID 2014 -
 
  return : ret
.endif
.if messages == WM_CLOSE ;; if we have a click on the Red X hhhhh
    invoke MessageBox,0,addr WhenClosed,addr MessageBoxCaption,MB_OK ;; Show this Message
invoke EndDialog,hwnd,0 ;; End the Dialog Sir !!!
ret

.endif
xor eax,eax ;; eax = 0
ret
WinProcedure endp ;; End of My Window Procedure
end begin ;;;;;;;;;;;;;;;;;;;;; End of Program ;;;;;;;;;;;;;;;;;;;;;;;;;;

 

أريد أن أبرمج نفس البرنامج بلغة السي،،، :D

 

خلاصة الموضوع أنني أريد معرفة طريقة دمج ملف الرسورس مع السورس كود و من تم المناداة على نافذة الحوار من خلال GetModuleHandle و DialogBoxParam ... كما نفعل في لغة الأسمبلي ،،،

 

C:\MASM32\BIN\Cvtres.exe /machine:ix86 Test.res

C:\Masm32\Bin\ML.EXE /c /coff /Cp /nologo /I"C:\Masm32\Include" TheHiddenGhostApplication.asm

C:\Masm32\Bin\LINK.EXE /SUBSYSTEM:WINDOWS /RELEASE /VERSION:4.0 /LIBPATH:"C:\Masm32\Lib" TheHiddenGhostApplication.obj Test.obj

في انتظار الإجابة ،،، :P

 

TheHiddenGhostApplication.zip

rS3eY.png
#2 أفضل إجابة

ماتقوم به لاعلاقة له بالأسمبلي فعلياً بل بالـwinapi. يمكنك إنشاء ملف المصادر يدوياً أو عن طريق فجيول c++ أو بإستخدام أحد أدوات تحرير المصادر مثل ResEdit.

تصميم نافذة مع زر للخروج وزر لعرض رسالة:

post-231926-0-40536500-1361408423_thumb.

إحفظ الملف وسيولد ملف المصادر example.rc ويحتوي:

#include <windows.h>
#include <commctrl.h>
#include <richedit.h>
#include "resource.h"


LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
IDD_DIALOG DIALOG 0, 0, 186, 95
STYLE DS_3DLOOK | DS_CENTER | DS_MODALFRAME | DS_SHELLFONT | WS_CAPTION | WS_VISIBLE | WS_POPUP | WS_SYSMENU
CAPTION "Example"
FONT 8, "Ms Shell Dlg"
{
    PUSHBUTTON  "Exit", IDD_EXIT, 129, 7, 50, 14
    PUSHBUTTON  "Say Hello", IDD_HELLO, 129, 24, 50, 14
}
وملف رأسي resource.h يحتوي ثوابت الأزرار:
#ifndef IDC_STATIC
#define IDC_STATIC (-1)
#endif

#define IDD_DIALOG                              101
#define IDD_EXIT                                1001
#define IDD_HELLO                               1002
البرنامج example.cpp:
#include <windows.h>
#include "resource.h"

INT_PTR CALLBACK DialogProc(HWND, UINT, WPARAM, LPARAM);

INT WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   PSTR lpCmdLine,
                   INT nCmdShow)
{
    DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_DIALOG), NULL, DialogProc, NULL);

    return 0;
}

INT_PTR CALLBACK DialogProc(HWND hwndDlg,
                            UINT uMsg,
                            WPARAM wParam,
                            LPARAM lParam)
{
    if( uMsg == WM_CLOSE ) {
        DestroyWindow(hwndDlg);
    }

    else if( uMsg == WM_DESTROY ) {
        PostQuitMessage(0);
    }
    
    else if( uMsg == WM_COMMAND ) {
        if( wParam == IDD_EXIT )
            DestroyWindow(hwndDlg);

        else if( wParam == IDD_HELLO )
            MessageBox(hwndDlg, TEXT("Hello There"), TEXT("Hello"), MB_OK);
    }

    return 0;
}
الشيء المختلف أنك لست بحاجة لإستدعاء GetModuleHandle لأن النظام سيمرر hInstance للدالة الرأسية. ربما تحتاجها لو أنشأت مربع الحوار من خارج الدالة الرئيسية.

بالنسبة للتصريف، أعدّ متغيرات النظام عن طريق السكربت vcvars32.bat (يأتي مع فجيول c++):

>"C:\Program Files\Microsoft Visual Studio 8\Common7\Tools\vsvars32.bat"
Setting environment for using Microsoft Visual Studio 2005 x86 tools.

>
إبن ملف المصادر example.rc:
>rc example.rc>
سيولد ملف ثنائي اسمه example.RES، إبنه مع example.cpp:
>cl example.cpp example.RES user32.libMicrosoft ® 32-bit C/C++ Optimizing Compiler Version 14.00.50727.762 for 80x86Copyright © Microsoft Corporation.  All rights reserved.example.cppMicrosoft ® Incremental Linker Version 8.00.50727.762Copyright © Microsoft Corporation.  All rights reserved./out:example.exeexample.objexample.RESuser32.lib>

وستنشأ نافذة:

post-231926-0-77334900-1361408424.png

الملفات مرفقة.

example.zip

2

هذا الموضوع مغلق.

مواضيع مشابهة