Win32SDK对话框模板

来源:互联网 发布:powershell安装软件 编辑:程序博客网 时间:2024/06/06 11:27

前言

vc6向导生成Win32SDK时,没有对话框模板。
整理了一个, 写测试程序用.

Win32SDK对话框模板

// hw.cpp : Defines the entry point for the application.//#include "stdafx.h"#include <windows.h>#include <tchar.h>#include <stdio.h>#pragma comment(lib, "user32.lib")#include <Shellapi.h>#pragma comment(lib, "Shell32.lib")#include "resource.h"#include "constDefine.h"#include "constDefine.h"HINSTANCE g_hInstance = NULL;HWND g_hMainWnd = NULL;LRESULT CALLBACK    MainDlgProc(HWND, UINT, WPARAM, LPARAM);void fnCenterWindow(HWND hWnd);void fnSetWndText(HWND hWnd, const TCHAR* pcTip);void fnSetCtrlText(int iCtrlId, const TCHAR* pcTip);LRESULT OnInitDialog(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);LRESULT OnClose(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);LRESULT OnCancel(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);LRESULT OnOk(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);LRESULT OnDropFiles(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);// 做一些测试任务, 发行时,里面的内容会被关掉void fnTest_On_WinMain();int APIENTRY WinMain(HINSTANCE hInstance,                     HINSTANCE hPrevInstance,                     LPSTR     lpCmdLine,                     int       nCmdShow){    g_hInstance = hInstance;    fnTest_On_WinMain();    return DialogBox(hInstance, (LPCTSTR)IDD_MAIN_DLG, GetDesktopWindow(), (DLGPROC)MainDlgProc);}LRESULT CALLBACK MainDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){    BOOL bRc = TRUE;    WORD wCtrlId = LOWORD(wParam);    WORD wNotifyCode = HIWORD(wParam);    HWND hSubWnd = (HWND)lParam;    switch (message) {        case WM_INITDIALOG: {                OnInitDialog(hWnd, message, wParam, lParam);            }            break;        case WM_COMMAND:            switch (wCtrlId) {                case IDCANCEL:                    OnCancel(hWnd, message, wParam, lParam);                    break;                case IDOK:                    OnOk(hWnd, message, wParam, lParam);                    break;                default:                    break;            }            break;        case WM_CLOSE:            OnClose(hWnd, message, wParam, lParam);            break;        case WM_DROPFILES:            OnDropFiles(hWnd, message, wParam, lParam);            break;        default:            bRc = FALSE;            break;    }    return bRc;}void fnCenterWindow(HWND hWnd){    HWND hwndOwner;    RECT rc;    RECT rcDlg;    RECT rcOwner;    hwndOwner = GetParent(hWnd);    if (NULL == hwndOwner) {        hwndOwner = GetDesktopWindow();    }    GetWindowRect(hwndOwner, &rcOwner);    GetWindowRect(hWnd, &rcDlg);    CopyRect(&rc, &rcOwner);    OffsetRect(&rcDlg, -rcDlg.left, -rcDlg.top);    OffsetRect(&rc, -rc.left, -rc.top);    OffsetRect(&rc, -rcDlg.right, -rcDlg.bottom);    SetWindowPos(hWnd,                 HWND_TOP,                 rcOwner.left + (rc.right / 2),                 rcOwner.top + (rc.bottom / 2),                 0,                 0,                 SWP_NOSIZE);}void fnSetCtrlText(int iCtrlId, const TCHAR* pcTip){    HWND hWnd = NULL;    if (NULL != g_hMainWnd) {        hWnd = GetDlgItem(g_hMainWnd, iCtrlId);        fnSetWndText(hWnd, pcTip);    }}void fnSetWndText(HWND hWnd, const TCHAR* pcTip){    if (NULL != hWnd) {        SetWindowText(hWnd, (NULL != pcTip) ? pcTip : _T(""));    }}LRESULT OnInitDialog(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){    g_hMainWnd = hWnd;    fnSetWndText(g_hMainWnd, G_STR_PROG_NAME);    fnCenterWindow(hWnd);    return S_OK;}LRESULT OnClose(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){    ::MessageBox(g_hMainWnd, "关闭", "提示", MB_OK);    EndDialog(hWnd, LOWORD(wParam));    return S_OK;}LRESULT OnCancel(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){    ::MessageBox(g_hMainWnd, "取消", "提示", MB_OK);    EndDialog(hWnd, LOWORD(wParam));    return S_OK;}LRESULT OnOk(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){    ::MessageBox(g_hMainWnd, "确定", "提示", MB_OK);    EndDialog(hWnd, LOWORD(wParam));    return S_OK;}LRESULT OnDropFiles(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){    POINT pt;     UINT uFilesCnt = 0;    UINT uIndex = 0;    HDROP hDropFile = (HDROP)wParam;    char lpszFile[MAXBYTE] = {'\0'};     DragQueryPoint(hDropFile, &pt);     uFilesCnt = DragQueryFile(hDropFile, -1, (LPSTR) NULL, 0);     for(uIndex = 0; uIndex < uFilesCnt; uIndex++) {         DragQueryFile(hDropFile, uIndex, lpszFile, sizeof(lpszFile));         fnSetCtrlText(IDC_EDIT, lpszFile);    }     DragFinish(hDropFile);     return S_OK;}void fnTest_On_WinMain(){}
0 0
原创粉丝点击