Programming/Visual Basic

VB Application XP 스타일 적용하기

bcheul 2008. 5. 14. 16:13

1. 먼저 일반적으로 EXE 만들듯이 프로그램을 작성합니다. 테스트를 위해 그냥 기본 컨
트롤 몇가지만 넣어두면 되겠지요.

2. 프로그램을 컴파일합니다. (test.exe) -> 어차피, 나중에 컴파일하더라도 실행 파일
명만 MANIFEST 파일과 맞추면 굳이 여기서 안해도 됩니다..

3. 메모장으로 test.exe.MANIFEST 이라는 파일을 만듭니다.
뒤에 붙는 MANIFEST는 반드시 모두 대문자여야 하며, 앞부분은 실행파일명으로 합니다.
그 파일 안에

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity version="1.0.0.0" processorArchitecture="x86" name="prjThemed"
type="win32" />
<dependency>
<dependentAssembly>
<assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls"
version="6.0.0.0" processorArchitecture="x86" publicKeyToken="6595b64144ccf1df"
language="*" />
</dependentAssembly>
</dependency>
</assembly>

라는 내용을 넣습니다.

4. 다시 비베로 돌아와서, 폼의 선언부에 다음 코드를 넣습니다.

Private Type INITCOMMONCONTROLSEX_TYPE
dwSize As Long
dwICC As Long
End Type
Private Declare Function InitCommonControlsEx Lib "comctl32.dll" (lpInitCtrls As
_ INITCOMMONCONTROLSEX_TYPE) As Long
Private Const ICC_INTERNET_CLASSES = &H800

5. Form_Load 이벤트에 다음 코드를 넣습니다.

Dim comctls As INITCOMMONCONTROLSEX_TYPE ' identifies the control to register
Dim retval As Long ' generic return value
With comctls
.dwSize = Len(comctls)
.dwICC = ICC_INTERNET_CLASSES
End With

retval = InitCommonControlsEx(comctls)

6. 다시 컴파일합니다. 당연히 test.exe(이전 실행파일명)으로 해야겠죠.

자! 이제 XP에서 이 컴파일된 파일을 실행하면 비주얼 베이직의 기본 컨트롤들이 모두
XP의 비주얼 스타일이 적용된 상태로 나타날 것입니다. 물론 UserControl은 안되겠죠..
아직 MSCOMCTL.OCX에 있는 툴바와 같은 것도 되는지는 테스트 못해봤습니다.

위의 글은 제가 아래 원문을 토대로 직접 테스트한 후 간단하게 요약한 것입니다.
원문의 첫 부분에는, 안 되는 이유가 이전 버전의 Common Controls를 사용하기 때문이라
고 합니다. 아무튼 실행만 잘 되면 되겠죠~! 참고로 이것은 (당연하겠지만) XP에서만
됩니다. 윈98 같은 곳에서 실행하면 아무런 차이 없이 그냥 실행됩니다.

참고로 XP가 아닌 곳에서 실행하더라도 아무 에러 없이 잘 되므로, 윈도우 버전에 따라
코드를 다르게 작성할 필요가 없습니다. 제가 윈98과 XP에서 테스트한 결과입니다.

자료 출처 : www.howtobank.net

그럼 원문입니다..
------------------------------------------------------------------
Real Windows XP Controls in Windows XP / VB6 without images or custom controls

Windows XP user?
So am I. But I didn't want to buy VB.NET. VB6 works just fine, thank you - except
for one thing: "Visual Styles". How do you get your controls to have the new look
and feel of Windows XP? Images or custom controls work, but the're big, hard to
use, slow, and they usually don't support Windows XP visual styles (themes) - let
alone large fonts or any of the other features in true Windows XP controls. So
how do we make these "true" controls. It's easier than you might imagine.

Step 1: Create a new project. Add your controls, just like you would normally.
Add your code. It is recommended that you add the themed controls last because it
is a simple procedure that can be applied once your entire project is done. There
is no need to use custom controls, or to add special source. All nececary source
is added when you theme your project (only about 10 lines)

Step 2: Compile (make) your application into an EXE file. If you open the
application now it will have the "classic" visual style. This is for a reason.
Your application is using the old Windows Common controls. How do we change this?
With a MANIFEST file.

If you're not using Windows XP, stop here. MANIFEST files work only under Windows
XP. You can add one without ill effects under other Windows operating systems,
but you won't get the new controls if you don't have Windows XP. For Windows-XP
like controls without Windows XP, this is the wrong place.

What is a MANIFEST file? A MANIFEST file is a text file with the same name as
your EXE but with .MANIFEST on the end. For example, the MANIFEST file
for "test.exe" would be "test.exe.MANIFEST". The ".MANIFEST" must be in all
capitol letters.

Step 3: Create a new text file with the same name as your EXE, except
with ".MANIFEST" on the end. ".MANIFEST" must be in all caps. For example,
for "test.exe", you would make a text file named "test.exe.MANIFEST". Notepad
will suffice for creating the file.

Step 4: Add the following text to your MANIFEST file:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity version="1.0.0.0" processorArchitecture="x86" name="prjThemed"
type="win32" />
<dependency>
<dependentAssembly>
<assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls"
version="6.0.0.0" processorArchitecture="x86" publicKeyToken="6595b64144ccf1df"
language="*" />
</dependentAssembly>
</dependency>
</assembly>


Step 5: Add the following code to your project in the startup form:

Private Type INITCOMMONCONTROLSEX_TYPE
dwSize As Long
dwICC As Long
End Type
Private Declare Function InitCommonControlsEx Lib "comctl32.dll" (lpInitCtrls As
_ INITCOMMONCONTROLSEX_TYPE) As Long
Private Const ICC_INTERNET_CLASSES = &H800

Step 6: Add the following code to the Form_Load procedure of your starup form:

Dim comctls As INITCOMMONCONTROLSEX_TYPE ' identifies the control to register
Dim retval As Long ' generic return value
With comctls
.dwSize = Len(comctls)
.dwICC = ICC_INTERNET_CLASSES
End With

retval = InitCommonControlsEx(comctls)


Step 7: Recompile (make) your EXE, using the same EXE name as before (and the
same name as your MANIFEST file, minus the ".MANIFEST"). Execute your EXE file.

That's it! You can add controls to your project just like a normal VB project!

You can download a sample project and MANIFEST file below. Just right click on
the project file and choose "compile" to compile the sample (you can also compile
it from within the VB IDE). The project is just a simple demonstration of some of
the Windows common controls.