vc++写安装界面
#include <tchar.h>
#include <windows.h>
#include <stdio.h>
#include <WINUSER.H>
#include "resource.h"
#define BITPX1 65
#define BITPY1 136
#define BITW1 103
#define BITH1 25
#define BITWIDTH 560
#define BITHEIGHT 400
#define BITBZ1 0x1
#define BITBZ2 0x2
#define BITBZ3 0x4
#define BITBZ4 0x8
#define BITBZ5 0x10
#define BITBZ6 0x20
#define BITBZ0 0x80
HBITMAP hinstallbmp;
HINSTANCE hInst;
BYTE setupbz=0;
BYTE CheckButtonPos( HWND, LPPOINT);
void PaintStatus( HWND,BYTE);
void Paintmain( HWND);
void install_run(HWND);
LRESULT WINAPI WndProc(HWND hWnd,UINT Message,WPARAM wParam,LPARAM lParam)
{
static DWORD dwButton=0;
POINT pt;
switch(Message)
{
case WM_CREATE:
hinstallbmp = LoadBitmap(hInst,MAKEINTRESOURCE(INSTALLBMP));
break;
case WM_PAINT:
Paintmain(hWnd);
return DefWindowProc(hWnd,Message,wParam,lParam);
case WM_SETCURSOR:
GetCursorPos( &pt );
setupbz = CheckButtonPos(hWnd, &pt);
if (setupbz){
PaintStatus(hWnd,setupbz);
SetCursor(LoadImage(hInst, "harrow",IMAGE_CURSOR, 0,0,LR_DEFAULTSIZE));
}
else {
Paintmain(hWnd);
SetCursor(LoadCursor(NULL,IDC_ARROW));
}
return DefWindowProc(hWnd,Message,wParam,lParam);
break;
case WM_LBUTTONUP:
if(!setupbz) return DefWindowProc(hWnd,Message,wParam,lParam);
install_run(hWnd);
setupbz=0;
break;
case WM_QUIT:
DeleteObject(hinstallbmp);
return(DefWindowProc(hWnd,Message,wParam,lParam));
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return(DefWindowProc(hWnd,Message,wParam,lParam));
}
return(0);
}
int WINAPI WinMain(HINSTANCE hInst0,HINSTANCE hPrevInstance,LPSTR lpszCmdParam,int nCmdShow)
{
MSG Message;
WNDCLASS wc;
HWND hWnd;
int cx,cy;
hInst=hInst0;
if(!hPrevInstance) {
wc.cbClsExtra=0;
wc.cbWndExtra=0;
wc.hbrBackground=CreateSolidBrush(RGB(0,255,255));
wc.hCursor=LoadCursor(NULL,IDC_ARROW);
wc.hIcon=LoadIcon(hInst0,MAKEINTRESOURCE("INSTALLICO"));
wc.hInstance=hInst0;
wc.lpfnWndProc=WndProc;
wc.lpszClassName=_T("Install");
wc.lpszMenuName=(LPSTR)NULL;
wc.style=0;
RegisterClass(&wc);
}
cx=GetSystemMetrics(SM_CXFULLSCREEN);
if(cx>BITWIDTH+2) cx=(cx-BITWIDTH)/2;
else cx=0;
cy=GetSystemMetrics(SM_CYFULLSCREEN);
if(cy>BITHEIGHT+4) cy=(cy-BITHEIGHT)/2;
else cy=0;
hWnd=CreateWindowEx(WS_EX_WINDOWEDGE,"Install","系统",
WS_POPUP|WS_DLGFRAME,cx,cy,BITWIDTH+3,BITHEIGHT+2,
NULL,NULL,hInst0,lpszCmdParam);
ShowWindow(hWnd,nCmdShow);
UpdateWindow(hWnd);
while(GetMessage(&Message,NULL,0,0))
{ TranslateMessage(&Message);
DispatchMessage(&Message);
}
return Message.wParam;
}
BYTE CheckButtonPos( HWND hWnd, LPPOINT lppt)
{
POINT pt;
RECT rc;
BYTE dwButton;
int w,h;
dwButton = 0;
if (lppt) {
pt = *lppt;
ScreenToClient(hWnd,&pt);
GetClientRect(hWnd,&rc);
if (!PtInRect(&rc,pt)) return 0;
w=BITPX1;h=BITPY1;
if(pt.x>=w && pt.x<w+BITW1 && pt.y >= h && pt.y < h +BITH1) {
dwButton |= BITBZ1;
return dwButton;
}
w =120; h =168;
if(pt.x>=w && pt.x<w+BITW1 && pt.y >= h && pt.y < h +BITH1) {
dwButton |= BITBZ2;
return dwButton;
}
w =180; h =220;
if(pt.x>=w && pt.x<w+BITW1 && pt.y >= h && pt.y < h +BITH1) {
dwButton |= BITBZ3;
return dwButton;
}
w =235; h =275;
if(pt.x>=w && pt.x<w+BITW1 && pt.y >= h && pt.y < h +BITH1) {
dwButton |= BITBZ4;
return dwButton;
}
w=364;h=350;
if(pt.x>=w && pt.x<w+44 && pt.y >= h && pt.y < h +20) {
dwButton |= BITBZ5;
return dwButton;
}
w = 453;
if(pt.x>=w && pt.x<w+44 && pt.y >= h && pt.y < h +20) {
dwButton |= BITBZ6;
return dwButton;
}
}
return dwButton;
}
void PaintStatus( HWND hWnd,BYTE dwButton )
{
HDC hDC;
HPEN hPen = (HPEN)NULL;
HPEN hOldPen = (HPEN)NULL;
int x1,y1,w1,h1;
int h0,w0=30;
h0=30;
x1=BITPX1; y1=BITPY1;
w1=BITW1; h1=BITH1;
if (dwButton & BITBZ1) {x1 += 1; y1 -=5;}
else if (dwButton & BITBZ2) {x1 += 55; y1 += 40;}
else if (dwButton & BITBZ3) {x1 += 120; y1 += 90;}
else if (dwButton & BITBZ4) {x1 += 183; y1 += 138;}
else if (dwButton & BITBZ5){
x1=365;y1=340;h1=20;w1=42;
}
else if (dwButton & BITBZ6){
x1=453;y1=340;w1=42;h1=20;
}
hDC = GetDC(hWnd);
hPen = CreatePen(PS_SOLID ,0,RGB(0,0,0));
hOldPen=SelectObject(hDC,hPen);
MoveToEx(hDC,x1,y1,NULL);
LineTo(hDC,x1+w1,y1);
MoveToEx(hDC,x1,y1-1,NULL);
LineTo(hDC,x1+w1,y1-1);
MoveToEx(hDC,x1-1,y1,NULL);
LineTo(hDC,x1-1,y1+h1+1);
MoveToEx(hDC,x1,y1,NULL);
LineTo(hDC,x1,y1+h1+1);
hPen = CreatePen(PS_SOLID ,0,RGB(192,192,192));
SelectObject(hDC,hPen);
MoveToEx(hDC,x1,y1+h1,NULL);
LineTo(hDC,x1+w1+2,y1+h1);
MoveToEx(hDC,x1,y1+1+h1,NULL);
LineTo(hDC,x1+w1+2,y1+1+h1);
MoveToEx(hDC,x1+w1,y1,NULL);
LineTo(hDC,x1+w1,y1+h1);
MoveToEx(hDC,x1+w1+1,y1,NULL);
LineTo(hDC,x1+w1+1,y1+h1);
SelectObject(hDC,hOldPen);
DeleteObject(hPen);
ReleaseDC(hWnd,hDC);
return;
}
void Paintmain( HWND hWnd)
{
HDC hMemDC,hDC;
HBITMAP hBmpOld;
hDC=GetDC(hWnd);
hMemDC = CreateCompatibleDC(hDC);
hBmpOld = SelectObject(hMemDC,hinstallbmp);
BitBlt(hDC,0,0,BITWIDTH,BITHEIGHT,hMemDC,0,0,SRCCOPY);
SelectObject(hMemDC,hBmpOld);
DeleteDC(hMemDC);
ReleaseDC(hWnd,hDC);
return;
}
void install_run(HWND hWnd)
{
if( setupbz & BITBZ1 ) {
ShellExecute(NULL,"open","SQL Server个人版\\AUTORUN.exe",
NULL,NULL,SW_SHOWNORMAL);
}
else if( setupbz & BITBZ2 ) {
ShellExecute(NULL,"open","系统\\dotnetfx.exe",
NULL,NULL,SW_SHOWNORMAL);
}
else if( setupbz & BITBZ3 ) {
ShellExecute(NULL,"open"," 2005 Vol 1 ASP NET Final\\NetAdvantageAspNET51.exe",
NULL,NULL,SW_SHOWNORMAL);
}
else if( setupbz & BITBZ4 ) {
ShellExecute(NULL,"open","系统\\setup.exe",
NULL,NULL,SW_SHOWNORMAL);
}
else if( setupbz & BITBZ5) {
BYTE string0[200];
GetCurrentDirectory(200,string0);
ShellExecute(NULL,"open","explorer.exe",
string0,NULL,SW_SHOWNORMAL);
}
else if( setupbz & BITBZ6 ) {
PostMessage(hWnd,WM_QUIT,0,0);
}
setupbz=0;
return;
}