nanogui: Thread: A one button program


[<<] [<] Page 1 of 1 [>] [>>]
Subject: A one button program
From: "Alfredo Masias" ####@####.####
Date: 7 Sep 2000 16:45:48 -0000
Message-Id: <NEBBJKFABIGEJJJJPNAAEEECCAAA.jamacias@quintron.com>

Hi.
I am having problems displaying a button on my form.  A blank empty for
shows up ok but no button.  My code follows below.  Do you see any problem
with it?
(It ran ok in VC++ just by changing WINAPI to APIENTRY)
Any hints will be deeply appreciated

Alfredo Macias
Quintron Systems
(805)928-4343

********************************************************
#include <windows.h>
LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam,
		LPARAM lParam);
HDC dc;
HWND button1;
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
	LPSTR lpszCmdLine, int nCmdShow)

{
	WNDCLASS wc;
	HWND hWnd;
	MSG msg;
	wc.style = CS_HREDRAW|CS_VREDRAW|CS_BYTEALIGNCLIENT;
	wc.lpfnWndProc = WndProc;
	wc.cbClsExtra = 0;
	wc.cbWndExtra = 0;
	wc.hInstance = hInstance;
	wc.hIcon = NULL;
	wc.hCursor = LoadCursor(NULL,IDC_ARROW);
	wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
	wc.lpszMenuName = NULL;
	wc.lpszClassName = "ButtonExample";
	RegisterClass(&wc);
	hWnd = CreateWindow(wc.lpszClassName,"Using A Button",
	WS_OVERLAPPEDWINDOW,100,100,300,200,
	NULL,NULL,hInstance,NULL);
	button1 = CreateWindow("BUTTON","Hit Me",WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
	90,50,120,40,hWnd,NULL,hInstance,NULL);
	ShowWindow(hWnd,nCmdShow);
	UpdateWindow(hWnd);
	while (GetMessage(&msg,NULL,0,0))
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}
	return msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam,
		LPARAM lParam){
	switch(uMsg){
		case WM_COMMAND:{
			if ((HWND)lParam==button1)
				MessageBox(hwnd,"Clicked!","Ooohhh",MB_OK);
			return 0;
		}
		case WM_DESTROY:{
			PostQuitMessage(0);
			break;
		}
		default:{
			return DefWindowProc(hwnd,uMsg,wParam,lParam);
		}
	}
	return 0;
}

Subject: Re: A one button program
From: Marek Peca ####@####.####
Date: 7 Sep 2000 17:07:01 -0000
Message-Id: <Pine.LNX.4.10.10009071706260.13809-200000@tynska.cuni.cz>

Hello,

yes, you forgot a MwRegisterButtonControl call -- I've written you about
it twice, also in my sample program it is (i attach it for others to look
-- very ugly, but I've no time now to tidy it).

Marek.

> I am having problems displaying a button on my form.  A blank empty for
> shows up ok but no button.  My code follows below.  Do you see any problem
> with it?

#include <microwin/windows.h>



UINT stuff;

HWND tlac, mlac;



LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);



int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)

{

  WNDCLASS wc;

  HWND hWnd;

  MSG msg;



  wc.cbClsExtra = 0; wc.cbWndExtra = 0;

  wc.style = CS_HREDRAW | CS_VREDRAW;

  wc.lpfnWndProc = WndProc;

  wc.hInstance = hInstance;

  wc.hbrBackground = (HBRUSH) GetStockObject(GRAY_BRUSH);

  wc.lpszClassName = "HlavniOkno";

  RegisterClass(&wc);

  

  hWnd = CreateWindowEx(0L, wc.lpszClassName, "Titulek!", WS_OVERLAPPEDWINDOW | WS_VISIBLE,

                      CW_USEDEFAULT, CW_USEDEFAULT, 600, 400, NULL, NULL, hInstance, NULL);

  MwRegisterButtonControl(NULL);

  tlac = CreateWindowEx(0L, "BUTTON", "Staniz se.",BS_DEFPUSHBUTTON|WS_CHILD|WS_VISIBLE|WS_BORDER,

                        300,200,100,40,hWnd,NULL,hInstance,NULL);

  tlac = CreateWindowEx(0L, "BUTTON", "??",/* BS_PUSHBUTTON| */ WS_CHILD|WS_VISIBLE|WS_BORDER,

                        450,200,100,40,hWnd,NULL,hInstance,NULL);

  MwRegisterStaticControl(NULL);

  CreateWindowEx(0L, "STATIC", "320 K", WS_BORDER|SS_CENTER|WS_CHILD|WS_VISIBLE, 30, 100, 40, 20, hWnd,NULL,hInstance,NULL);

  MwRegisterEditControl(NULL);

  CreateWindowEx(0L, "EDIT", "prd", WS_CHILD|WS_VISIBLE, 30, 200, 400, 20, hWnd,NULL,hInstance,NULL);



  ShowWindow(hWnd, SW_SHOW);

  UpdateWindow(hWnd);

  

  while (GetMessage(&msg,NULL,0,0)) {

    TranslateMessage(&msg);

    DispatchMessage(&msg);

  }

  return msg.wParam;

}





void Napis(HWND hWnd, int zam)

{

  HDC dc;



  dc = GetDC(hWnd);

  SetBkColor(dc, RGB(0,0,0));

  SetTextColor(dc, RGB(255,200,0));

  if (zam)

    TextOut(dc, 30, 30, "At zije Slunicko!", 17);

  else

    TextOut(dc, 30, 30, "In saecula.", 11);

  ReleaseDC(hWnd, dc);

}





LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)

{

  switch (uMsg) {

  case WM_COMMAND: {

    Napis(hWnd, (lParam == tlac));

    break;

  }

  case WM_DESTROY: {

    PostQuitMessage(0);

    break;

  }

  default:

    return DefWindowProc(hWnd,uMsg,wParam,lParam);

  }

  return(0);

}   

Subject: Re: A one button program
From: "Greg Haerr" ####@####.####
Date: 7 Sep 2000 18:16:48 -0000
Message-Id: <011401c018f8$3ff4ae90$6817dbd0@censoft.com>

: yes, you forgot a MwRegisterButtonControl call -- I've written you about
: it twice, also in my sample program it is (i attach it for others to look

Yes, the MwRegisterButtonControl is required and not win32,
this is since the application is linked with the server, controls
aren't dragged in unless they're used, and this is the linker symbol
that drags in (and registers) the button control.

Regards,

Greg

[<<] [<] Page 1 of 1 [>] [>>]


Powered by ezmlm-browse 0.20.