|
日時: 2009/08/11 22:47
名前: lightbox
|
拡張子:
hWnd = CreateWindow(
"listbox",
NULL,
WS_CHILD | LBS_SORT,
0,0,0,0,
hTarget,
(HMENU)0,
NULL,
NULL
);
ダミーで良いのでダイアログのリソースが必要です
拡張子:
// *********************************************************
// ダイアログウインドウハンドルを使用して
// データをソートする
// *********************************************************
#include <windows.h>
#include <windowsx.h>
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <tchar.h>
#include <stdio.h>
LRESULT CALLBACK DialogProc( HWND, UINT, WPARAM, LPARAM );
// *********************************************************
// Windows アプリケーションとしてのエントリポイント
// Link.exe で /SUBSYSTEM:WINDOWS がデフォルトで
// 指定される事になります
// *********************************************************
int APIENTRY _tWinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow
)
{
// ダイアログ表示
DialogBox(
hInstance,
(LPCTSTR)1,
GetDesktopWindow(),
(DLGPROC)DialogProc);
return 0;
}
LRESULT CALLBACK DialogProc( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
{
HWND hWnd;
int nCnt;
int i;
char buff[512];
switch( message ) {
case WM_INITDIALOG:
hWnd = CreateWindow(
"listbox",
NULL,
WS_CHILD | LBS_SORT,
0,0,0,0,
hDlg,
(HMENU)0,
NULL,
NULL
);
ListBox_AddString( hWnd, "C" );
ListBox_AddString( hWnd, "B" );
ListBox_AddString( hWnd, "A" );
nCnt = ListBox_GetCount( hWnd );
for( i = 0; i < nCnt; i++ ) {
ListBox_GetText( hWnd, i, buff );
MessageBox( hDlg, buff, "", MB_OK );
}
DestroyWindow( hWnd );
EndDialog( hDlg, 0 );
break;
}
return FALSE;
}
コンソール用
拡張子:
// *********************************************************
// デスクトップウインドウハンドルを使用して
// データをソートする
// *********************************************************
#include <windows.h>
#include <windowsx.h>
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <tchar.h>
#include <stdio.h>
LRESULT CALLBACK DialogProc( HWND, UINT, WPARAM, LPARAM );
// *********************************************************
// Windows アプリケーションとしてのエントリポイント
// Link.exe で /SUBSYSTEM:WINDOWS がデフォルトで
// 指定される事になります
// *********************************************************
/*
int APIENTRY _tWinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow
)
*/
int main( )
{
HINSTANCE hInstance;
hInstance = (HINSTANCE)GetModuleHandle(NULL);
// ダイアログ表示
DialogBox(
hInstance,
(LPCTSTR)1,
GetDesktopWindow(),
(DLGPROC)DialogProc);
return 0;
}
LRESULT CALLBACK DialogProc( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
{
HWND hWnd;
int nCnt;
int i;
char buff[512];
switch( message ) {
case WM_INITDIALOG:
hWnd = CreateWindow(
"listbox",
NULL,
WS_CHILD | LBS_SORT,
0,0,0,0,
hDlg,
(HMENU)0,
NULL,
NULL
);
ListBox_AddString( hWnd, "C" );
ListBox_AddString( hWnd, "B" );
ListBox_AddString( hWnd, "A" );
nCnt = ListBox_GetCount( hWnd );
for( i = 0; i < nCnt; i++ ) {
ListBox_GetText( hWnd, i, buff );
printf( "%s\n", buff );
}
DestroyWindow( hWnd );
EndDialog( hDlg, 0 );
break;
}
return FALSE;
}
|