⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 d_box.cpp

📁 USB通讯控件,Bulk通讯方式,可以直接从USB设备中读取数据保存为文件,或者把文件发送给USB设备,用于三星2410相关开发.
💻 CPP
字号:
#define STRICT
#define WIN32_LEAN_AND_MEAN

#include "Forcelib.h"
#include <windows.h>
#include <windowsx.h>
#include <commctrl.h>
#include <tchar.h>
#include <string.h>
#include <process.h>
#include <stdlib.h>
#include <stdio.h>
//#include <stdafx.h>

#include "resource.h"

#include "def.h"
#include "d_box.h"
//#include "dnw.h"
//#include "engine.h"
//#include "fileopen.h"

//extern TCHAR szFileName[256];
//extern HINSTANCE hInstance;

// 'volatile' is important because _hDlgDownloadProgress is accessed in two threads.
volatile HWND _hDlgDownloadProgress=NULL; 
HWND _hProgressControl;
HWND _hDlg;
volatile HWND _hDlgSerialSettings;

int downloadCanceled;

UINT hex2int(TCHAR *str);

BOOL CALLBACK DownloadProgressProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
    TCHAR szTitle[256];

	INITCOMMONCONTROLSEX icex;// Ensure that "comctl32.lib" is loaded. 
	icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
	icex.dwICC  = ICC_PROGRESS_CLASS;
	InitCommonControlsEx(&icex); 

    switch(message)
    {
    case WM_INITDIALOG:
		lstrcpy(szTitle,TEXT("Progress"));
		//lstrcat(szTitle,szFileName);
		SetWindowText(hDlg,szTitle);
		_hDlgDownloadProgress=hDlg;
		_hDlg=hDlg;
		return TRUE;
		
    case WM_CLOSE: 
		//If the [X] button is clicked, WM_CLOSE message is received.
		//Originally, DefWindowProc() called DestroyWindow();
		//But, there is no DefWindowProc(), We have to process WM_CLOSE message.
		DestroyWindow(hDlg);
		_hDlgDownloadProgress=NULL;
		downloadCanceled=1;
		//break;
		return TRUE; //why not?
    }
	
    return FALSE;
}

void InitDownloadProgress(void)
{
    while(_hDlgDownloadProgress==NULL); //wait until the progress dialog box is ready.
	
    _hProgressControl=GetDlgItem(_hDlgDownloadProgress,IDC_PROGRESS1);
    SendMessage(_hProgressControl,PBM_SETRANGE,0,MAKELPARAM(0, 100));
    downloadCanceled=0;
}

void DisplayDownloadProgress(int percent)
{
    TCHAR szTitle[256];
	sprintf(szTitle,"完成%d",percent);
	lstrcat(szTitle,TEXT("%"));
	if(percent>99)
		sprintf(szTitle,"正在保存数据,请稍候...");
	//lstrcat(szTitle,szFileName);
	SetWindowText(_hDlg,szTitle);
	SendMessage(_hProgressControl,PBM_SETPOS,(WPARAM)percent,0); 
}

void CloseDownloadProgress(void)
{
    if(_hDlgDownloadProgress!=NULL)
    {
		//DestroyWindow(_hDlgDownloadProgress); 
		//Doesn't work because CloseDownloadProgress() is called another thread,
		//which is different the thread calling CreatDialog().
		
        SendMessage(_hDlgDownloadProgress,WM_CLOSE,0,0); 
		_hDlgDownloadProgress=NULL;
    }
}

UINT hex2int(TCHAR *str)
{
    int i;
    UINT number=0; 
    int order=1;
    TCHAR ch;
    for(i=lstrlen(str)-1;i>=0;i--)
    {
		ch=str[i];
		if(ch=='x' || ch=='X')break;
		
		if(ch>='0' && ch<='9')
		{
			number+=order*(ch-'0');
			order*=16;
		}
		if(ch>='A' && ch<='F')
		{
			number+=order*(ch-'A'+10);
			order*=16;
		}
		if(ch>='a' && ch<='f')
		{
			number+=order*(ch-'a'+10);
			order*=16;
		}
    }
    return number;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -