combobox를 win32api로 만들어봤습니다.

mydream의 이미지

#include <windows.h>
#include <tchar.h>
#include <string.h>
#define ID_COMBOBOX 100
TCHAR *items[]={TEXT("APPLE"), TEXT("Orange"), TEXT("Melon"), TEXT("Grape"), TEXT("Strawberry")};
HWND hCombo;
HINSTANCE hgInstance;
LRESULT CALLBACK WndProc(HWND hwnd , UINT message, WPARAM wparam, LPARAM lparam) {
	int i;
	TCHAR str[128];
	static TCHAR tmbuffer[128];
	switch(message) {
		case WM_CREATE:
			hCombo=CreateWindow(TEXT("combobox"), TEXT(""), WS_CHILD | WS_VISIBLE | CBS_DROPDOWN | WS_OVERLAPPED | CBS_HASSTRINGS,10, 10, 100, 200, hwnd, (HMENU)ID_COMBOBOX, hgInstance, NULL);
			tmbuffer[0]=TEXT('\0');
			for(i=0;i<5;i++) {
				SendMessage(hCombo, (UINT)CB_ADDSTRING, (WPARAM)0, (LPARAM)items[i]);
				_stprintf(tmbuffer, TEXT("%s %d"), tmbuffer, i);
			}
			//SendMessage(hCombo, CB_SETCURSEL, (WPARAM)2, (LPARAM)0);
			//ShowWindow(hCombo, SW_SHOWNORMAL);
 
			return 0;
		case WM_COMMAND:
			switch(LOWORD(wparam)) {
			case ID_COMBOBOX:
				switch(HIWORD(wparam)) {
					case CBN_SELCHANGE:
						i=SendMessage(hCombo, CB_GETCURSEL, 0, 0);
						SendMessage(hCombo, CB_GETLBTEXT, i, (LPARAM)str);
						SetWindowText(hwnd, str);
						break;
					case CBN_EDITCHANGE:
						GetWindowText(hCombo, str, 128);
						SetWindowText(hwnd, str);
						break;
				}
			}
			return 0;
		case WM_PAINT:
			{
				PAINTSTRUCT pst;
				HDC hdc=BeginPaint(hwnd, &pst);
				TextOut(hdc, 50, 400, tmbuffer, _tcslen(tmbuffer));
				EndPaint(hwnd, &pst);
				return 0;
			}
		case WM_DESTROY:
			PostQuitMessage(0);
			return 0;
	}
	return DefWindowProc(hwnd, message, wparam, lparam);
}
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) {
	WNDCLASS WndCls;
	WndCls.cbClsExtra=0;
	WndCls.cbWndExtra=0;
	WndCls.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
	WndCls.hCursor=LoadCursor(NULL, IDC_ARROW);
	WndCls.hIcon=NULL;
	WndCls.hInstance=hgInstance=hInstance;
	WndCls.lpfnWndProc=WndProc;
	LPCTSTR clsname=TEXT("combobox");
	WndCls.lpszClassName=clsname;
	WndCls.lpszMenuName=NULL;
	WndCls.style=CS_HREDRAW | CS_VREDRAW;
	RegisterClass(&WndCls);
	HWND hwnd=CreateWindow(clsname, TEXT("Displaying combobox"), WS_OVERLAPPEDWINDOW, 300, 300, 500, 500, NULL, NULL, hInstance, NULL);
	ShowWindow(hwnd, nShowCmd);
	MSG message;
 
	while( GetMessage(&message, NULL, 0, 0)  ) {
		TranslateMessage(&message);
		DispatchMessage(&message);
	}
 
	return (int)message.wParam;
}

그런데 콤보박스가 제대로 화면에 나타나지 않습니다. 어디가 잘못된 것인가요?

익명 사용자의 이미지

LPCTSTR clsname=TEXT("combobox");
WndCls.lpszClassName=clsname;

HWND hwnd=CreateWindow(clsname, ...(생략)

부모의 클래스명이 "combobox"인데, 자식도 "combobox"이니 컴파일러가 부모자식 눈에 뵈는게 없어서 안나타날듯 싶군요.. ^^);;

mydream의 이미지

겹치면 안되는 것이었군요. 이것 때문에 3일 헤맸습니다.

익명 사용자의 이미지

윈도우 프로그래밍 시작하면 다들 한번쯤 클래스명 때문에 고생하지요.. :)
즐프하세요~!

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.