Windows XP-Style Programming

Windows XP-Style Programming

In the Windows XP operating system, as can be easily noticed, the window style and the design of controls have changed. Still, if desired, you can return to the classic Windows style by setting this property (Fig. 10.1).

image from book
Figure 10.1: Changing the style of windows and controls in Windows XP

It is necessary to distinguish window appearance and control style (Fig. 10.2).

image from book
Figure 10.2: Window and button styles

In contrast to window style, which is automatically formed by the operating system, the style of controls must be defined by the programmer. Because of this, all window controls of the programs written before the release of Windows XP have the old style. However, even if you program under Windows XP, the new style won't appear automatically if you are not using Delphi or C Builder. To achieve this goal, it is necessary to use an appropriate technology. This technology is the one that I'll describe now.

The USER32.DLL library was always responsible for displaying window controls. Consequently, you always include the INCLUDELIB USER32 .LIB directive into your programs to gain the possibility of controlling these window elements. This library continues to work in Windows XP and continues to display controls in the old style. For the new style of window controls, it is the COMCTL32.DLL library responsible for supporting it. In other words, to support window controls in the style of Windows XP, it is necessary to add the INLUDELIB COMCTL32 .LIB into your programs. This, however, is not sufficient. The following steps are also required:

  1. Initialize the COMCTL32.DLL library using the initCommonControls or InitCommonControlsEx functions.

  2. Create a special structure that would inform the operating system about your intention to use the new style of displaying window controls. This structure must be written in extensible markup language (XML). Its text is as follows :

 <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <assembly xmlns="urn:schemas-microsoft-com:asm.vl" manifestVersion="1.0"> <description>Windows XP program</description> <assemblyldentity     version="1.0.0.0"     processorArchitecture="X86"     name="m.exe"     type="win32" /> <dependency>     <dependentAssembly>     <assemblyldentity         type="win32"         name="Microsoft.Windows.Common-Controls"         version="6.0.0.0"         processorArchitecture="X86"         publicKeyToken="6595b64144ccfldf"         language="*"     />  </dependentAssembly> </dependency> </assembly> 

Pay special attention to the version=6.0.0.0 line. It informs the operating system that it is necessary to use the functions of COMCTL32.DLL library version 6.0. The name=m.exe string specifies the name of your program.

I think that you'll immediately ask: How is it possible to integrate this text into my programs? In fact, there are two ways of doing so:

  • If the text of your program is named, say, M.ASM, and the program, accordingly , is named M.EXE, then the XML code must be inserted into the file called M.EXE.MANIFEST. This file must be located in the same directory as the executable module M.EXE. This will be enough to display window controls in the new style. However, this is not always convenient , because the file with the manifest filename extension can be accidentally deleted or corrupted. Therefore, another, more reliable method is preferable.

  • XML text can be included in the resource file. This is achieved by inserting the following string into the beginning of the file " l 24 m.xml ". It is supposed that the XML code is located in the M.XML file. The resource compiler RC.EXE will compile this text into the object module; from there, it will be copied into the executable module.

At this point, I complete the theoretical considerations. You can start writing programs with elements in the Windows XP style right now (Listing 10.4 and Fig. 10.3).

image from book
Figure 10.3: Window created by the program in Listing 10.4
Listing 10.4: A simple program presenting a window with elements in the Windows XP style
image from book
 // The M.RC file // Constant definitions // Window styles 1   24     "m.xml" #define WS_VSCROLL      200000h #define CBS_DROPDOWNLIST3h #define WS_OVERLAPPED   Oh #define WS_CAPTION      0C00000h #define IDC_COMBOBOX1   101 #define WS_SYSMENU      Ox00080000L #define WS_MINIMIZEBOX  0x00020000L #define WS_MAXIMIZEBOX  0x000l0000L // Style of all window elements #define WS_CHILD        0x40000000L // Window elements must // be initially visible #define WS_VISIBLE      0x10000000L // Using the <Tab> key, // it is possible to sequentially initialize // the button style #define BS_PUSHBUTTON   0x00000000L // Center the button text #define BS_CENTER       0x00000300L #define DS_LOCALEDIT    0x20L // Dialog definition DIAL1 DIALOG 0, 0, 240, 80 STYLE WS_OVERLAPPED  WS_CAPTION  WS_SYSMENU  WS_MINIMIZEBOX  WS_MAXIMIZEBOX CAPTION "Dialog example" FONT 8, "Arial" {  CONTROL "Exit", 5, "button", BS_PUSHBUTTON  BS_CENTER  WS_CHILD  WS_VISIBLE, 180, 30, 50, 14  CONTROL "ComboBox1", IDC_COMBOBOX1, "combobox", CBS_DROPDOWNLIST  WS_CHILD  WS_VISIBLE  WS_VSCROLL, 24, 30, 124, 16 } .586P ; Flat memory model .MODEL FLAT, stdcall ; INCLUDELIB directives for linking libraries includelib d:\masm32\lib\comctl32.lib includelib d:\masm32\lib\user32.lib includelib d: \masm32\lib\kernel32.lib ; --------------------------------------- ; Constants ; The message arrives when the window is closed WM_CLOSE      equ l0h WM_INITDIALOG equ 110h WM_COMMAND    equ 111h ; Prototypes of external procedures EXTERN     InitCommonControls@0:NEAR EXTERN     UnregisterHotKey@8:NEAR EXTERN     RegisterHotKey@16:NEAR EXTERN     MessageBoxA@16:NEAR EXTERN     ExitProcess@4:NEAR EXTERN     GetModuleHandleA@4:NEAR EXTERN     DialogBoxParamA@20:NEAR EXTERN     EndDialog@8:NEAR EXTERN     SendMessageA@16:NEAR EXTERN     GetDlgItem@8:NEAR EXTERN     MessageBoxA@16:NEAR ; Data segment _DATA SEGMENT HINST DD 0  ; Application descriptor PA   DB "DIAL1", 0 STR1 DB "Invalid character!", 0 STR2 DB "Error!", 0 _DATA ENDS ; Code segment _TEXT SEGMENT START:   CALL InitCommonControls@0 ; Get the application descriptor    PUSH 0    CALL GetModuleHandleA@4    MOV  [HINST], EAX ;-------------------------    PUSH 0    PUSH OFFSET WNDPROC    PUSH 0    PUSH OFFSET PA    PUSH [HINST]    CALL DialogBoxParamA@20    CMP  EAX, -1    JNE  KOL KOL: ;-------------------    PUSH 0    CALL ExitProcess@4 ;------------------------------- ; Window procedure ; Position of parameters in the stack ; [EBP+014H]  ; LPARAM ; [EBP+10H]   ; WAPARAM ; [EBP+0CH]   ; MES ; [EBP+8]     ; HWND WNDPROC   PROC    PUSH EBP    MOV  EBP, ESP    PUSH EBX    PUSH ESI    PUSH EDI ;-----------------------------    CMP  DWORD PTR [EBP+0CH], WM_CLOSE    JNE  LI    PUSH 0    PUSH DWORD PTR [EBP+08H]    CALL EndDialog@8    MOV  EAX, 1    JMP  FIN L1:    CMP  DWORD PTR [EBP+0CH], WM_INITDIALOG    JNE  L2    MOV  EAX, 1    JMP  FIN L2:    CMP  DWORD PTR [EBP+0CH], WM_COMMAND    JNE  FINISH ; Exit button?    CMP  WORD PTR [EBP+10H], 5    JNE  FINISH    PUSH 0    PUSH DWORD PTR [EBP+08H]    CALL EndDialog@8    MOV  EAX, 1    JMP  FIN FINISH:    MOV  EAX, 0 FIN:    POP  EDI    POP  ESI    POP  EBX    POP  EBP    RET  16 WNDPROC ENDP _TEXT ENDS END START 
image from book
 

Because I only wanted to demonstrate the possibilities of using new styles of displaying elements, the program is elementary. The window contains only two elements: a button and a combobox. I'd like to emphasize again that window style has no relation to the theory. On the contrary, it is automatically formed by the operating system.

To assemble and link the program, issue the following commands:

 ML /c /coff "m.asm" RC "m.rc" LINK /SUBSYSTEM:WINDOWS "m.obj" "m.res" 

The use of TASM32 isn't considered here.



The Assembly Programming Master Book
The Assembly Programming Master Book
ISBN: 8170088178
EAN: 2147483647
Year: 2004
Pages: 140
Authors: Vlad Pirogov

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net