?? pcmciadetect.cpp
字號:
// pcmciadetect.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include "resource.h"
#define MAX_LOADSTRING 100
// Global Variables:
HINSTANCE hInst; // current instance
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text
HANDLE hListBox;
HANDLE hBtnStart;
// Foward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
MSG msg;
HACCEL hAccelTable;
// Initialize global strings
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_PCMCIADETECT, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);
// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}
hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_PCMCIADETECT);
// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
}
//
// FUNCTION: MyRegisterClass()
//
// PURPOSE: Registers the window class.
//
// COMMENTS:
//
// This function and its usage is only necessary if you want this code
// to be compatible with Win32 systems prior to the 'RegisterClassEx'
// function that was added to Windows 95. It is important to call this function
// so that the application will get 'well formed' small icons associated
// with it.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASS wc;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = (WNDPROC) WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = 0;
wc.hCursor = 0;
wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = 0;
wc.lpszClassName = szWindowClass;
return RegisterClass(&wc);
}
//
// FUNCTION: InitInstance(HANDLE, int)
//
// PURPOSE: Saves instance handle and creates main window
//
// COMMENTS:
//
// In this function, we save the instance handle in a global variable and
// create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
hInst = hInstance; // Store instance handle in our global variable
hWnd = CreateWindow(szWindowClass, szTitle, WS_BORDER | WS_CAPTION | WS_SYSMENU | WS_VISIBLE,
0, 0, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
if (!hWnd)
{
return FALSE;
}
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}
//
// FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
//
// PURPOSE: Processes messages for the main window.
//
// WM_COMMAND - process the application menu
// WM_PAINT - Paint the main window
// WM_DESTROY - post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
TCHAR szHello[MAX_LOADSTRING];
LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);
switch (message)
{
case WM_CREATE:
RECT rcClient;
GetClientRect(hWnd, &rcClient);
hListBox = CreateWindow(TEXT("LISTBOX"),TEXT(""), WS_BORDER | WS_VISIBLE | WS_VSCROLL,
0, 10, rcClient.right-90, rcClient.bottom-30, hWnd, NULL, hInst, 0);
//hBtnStart = CreateWindow(TEXT("BUTTON"),TEXT("Start"), WS_VISIBLE,
// rcClient.right-90, 10, 50 , 21, hWnd, NULL, hInst, 0);
break;
case WM_DEVICECHANGE:
TCHAR * szParam;
TCHAR szNum[MAX_PATH];
PDEV_BROADCAST_HDR pdbhDeviceHeader;
SendMessage(hListBox, LB_ADDSTRING, 0, (LPARAM)TEXT("WM_DEVICECHANGE:"));
switch(wParam)
{
case DBT_DEVICEARRIVAL:
SendMessage(hListBox, LB_ADDSTRING, 0, (LPARAM)TEXT("Card was inserted."));
break;
case DBT_DEVICEREMOVECOMPLETE:
SendMessage(hListBox, LB_ADDSTRING, 0, (LPARAM)TEXT("Card was removed."));
break;
}
szParam = (TCHAR *)LocalAlloc(LMEM_ZEROINIT, MAX_PATH);
_tcscpy(szParam, TEXT("wParam: "));
_ltow(wParam, szNum, 16); //convert i to hex string
_tcscat(szParam, szNum);
SendMessage(hListBox, LB_ADDSTRING, 0, (LPARAM)szParam);
memset(szParam, 0, MAX_PATH);
_tcscpy(szParam, TEXT("lParam: "));
_ltow(lParam, szNum, 16); //convert i to hex string
_tcscat(szParam, szNum);
pdbhDeviceHeader = (PDEV_BROADCAST_HDR)lParam;
switch(pdbhDeviceHeader->dbch_devicetype)
{
case DBT_DEVTYP_PORT:
PDEV_BROADCAST_PORT pdbpPortDeviceHeader;
pdbpPortDeviceHeader = (PDEV_BROADCAST_PORT)lParam;
SendMessage(hListBox, LB_ADDSTRING, 0, (LPARAM)TEXT("Device is a serial/parallel port."));
SendMessage(hListBox, LB_ADDSTRING, 0, (LPARAM)pdbpPortDeviceHeader->dbcp_name);
break;
case DBT_DEVTYP_NET:
SendMessage(hListBox, LB_ADDSTRING, 0, (LPARAM)TEXT("Device is a network interface card."));
break;
default:
SendMessage(hListBox, LB_ADDSTRING, 0, (LPARAM)TEXT("Device is of an unknown type."));
}
SendMessage(hListBox, LB_ADDSTRING, 0, (LPARAM)szParam);
LocalFree(szParam);
SendMessage(hListBox, LB_ADDSTRING, 0, (LPARAM)TEXT(""));
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code here...
RECT rt;
GetClientRect(hWnd, &rt);
rt.top = rt.bottom - 15;
DrawText(hdc, szHello, _tcslen(szHello), &rt, DT_LEFT);
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -